Skip to content
Snippets Groups Projects
Commit c5e608ba authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #112 from greezybacon/issue/draft-cleanup

Cleanup drafts on ticket processing

Peter Rotich <peter@osticket.com>
parents bbbaba3d 3d39e978
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,11 @@ class Cron { ...@@ -35,6 +35,11 @@ class Cron {
if($ost) $ost->purgeLogs(); if($ost) $ost->purgeLogs();
} }
function PurgeDrafts() {
require_once(INCLUDE_DIR.'class.draft.php');
Draft::cleanup();
}
function CleanOrphanedFiles() { function CleanOrphanedFiles() {
require_once(INCLUDE_DIR.'class.file.php'); require_once(INCLUDE_DIR.'class.file.php');
AttachmentFile::deleteOrphans(); AttachmentFile::deleteOrphans();
...@@ -49,6 +54,7 @@ class Cron { ...@@ -49,6 +54,7 @@ class Cron {
self::TicketMonitor(); self::TicketMonitor();
self::PurgeLogs(); self::PurgeLogs();
self::CleanOrphanedFiles(); self::CleanOrphanedFiles();
self::PurgeDrafts();
} }
} }
?> ?>
...@@ -149,6 +149,14 @@ class Draft { ...@@ -149,6 +149,14 @@ class Draft {
$sql .= ' AND staff_id='.db_input($staff_id); $sql .= ' AND staff_id='.db_input($staff_id);
return (!db_query($sql) || !db_affected_rows()); return (!db_query($sql) || !db_affected_rows());
} }
static function cleanup() {
// Keep client drafts for two weeks (14 days)
$sql = 'DELETE FROM '.DRAFT_TABLE
." WHERE `namespace` LIKE 'ticket.client.%'
AND datediff(now(), updated) > 14";
return db_query($sql);
}
} }
?> ?>
...@@ -728,6 +728,7 @@ class Ticket { ...@@ -728,6 +728,7 @@ class Ticket {
$this->reload(); $this->reload();
$this->logEvent('closed'); $this->logEvent('closed');
$this->deleteDrafts();
return true; return true;
} }
...@@ -1676,9 +1677,15 @@ class Ticket { ...@@ -1676,9 +1677,15 @@ class Ticket {
foreach (DynamicFormEntry::forTicket($this->getId()) as $form) foreach (DynamicFormEntry::forTicket($this->getId()) as $form)
$form->delete(); $form->delete();
$this->deleteDrafts();
return true; return true;
} }
function deleteDrafts() {
Draft::deleteForNamespace('ticket.%.' . $this->getId());
}
function update($vars, &$errors) { function update($vars, &$errors) {
global $cfg, $thisstaff; global $cfg, $thisstaff;
......
...@@ -70,13 +70,13 @@ if($_POST && !$errors): ...@@ -70,13 +70,13 @@ if($_POST && !$errors):
$msg='Reply posted successfully'; $msg='Reply posted successfully';
$ticket->reload(); $ticket->reload();
// Cleanup drafts for the ticket. If not closed, only clean
// for this staff. Else clean all drafts for the ticket.
Draft::deleteForNamespace('ticket.%.' . $ticket->getId(),
$ticket->isClosed() ? false : $thisstaff->getId());
if($ticket->isClosed() && $wasOpen) if($ticket->isClosed() && $wasOpen)
$ticket=null; $ticket=null;
else
// Still open -- cleanup response draft for this user
Draft::deleteForNamespace(
'ticket.response.' . $ticket->getId(),
$thisstaff->getId());
} elseif(!$errors['err']) { } elseif(!$errors['err']) {
$errors['err']='Unable to post the reply. Correct the errors below and try again!'; $errors['err']='Unable to post the reply. Correct the errors below and try again!';
...@@ -174,17 +174,13 @@ if($_POST && !$errors): ...@@ -174,17 +174,13 @@ if($_POST && !$errors):
$wasOpen = ($ticket->isOpen()); $wasOpen = ($ticket->isOpen());
if(($note=$ticket->postNote($vars, $errors, $thisstaff))) { if(($note=$ticket->postNote($vars, $errors, $thisstaff))) {
// Cleanup drafts for the ticket. If not closed, only clean
// note drafts for this staff. Else clean all drafts for the ticket.
Draft::deleteForNamespace(
sprintf('ticket.%s.%d',
$ticket->isClosed() ? '%' : 'note',
$ticket->getId()),
$ticket->isOpen() ? $thisstaff->getId() : false);
$msg='Internal note posted successfully'; $msg='Internal note posted successfully';
if($wasOpen && $ticket->isClosed()) if($wasOpen && $ticket->isClosed())
$ticket = null; //Going back to main listing. $ticket = null; //Going back to main listing.
else
// Ticket is still open -- clear draft for the note
Draft::deleteForNamespace('ticket.note.'.$ticket->getId(),
$thisstaff->getId());
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment