From b47f838e627e1c12fe850495e23443118499ad7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Tue, 10 Nov 2020 15:14:49 +0000 Subject: [PATCH] PMCORE-2412 --- workflow/engine/bin/cron.php | 3 +- workflow/engine/bin/cron_single.php | 7 +++ workflow/engine/bin/webentriescron.php | 3 ++ .../ProcessMaker/BusinessModel/WebEntry.php | 51 ++++++++++++++----- 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 workflow/engine/bin/webentriescron.php diff --git a/workflow/engine/bin/cron.php b/workflow/engine/bin/cron.php index 7b552d923..71e2cfb6d 100644 --- a/workflow/engine/bin/cron.php +++ b/workflow/engine/bin/cron.php @@ -17,7 +17,8 @@ try { 'ldapcron' => ['title' => 'LDAP Advanced CRON'], 'messageeventcron' => ['title' => 'Message-Event CRON'], 'timereventcron' => ['title' => 'Timer-Event CRON'], - 'sendnotificationscron' => ['title' => 'Send-Notifications CRON'] + 'sendnotificationscron' => ['title' => 'Send-Notifications CRON'], + 'webentriescron' => ['title' => 'Wen Entries CRON'] ]; //Define constants diff --git a/workflow/engine/bin/cron_single.php b/workflow/engine/bin/cron_single.php index 83c5fa260..f1c7fe678 100644 --- a/workflow/engine/bin/cron_single.php +++ b/workflow/engine/bin/cron_single.php @@ -8,6 +8,7 @@ * @see workflow/engine/bin/timereventcron.php * @see workflow/engine/bin/ldapcron.php * @see workflow/engine/bin/sendnotificationscron.php + * @see workflow/engine/bin/webentriescron.php * @see workflow/engine/methods/setup/cron.php * * @link https://wiki.processmaker.com/3.2/Executing_cron.php @@ -22,6 +23,7 @@ require_once __DIR__ . '/../../../gulliver/system/class.g.php'; require_once __DIR__ . '/../../../bootstrap/autoload.php'; require_once __DIR__ . '/../../../bootstrap/app.php'; +use ProcessMaker\BusinessModel\WebEntry; use ProcessMaker\Core\JobsManager; use ProcessMaker\Core\System; use ProcessMaker\Plugins\PluginRegistry; @@ -302,6 +304,11 @@ try { case 'sendnotificationscron': sendNotifications(); break; + case 'webentriescron': + setExecutionMessage('Deleting web entry cases created one week ago or more'); + WebEntry::deleteOldWebEntries(); + setExecutionResultMessage('FINISHED'); + break; /*----------------------------------********---------------------------------*/ case 'actionsByEmailEmailResponse': (new ResponseReader)->actionsByEmailEmailResponse(); diff --git a/workflow/engine/bin/webentriescron.php b/workflow/engine/bin/webentriescron.php new file mode 100644 index 000000000..a5b732fba --- /dev/null +++ b/workflow/engine/bin/webentriescron.php @@ -0,0 +1,3 @@ +statement($sql); + DB::connection('workflow')->statement($query); + } + + /** + * Delete web entries created one week ago or more + */ + public static function deleteOldWebEntries() + { + // Define some values for PM tables classes + if (!defined('PATH_WORKSPACE')) { + define('PATH_WORKSPACE', PATH_DB . config('system.workspace') . PATH_SEP); + } + set_include_path(get_include_path() . PATH_SEPARATOR . PATH_WORKSPACE); + + // Calculate date, one week ago from today + $date = now()->subWeek()->format('Y-m-d H:i:s'); + + // Build query + $query = "SELECT `APP_UID` FROM `APPLICATION` WHERE `APP_NUMBER` < 0 AND `APP_CREATE_DATE` < '{$date}'"; + + // Execute query + $cases = DB::connection('workflow')->select($query); + + // Delete cases, one by one with all related records + $casesInstance = new Cases(); + foreach ($cases as $case) { + $casesInstance->removeCase($case->APP_UID); + } } }