From bcf784254f7c7592027c66e0d40011d0a54f7e3d Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 13 Jan 2025 13:06:00 +0000 Subject: [PATCH] Replace Logger with DI::logger() in Expire Worker classes --- src/Worker/Expire.php | 17 ++++--- src/Worker/ExpireAndRemoveUsers.php | 42 ++++++++--------- src/Worker/ExpirePosts.php | 73 ++++++++++++++--------------- 3 files changed, 65 insertions(+), 67 deletions(-) diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index baaef454ff..77a37e4b5f 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -8,7 +8,6 @@ namespace Friendica\Worker; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; @@ -28,39 +27,39 @@ class Expire if (intval($param) > 0) { $user = DBA::selectFirst('user', ['uid', 'username', 'expire'], ['uid' => $param]); if (DBA::isResult($user)) { - Logger::info('Expire items', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]); + DI::logger()->info('Expire items', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]); $expired = Item::expire($user['uid'], $user['expire']); - Logger::info('Expire items done', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire'], 'expired' => $expired]); + DI::logger()->info('Expire items done', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire'], 'expired' => $expired]); } return; } elseif ($param == 'hook' && !empty($hook_function)) { foreach (Hook::getByName('expire') as $hook) { if ($hook[1] == $hook_function) { - Logger::info('Calling expire hook', ['hook' => $hook[1]]); + DI::logger()->info('Calling expire hook', ['hook' => $hook[1]]); Hook::callSingle('expire', $hook, $data); } } return; } - Logger::notice('start expiry'); + DI::logger()->notice('start expiry'); $r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]); while ($row = DBA::fetch($r)) { - Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]); + DI::logger()->info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]); Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true], 'Expire', (int)$row['uid']); } DBA::close($r); - Logger::notice('calling hooks'); + DI::logger()->notice('calling hooks'); foreach (Hook::getByName('expire') as $hook) { - Logger::info('Calling expire', ['hook' => $hook[1]]); + DI::logger()->info('Calling expire', ['hook' => $hook[1]]); Worker::add(['priority' => $appHelper->getQueueValue('priority'), 'created' => $appHelper->getQueueValue('created'), 'dont_fork' => true], 'Expire', 'hook', $hook[1]); } - Logger::notice('calling hooks done'); + DI::logger()->notice('calling hooks done'); return; } diff --git a/src/Worker/ExpireAndRemoveUsers.php b/src/Worker/ExpireAndRemoveUsers.php index 0679f9fdab..816475e8ee 100644 --- a/src/Worker/ExpireAndRemoveUsers.php +++ b/src/Worker/ExpireAndRemoveUsers.php @@ -7,9 +7,9 @@ namespace Friendica\Worker; -use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Model\User; @@ -45,21 +45,21 @@ class ExpireAndRemoveUsers while ($user = DBA::fetch($users)) { $pcid = Contact::getPublicIdByUserId($user['uid']); - Logger::info('Removing user - start', ['uid' => $user['uid'], 'pcid' => $pcid]); + DI::logger()->info('Removing user - start', ['uid' => $user['uid'], 'pcid' => $pcid]); // We have to delete photo entries by hand because otherwise the photo data won't be deleted $result = Photo::delete(['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted user photos', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted user photos', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting user photos', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting user photos', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } if (!empty($pcid)) { $result = DBA::delete('post-tag', ['cid' => $pcid]); if ($result) { - Logger::debug('Deleted post-tag entries', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted post-tag entries', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting post-tag entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting post-tag entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } $tables = ['post', 'post-user', 'post-thread', 'post-thread-user']; @@ -73,9 +73,9 @@ class ExpireAndRemoveUsers foreach (['owner-id', 'author-id', 'causer-id'] as $field) { $result = DBA::delete($table, [$field => $pcid]); if ($result) { - Logger::debug('Deleted entries', ['table' => $table, 'field' => $field, 'result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted entries', ['table' => $table, 'field' => $field, 'result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting entries', ['table' => $table, 'field' => $field, 'errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting entries', ['table' => $table, 'field' => $field, 'errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } } } @@ -86,18 +86,18 @@ class ExpireAndRemoveUsers if (DBA::isResult($self)) { $result = DBA::delete('contact', ['nurl' => $self['nurl'], 'self' => false]); if ($result) { - Logger::debug('Deleted the user contact for other users', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted the user contact for other users', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting the user contact for other users', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting the user contact for other users', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } } // Delete all contacts of this user $result = DBA::delete('contact', ['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted user contacts', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted user contacts', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting user contacts', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting user contacts', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } // These tables contain the permissionset which will also be deleted when a user is deleted. @@ -107,33 +107,33 @@ class ExpireAndRemoveUsers if (DBStructure::existsTable('item')) { $result = DBA::delete('item', ['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted user items', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted user items', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting user items', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting user items', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } } $result = DBA::delete('post-user', ['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted post-user entries', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted post-user entries', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting post-user entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting post-user entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } $result = DBA::delete('profile_field', ['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted profile_field entries', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted profile_field entries', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting profile_field entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting profile_field entries', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } $result = DBA::delete('user', ['uid' => $user['uid']]); if ($result) { - Logger::debug('Deleted user record', ['result' => $result, 'rows' => DBA::affectedRows()]); + DI::logger()->debug('Deleted user record', ['result' => $result, 'rows' => DBA::affectedRows()]); } else { - Logger::warning('Error deleting user record', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); + DI::logger()->warning('Error deleting user record', ['errno' => DBA::errorNo(), 'errmsg' => DBA::errorMessage()]); } - Logger::info('Removing user - done', ['uid' => $user['uid']]); + DI::logger()->info('Removing user - done', ['uid' => $user['uid']]); } DBA::close($users); } diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php index 74a11687e8..e1c8fe1685 100644 --- a/src/Worker/ExpirePosts.php +++ b/src/Worker/ExpirePosts.php @@ -7,7 +7,6 @@ namespace Friendica\Worker; -use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\Database; use Friendica\Database\DBA; @@ -27,36 +26,36 @@ class ExpirePosts */ public static function execute() { - Logger::notice('Expire posts - start'); + DI::logger()->notice('Expire posts - start'); if (!DBA::acquireOptimizeLock()) { - Logger::warning('Lock could not be acquired'); + DI::logger()->warning('Lock could not be acquired'); Worker::defer(); return; } - Logger::notice('Expire posts - Delete expired origin posts'); + DI::logger()->notice('Expire posts - Delete expired origin posts'); self::deleteExpiredOriginPosts(); - Logger::notice('Expire posts - Delete orphaned entries'); + DI::logger()->notice('Expire posts - Delete orphaned entries'); self::deleteOrphanedEntries(); - Logger::notice('Expire posts - delete external posts'); + DI::logger()->notice('Expire posts - delete external posts'); self::deleteExpiredExternalPosts(); if (DI::config()->get('system', 'add_missing_posts')) { - Logger::notice('Expire posts - add missing posts'); + DI::logger()->notice('Expire posts - add missing posts'); self::addMissingEntries(); } - Logger::notice('Expire posts - delete unused attachments'); + DI::logger()->notice('Expire posts - delete unused attachments'); self::deleteUnusedAttachments(); - Logger::notice('Expire posts - delete unused item-uri entries'); + DI::logger()->notice('Expire posts - delete unused item-uri entries'); self::deleteUnusedItemUri(); DBA::releaseOptimizeLock(); - Logger::notice('Expire posts - done'); + DI::logger()->notice('Expire posts - done'); } /** @@ -71,7 +70,7 @@ class ExpirePosts return; } - Logger::notice('Delete expired posts'); + DI::logger()->notice('Delete expired posts'); // physically remove anything that has been deleted for more than two months $condition = ["`gravity` = ? AND `deleted` AND `edited` < ?", Item::GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')]; $pass = 0; @@ -80,7 +79,7 @@ class ExpirePosts $rows = DBA::select('post-user', ['uri-id', 'uid'], $condition, ['limit' => $limit]); $affected_count = 0; while ($row = Post::fetch($rows)) { - Logger::info('Delete expired item', ['pass' => $pass, 'uri-id' => $row['uri-id']]); + DI::logger()->info('Delete expired item', ['pass' => $pass, 'uri-id' => $row['uri-id']]); Post\User::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]); $affected_count += DBA::affectedRows(); Post\Origin::delete(['parent-uri-id' => $row['uri-id'], 'uid' => $row['uid']]); @@ -88,7 +87,7 @@ class ExpirePosts } DBA::close($rows); DBA::commit(); - Logger::notice('Delete expired posts - done', ['pass' => $pass, 'rows' => $affected_count]); + DI::logger()->notice('Delete expired posts - done', ['pass' => $pass, 'rows' => $affected_count]); } while ($affected_count); } @@ -99,7 +98,7 @@ class ExpirePosts */ private static function deleteOrphanedEntries() { - Logger::notice('Delete orphaned entries'); + DI::logger()->notice('Delete orphaned entries'); // "post-user" is the leading table. So we delete every entry that isn't found there $tables = ['item', 'post', 'post-content', 'post-thread', 'post-thread-user']; @@ -108,10 +107,10 @@ class ExpirePosts continue; } - Logger::notice('Start collecting orphaned entries', ['table' => $table]); + DI::logger()->notice('Start collecting orphaned entries', ['table' => $table]); $uris = DBA::select($table, ['uri-id'], ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user`)"]); $affected_count = 0; - Logger::notice('Deleting orphaned entries - start', ['table' => $table]); + DI::logger()->notice('Deleting orphaned entries - start', ['table' => $table]); while ($rows = DBA::toArray($uris, false, 100)) { $ids = array_column($rows, 'uri-id'); DBA::delete($table, ['uri-id' => $ids]); @@ -119,9 +118,9 @@ class ExpirePosts } DBA::close($uris); DBA::commit(); - Logger::notice('Orphaned entries deleted', ['table' => $table, 'rows' => $affected_count]); + DI::logger()->notice('Orphaned entries deleted', ['table' => $table, 'rows' => $affected_count]); } - Logger::notice('Delete orphaned entries - done'); + DI::logger()->notice('Delete orphaned entries - done'); } /** @@ -131,7 +130,7 @@ class ExpirePosts */ private static function addMissingEntries() { - Logger::notice('Adding missing entries'); + DI::logger()->notice('Adding missing entries'); $rows = 0; $userposts = DBA::select('post-user', [], ["`uri-id` not in (select `uri-id` from `post`)"]); @@ -142,9 +141,9 @@ class ExpirePosts } DBA::close($userposts); if ($rows > 0) { - Logger::notice('Added post entries', ['rows' => $rows]); + DI::logger()->notice('Added post entries', ['rows' => $rows]); } else { - Logger::notice('No post entries added'); + DI::logger()->notice('No post entries added'); } $rows = 0; @@ -157,9 +156,9 @@ class ExpirePosts } DBA::close($userposts); if ($rows > 0) { - Logger::notice('Added post-thread entries', ['rows' => $rows]); + DI::logger()->notice('Added post-thread entries', ['rows' => $rows]); } else { - Logger::notice('No post-thread entries added'); + DI::logger()->notice('No post-thread entries added'); } $rows = 0; @@ -172,9 +171,9 @@ class ExpirePosts } DBA::close($userposts); if ($rows > 0) { - Logger::notice('Added post-thread-user entries', ['rows' => $rows]); + DI::logger()->notice('Added post-thread-user entries', ['rows' => $rows]); } else { - Logger::notice('No post-thread-user entries added'); + DI::logger()->notice('No post-thread-user entries added'); } } @@ -196,10 +195,10 @@ class ExpirePosts ['order' => ['received' => true]] ); if (empty($item['uri-id'])) { - Logger::warning('No item with uri-id found - we better quit here'); + DI::logger()->warning('No item with uri-id found - we better quit here'); return; } - Logger::notice('Start collecting orphaned URI-ID', ['last-id' => $item['uri-id']]); + DI::logger()->notice('Start collecting orphaned URI-ID', ['last-id' => $item['uri-id']]); $condition = [ "`id` < ? AND NOT EXISTS(SELECT `uri-id` FROM `post-user` WHERE `uri-id` = `item-uri`.`id`) @@ -226,17 +225,17 @@ class ExpirePosts ++$pass; $uris = DBA::select('item-uri', ['id'], $condition, ['limit' => $limit]); $total = DBA::numRows($uris); - Logger::notice('Start deleting orphaned URI-ID', ['pass' => $pass, 'last-id' => $item['uri-id']]); + DI::logger()->notice('Start deleting orphaned URI-ID', ['pass' => $pass, 'last-id' => $item['uri-id']]); $affected_count = 0; while ($rows = DBA::toArray($uris, false, 100)) { $ids = array_column($rows, 'id'); DBA::delete('item-uri', ['id' => $ids]); $affected_count += DBA::affectedRows(); - Logger::debug('Deleted', ['pass' => $pass, 'affected_count' => $affected_count, 'total' => $total]); + DI::logger()->debug('Deleted', ['pass' => $pass, 'affected_count' => $affected_count, 'total' => $total]); } DBA::close($uris); DBA::commit(); - Logger::notice('Orphaned URI-ID entries removed', ['pass' => $pass, 'rows' => $affected_count]); + DI::logger()->notice('Orphaned URI-ID entries removed', ['pass' => $pass, 'rows' => $affected_count]); } while ($affected_count); } @@ -257,7 +256,7 @@ class ExpirePosts } if (!empty($expire_days)) { - Logger::notice('Start collecting expired threads', ['expiry_days' => $expire_days]); + DI::logger()->notice('Start collecting expired threads', ['expiry_days' => $expire_days]); $condition = [ "`received` < ? AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-thread-user` @@ -281,7 +280,7 @@ class ExpirePosts ++$pass; $uris = DBA::select('post-thread', ['uri-id'], $condition, ['limit' => $limit]); - Logger::notice('Start deleting expired threads', ['pass' => $pass]); + DI::logger()->notice('Start deleting expired threads', ['pass' => $pass]); $affected_count = 0; while ($rows = DBA::toArray($uris, false, 100)) { $ids = array_column($rows, 'uri-id'); @@ -290,12 +289,12 @@ class ExpirePosts } DBA::close($uris); DBA::commit(); - Logger::notice('Deleted expired threads', ['pass' => $pass, 'rows' => $affected_count]); + DI::logger()->notice('Deleted expired threads', ['pass' => $pass, 'rows' => $affected_count]); } while ($affected_count); } if (!empty($expire_days_unclaimed)) { - Logger::notice('Start collecting unclaimed public items', ['expiry_days' => $expire_days_unclaimed]); + DI::logger()->notice('Start collecting unclaimed public items', ['expiry_days' => $expire_days_unclaimed]); $condition = [ "`gravity` = ? AND `uid` = ? AND `received` < ? AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` != ? @@ -309,17 +308,17 @@ class ExpirePosts ++$pass; $uris = DBA::select('post-user', ['uri-id'], $condition, ['limit' => $limit]); $total = DBA::numRows($uris); - Logger::notice('Start deleting unclaimed public items', ['pass' => $pass]); + DI::logger()->notice('Start deleting unclaimed public items', ['pass' => $pass]); $affected_count = 0; while ($rows = DBA::toArray($uris, false, 100)) { $ids = array_column($rows, 'uri-id'); DBA::delete('item-uri', ['id' => $ids]); $affected_count += DBA::affectedRows(); - Logger::debug('Deleted', ['pass' => $pass, 'affected_count' => $affected_count, 'total' => $total]); + DI::logger()->debug('Deleted', ['pass' => $pass, 'affected_count' => $affected_count, 'total' => $total]); } DBA::close($uris); DBA::commit(); - Logger::notice('Deleted unclaimed public items', ['pass' => $pass, 'rows' => $affected_count]); + DI::logger()->notice('Deleted unclaimed public items', ['pass' => $pass, 'rows' => $affected_count]); } while ($affected_count); } }