define('BLOCK_R_MAX_WIDTH', $rmax);
// check if major upgrade needed - also present in login/index.php
- if (empty($CFG->version) or (int)$CFG->version < 2009011600) { //1.9 or older
+ if (empty($CFG->version) or (int)$CFG->version < 2009011900) { //1.9 or older
@require_logout();
redirect("$CFG->wwwroot/$CFG->admin/");
}
$string['dbupdatefailed'] = 'Database update failed';
$string['dbsessionbroken'] = 'Serious database session problem detected.<br /><br />Please notify server administrator.';
$string['dbsessionhandlerproblem'] = 'Setting up of database session failed.<br /><br />Please notify server administrator.';
+$string['dbsessionmysqlpacketsize'] = 'Serious session error detected.<br /><br />Please notify administrator, this problem is most probably caused by small value in max_packet_size MySQL setting.';
$string['ddlexecuteerror'] = 'DDL sql execution error';
$string['ddlfieldalreadyexists'] = 'Field \"$a\" does not exist';
$string['ddlfieldnotexist'] = 'Field \"$a->fieldname\" does not exist in table \"$a->tablename\"';
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20090114" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090119" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
<FIELD NAME="state" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="0 means normal session" PREVIOUS="id" NEXT="sid"/>
<FIELD NAME="sid" TYPE="char" LENGTH="128" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Session id" PREVIOUS="state" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sid" NEXT="sessdata"/>
- <FIELD NAME="sessdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="session content" PREVIOUS="userid" NEXT="sessdatahash"/>
- <FIELD NAME="sessdatahash" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="verifies integrity of sessdata" PREVIOUS="sessdata" NEXT="timecreated"/>
- <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sessdatahash" NEXT="timemodified"/>
+ <FIELD NAME="sessdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="session content" PREVIOUS="userid" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sessdata" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated" NEXT="firstip"/>
<FIELD NAME="firstip" TYPE="char" LENGTH="45" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified" NEXT="lastip"/>
<FIELD NAME="lastip" TYPE="char" LENGTH="45" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="firstip"/>
upgrade_main_savepoint($result, 2009011303);
}
- if ($result && $oldversion < 2009011600) {
+ if ($result && $oldversion < 2009011900) {
/// Define table sessions2 to be dropped
$table = new xmldb_table('sessions2');
$table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
- $table->add_field('sessdatahash', XMLDB_TYPE_CHAR, '40', null, null, null, null, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null, null, null);
$dbman->create_table($table);
/// Main savepoint reached
- upgrade_main_savepoint($result, 2009011600);
+ upgrade_main_savepoint($result, 2009011900);
}
global $CFG;
if (!defined('NO_MOODLE_COOKIES')) {
- if (empty($CFG->version) or $CFG->version < 2009011600) {
+ if (empty($CFG->version) or $CFG->version < 2009011900) {
// no session before sessions table gets greated
define('NO_MOODLE_COOKIES', true);
} else if (CLI_SCRIPT) {
global $DB;
$this->database = $DB;
parent::__construct();
+
+ if (!empty($this->record->state)) {
+ // something is very wrong
+ session_kill($this->record->sid);
+
+ if ($this->record->state == 9) {
+ print_error('dbsessionmysqlpacketsize', 'error');
+ }
+ }
}
protected function init_session_storage() {
$record->state = 0;
$record->sid = $sid;
$record->sessdata = null;
- $record->sessdatahash = null;
$record->userid = 0;
$record->timecreated = $record->timemodified = time();
$record->firstip = $record->lastip = getremoteaddr();
//time out session
$record->state = 0;
$record->sessdata = null;
- $record->sessdatahash = null;
$record->userid = 0;
$record->timecreated = $record->timemodified = time();
$record->firstip = $record->lastip = getremoteaddr();
}
}
- if ($record->sessdata !== null) {
- if (md5($record->sessdata) !== $record->sessdatahash) {
- // probably this is caused by misconfigured mysql - the allowed request size might be too small
- try {
- $this->database->delete_records('sessions', array('sid'=>$record->sid));
- } catch (dml_exception $ignored) {
- }
- print_error('dbsessionbroken', 'error');
- }
-
- $data = base64_decode($record->sessdata);
- } else {
- $data = '';
- }
+ $data = is_null($record->sessdata) ? '' : base64_decode($record->sessdata);
unset($record->sessdata); // conserve memory
$this->record = $record;
public function handler_write($sid, $session_data) {
global $USER;
- try {
- if (isset($this->record->id)) {
- $record->sid = $sid; // might be regenerating sid
- $this->record->sessdata = base64_encode($session_data); // there might be some binary mess :-(
- $this->record->sessdatahash = md5($this->record->sessdata);
- $this->record->userid = empty($USER->realuser) ? $USER->id : $USER->realuser;
- $this->record->timemodified = time();
- $this->record->lastip = getremoteaddr();
+ $userid = 0;
+ if (!empty($USER->realuser)) {
+ $userid = $USER->realuser;
+ } else if (!empty($USER->id)) {
+ $userid = $USER->id;
+ }
+
+ if (isset($this->record->id)) {
+ $record->state = 0;
+ $record->sid = $sid; // might be regenerating sid
+ $this->record->sessdata = base64_encode($session_data); // there might be some binary mess :-(
+ $this->record->userid = $userid;
+ $this->record->timemodified = time();
+ $this->record->lastip = getremoteaddr();
- // TODO: verify session changed before doing update
+ // TODO: verify session changed before doing update
+ try {
$this->database->update_record_raw('sessions', $this->record);
+ } catch (dml_exception $ex) {
+ if ($this->database->get_dbfamily() === 'mysql') {
+ try {
+ $this->database->set_field('sessions', 'state', 9, array('id'=>$this->record->id));
+ } catch (Exception $ignored) {
- } else {
- // session already destroyed
- $record = new object();
- $record->state = 0;
- $record->sid = $sid;
- $record->sessdata = base64_encode($session_data); // there might be some binary mess :-(
- $record->sessdatahash = md5($record->sessdata);
- $record->userid = empty($USER->realuser) ? $USER->id : $USER->realuser;
- $record->timecreated = $record->timemodified = time();
- $record->firstip = $record->lastip = getremoteaddr();
- $record->id = $this->database->insert_record_raw('sessions', $record);
- $this->record = $record;
+ }
+ error_log('Can not write session - please verify max_packet_size is at least 4MB');
+ } else {
+ error_log('Can not write session');
+ }
+ }
+ } else {
+ // session already destroyed
+ $record = new object();
+ $record->state = 0;
+ $record->sid = $sid;
+ $record->sessdata = base64_encode($session_data); // there might be some binary mess :-(
+ $record->userid = $userid;
+ $record->timecreated = $record->timemodified = time();
+ $record->firstip = $record->lastip = getremoteaddr();
+ $record->id = $this->database->insert_record_raw('sessions', $record);
+ $this->record = $record;
+
+ try {
$this->database->get_session_lock($this->record->id);
+ } catch (dml_exception $ex) {
+ error_log('Can not write new session');
}
- } catch (dml_exception $ex) {
- error_log('Can not write session');
}
return true;
require_once("../config.php");
/// check if major upgrade needed - also present in /index.php
- if ((int)$CFG->version < 2009011600) { //1.9 or older
+ if ((int)$CFG->version < 2009011900) { //1.9 or older
@require_logout();
redirect("$CFG->wwwroot/$CFG->admin/");
}
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2009011600; // YYYYMMDD = date of the last version bump
+ $version = 2009011900; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20090119)'; // Human-friendly version name