From 0f9b3bcc27e7daf7d605a7a38310a8f62b9a76e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 17 Apr 2010 03:13:30 -0400 Subject: [feature/system-cron] Refactored cron task naming, loading and running. PHPBB3-9596 --- phpBB/includes/cron/cron_lock.php | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 phpBB/includes/cron/cron_lock.php (limited to 'phpBB/includes/cron/cron_lock.php') diff --git a/phpBB/includes/cron/cron_lock.php b/phpBB/includes/cron/cron_lock.php new file mode 100644 index 0000000000..1046d62da4 --- /dev/null +++ b/phpBB/includes/cron/cron_lock.php @@ -0,0 +1,75 @@ += time()) + { + return false; + } + } + + $this->cron_id = time() . ' ' . unique_id(); + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($this->cron_id) . "' + WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'"; + $db->sql_query($sql); + + // another cron process altered the table between script start and UPDATE query so exit + if ($db->sql_affectedrows() != 1) + { + return false; + } + + return true; + } + + function unlock() + { + global $db; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '0' + WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($this->cron_id) . "'"; + $db->sql_query($sql); + } +} -- cgit v1.2.1