Replace Logger with DI::logger() in Remove Worker classes

This commit is contained in:
Art4 2025-01-13 13:13:50 +00:00
parent c90b485089
commit 1762d1e72d
4 changed files with 23 additions and 25 deletions

View file

@ -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;
}

View file

@ -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]);

View file

@ -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]);
}
}

View file

@ -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());
}
}