Skip to content

Commit

Permalink
Fix. Cron. Fixed updateTask function to save the last_call param. (#343)
Browse files Browse the repository at this point in the history
* Fix. Cron. Fixed updateTask function to save the last_call param.

* Fix phpcs.
  • Loading branch information
svfcode authored May 20, 2024
1 parent 744e3a3 commit 74f2800
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/CleantalkSP/SpbctWP/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 74f2800

Please sign in to comment.