From 131688cf9456f1f30a2ff28f1296a75eb302e912 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 5 Oct 2012 11:58:37 +0800 Subject: [PATCH 1/3] MDL-34274 book: Adding ability to log chapter view and chapter print --- mod/book/db/log.php | 7 ++++--- mod/book/tool/print/db/log.php | 3 ++- mod/book/tool/print/index.php | 2 +- mod/book/tool/print/version.php | 2 +- mod/book/version.php | 2 +- mod/book/view.php | 3 ++- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mod/book/db/log.php b/mod/book/db/log.php index d0292b6b455..668a01c8d1d 100644 --- a/mod/book/db/log.php +++ b/mod/book/db/log.php @@ -25,7 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $logs = array( - array('module'=>'book', 'action'=>'add', 'mtable'=>'book', 'field'=>'name'), - array('module'=>'book', 'action'=>'update', 'mtable'=>'book', 'field'=>'name'), - array('module'=>'book', 'action'=>'view', 'mtable'=>'book', 'field'=>'name') + array('module' => 'book', 'action' => 'add', 'mtable' => 'book', 'field' => 'name'), + array('module' => 'book', 'action' => 'update', 'mtable' => 'book', 'field' => 'name'), + array('module' => 'book', 'action' => 'view', 'mtable' => 'book', 'field' => 'name'), + array('module' => 'book', 'action' => 'view chapter', 'mtable' => 'book_chapters', 'field' => 'title') ); diff --git a/mod/book/tool/print/db/log.php b/mod/book/tool/print/db/log.php index 6b23d114667..64e93434fb9 100644 --- a/mod/book/tool/print/db/log.php +++ b/mod/book/tool/print/db/log.php @@ -25,5 +25,6 @@ defined('MOODLE_INTERNAL') || die(); $logs = array( - array('module'=>'book', 'action'=>'print', 'mtable'=>'book', 'field'=>'name') + array('module' => 'book', 'action' => 'print', 'mtable' => 'book', 'field' => 'name'), + array('module' => 'book', 'action' => 'print chapter', 'mtable' => 'book_chapters', 'field' => 'title') ); diff --git a/mod/book/tool/print/index.php b/mod/book/tool/print/index.php index f33f9a11ad7..36e6bf91632 100644 --- a/mod/book/tool/print/index.php +++ b/mod/book/tool/print/index.php @@ -77,7 +77,7 @@ if ($chapter) { require_capability('mod/book:viewhiddenchapters', $context); } - add_to_log($course->id, 'book', 'print', 'tool/print/index.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id); + add_to_log($course->id, 'book', 'print chapter', 'tool/print/index.php?id='.$cm->id.'&chapterid='.$chapter->id, $chapter->id, $cm->id); // page header ?> diff --git a/mod/book/tool/print/version.php b/mod/book/tool/print/version.php index 2951ef06e35..a748cf7063b 100644 --- a/mod/book/tool/print/version.php +++ b/mod/book/tool/print/version.php @@ -25,5 +25,5 @@ defined('MOODLE_INTERNAL') || die; $plugin->component = 'booktool_print'; // Full name of the plugin (used for diagnostics) -$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2012100500; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2012061700; // Requires this Moodle version diff --git a/mod/book/version.php b/mod/book/version.php index 2145e072084..fd723af5b77 100644 --- a/mod/book/version.php +++ b/mod/book/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die; $module->component = 'mod_book'; // Full name of the plugin (used for diagnostics) -$module->version = 2012090400; // The current module version (Date: YYYYMMDDXX) +$module->version = 2012100500; // The current module version (Date: YYYYMMDDXX) $module->requires = 2012061700; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/book/view.php b/mod/book/view.php index 91b83b88f72..e94f086a0b9 100644 --- a/mod/book/view.php +++ b/mod/book/view.php @@ -75,6 +75,7 @@ if ($allowedit and !$chapters) { } // Check chapterid and read chapter data if ($chapterid == '0') { // Go to first chapter if no given. + add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id, $book->id, $cm->id); foreach ($chapters as $ch) { if ($edit) { $chapterid = $ch->id; @@ -106,7 +107,7 @@ unset($chapterid); // Security checks END. -add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id); +add_to_log($course->id, 'book', 'view chapter', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $chapter->id, $cm->id); // Read standard strings. $strbooks = get_string('modulenameplural', 'mod_book'); From d3bf90ae046f1411d10533ad57ff316014f894ff Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 5 Oct 2012 11:24:13 +0800 Subject: [PATCH 2/3] MDL-34274 book: Adding ability to log chapter updates --- mod/book/db/log.php | 2 ++ mod/book/edit.php | 4 ++-- mod/book/tool/importhtml/locallib.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mod/book/db/log.php b/mod/book/db/log.php index 668a01c8d1d..f65fe240fc7 100644 --- a/mod/book/db/log.php +++ b/mod/book/db/log.php @@ -28,5 +28,7 @@ $logs = array( array('module' => 'book', 'action' => 'add', 'mtable' => 'book', 'field' => 'name'), array('module' => 'book', 'action' => 'update', 'mtable' => 'book', 'field' => 'name'), array('module' => 'book', 'action' => 'view', 'mtable' => 'book', 'field' => 'name'), + array('module' => 'book', 'action' => 'add chapter', 'mtable' => 'book_chapters', 'field' => 'title'), + array('module' => 'book', 'action' => 'update chapter', 'mtable'=> 'book_chapters', 'field' => 'title'), array('module' => 'book', 'action' => 'view chapter', 'mtable' => 'book_chapters', 'field' => 'title') ); diff --git a/mod/book/edit.php b/mod/book/edit.php index 541233daf48..e379ec05586 100644 --- a/mod/book/edit.php +++ b/mod/book/edit.php @@ -74,7 +74,7 @@ if ($mform->is_cancelled()) { $DB->update_record('book_chapters', $data); add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id); - add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $book->id, $cm->id); + add_to_log($course->id, 'book', 'update chapter', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $data->id, $cm->id); } else { // adding new chapter @@ -100,7 +100,7 @@ if ($mform->is_cancelled()) { $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id)); add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id); - add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $book->id, $cm->id); + add_to_log($course->id, 'book', 'add chapter', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $data->id, $cm->id); } book_preload_chapters($book); // fix structure diff --git a/mod/book/tool/importhtml/locallib.php b/mod/book/tool/importhtml/locallib.php index b846573267d..c37976f5523 100644 --- a/mod/book/tool/importhtml/locallib.php +++ b/mod/book/tool/importhtml/locallib.php @@ -84,7 +84,7 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $ $chapter->id = $DB->insert_record('book_chapters', $chapter); $chapters[$chapter->id] = $chapter; - add_to_log($book->course, 'book', 'update', 'view.php?id='.$context->instanceid.'&chapterid='.$chapter->id, $book->id, $context->instanceid); + add_to_log($book->course, 'book', 'add chapter', 'view.php?id='.$context->instanceid.'&chapterid='.$chapter->id, $chapter->id, $context->instanceid); } } } From 0f357885b2f3f6ac210f87593cc6538db65c2447 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Thu, 11 Oct 2012 13:32:00 +0800 Subject: [PATCH 3/3] MDL-34274 book: adding restore log rules for the new actions --- mod/book/backup/moodle2/restore_book_activity_task.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mod/book/backup/moodle2/restore_book_activity_task.class.php b/mod/book/backup/moodle2/restore_book_activity_task.class.php index 3755f6830ec..f76ec3ccf96 100644 --- a/mod/book/backup/moodle2/restore_book_activity_task.class.php +++ b/mod/book/backup/moodle2/restore_book_activity_task.class.php @@ -111,6 +111,10 @@ class restore_book_activity_task extends restore_activity_task { // To convert old 'generateimscp' log entries $rules[] = new restore_log_rule('book', 'generateimscp', 'tool/generateimscp/index.php?id={course_module}', '{book}', 'book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}'); + $rules[] = new restore_log_rule('book', 'print chapter', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}'); + $rules[] = new restore_log_rule('book', 'update chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}'); + $rules[] = new restore_log_rule('book', 'add chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}'); + $rules[] = new restore_log_rule('book', 'view chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}'); return $rules; }