From 1762d1e72d741b41d64b5884da76dc6f40a84d5a Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 13 Jan 2025 13:13:50 +0000 Subject: [PATCH] Replace Logger with DI::logger() in Remove Worker classes --- src/Worker/Contact/Remove.php | 4 ++-- src/Worker/Contact/RemoveContent.php | 3 +-- src/Worker/RemoveUnusedAvatars.php | 24 ++++++++++++------------ src/Worker/RemoveUnusedContacts.php | 17 ++++++++--------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/Worker/Contact/Remove.php b/src/Worker/Contact/Remove.php index 870edbb502..d9c4c96a41 100644 --- a/src/Worker/Contact/Remove.php +++ b/src/Worker/Contact/Remove.php @@ -7,8 +7,8 @@ namespace Friendica\Worker\Contact; -use Friendica\Core\Logger; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; /** @@ -29,7 +29,7 @@ class Remove extends RemoveContent } $ret = Contact::deleteById($id); - Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]); + DI::logger()->info('Deleted contact', ['id' => $id, 'result' => $ret]); return true; } diff --git a/src/Worker/Contact/RemoveContent.php b/src/Worker/Contact/RemoveContent.php index 5aea6f8e63..762ff7a6d4 100644 --- a/src/Worker/Contact/RemoveContent.php +++ b/src/Worker/Contact/RemoveContent.php @@ -7,7 +7,6 @@ namespace Friendica\Worker\Contact; -use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; @@ -25,7 +24,7 @@ class RemoveContent return false; } - Logger::info('Start deleting contact content', ['cid' => $id]); + DI::logger()->info('Start deleting contact content', ['cid' => $id]); // Now we delete the contact and all depending tables DBA::delete('post-tag', ['cid' => $id]); diff --git a/src/Worker/RemoveUnusedAvatars.php b/src/Worker/RemoveUnusedAvatars.php index a6426be115..8cebde12d2 100644 --- a/src/Worker/RemoveUnusedAvatars.php +++ b/src/Worker/RemoveUnusedAvatars.php @@ -8,8 +8,8 @@ namespace Friendica\Worker; use Friendica\Contact\Avatar; -use Friendica\Core\Logger; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Photo; @@ -32,7 +32,7 @@ class RemoveUnusedAvatars ]; $total = DBA::count('contact', $condition); - Logger::notice('Starting removal', ['total' => $total]); + DI::logger()->notice('Starting removal', ['total' => $total]); $count = 0; $contacts = DBA::select('contact', ['id', 'uri-id', 'uid', 'photo', 'thumb', 'micro'], $condition); while ($contact = DBA::fetch($contacts)) { @@ -40,11 +40,11 @@ class RemoveUnusedAvatars Contact::update(['photo' => '', 'thumb' => '', 'micro' => ''], ['id' => $contact['id']]); } if ((++$count % 1000) == 0) { - Logger::info('In removal', ['count' => $count, 'total' => $total]); + DI::logger()->info('In removal', ['count' => $count, 'total' => $total]); } } DBA::close($contacts); - Logger::notice('Removal done', ['count' => $count, 'total' => $total]); + DI::logger()->notice('Removal done', ['count' => $count, 'total' => $total]); self::fixPhotoContacts(); self::deleteDuplicates(); @@ -56,7 +56,7 @@ class RemoveUnusedAvatars $deleted = 0; $updated1 = 0; $updated2 = 0; - Logger::notice('Starting contact fix'); + DI::logger()->notice('Starting contact fix'); $photos = DBA::select('photo', [], ["`uid` = ? AND `contact-id` IN (SELECT `id` FROM `contact` WHERE `uid` != ?) AND `contact-id` != ? AND `scale` IN (?, ?, ?)", 0, 0, 0, 4, 5, 6]); while ($photo = DBA::fetch($photos)) { $total++; @@ -65,7 +65,7 @@ class RemoveUnusedAvatars if ($photo['resource-id'] == $resource) { $contact = DBA::selectFirst('contact', [], ['nurl' => $photo_contact['nurl'], 'uid' => 0]); if (!empty($contact['photo']) && ($contact['photo'] == $photo_contact['photo'])) { - Logger::notice('Photo updated to public user', ['id' => $photo['id'], 'contact-id' => $contact['id']]); + DI::logger()->notice('Photo updated to public user', ['id' => $photo['id'], 'contact-id' => $contact['id']]); DBA::update('photo', ['contact-id' => $contact['id']], ['id' => $photo['id']]); $updated1++; } @@ -74,7 +74,7 @@ class RemoveUnusedAvatars $contacts = DBA::select('contact', [], ['nurl' => $photo_contact['nurl']]); while ($contact = DBA::fetch($contacts)) { if ($photo['resource-id'] == Photo::ridFromURI($contact['photo'])) { - Logger::notice('Photo updated to given user', ['id' => $photo['id'], 'contact-id' => $contact['id'], 'uid' => $contact['uid']]); + DI::logger()->notice('Photo updated to given user', ['id' => $photo['id'], 'contact-id' => $contact['id'], 'uid' => $contact['uid']]); DBA::update('photo', ['contact-id' => $contact['id'], 'uid' => $contact['uid']], ['id' => $photo['id']]); $updated = true; $updated2++; @@ -82,14 +82,14 @@ class RemoveUnusedAvatars } DBA::close($contacts); if (!$updated) { - Logger::notice('Photo deleted', ['id' => $photo['id']]); + DI::logger()->notice('Photo deleted', ['id' => $photo['id']]); Photo::delete(['id' => $photo['id']]); $deleted++; } } } DBA::close($photos); - Logger::notice('Contact fix done', ['total' => $total, 'updated1' => $updated1, 'updated2' => $updated2, 'deleted' => $deleted]); + DI::logger()->notice('Contact fix done', ['total' => $total, 'updated1' => $updated1, 'updated2' => $updated2, 'deleted' => $deleted]); } private static function deleteDuplicates() @@ -98,20 +98,20 @@ class RemoveUnusedAvatars $total = 0; $deleted = 0; - Logger::notice('Starting duplicate removal'); + DI::logger()->notice('Starting duplicate removal'); $photos = DBA::p("SELECT `photo`.`id`, `photo`.`uid`, `photo`.`scale`, `photo`.`album`, `photo`.`contact-id`, `photo`.`resource-id`, `contact`.`photo`, `contact`.`thumb`, `contact`.`micro` FROM `photo` INNER JOIN `contact` ON `contact`.`id` = `photo`.`contact-id` and `photo`.`contact-id` != ? AND `photo`.`scale` IN (?, ?, ?)", 0, 4, 5, 6); while ($photo = DBA::fetch($photos)) { $resource = Photo::ridFromURI($photo[$size[$photo['scale']]]); if ($resource != $photo['resource-id'] && !empty($resource)) { $total++; if (DBA::exists('photo', ['resource-id' => $resource, 'scale' => $photo['scale']])) { - Logger::notice('Photo deleted', ['id' => $photo['id']]); + DI::logger()->notice('Photo deleted', ['id' => $photo['id']]); Photo::delete(['id' => $photo['id']]); $deleted++; } } } DBA::close($photos); - Logger::notice('Duplicate removal done', ['total' => $total, 'deleted' => $deleted]); + DI::logger()->notice('Duplicate removal done', ['total' => $total, 'deleted' => $deleted]); } } diff --git a/src/Worker/RemoveUnusedContacts.php b/src/Worker/RemoveUnusedContacts.php index 9ee7390ca9..3419b69421 100644 --- a/src/Worker/RemoveUnusedContacts.php +++ b/src/Worker/RemoveUnusedContacts.php @@ -8,7 +8,6 @@ namespace Friendica\Worker; use Friendica\Contact\Avatar; -use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -27,21 +26,21 @@ class RemoveUnusedContacts { $loop = 0; while (self::removeContacts(++$loop)) { - Logger::info('In removal', ['loop' => $loop]); + DI::logger()->info('In removal', ['loop' => $loop]); } - Logger::notice('Remove apcontact entries with no related contact'); + DI::logger()->notice('Remove apcontact entries with no related contact'); DBA::delete('apcontact', ["`uri-id` NOT IN (SELECT `uri-id` FROM `contact`) AND `updated` < ?", DateTimeFormat::utc('now - 30 days')]); - Logger::notice('Removed apcontact entries with no related contact', ['count' => DBA::affectedRows()]); + DI::logger()->notice('Removed apcontact entries with no related contact', ['count' => DBA::affectedRows()]); - Logger::notice('Remove diaspora-contact entries with no related contact'); + DI::logger()->notice('Remove diaspora-contact entries with no related contact'); DBA::delete('diaspora-contact', ["`uri-id` NOT IN (SELECT `uri-id` FROM `contact`) AND `updated` < ?", DateTimeFormat::utc('now - 30 days')]); - Logger::notice('Removed diaspora-contact entries with no related contact', ['count' => DBA::affectedRows()]); + DI::logger()->notice('Removed diaspora-contact entries with no related contact', ['count' => DBA::affectedRows()]); } public static function removeContacts(int $loop): bool { - Logger::notice('Starting removal', ['loop' => $loop]); + DI::logger()->notice('Starting removal', ['loop' => $loop]); $condition = [ "`id` != ? AND `uid` = ? AND NOT `self` AND NOT `uri-id` IN (SELECT `uri-id` FROM `contact` WHERE `uid` != ?) @@ -64,7 +63,7 @@ class RemoveUnusedContacts "(NOT `network` IN (?, ?, ?, ?, ?, ?) OR `archive`)", Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB ]; - + $condition = DBA::mergeConditions($condition2, $condition); } @@ -102,7 +101,7 @@ class RemoveUnusedContacts Contact::deleteById($contact['id']); } DBA::close($contacts); - Logger::notice('Removal done', ['count' => $count]); + DI::logger()->notice('Removal done', ['count' => $count]); return ($count == 1000 && Worker::isInMaintenanceWindow()); } }