From 982e607106a429d684c96a8549abe149b5efde19 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Tue, 13 Aug 2024 11:31:23 +0300 Subject: [PATCH] ~ Do not log CMS Update Found more than once per version Part 2: WordPress Signed-off-by: Nicholas K. Dionysopoulos --- src/Task/WordPressUpdateDirector.php | 76 ++++++++++++++++++---------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/src/Task/WordPressUpdateDirector.php b/src/Task/WordPressUpdateDirector.php index 7a041b46..ad1ed655 100644 --- a/src/Task/WordPressUpdateDirector.php +++ b/src/Task/WordPressUpdateDirector.php @@ -202,25 +202,6 @@ function (int $siteId) { // Get the site's configuration $siteConfig = $site->getConfig() ?? new Registry(); - // Log a report entry: we found an update for the site - try - { - Reports::fromCoreUpdateFound( - $site->getId(), - $siteConfig->get('core.current.version'), - $siteConfig->get('core.latest.version') - )->save(); - } - catch (\Throwable $e) - { - $this->logger->error( - sprintf( - 'Problem saving report log entry [%s:%s]: %d %s', - $e->getFile(), $e->getLine(), $e->getCode(), $e->getMessage() - ) - ); - } - // Process the update action for the site $updateAction = $siteConfig->get("config.core_update.install", '') ?: $this->container->appConfig->get('tasks_coreupdate_install', 'patch'); @@ -229,6 +210,14 @@ function (int $siteId) { switch ($updateAction) { case "none": + if (!$this->mustSchedule($site, true)) + { + continue 2; + } + + // Log a report entry: we found an update for the site + $this->logCoreUpdateFoundToSiteReports($site, $siteConfig); + $this->logger->info( sprintf( 'Site %d (%s) is configured to neither update, nor send emails.', @@ -246,14 +235,17 @@ function (int $siteId) { continue 2; } + // Log a report entry: we found an update for the site + $this->logCoreUpdateFoundToSiteReports($site, $siteConfig); + $this->logger->info( - sprintf( - 'Site %d (%s) is configured to only send an email about WordPress %s availability.', - $id, - $site->name, - $siteConfig->get('core.latest.version') - ) - ); + sprintf( + 'Site %d (%s) is configured to only send an email about WordPress %s availability.', + $id, + $site->name, + $siteConfig->get('core.latest.version') + ) + ); $this->sendEmail('wordpressupdate_found', $site); break; @@ -274,6 +266,9 @@ function (int $siteId) { ) ); + // Log a report entry: we found an update for the site + $this->logCoreUpdateFoundToSiteReports($site, $siteConfig); + // Send email $this->sendEmail('wordpressupdate_will_install', $site); @@ -460,4 +455,33 @@ function (Site $site) use ($latestVersion) { return true; } + /** + * Add a Site Reports log entry about finding a new CMS version. + * + * @param Site $site + * @param Registry $siteConfig + * + * @return void + * @since 1.2.2 + */ + private function logCoreUpdateFoundToSiteReports(Site $site, Registry $siteConfig): void + { + try + { + Reports::fromCoreUpdateFound( + $site->getId(), + $siteConfig->get('core.current.version'), + $siteConfig->get('core.latest.version') + )->save(); + } + catch (\Throwable $e) + { + $this->logger->error( + sprintf( + 'Problem saving report log entry [%s:%s]: %d %s', + $e->getFile(), $e->getLine(), $e->getCode(), $e->getMessage() + ) + ); + } + } }