From ecaed2a8450ab8423b4e5ef60ac9a249be60901a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Dec 2021 09:07:54 -0500 Subject: [PATCH 1/3] Update DateTimeFormat documentation - Remove an explicit default value parameter --- src/Module/Api/ApiResponse.php | 2 +- src/Security/OAuth.php | 2 +- src/Util/DateTimeFormat.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index 8f4931383..c4b9b1e94 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -103,7 +103,7 @@ class ApiResponse extends Response 'alternate' => $user_info['url'], 'self' => $this->baseUrl . '/' . $this->args->getQueryString(), 'base' => $this->baseUrl, - 'updated' => DateTimeFormat::utc(null, DateTimeFormat::API), + 'updated' => DateTimeFormat::utcNow(DateTimeFormat::API), 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'language' => $user_info['lang'], 'logo' => $this->baseUrl . '/images/friendica-32.png', diff --git a/src/Security/OAuth.php b/src/Security/OAuth.php index 2f5dd3964..b3573fd68 100644 --- a/src/Security/OAuth.php +++ b/src/Security/OAuth.php @@ -176,7 +176,7 @@ class OAuth 'write' => (stripos($scope, BaseApi::SCOPE_WRITE) !== false), 'follow' => (stripos($scope, BaseApi::SCOPE_FOLLOW) !== false), 'push' => (stripos($scope, BaseApi::SCOPE_PUSH) !== false), - 'created_at' => DateTimeFormat::utcNow(DateTimeFormat::MYSQL)]; + 'created_at' => DateTimeFormat::utcNow()]; foreach ([BaseApi::SCOPE_READ, BaseApi::SCOPE_WRITE, BaseApi::SCOPE_WRITE, BaseApi::SCOPE_PUSH] as $scope) { if ($fields[$scope] && !$application[$scope]) { diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index 141fa37f6..af1c0fc7a 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -52,7 +52,7 @@ class DateTimeFormat * @return string * @throws Exception */ - public static function utc($time, $format = self::MYSQL) + public static function utc(string $time, string $format = self::MYSQL): string { return self::convert($time, 'UTC', 'UTC', $format); } @@ -102,7 +102,7 @@ class DateTimeFormat * @return string * @throws Exception */ - public static function utcNow($format = self::MYSQL) + public static function utcNow(string $format = self::MYSQL): string { return self::utc('now', $format); } From 80da47921e2faa528bd16e587fe23ec340c847d6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Dec 2021 09:19:01 -0500 Subject: [PATCH 2/3] Replace references to UTC_TIMESTAMP in SQL queries with a DateTimeFormat generated parameter --- mod/photos.php | 2 +- mod/wallmessage.php | 5 +++-- src/Core/Worker.php | 2 +- src/Model/Item.php | 4 ++-- src/Model/PushSubscriber.php | 2 +- src/Model/Tag.php | 5 +++-- src/Module/OAuth/Token.php | 5 +++-- src/Worker/CleanWorkerQueue.php | 3 ++- src/Worker/ExpireAndRemoveUsers.php | 7 ++++--- src/Worker/ExpireConversations.php | 3 ++- src/Worker/ExpirePosts.php | 15 ++++++++------- src/Worker/PollContacts.php | 2 +- src/Worker/RemoveUnusedContacts.php | 7 ++++--- src/Worker/UpdateGServers.php | 3 ++- 14 files changed, 37 insertions(+), 28 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 4d7565831..9b6986746 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -604,7 +604,7 @@ function photos_post(App $a) * they acquire comments, likes, dislikes, and/or tags */ - $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]); + $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > ?', $album, $page_owner_uid, DateTimeFormat::utc('now - 3 hours')]); if (!DBA::isResult($r) || ($album == DI::l10n()->t(Photo::PROFILE_PHOTOS))) { $visible = 1; diff --git a/mod/wallmessage.php b/mod/wallmessage.php index 3f9d24ac3..d4988aa0c 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -27,6 +27,7 @@ use Friendica\DI; use Friendica\Model\Mail; use Friendica\Model\Profile; use Friendica\Model\User; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; function wallmessage_post(App $a) { @@ -56,7 +57,7 @@ function wallmessage_post(App $a) { return; } - $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]); + $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]); if ($total > $user['cntunkmail']) { notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); return; @@ -110,7 +111,7 @@ function wallmessage_content(App $a) { return; } - $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]); + $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]); if ($total > $user['cntunkmail']) { notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); return; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 8dd1ece8e..7149dd9ce 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -754,7 +754,7 @@ class Worker } $stamp = (float)microtime(true); - $jobs = DBA::count('workerqueue', ["`done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ? MINUTE", $interval]); + $jobs = DBA::count('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $interval . ' minute')]); self::$db_duration += (microtime(true) - $stamp); self::$db_duration_stat += (microtime(true) - $stamp); $jobs_per_minute[$interval] = number_format($jobs / $interval, 0); diff --git a/src/Model/Item.php b/src/Model/Item.php index 50246553a..ca5e4bec0 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2258,8 +2258,8 @@ class Item $condition[] = $network; } - $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY"; - $condition[] = $days; + $condition[0] .= " AND `received` < ?"; + $condition[] = DateTimeFormat::utc('now - ' . $days . ' day'); $items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition); diff --git a/src/Model/PushSubscriber.php b/src/Model/PushSubscriber.php index 8593478de..400336970 100644 --- a/src/Model/PushSubscriber.php +++ b/src/Model/PushSubscriber.php @@ -54,7 +54,7 @@ class PushSubscriber { // We'll push to each subscriber that has push > 0, // i.e. there has been an update (set in notifier.php). - $subscribers = DBA::select('push_subscriber', ['id', 'push', 'callback_url', 'nickname'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]); + $subscribers = DBA::select('push_subscriber', ['id', 'push', 'callback_url', 'nickname'], ["`push` > 0 AND `next_try` < ?", DateTimeFormat::utcNow()]); while ($subscriber = DBA::fetch($subscribers)) { // We always handle retries with low priority diff --git a/src/Model/Tag.php b/src/Model/Tag.php index fb301d143..a61d0e785 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -29,6 +29,7 @@ use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; /** @@ -547,7 +548,7 @@ class Tag { // Get a uri-id that is at least X hours old. // We use the uri-id in the query for the hash tags since this is much faster - $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period], + $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')], ['order' => ['received' => true]]); if (empty($post['uri-id'])) { return []; @@ -600,7 +601,7 @@ class Tag { // Get a uri-id that is at least X hours old. // We use the uri-id in the query for the hash tags since this is much faster - $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period], + $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')], ['order' => ['received' => true]]); if (empty($post['uri-id'])) { return []; diff --git a/src/Module/OAuth/Token.php b/src/Module/OAuth/Token.php index d41708a09..efd4000f6 100644 --- a/src/Module/OAuth/Token.php +++ b/src/Module/OAuth/Token.php @@ -27,6 +27,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseApi; use Friendica\Security\OAuth; +use Friendica\Util\DateTimeFormat; /** * @see https://docs.joinmastodon.org/spec/oauth/ @@ -76,8 +77,8 @@ class Token extends BaseApi $token = OAuth::createTokenForUser($application, 0, ''); } elseif ($request['grant_type'] == 'authorization_code') { // For security reasons only allow freshly created tokens - $condition = ["`redirect_uri` = ? AND `id` = ? AND `code` = ? AND `created_at` > UTC_TIMESTAMP() - INTERVAL ? MINUTE", - $request['redirect_uri'], $application['id'], $request['code'], 5]; + $condition = ["`redirect_uri` = ? AND `id` = ? AND `code` = ? AND `created_at` > ?", + $request['redirect_uri'], $application['id'], $request['code'], DateTimeFormat::utc('now - 5 minutes')]; $token = DBA::selectFirst('application-view', ['access_token', 'created_at'], $condition); if (!DBA::isResult($token)) { diff --git a/src/Worker/CleanWorkerQueue.php b/src/Worker/CleanWorkerQueue.php index 15b0a4db1..b4fb92732 100644 --- a/src/Worker/CleanWorkerQueue.php +++ b/src/Worker/CleanWorkerQueue.php @@ -24,6 +24,7 @@ namespace Friendica\Worker; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Util\DateTimeFormat; /** * Delete all done workerqueue entries @@ -32,7 +33,7 @@ class CleanWorkerQueue { public static function execute() { - DBA::delete('workerqueue', ['`done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 1 HOUR']); + DBA::delete('workerqueue', ["`done` AND `executed` < ?", DateTimeFormat::utc('now - 1 hour')]); // Optimizing this table only last seconds if (DI::config()->get('system', 'optimize_tables')) { diff --git a/src/Worker/ExpireAndRemoveUsers.php b/src/Worker/ExpireAndRemoveUsers.php index c2da44d36..419069d30 100644 --- a/src/Worker/ExpireAndRemoveUsers.php +++ b/src/Worker/ExpireAndRemoveUsers.php @@ -25,6 +25,7 @@ use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Model\Photo; use Friendica\Model\User; +use Friendica\Util\DateTimeFormat; /** * Expire and remove user entries @@ -34,8 +35,8 @@ class ExpireAndRemoveUsers public static function execute() { // expire any expired regular accounts. Don't expire forums. - $condition = ["NOT `account_expired` AND `account_expires_on` > ? AND `account_expires_on` < UTC_TIMESTAMP() AND `page-flags` = ? AND `uid` != ?", - DBA::NULL_DATETIME, User::PAGE_FLAGS_NORMAL, 0]; + $condition = ["NOT `account_expired` AND `account_expires_on` > ? AND `account_expires_on` < ? AND `page-flags` = ? AND `uid` != ?", + DBA::NULL_DATETIME, DateTimeFormat::utcNow(), User::PAGE_FLAGS_NORMAL, 0]; DBA::update('user', ['account_expired' => true], $condition); // Ensure to never remove the user with uid=0 @@ -52,7 +53,7 @@ class ExpireAndRemoveUsers DBA::close($users); // delete user records for recently removed accounts - $users = DBA::select('user', ['uid'], ["`account_removed` AND `account_expires_on` < UTC_TIMESTAMP() AND `uid` != ?", 0]); + $users = DBA::select('user', ['uid'], ["`account_removed` AND `account_expires_on` < ? AND `uid` != ?", DateTimeFormat::utcNow(), 0]); while ($user = DBA::fetch($users)) { // We have to delete photo entries by hand because otherwise the photo data won't be deleted Photo::delete(['uid' => $user['uid']]); diff --git a/src/Worker/ExpireConversations.php b/src/Worker/ExpireConversations.php index f7aa593cf..019b4e108 100644 --- a/src/Worker/ExpireConversations.php +++ b/src/Worker/ExpireConversations.php @@ -23,6 +23,7 @@ namespace Friendica\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Util\DateTimeFormat; class ExpireConversations { @@ -36,6 +37,6 @@ class ExpireConversations return; } - DBA::delete('conversation', ["`received` < UTC_TIMESTAMP() - INTERVAL ? DAY", $days]); + DBA::delete('conversation', ["`received` < ?", DateTimeFormat::utc('now - ' . $days . ' days')]); } } diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 8d7b8c6ee..d1aa98d05 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -29,6 +29,7 @@ use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; +use Friendica\Util\DateTimeFormat; class ExpirePosts { @@ -67,7 +68,7 @@ class ExpirePosts { Logger::notice('Delete expired posts'); // physically remove anything that has been deleted for more than two months - $condition = ["`gravity` = ? AND `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY", GRAVITY_PARENT]; + $condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')]; $rows = Post::select(['guid', 'uri-id', 'uid'], $condition); while ($row = Post::fetch($rows)) { Logger::info('Delete expired item', ['uri-id' => $row['uri-id'], 'guid' => $row['guid']]); @@ -170,7 +171,7 @@ class ExpirePosts { // We have to avoid deleting newly created "item-uri" entries. // So we fetch a post that had been stored yesterday and only delete older ones. - $item = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1], + $item = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - 1 day')], ['order' => ['received' => true]]); if (empty($item['uri-id'])) { Logger::warning('No item with uri-id found - we better quit here'); @@ -222,7 +223,7 @@ class ExpirePosts if (!empty($expire_days)) { Logger::notice('Start collecting expired threads', ['expiry_days' => $expire_days]); $uris = DBA::select('item-uri', ['id'], ["`id` IN - (SELECT `uri-id` FROM `post-thread` WHERE `received` < UTC_TIMESTAMP() - INTERVAL ? DAY + (SELECT `uri-id` FROM `post-thread` WHERE `received` < ? AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-thread-user` WHERE (`mention` OR `starred` OR `wall` OR `pinned`) AND `uri-id` = `post-thread`.`uri-id`) AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-category` @@ -235,7 +236,7 @@ class ExpirePosts WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`) AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content` WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`))", - $expire_days, Item::PT_PERSONAL_NOTE]); + DateTimeFormat::utc('now - ' . (int)$expire_days . ' days'), Item::PT_PERSONAL_NOTE]); Logger::notice('Start deleting expired threads'); $affected_count = 0; @@ -252,12 +253,12 @@ class ExpirePosts if (!empty($expire_days_unclaimed)) { Logger::notice('Start collecting unclaimed public items', ['expiry_days' => $expire_days_unclaimed]); $uris = DBA::select('item-uri', ['id'], ["`id` IN - (SELECT `uri-id` FROM `post-user` WHERE `gravity` = ? AND `uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY + (SELECT `uri-id` FROM `post-user` WHERE `gravity` = ? AND `uid` = ? AND `received` < ? AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` != ? AND `i`.`parent-uri-id` = `post-user`.`uri-id`) AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` = ? - AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > UTC_TIMESTAMP() - INTERVAL ? DAY))", - GRAVITY_PARENT, 0, $expire_days_unclaimed, 0, 0, $expire_days_unclaimed]); + AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > ?))", + GRAVITY_PARENT, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days'), 0, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days')]); Logger::notice('Start deleting unclaimed public items'); $affected_count = 0; diff --git a/src/Worker/PollContacts.php b/src/Worker/PollContacts.php index da4ac2142..313a8c681 100644 --- a/src/Worker/PollContacts.php +++ b/src/Worker/PollContacts.php @@ -45,7 +45,7 @@ class PollContacts if (!empty($abandon_days)) { $condition = DBA::mergeConditions($condition, - ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `login_date` > UTC_TIMESTAMP() - INTERVAL ? DAY)", 0, $abandon_days]); + ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `login_date` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]); } else { $condition = DBA::mergeConditions($condition, ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`)", 0]); diff --git a/src/Worker/RemoveUnusedContacts.php b/src/Worker/RemoveUnusedContacts.php index f93e3eb50..1a184478a 100644 --- a/src/Worker/RemoveUnusedContacts.php +++ b/src/Worker/RemoveUnusedContacts.php @@ -26,6 +26,7 @@ use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Model\Photo; +use Friendica\Util\DateTimeFormat; /** * Removes public contacts that aren't in use @@ -35,13 +36,13 @@ class RemoveUnusedContacts public static function execute() { $condition = ["`id` != ? AND `uid` = ? AND NOT `self` AND NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` != ?) - AND (NOT `network` IN (?, ?, ?, ?, ?, ?) OR (`archive` AND `success_update` < UTC_TIMESTAMP() - INTERVAL ? DAY)) + AND (NOT `network` IN (?, ?, ?, ?, ?, ?) OR (`archive` AND `success_update` < ?)) AND NOT `id` IN (SELECT `author-id` FROM `post-user`) AND NOT `id` IN (SELECT `owner-id` FROM `post-user`) AND NOT `id` IN (SELECT `causer-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `post-tag`) AND NOT `id` IN (SELECT `contact-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `user-contact`) AND NOT `id` IN (SELECT `cid` FROM `event`) AND NOT `id` IN (SELECT `contact-id` FROM `group_member`) - AND `created` < UTC_TIMESTAMP() - INTERVAL ? DAY", - 0, 0, 0, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB, 365, 30]; + AND `created` < ?", + 0, 0, 0, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB, DateTimeFormat::utc('now - 365 days'), DateTimeFormat::utc('now - 30 days')]; $total = DBA::count('contact', $condition); Logger::notice('Starting removal', ['total' => $total]); diff --git a/src/Worker/UpdateGServers.php b/src/Worker/UpdateGServers.php index 38ab6e5d3..7581065d9 100644 --- a/src/Worker/UpdateGServers.php +++ b/src/Worker/UpdateGServers.php @@ -25,6 +25,7 @@ use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; class UpdateGServers @@ -47,7 +48,7 @@ class UpdateGServers } $total = DBA::count('gserver'); - $condition = ["`next_contact` < UTC_TIMESTAMP() AND (`nurl` != ? OR `url` != ?)", '', '']; + $condition = ["`next_contact` < ? AND (`nurl` != ? OR `url` != ?)", DateTimeFormat::utcNow(), '', '']; $outdated = DBA::count('gserver', $condition); Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]); From 423892b814f63d631997382f7d1112357ed070b0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Dec 2021 09:20:50 -0500 Subject: [PATCH 3/3] Replace references to NOW() in SQL queries with a DateTimeFormat generated parameter --- src/Core/Cache/Type/DatabaseCache.php | 2 +- src/Worker/ClearCache.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Core/Cache/Type/DatabaseCache.php b/src/Core/Cache/Type/DatabaseCache.php index ef6a30afe..55282a73e 100644 --- a/src/Core/Cache/Type/DatabaseCache.php +++ b/src/Core/Cache/Type/DatabaseCache.php @@ -146,7 +146,7 @@ class DatabaseCache extends AbstractCache implements ICanCache { try { if ($outdated) { - return $this->dba->delete('cache', ['`expires` < NOW()']); + return $this->dba->delete('cache', ['`expires` < ?', DateTimeFormat::utcNow()]); } else { return $this->dba->delete('cache', ['`k` IS NOT NULL ']); } diff --git a/src/Worker/ClearCache.php b/src/Worker/ClearCache.php index 33bf58947..80dc5ec8c 100644 --- a/src/Worker/ClearCache.php +++ b/src/Worker/ClearCache.php @@ -23,6 +23,7 @@ namespace Friendica\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Util\DateTimeFormat; /** * Clear cache entries @@ -31,15 +32,13 @@ class ClearCache { public static function execute() { - $a = DI::app(); - // clear old cache DI::cache()->clear(); // Delete the cached OEmbed entries that are older than three month - DBA::delete('oembed', ["`created` < NOW() - INTERVAL 3 MONTH"]); + DBA::delete('oembed', ["`created` < ?", DateTimeFormat::utc('now - 3 months')]); // Delete the cached "parsed_url" entries that are expired - DBA::delete('parsed_url', ["`expires` < NOW()"]); + DBA::delete('parsed_url', ["`expires` < ?", DateTimeFormat::utcNow()]); } }