Skip to content

Commit

Permalink
Don't run cron or cache clears on a site with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
apotek committed Oct 31, 2024
1 parent 368421d commit fea1674
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/Robo/Plugin/Commands/DevelopmentModeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ public function databaseRefreshDdev(
$dbPathProvidedByUser = $dbPath !== '';

if (!$dbPathProvidedByUser) {
$dbPath = $this->databaseDownload($io, $siteName);
try {
$dbPath = $this->databaseDownload($io, $siteName);
} catch (TaskException $e) {
$resultData = new ResultData(ResultData::EXITCODE_ERROR, $e->getMessage());
$io->yell("$siteName: No database configured. Download/import skipped.");
// @todo: Should we run a site-install by default? The "common"
// site ends up here, but we could change that.
return $resultData;
}
// If we don't have a file path string here, the action was
// cancelled and we should respond with the cancellation.
if (!is_string($dbPath)) {
Expand Down Expand Up @@ -195,7 +203,8 @@ public function databaseRefreshTugboat(ConsoleIO $io): ResultData
} catch (TaskException $e) {
$io->yell("$siteName: No database configured. Download/import skipped.");
$resultData->append($e->getMessage());
// @todo: Should we run a site-install by default?
// @todo: Should we run a site-install by default? The "common"
// site ends up here, but we could change that.
continue;
}
if (!is_string($dbPath) || $dbPath === '') {
Expand Down Expand Up @@ -316,7 +325,7 @@ protected function devRefreshDrupal(
$this->frontendDevEnable($io, $siteName, ['yes' => true]);
/** @var Result|ResultData $result */
$result = $this->databaseRefreshDdev($io, siteName: $siteName, options: ['db' => $databasePath]);
if ($result->wasCancelled()) {
if ($result->wasCancelled() || $result->getExitCode() !== ResultData::EXITCODE_OK) {
return $result;
}

Expand Down
24 changes: 21 additions & 3 deletions src/Robo/Plugin/Traits/SitesConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ trait SitesConfigTrait
*/
public function getAllSitesConfig(): mixed
{
if (!file_exists($this->sitesConfigFile)) {
throw new TaskException($this, "$this->sitesConfigFile not found.");
static $allSitesConfig = null;
if (is_null($allSitesConfig)) {
if (!file_exists($this->sitesConfigFile)) {
throw new TaskException($this, "$this->sitesConfigFile not found.");
}
$allSitesConfig = Yaml::parseFile($this->sitesConfigFile);
}
return Yaml::parseFile($this->sitesConfigFile);
return $allSitesConfig;
}

/**
Expand Down Expand Up @@ -108,6 +112,20 @@ public function getSiteConfigItem(string $key, string $siteName = 'default', boo
return $siteConfig[$key];
}

/**
* Check if a site has an S3 bucket/has data.
*
* @throws \Robo\Exception\TaskException
*/
protected function hasData(string $siteName = 'default'): bool
{
$db = $this->getSiteConfigItem(
key: 'database_s3_bucket',
siteName: $siteName
);
return (is_string($db) && mb_strlen($db));
}

/**
* Write sites configuration file.
*
Expand Down

0 comments on commit fea1674

Please sign in to comment.