MDL-40058 mod_wiki: Replaced add_to_log for override locks with event

This commit is contained in:
Rajesh Taneja
2013-12-11 13:52:59 +11:00
committed by Marina Glancy
parent 3e5e78a2c9
commit b3dd79d101
4 changed files with 105 additions and 1 deletions
@@ -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 locks deleted (override locks)
*
* @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 locks deleted (override locks)
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_locks_deleted extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventpagelocksdeleted', 'mod_wiki');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id ' . $this->userid . ' deleted locks for page id ' . $this->objectid;
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return(array($this->courseid, 'wiki', 'overridelocks', '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
@@ -64,6 +64,7 @@ $string['editingpage'] = 'Editing this page \'{$a}\'';
$string['editsection'] = 'edit';
$string['eventdiffviewed'] = 'Wiki diff viewed';
$string['eventhistoryviewed'] = 'Wiki history viewed';
$string['eventpagelocksdeleted'] = 'Wiki page locks deleted';
$string['eventpageviewed'] = 'Wiki page viewed';
$string['eventpageupdated'] = 'Wiki page updated';
$string['eventversionrestored'] = 'Wiki version restored';
+21
View File
@@ -999,10 +999,20 @@ function wiki_set_lock($pageid, $userid, $section = null, $insert = false) {
/**
* Deletes wiki_locks that are not in use. (F.Ex. after submitting the changes). If no userid is present, it deletes ALL the wiki_locks of a specific page.
*
* @param int $pageid page id.
* @param int $userid id of user for which lock is deleted.
* @param string $section section to be deleted.
* @param bool $delete_from_db deleted from db.
* @param bool $delete_section_and_page delete section and page version.
*/
function wiki_delete_locks($pageid, $userid = null, $section = null, $delete_from_db = true, $delete_section_and_page = false) {
global $DB;
$wiki = wiki_get_wiki_from_pageid($pageid);
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
$context = context_module::instance($cm->id);
$params = array('pageid' => $pageid);
if (!empty($userid)) {
@@ -1019,6 +1029,17 @@ function wiki_delete_locks($pageid, $userid = null, $section = null, $delete_fro
$params['sectionname'] = null;
$DB->delete_records('wiki_locks', $params);
}
$event = \mod_wiki\event\page_locks_deleted::create(
array(
'context' => $context,
'objectid' => $pageid,
'relateduserid' => $userid,
'other' => array(
'section' => $section
)
));
// No need to add snapshot, as important data is section, userid and pageid, which is part of event.
$event->trigger();
} else {
$DB->set_field('wiki_locks', 'lockedat', time(), $params);
}
-1
View File
@@ -77,7 +77,6 @@ $wikipage->set_page($page);
if (!empty($section)) {
$wikipage->set_section($sectioncontent, $section);
}
add_to_log($course->id, "wiki", "overridelocks", "view.php?pageid=".$pageid, $pageid, $cm->id);
$wikipage->print_header();