diff --git a/lib/CleantalkSP/SpbctWP/Cron.php b/lib/CleantalkSP/SpbctWP/Cron.php index 0e6580cbb..a21f31731 100644 --- a/lib/CleantalkSP/SpbctWP/Cron.php +++ b/lib/CleantalkSP/SpbctWP/Cron.php @@ -110,10 +110,11 @@ public function saveTasks($tasks = array()) * @param int $period * @param int|null $first_call * @param array $params + * @param int $last_call * * @return bool */ - public static function addTask($task, $handler, $period, $first_call = null, $params = array()) + public static function addTask($task, $handler, $period, $first_call = null, $params = array(), $last_call = 0) { $first_call = $first_call ?: time() + $period; @@ -130,7 +131,7 @@ public static function addTask($task, $handler, $period, $first_call = null, $pa 'period' => $period, 'params' => $params, 'processing' => false, - 'last_call' => 0, + 'last_call' => $last_call, ); return update_option(self::CRON_OPTION_NAME, $tasks); @@ -169,9 +170,13 @@ public static function removeTask($task) */ public static function updateTask($task, $handler, $period, $first_call = null, $params = array()) { + $task_temp = self::getTask($task); + self::removeTask($task); - return self::addTask($task, $handler, $period, $first_call, $params); + $task_last_call = isset($task_temp['last_call']) ? $task_temp['last_call'] : 0; + + return self::addTask($task, $handler, $period, $first_call, $params, $task_last_call); } /**