mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-40922 mod_folder: replaced the 'edit' add_to_log call with an event
This commit is contained in:
parent
6f3e33c947
commit
81ec45ea11
76
mod/folder/classes/event/folder_updated.php
Normal file
76
mod/folder/classes/event/folder_updated.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The mod_folder folder updated event.
|
||||
*
|
||||
* @package mod_folder
|
||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_folder\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class folder_updated extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'folder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventfolderupdated', 'mod_folder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' updated the folder activity with instance id ' . $this->objectid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/folder/edit.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'folder', 'edit', 'edit.php?id=' . $this->context->instanceid, $this->objectid,
|
||||
$this->context->instanceid);
|
||||
}
|
||||
}
|
@ -63,7 +63,16 @@ if ($mform->is_cancelled()) {
|
||||
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0);
|
||||
$DB->set_field('folder', 'revision', $folder->revision+1, array('id'=>$folder->id));
|
||||
|
||||
add_to_log($course->id, 'folder', 'edit', 'edit.php?id='.$cm->id, $folder->id, $cm->id);
|
||||
// Update the variable of the folder revision so we can pass it as an accurate snapshot later.
|
||||
$folder->revision = $folder->revision + 1;
|
||||
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $folder->id
|
||||
);
|
||||
$event = \mod_folder\event\folder_updated::create($params);
|
||||
$event->add_record_snapshot('folder', $folder);
|
||||
$event->trigger();
|
||||
|
||||
redirect($redirecturl);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
$string['contentheader'] = 'Content';
|
||||
$string['dnduploadmakefolder'] = 'Unzip files and create folder';
|
||||
$string['eventfolderupdated'] = 'Folder updated';
|
||||
$string['folder:addinstance'] = 'Add a new folder';
|
||||
$string['folder:managefiles'] = 'Manage files in folder module';
|
||||
$string['folder:view'] = 'View folder content';
|
||||
|
70
mod/folder/tests/events_test.php
Normal file
70
mod/folder/tests/events_test.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Events tests.
|
||||
*
|
||||
* @package mod_folder
|
||||
* @category test
|
||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class mod_folder_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the folder updated event.
|
||||
*
|
||||
* There is no external API for updating a folder, so the unit test will simply create
|
||||
* and trigger the event and ensure the legacy log data is returned as expected.
|
||||
*/
|
||||
public function test_folder_updated() {
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$folder = $this->getDataGenerator()->create_module('folder', array('course' => $course->id));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($folder->cmid),
|
||||
'objectid' => $folder->id,
|
||||
'courseid' => $course->id
|
||||
);
|
||||
$event = \mod_folder\event\folder_updated::create($params);
|
||||
$event->add_record_snapshot('folder', $folder);
|
||||
|
||||
// Trigger and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_folder\event\folder_updated', $event);
|
||||
$this->assertEquals(context_module::instance($folder->cmid), $event->get_context());
|
||||
$this->assertEquals($folder->id, $event->objectid);
|
||||
$expected = array($course->id, 'folder', 'edit', 'edit.php?id=' . $folder->cmid, $folder->id, $folder->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user