Skip to content

Commit

Permalink
~ Do not log CMS Update Found more than once per version
Browse files Browse the repository at this point in the history
Part 2: WordPress

Signed-off-by: Nicholas K. Dionysopoulos <nicholas@akeeba.com>
  • Loading branch information
nikosdion committed Aug 13, 2024
1 parent 0c3e298 commit 982e607
Showing 1 changed file with 50 additions and 26 deletions.
76 changes: 50 additions & 26 deletions src/Task/WordPressUpdateDirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.',
Expand All @@ -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;
Expand All @@ -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);

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

0 comments on commit 982e607

Please sign in to comment.