Skip to content

Commit

Permalink
Collab: Add logging when user gets session problem on saving #17782
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-platts authored and sammarshallou committed Jun 9, 2015
1 parent e34ec75 commit 7f702f2
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
105 changes: 105 additions & 0 deletions classes/event/save_failed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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/>.

/**
*
* @package mod_ouwiki
* @copyright 2015 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_ouwiki\event;

defined('MOODLE_INTERNAL') || die();

/**
* The mod_ouwiki page saving failed event class.
*
* @package mod_ouwiki
* @since Moodle 2.7
* @copyright 2015 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class save_failed extends \core\event\base {

/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
}

/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$string = 'OUwiki page edit failed due to session error.';
if (!empty($this->other['pid'])) {
$string .= " Wiki cm id '{$this->other['pid']}'.";
}
return $string;
}

/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event:savefailed', 'mod_ouwiki');
}

/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url($this->other['page']);
}

/**
* Return the legacy event log data.
*
* @return array|null
*/
protected function get_legacy_logdata() {
global $SITE;
$url = str_replace('/mod/ouwiki/', '', $this->other['page']);
return array($SITE->id, 'ouwiki', 'error editpage', $this->other['page'], 'session error',
$this->contextinstanceid);
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();

if (!isset($this->other['page'])) {
throw new \coding_exception('The \'page\' value must be set in other.');
}
}

}
16 changes: 16 additions & 0 deletions confirmloggedin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
require_login(null, true);
require_sesskey();
} catch (moodle_exception $e) {
$pid = 0;
$url = '/mod/ouwiki/edit.php';
if (!empty($_SERVER['HTTP_REFERER'])) {
$url = new moodle_url($_SERVER['HTTP_REFERER']);
$rpid = $url->get_param('id');
if (!empty($rpid)) {
$pid = $rpid;
}
$url = $url->out_as_local_url();
}
$params = array(
'context' => context_system::instance(),
'other' => array('page' => $url, 'pid' => $pid)
);
$event = \mod_ouwiki\event\save_failed::create($params);
$event->trigger();
exit;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/ouwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,5 @@
$string['event:ouwikidelete'] = 'ouwiki version delete';
$string['event:ouwikipagecreated'] = 'ouwiki page created';
$string['event:ouwikipageupdated'] = 'ouwiki page updated';
$string['event:savefailed'] = 'Session fail on page save';
$string['ouwikicrontask'] = 'OU wiki maintenance jobs';
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$plugin->version = 2014120300;
$plugin->version = 2015051100;
$plugin->requires = 2014051200;
$plugin->component = 'mod_ouwiki';
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 7f702f2

Please sign in to comment.