Replace references to UTC_TIMESTAMP in SQL queries with a DateTimeFormat generated parameter
This commit is contained in:
parent
ecaed2a845
commit
80da47921e
14 changed files with 37 additions and 28 deletions
|
@ -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')) {
|
||||
|
|
|
@ -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']]);
|
||||
|
|
|
@ -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')]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue