Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-16296

unable to delete nwiki course module instance

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      apache 2 , php 5.x , mysql 5.x , moodle 1.9.2
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      i am unable to remove (delete) instances of wiki (nwiki) from any course

      i tracked it down to mod/wiki/lib.php line 214
      if (! $wikimanager->get_wiki_by_id($id))

      { return false; }

      it returns false for some reason, where it should not.

      i hope some one who knows the wiki (dfwiki,nwiki) code can figure it out easily

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            carolinemoore Caroline Moore added a comment -
            Show
            carolinemoore Caroline Moore added a comment - This may be related to MDL-16324 . ( http://tracker.moodle.org/browse/MDL-16324 )
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            it is a duplicate
            since i confirm i have the same issue.

            btw,
            i was doing some digging (and did not finish, there is alllllot of debris in the code

            i worked around it by disabling some of the wiki checks
            in file "mod/wiki/lib.php" around line 205 in function "wiki_delete_instance"

            it is a little mess right now, so i can not post it here but after i skip one of the
            "is wiki instance exists in the db" checks i move on and delete the instance of that wiki
            in the course so it will not appear in the course's syllabus , no matter what !

            it happens when... it can not find the wiki in the db and it quits without deleting the actual
            reference (instance) to it in the main course syllabus.

            Show
            nadavkav Nadav Kavalerchik added a comment - it is a duplicate since i confirm i have the same issue. btw, i was doing some digging (and did not finish, there is alllllot of debris in the code i worked around it by disabling some of the wiki checks in file "mod/wiki/lib.php" around line 205 in function "wiki_delete_instance" it is a little mess right now, so i can not post it here but after i skip one of the "is wiki instance exists in the db" checks i move on and delete the instance of that wiki in the course so it will not appear in the course's syllabus , no matter what ! it happens when... it can not find the wiki in the db and it quits without deleting the actual reference (instance) to it in the main course syllabus.
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            moodle/course/rest.php (DELETE) line 177~

            i have remarked the php die; function

              $deleteinstancefunction = $mod->name."_delete_instance";
             
                            // Run the module's cleanup funtion.
                            if (!$deleteinstancefunction($cm->instance)) {
                                error_log("Ajax rest.php: Could not delete the $mod->name (instance)");
                                //die;
                            }

            $deleteinstancefunction is wiki_delete_instance (in file mod/wiki/lib.php , line 224)

            which does not seem to work since the global $WS is not set with any values but
            it is expected to help us delete the wiki instance.

            so, to work around it, i have added the following two lines

            $WS->dfwiki->course = $wikimanager->persistencemanager->wikis[$id]->course;
            $WS->dfwiki->id = $id;

            into the function wiki_delete_instance as follows:

            function wiki_delete_instance($id) {
            /// Given an ID of an instance of this module,
            /// this function will permanently delete the instance
            /// and any data that depends on it.
            	global $WS;
             
                $wikimanager = wiki_manager_get_instance();
             
                //get dfwiki entry
                if (! $wikimanager->get_wiki_by_id($id)) {
                    return false;
                }
             
                //get modules id
                if (! $module = get_record("modules", "name", 'wiki')){
                    return false;
                }
             
            $WS->dfwiki->course = $wikimanager->persistencemanager->wikis[$id]->course;
            $WS->dfwiki->id = $id;
             
                //get cm id
                if (! $WS->cm = get_record("course_modules", "course", $WS->dfwiki->course, "module", $module->id, "instance", $id)){
                    return false;
                }
             
                //delete uploaded files
                wiki_upload_config($WS);
                if (!wiki_upload_deldir($WS)){
                    return false;
                }
             
                # Delete any dependent records here #
                return $wikimanager->delete_wiki($WS->dfwiki->id);
            }

            and just to make sure it all works fine,
            (because it did not always remove the wiki instance from the course's section)
            i added the following code to
            moodle/course/rest.php (DELETE) line 185~

                            // Remove the course_modules entry.
                            if (!delete_course_module($cm->id)) {
                                error_log("Ajax rest.php: Could not delete the $cm->id (coursemodule)");
                                //die;
                            }
                  
                            if (!delete_mod_from_section($cm->id, "$cm->section")) {
                                error_log("Could not delete the $cm->id from section $cm->section");
            		    //die;
                            }

            Show
            nadavkav Nadav Kavalerchik added a comment - moodle/course/rest.php (DELETE) line 177~ i have remarked the php die; function $deleteinstancefunction = $mod->name."_delete_instance";   // Run the module's cleanup funtion. if (!$deleteinstancefunction($cm->instance)) { error_log("Ajax rest.php: Could not delete the $mod->name (instance)"); //die; } $deleteinstancefunction is wiki_delete_instance (in file mod/wiki/lib.php , line 224) which does not seem to work since the global $WS is not set with any values but it is expected to help us delete the wiki instance. so, to work around it, i have added the following two lines $WS->dfwiki->course = $wikimanager->persistencemanager->wikis[$id]->course; $WS->dfwiki->id = $id; into the function wiki_delete_instance as follows: function wiki_delete_instance($id) { /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. global $WS;   $wikimanager = wiki_manager_get_instance();   //get dfwiki entry if (! $wikimanager->get_wiki_by_id($id)) { return false; }   //get modules id if (! $module = get_record("modules", "name", 'wiki')){ return false; }   $WS->dfwiki->course = $wikimanager->persistencemanager->wikis[$id]->course; $WS->dfwiki->id = $id;   //get cm id if (! $WS->cm = get_record("course_modules", "course", $WS->dfwiki->course, "module", $module->id, "instance", $id)){ return false; }   //delete uploaded files wiki_upload_config($WS); if (!wiki_upload_deldir($WS)){ return false; }   # Delete any dependent records here # return $wikimanager->delete_wiki($WS->dfwiki->id); } and just to make sure it all works fine, (because it did not always remove the wiki instance from the course's section) i added the following code to moodle/course/rest.php (DELETE) line 185~ // Remove the course_modules entry. if (!delete_course_module($cm->id)) { error_log("Ajax rest.php: Could not delete the $cm->id (coursemodule)"); //die; } if (!delete_mod_from_section($cm->id, "$cm->section")) { error_log("Could not delete the $cm->id from section $cm->section"); //die; }
            Hide
            cirano David Herney Bernal added a comment -

            In file mod/wiki/lib/moodle/persistence_manager.php and file mod/wiki/lib/wiki_manager.php the function "delete_wiki" doesn't return value and PHP assumes "false". moodle shows "could not delete the wiki (instance)". The solution is adding "return" in the function.

            Now:
            function delete_wiki($wikiid)

            { $this->wikipersistor->delete_wiki($wikiid); }

            New:
            function delete_wiki($wikiid)

            { return $this->wikipersistor->delete_wiki($wikiid); }
            Show
            cirano David Herney Bernal added a comment - In file mod/wiki/lib/moodle/persistence_manager.php and file mod/wiki/lib/wiki_manager.php the function "delete_wiki" doesn't return value and PHP assumes "false". moodle shows "could not delete the wiki (instance)". The solution is adding "return" in the function. Now: function delete_wiki($wikiid) { $this->wikipersistor->delete_wiki($wikiid); } New: function delete_wiki($wikiid) { return $this->wikipersistor->delete_wiki($wikiid); }
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            thanks ! (that helped allot)

            here is a link to the new updated version with hebrew translations too
            http://www.tikshuv.org.il/moodle/contrib/mod/NWiki2.0_Moodle1.9_rev2009012201-heb.tar.gz

            Show
            nadavkav Nadav Kavalerchik added a comment - thanks ! (that helped allot) here is a link to the new updated version with hebrew translations too http://www.tikshuv.org.il/moodle/contrib/mod/NWiki2.0_Moodle1.9_rev2009012201-heb.tar.gz
            Hide
            salvetore Michael de Raadt added a comment -

            Thanks for reporting this issue.

            We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

            If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

            Michael d;

            lqjjLKA0p6

            Show
            salvetore Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            These are fixes to NWiki for Moodle 1.9
            Please integrate it or just leave it here
            as reference to those who use it

            Show
            nadavkav Nadav Kavalerchik added a comment - These are fixes to NWiki for Moodle 1.9 Please integrate it or just leave it here as reference to those who use it
            Hide
            salvetore Michael de Raadt added a comment -

            Thanks for reporting this issue.

            We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

            If you believe that this issue is still relevant to current versions (2.3 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

            Michael d;

            4d6f6f646c6521

            Show
            salvetore Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.3 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; 4d6f6f646c6521
            Hide
            nadavkav Nadav Kavalerchik added a comment -

            Works fine on latest stable Moodle version 2.4
            Please close

            Show
            nadavkav Nadav Kavalerchik added a comment - Works fine on latest stable Moodle version 2.4 Please close
            Hide
            salvetore Michael de Raadt added a comment -

            Closed as fixed. Thanks for confirming that, Nadav.

            Show
            salvetore Michael de Raadt added a comment - Closed as fixed. Thanks for confirming that, Nadav.

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: