Note: You are currently viewing documentation for Moodle 3.9. Up-to-date documentation for the latest stable version of Moodle may be available here: local/Recycle bin.

local/Recycle bin: Difference between revisions

From MoodleDocs
(tidy up)
No edit summary
Line 9: Line 9:
This is a [[:Category:Contributed_code|contributed (third party)]] plugin for Moodle written by Skylar Kelty and shared on Moodle.org
This is a [[:Category:Contributed_code|contributed (third party)]] plugin for Moodle written by Skylar Kelty and shared on Moodle.org


This plugin adds a "recycle bin" for course modules to Moodle.
This plugin adds a "recycle bin" for course modules to Moodle. The recycle bin stores course modules when they're deleted and provides an interface for users to restore them should they need to. It can be configured to automatically purge items after a configurable length of time.


It requires a core hack as there is no pre-cm-deleted event, you will need to add a line to '/course/lib.php' (function course_delete_module), right after the first "if()".
It requires a core hack as there is no pre-cm-deleted event, you will need to add a line to '/course/lib.php' (function course_delete_module), right after the first "if()".


* You must first find the moodle/course folder and locate there the lib.php file that you will need to modify:
== Automatic Patching ==


[[File:lib_php file in a local moodle server.png|600px]]
Simply apply this diff using `patch`:
<code diff>
diff --git a/course/lib.php b/course/lib.php
index e49bdf1..5f8d6e6 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1654,6 +1654,9 @@ function course_delete_module($cmid) {
        return true;
    }


* You can edit the lib.php file easily with [https://notepad-plus-plus.org/ Notepad ++ for Windows].
+    // Notify the recycle bin plugin.
+    \local_recyclebin\Observer::pre_cm_delete($cm);
+
    // Get the module context.
    $modcontext = context_module::instance($cm->id);
</code>


[[File:lib_php original file opened in notepad plus plus.png|600px]]
== Manual Patching ==


* You need to find exactly these lines:
* First, open /course/lib.php in a text editor.


function course_delete_module($cmid) {
[[File:lib_php file in a local moodle server.png|600px]]
          return true;
      }


* And after those lines You will be adding exactly these two lines:
* You can edit the lib.php file easily with [https://notepad-plus-plus.org/ Notepad ++ for Windows].


    // Notify the recycle bin plugin.
[[File:lib_php original file opened in notepad plus plus.png|600px]]
    \local_recyclebin\Observer::pre_cm_delete($cm);


Your modified (hacked file) must look exactly like this lines 1658 and 1659 with the added text::
* You need to find these lines within the course_delete_module function:
<code php>
// Get the course module.
if (!$cm = $DB->get_record('course_modules', array('id' => $cmid))) {
    return true;
}
</code>
* After those two lines, add the following:
<code php>
// Notify the recycle bin plugin.
\local_recyclebin\Observer::pre_cm_delete($cm);
</code>
Your modified file must look exactly like this lines 1658 and 1659 with the added text::


[[File:lib_php modified file opened in notepad plus plus.png|600px]]
[[File:lib_php modified file opened in notepad plus plus.png|600px]]

Revision as of 09:27, 26 August 2015

This is a contributed (third party) plugin for Moodle written by Skylar Kelty and shared on Moodle.org

This plugin adds a "recycle bin" for course modules to Moodle. The recycle bin stores course modules when they're deleted and provides an interface for users to restore them should they need to. It can be configured to automatically purge items after a configurable length of time.

It requires a core hack as there is no pre-cm-deleted event, you will need to add a line to '/course/lib.php' (function course_delete_module), right after the first "if()".

Automatic Patching

Simply apply this diff using `patch`: diff --git a/course/lib.php b/course/lib.php index e49bdf1..5f8d6e6 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1654,6 +1654,9 @@ function course_delete_module($cmid) {

        return true;
    }

+ // Notify the recycle bin plugin. + \local_recyclebin\Observer::pre_cm_delete($cm); +

    // Get the module context.
    $modcontext = context_module::instance($cm->id);

Manual Patching

  • First, open /course/lib.php in a text editor.

lib php file in a local moodle server.png

lib php original file opened in notepad plus plus.png

  • You need to find these lines within the course_delete_module function:

// Get the course module. if (!$cm = $DB->get_record('course_modules', array('id' => $cmid))) {

   return true;

}

  • After those two lines, add the following:

// Notify the recycle bin plugin. \local_recyclebin\Observer::pre_cm_delete($cm); Your modified file must look exactly like this lines 1658 and 1659 with the added text::

lib php modified file opened in notepad plus plus.png

  • You will then have a Recycle bin available inside the Administration block:

Recycle bin is available.png