MDL-18014 Atto autosave: Use the $PAGE->url to differentiate autosave instances

This commit is contained in:
Damyon Wiese
2014-08-14 13:23:05 +08:00
parent d8733567ee
commit c07f86ce26
8 changed files with 62 additions and 24 deletions
+8 -7
View File
@@ -28,7 +28,7 @@ require_once(dirname(__FILE__) . '/../../../config.php');
$contextid = required_param('contextid', PARAM_INT);
$elementid = required_param('elementid', PARAM_ALPHANUMEXT);
$pagedomid = required_param('pagedomid', PARAM_ALPHANUMEXT);
$pagehash = required_param('pagehash', PARAM_ALPHANUMEXT);
$pageinstance = required_param('pageinstance', PARAM_ALPHANUMEXT);
list($context, $course, $cm) = get_context_info_array($contextid);
@@ -44,7 +44,7 @@ if ($action === 'save') {
$drafttext = required_param('drafttext', PARAM_RAW);
$params = array('elementid' => $elementid,
'userid' => $USER->id,
'pagedomid' => $pagedomid,
'pagehash' => $pagehash,
'contextid' => $contextid);
$record = $DB->get_record('editor_atto_autosave', $params);
@@ -57,7 +57,7 @@ if ($action === 'save') {
$record = new stdClass();
$record->elementid = $elementid;
$record->userid = $USER->id;
$record->pagedomid = $pagedomid;
$record->pagehash = $pagehash;
$record->contextid = $contextid;
$record->drafttext = $drafttext;
$record->pageinstance = $pageinstance;
@@ -76,8 +76,9 @@ if ($action === 'save') {
} else if ($action == 'resume') {
$params = array('elementid' => $elementid,
'userid' => $USER->id,
'pagedomid' => $pagedomid,
'pagehash' => $pagehash,
'contextid' => $contextid);
$newdraftid = required_param('draftid', PARAM_INT);
$record = $DB->get_record('editor_atto_autosave', $params);
@@ -86,10 +87,10 @@ if ($action === 'save') {
$record = new stdClass();
$record->elementid = $elementid;
$record->userid = $USER->id;
$record->pagedomid = $pagedomid;
$record->pagehash = $pagehash;
$record->contextid = $contextid;
$record->pageinstance = $pageinstance;
$record->pagedomid = $pagedomid;
$record->pagehash = $pagehash;
$record->draftid = $newdraftid;
$record->drafttext = '';
@@ -132,7 +133,7 @@ if ($action === 'save') {
} else if ($action == 'reset') {
$params = array('elementid' => $elementid,
'userid' => $USER->id,
'pagedomid' => $pagedomid,
'pagehash' => $pagehash,
'contextid' => $contextid);
$DB->delete_records('editor_atto_autosave', $params);
+2 -2
View File
@@ -9,7 +9,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="elementid" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The unique id for the text editor in the form."/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The contextid that the form was loaded with."/>
<FIELD NAME="pagedomid" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="The HTML DOM id of the page that loaded the form."/>
<FIELD NAME="pagehash" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="The HTML DOM id of the page that loaded the form."/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The id of the user that loaded the form."/>
<FIELD NAME="drafttext" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The draft text"/>
<FIELD NAME="draftid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Optional draft area id containing draft files."/>
@@ -17,7 +17,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="autosave_uniq_key" TYPE="unique" FIELDS="elementid, contextid, userid, pagedomid" COMMENT="Unique key for the user in the form in the page."/>
<KEY NAME="autosave_uniq_key" TYPE="unique" FIELDS="elementid, contextid, userid, pagehash" COMMENT="Unique key for the user in the form in the page."/>
</KEYS>
</TABLE>
</TABLES>
+2 -2
View File
@@ -62,7 +62,7 @@ function xmldb_editor_atto_upgrade($oldversion) {
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('elementid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('pagedomid', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
$table->add_field('pagehash', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('drafttext', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('draftid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
@@ -70,7 +70,7 @@ function xmldb_editor_atto_upgrade($oldversion) {
// Adding keys to table editor_atto_autosave.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('autosave_uniq_key', XMLDB_KEY_UNIQUE, array('elementid', 'contextid', 'userid', 'pagedomid'));
$table->add_key('autosave_uniq_key', XMLDB_KEY_UNIQUE, array('elementid', 'contextid', 'userid', 'pagehash'));
// Conditionally launch create table for editor_atto_autosave.
if (!$dbman->table_exists($table)) {
+2 -1
View File
@@ -169,7 +169,8 @@ class atto_texteditor extends texteditor {
'language' => $lang,
'directionality' => $directionality,
'filepickeroptions' => array(),
'plugins' => $plugins
'plugins' => $plugins,
'pageHash' => sha1($PAGE->url)
);
if ($fpoptions) {
$params['filepickeroptions'] = $fpoptions;
@@ -759,6 +759,18 @@ EditorAutosave.ATTRS= {
writeOnce: true
},
/**
* Unique hash for this page instance. Calculated from $PAGE->url in php.
*
* @attribute pageHash
* @type String
* @writeOnce
*/
pageHash: {
value: '',
writeOnce: true
},
/**
* The relative path to the ajax script.
*
@@ -825,7 +837,7 @@ EditorAutosave.prototype = {
draftid: draftid,
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -869,7 +881,7 @@ EditorAutosave.prototype = {
action: 'reset',
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -920,7 +932,7 @@ EditorAutosave.prototype = {
action: 'save',
drafttext: newText,
elementid: this.get('elementid'),
pagedomid: Y.one('body').get('id'),
pagehash: this.get('pageHash'),
pageinstance: this.autosaveInstance
};
File diff suppressed because one or more lines are too long
@@ -754,6 +754,18 @@ EditorAutosave.ATTRS= {
writeOnce: true
},
/**
* Unique hash for this page instance. Calculated from $PAGE->url in php.
*
* @attribute pageHash
* @type String
* @writeOnce
*/
pageHash: {
value: '',
writeOnce: true
},
/**
* The relative path to the ajax script.
*
@@ -820,7 +832,7 @@ EditorAutosave.prototype = {
draftid: draftid,
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -863,7 +875,7 @@ EditorAutosave.prototype = {
action: 'reset',
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -913,7 +925,7 @@ EditorAutosave.prototype = {
action: 'save',
drafttext: newText,
elementid: this.get('elementid'),
pagedomid: Y.one('body').get('id'),
pagehash: this.get('pageHash'),
pageinstance: this.autosaveInstance
};
+15 -3
View File
@@ -55,6 +55,18 @@ EditorAutosave.ATTRS= {
writeOnce: true
},
/**
* Unique hash for this page instance. Calculated from $PAGE->url in php.
*
* @attribute pageHash
* @type String
* @writeOnce
*/
pageHash: {
value: '',
writeOnce: true
},
/**
* The relative path to the ajax script.
*
@@ -121,7 +133,7 @@ EditorAutosave.prototype = {
draftid: draftid,
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -165,7 +177,7 @@ EditorAutosave.prototype = {
action: 'reset',
elementid: this.get('elementid'),
pageinstance: this.autosaveInstance,
pagedomid: Y.one('body').get('id')
pagehash: this.get('pageHash')
};
Y.io(url, {
@@ -216,7 +228,7 @@ EditorAutosave.prototype = {
action: 'save',
drafttext: newText,
elementid: this.get('elementid'),
pagedomid: Y.one('body').get('id'),
pagehash: this.get('pageHash'),
pageinstance: this.autosaveInstance
};