Skip to content
Snippets Groups Projects
Commit e700e0d5 authored by Jared Hancock's avatar Jared Hancock
Browse files

draft: Looks like Redactor doesn't urlencode()

Looks like Redactor finally quit double urlencoding() the autosave requests
Also, remove ALL drafts after 14 days.
parent 7098c2fb
No related branches found
No related tags found
No related merge requests found
......@@ -381,19 +381,20 @@ class DraftAjaxAPI extends AjaxController {
function _findDraftBody($vars) {
if (isset($vars['name'])) {
$parts = array();
// Support nested `name`, like trans[lang]
if (preg_match('`(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?`', $_POST['name'], $parts)) {
array_shift($parts);
$focus = $vars;
foreach ($parts as $p)
$focus = $focus[$p];
return urldecode($focus);
return $focus;
}
}
$field_list = array('response', 'note', 'answer', 'body',
'message', 'issue', 'description');
foreach ($field_list as $field) {
if (isset($vars[$field])) {
return urldecode($vars[$field]);
return $vars[$field];
}
}
......
......@@ -22,10 +22,10 @@ class Attachment extends VerySimpleModel {
'pk' => array('id'),
'select_related' => array('file'),
'joins' => array(
'thread_entry' => array(
'draft' => array(
'constraint' => array(
'type' => "'H'",
'object_id' => 'ThreadEntry.id',
'type' => "'D'",
'object_id' => 'Draft.id',
),
),
'file' => array(
......@@ -33,6 +33,12 @@ class Attachment extends VerySimpleModel {
'file_id' => 'AttachmentFile.id',
),
),
'thread_entry' => array(
'constraint' => array(
'type' => "'H'",
'object_id' => 'ThreadEntry.id',
),
),
),
);
......
......@@ -167,14 +167,12 @@ class Draft extends VerySimpleModel {
* are cleaned up.
*/
static function deleteForNamespace($namespace, $staff_id=false) {
$sql = 'DELETE attach FROM '.ATTACHMENT_TABLE.' attach
INNER JOIN '.DRAFT_TABLE.' draft
ON (attach.object_id = draft.id AND attach.`type`=\'D\')
WHERE draft.`namespace` LIKE '.db_input($namespace);
$attachments = Attachment::objects()
->filter(array('draft__namespace__like' => $namespace));
if ($staff_id)
$sql .= ' AND draft.staff_id='.db_input($staff_id);
if (!db_query($sql))
return false;
$attachments->filter(array('draft__staff_id' => $staff_id));
$attachments->delete();
$criteria = array('namespace__like'=>$namespace);
if ($staff_id)
......@@ -183,11 +181,10 @@ class Draft extends VerySimpleModel {
}
static function cleanup() {
// Keep client drafts for two weeks (14 days)
// Keep drafts for two weeks (14 days)
$sql = 'DELETE FROM '.DRAFT_TABLE
." WHERE `namespace` LIKE 'ticket.client.%'
AND ((updated IS NULL AND datediff(now(), created) > 14)
OR datediff(now(), updated) > 14)";
." WHERE (updated IS NULL AND datediff(now(), created) > 14)
OR datediff(now(), updated) > 14";
return db_query($sql);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment