MDL-40058 mod_wiki: Replaced add_to_log for page edit with event

This commit is contained in:
Rajesh Taneja
2013-12-11 13:52:59 +11:00
committed by Marina Glancy
parent 31383bcdad
commit fb92417b5e
4 changed files with 98 additions and 3 deletions
+83
View File
@@ -0,0 +1,83 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_wiki page updated.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_wiki page updated.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_updated extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['level'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpageupdated', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' viewed wiki page id ' . $this->objectid;
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return(array($this->courseid, 'wiki', 'edit', 'view.php?pageid=' . $this->objectid, $this->objectid,
$this->context->instanceid));
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid));
}
}
-1
View File
@@ -85,7 +85,6 @@ if ($option == get_string('save', 'wiki')) {
$wikipage->set_page($page);
$wikipage->set_newcontent($newcontent);
$wikipage->set_upload(true);
add_to_log($course->id, 'wiki', 'edit', "view.php?pageid=".$pageid, $pageid, $cm->id);
} else {
if ($option == get_string('preview')) {
if (!confirm_sesskey()) {
+1
View File
@@ -64,6 +64,7 @@ $string['editingpage'] = 'Editing this page \'{$a}\'';
$string['editsection'] = 'edit';
$string['eventhistoryviewed'] = 'Wiki history viewed';
$string['eventpageviewed'] = 'Wiki page viewed';
$string['eventpageupdated'] = 'Wiki page updated';
$string['eventversionrestored'] = 'Wiki version restored';
$string['files'] = 'Files';
$string['filenotuploadederror'] = 'File \'{$a}\' could not be uploaded correctly.';
+14 -2
View File
@@ -247,12 +247,24 @@ function wiki_save_page($wikipage, $newcontent, $userid) {
$version->userid = $userid;
$version->version++;
$version->timecreated = time();
$versionid = $DB->insert_record('wiki_versions', $version);
$version->id = $DB->insert_record('wiki_versions', $version);
$wikipage->timemodified = $version->timecreated;
$wikipage->userid = $userid;
$return = wiki_refresh_cachedcontent($wikipage, $newcontent);
$event = \mod_wiki\event\page_updated::create(
array(
'context' => $context,
'objectid' => $wikipage->id,
'relateduserid' => $userid,
'other' => array(
'newcontent' => $newcontent
)
));
$event->add_record_snapshot('wiki', $wiki);
$event->add_record_snapshot('wiki_pages', $wikipage);
$event->add_record_snapshot('wiki_versions', $version);
$event->trigger();
return $return;
} else {
return false;