mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Added admin events to the Moodle log - Issue #14
This commit is contained in:
@@ -17,14 +17,12 @@ php:
|
||||
- 5.6
|
||||
|
||||
env:
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_26_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_27_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_28_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_29_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=master
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_26_STABLE
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_27_STABLE
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_28_STABLE
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_29_STABLE
|
||||
|
||||
@@ -41,7 +41,7 @@ if ($mform->is_cancelled()) {
|
||||
$fromform = outagelib::parseformdata($fromform);
|
||||
$outage = new outage($fromform);
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/list.php#auth_outage_id=' . $id);
|
||||
redirect('/auth/outage/list.php#auth_outage_id_' . $id);
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
48
classes/event/outage_created.php
Normal file
48
classes/event/outage_created.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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/>.
|
||||
|
||||
namespace auth_outage\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage created class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_created extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'auth_outage';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' created a new outage title '{$this->other['title']}' "
|
||||
. " with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
return new \moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
|
||||
}
|
||||
}
|
||||
48
classes/event/outage_deleted.php
Normal file
48
classes/event/outage_deleted.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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/>.
|
||||
|
||||
namespace auth_outage\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage deleted class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_deleted extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'auth_outage';
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' deleted the outage titled '{$this->other['title']}' "
|
||||
. "with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
return new \moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
|
||||
}
|
||||
}
|
||||
49
classes/event/outage_updated.php
Normal file
49
classes/event/outage_updated.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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/>.
|
||||
|
||||
namespace auth_outage\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The auth_outage outage updated class.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_updated extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'auth_outage';
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' updated the outage title '{$this->other['title']}' "
|
||||
. "with id '{$this->other['id']}'.";
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
return new \moodle_url('/auth/outage/list.php');
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,7 @@ namespace auth_outage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
|
||||
final class outagedb
|
||||
{
|
||||
final class outagedb {
|
||||
/**
|
||||
* Private constructor, use static methods instead.
|
||||
*/
|
||||
@@ -86,23 +85,29 @@ final class outagedb
|
||||
// Do not change the original object.
|
||||
$outage = clone $outage;
|
||||
|
||||
// If new outage, set its creator.
|
||||
if ($outage->id === null) {
|
||||
$outage->createdby = $USER->id;
|
||||
}
|
||||
|
||||
// Update control fields.
|
||||
$outage->modifiedby = $USER->id;
|
||||
$outage->lastmodified = time();
|
||||
|
||||
// If new, create it and return the id.
|
||||
if ($outage->id === null) {
|
||||
return $DB->insert_record('auth_outage', $outage, true);
|
||||
// If new outage, set its creator.
|
||||
$outage->createdby = $USER->id;
|
||||
// Then create it, log it and adjust its id.
|
||||
$outage->id = $DB->insert_record('auth_outage', $outage, true);
|
||||
\auth_outage\event\outage_created::create(
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
} else {
|
||||
// Not new, clean up the class (remove creator field) then update.
|
||||
unset($outage->createdby);
|
||||
$DB->update_record('auth_outage', $outage);
|
||||
// Log it.
|
||||
\auth_outage\event\outage_updated::create(
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
}
|
||||
|
||||
// Clean up the class (remove creator field), then update it and return its id.
|
||||
unset($outage->createdby);
|
||||
$DB->update_record('auth_outage', $outage);
|
||||
// All done, return the id.
|
||||
return $outage->id;
|
||||
}
|
||||
|
||||
@@ -122,6 +127,12 @@ final class outagedb
|
||||
throw new \InvalidArgumentException('$id must be positive.');
|
||||
}
|
||||
|
||||
// Log it.
|
||||
$previous = $DB->get_record('auth_outage', ['id' => $id], '*', MUST_EXIST);
|
||||
$event = \auth_outage\event\outage_deleted::create(['objectid' => $id, 'other' => (array)$previous]);
|
||||
$event->add_record_snapshot('auth_outage', $previous);
|
||||
$event->trigger();
|
||||
|
||||
$DB->delete_records('auth_outage', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ if ($mform->is_cancelled()) {
|
||||
$fromform = outagelib::parseformdata($fromform);
|
||||
$outage = new outage($fromform);
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/list.php#auth_outage_id=' . $id);
|
||||
redirect('/auth/outage/list.php#auth_outage_id_' . $id);
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
@@ -45,4 +45,4 @@ $string['removeoutage'] = 'Remove Outage';
|
||||
$string['removeoutagewarning'] = 'You are about to permanently remove the outage below. This cannot be undone.';
|
||||
$string['outageslist'] = 'Outages List';
|
||||
$string['createoutage'] = 'Create Outage';
|
||||
$string['modify'] = 'Modify';
|
||||
$string['modify'] = 'Modify';
|
||||
|
||||
@@ -31,6 +31,6 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
|
||||
$plugin->version = 2016090100; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = $plugin->version; // Same as version
|
||||
$plugin->requires = 2013111811; // Requires Moodle 2.6 or later.
|
||||
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later.
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->maturity = MATURITY_ALPHA; // Not suitable for PRODUCTION environments yet!
|
||||
|
||||
Reference in New Issue
Block a user