Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Check cr:status in health check and adjust to site:importAll #16

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions Classes/Infrastructure/Healthcheck/CrHealthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace Neos\Neos\Setup\Infrastructure\Healthcheck;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepositoryRegistry\Exception\InvalidConfigurationException;
use Neos\Setup\Domain\Health;
use Neos\Setup\Domain\HealthcheckEnvironment;
use Neos\Setup\Domain\HealthcheckInterface;
Expand All @@ -15,8 +14,7 @@
class CrHealthcheck implements HealthcheckInterface
{
public function __construct(
private Connection $dbalConnection,
private ConfigurationManager $configurationManager
private ContentRepositoryRegistry $contentRepositoryRegistry
) {
}

Expand All @@ -27,11 +25,8 @@ public function getTitle(): string

public function execute(HealthcheckEnvironment $environment): Health
{
// TODO: Implement execute() method.

$crIdentifiers = array_keys(
$this->configurationManager
->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepositoryRegistry.contentRepositories') ?? []
$crIdentifiers = iterator_to_array(
$this->contentRepositoryRegistry->getContentRepositoryIds()
);

if (count($crIdentifiers) === 0) {
Expand All @@ -41,33 +36,32 @@ public function execute(HealthcheckEnvironment $environment): Health
);
}

$schemaManager = $this->dbalConnection->getSchemaManager();
if (!$schemaManager instanceof AbstractSchemaManager) {
throw new \RuntimeException('Failed to retrieve Schema Manager', 1691250062732);
}

$existingTableNames = $schemaManager->listTableNames();

$unSetupContentRepositories = [];
foreach ($crIdentifiers as $crIdentifier) {
$eventTableName = sprintf('cr_%s_events', $crIdentifier);

$isCrSetup = in_array($eventTableName, $existingTableNames, true);
if (!$isCrSetup) {
try {
$cr = $this->contentRepositoryRegistry->get($crIdentifier);
} catch (InvalidConfigurationException $e) {
return new Health(
sprintf('Content repository %s is invalid configured%s', $crIdentifier->value, $environment->isSafeToLeakTechnicalDetails() ? ': ' . $e->getMessage() : ''),
Status::ERROR(),
);
}
$crStatus = $cr->status();
if (!$crStatus->isOk()) {
$unSetupContentRepositories[] = $crIdentifier;
}
}

if (count($crIdentifiers) === count($unSetupContentRepositories)) {
$rest = $unSetupContentRepositories;
$first = array_shift($rest);
$additionalNote = sprintf(' or setup %s.', join(' or ', $rest));
$additionalNote = count($rest) ? sprintf(' or with %s.', join(' or ', $rest)) : '';

return new Health(
sprintf(
'No content repository is setup. Please run <code>{{flowCommand}} cr:setup%s</code>%s',
'<code>{{flowCommand}} cr:status</code> reported a problem. Please run <code>{{flowCommand}} cr:setup%s</code>%s',
$environment->isSafeToLeakTechnicalDetails() ? ' --content-repository ' . $first : '',
$environment->isSafeToLeakTechnicalDetails() && count($rest) ? $additionalNote : ''
$environment->isSafeToLeakTechnicalDetails() ? $additionalNote : ''
),
Status::ERROR(),
);
Expand All @@ -76,21 +70,19 @@ public function execute(HealthcheckEnvironment $environment): Health
if (count($unSetupContentRepositories)) {
$rest = $unSetupContentRepositories;
$first = array_shift($rest);
$additionalNote = sprintf(' or setup %s.', join(' or ', $rest));
$additionalNote = count($rest) ? sprintf(' or with %s.', join(' or ', $rest)) : '';

return new Health(
sprintf(
'%s Please run <code>{{flowCommand}} cr:setup%s</code>%s',
count($unSetupContentRepositories) > 1 ? 'Some content repositories are not setup.' : 'A content repository is not setup.',
'<code>{{flowCommand}} cr:status</code> reported a problem.',
$environment->isSafeToLeakTechnicalDetails() ? ' --content-repository ' . $first : '',
$environment->isSafeToLeakTechnicalDetails() && count($rest) ? $additionalNote : ''
$environment->isSafeToLeakTechnicalDetails() ? $additionalNote : ''
),
Status::WARNING(),
);
}

// TODO check if `cr:setup` needs to be rerun, to "migrate" projections?

if (count($crIdentifiers) === 1) {
return new Health(
sprintf('Content repository %sis setup.', $environment->isSafeToLeakTechnicalDetails() ? sprintf('"%s" ', $crIdentifiers[0]) : ''),
Expand Down
29 changes: 10 additions & 19 deletions Classes/Infrastructure/Healthcheck/SiteHealthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ public function execute(HealthcheckEnvironment $environment): Health
}

if (!$environment->isSafeToLeakTechnicalDetails()) {
// TODO adjust to 9.0
return new Health('No Neos site was created. Please visit the documentation how setup a site.', Status::WARNING());
return new Health('No Neos site was created. Please look into <code>{{flowCommand}} site:importall</code> or <code>{{flowCommand}} site:create</code>.', Status::WARNING());
}

$availableSitePackagesToBeImported = [];
foreach ($this->packageManager->getFilteredPackages('available', 'neos-site') as $sitePackage) {
$possibleSiteContentToImport = sprintf('resource://%s/Private/Content/events.jsonl', $sitePackage->getPackageKey());
$possibleSiteContentToImport = sprintf('resource://%s/Private/Content', $sitePackage->getPackageKey());
if (file_exists($possibleSiteContentToImport)) {
$availableSitePackagesToBeImported[] = $sitePackage->getPackageKey();
}
}

if (count($availableSitePackagesToBeImported) === 0) {
if (!$this->packageManager->isPackageAvailable('Neos.SiteKickstarter')) {
// TODO adjust to 9.0
return new Health(<<<MSG
No Neos site was created. You might want to install the site kickstarter: <code>composer require neos/site-kickstarter</code>.
Or you can create a new site package completely from scratch via <code>{{flowCommand}} package:create My.Site --package-type=neos-site</code>.
Expand All @@ -66,24 +64,17 @@ public function execute(HealthcheckEnvironment $environment): Health
MSG, Status::WARNING());
}

// TODO adjust to 9.0
return new Health(<<<MSG
No Neos site was created. You can kickstart a new site package via <code>{{flowCommand}} kickstart:site My.Site my-site</code>
and import it via <code>{{flowCommand}} site:import --package-key My.Site</code>
No Neos site was created. You can kickstart a new site package via <code>{{flowCommand}} kickstart:site My.Site</code>
and use it to create a site via <code>{{flowCommand}} site:create my-site My.Site My.Site:Document.Homepage</code>
MSG, Status::WARNING());
}

if (count($availableSitePackagesToBeImported) === 1 && $availableSitePackagesToBeImported[0] === 'Neos.Demo') {
// TODO adjust to 9.0 (make less specific to neos demo)
return new Health(<<<MSG
No Neos site was created. To import the site from Neos.Demo you can run <code>{{flowCommand}} site:create neosdemo Neos.Demo Neos.Demo:Document.Homepage</code> and <code>{{flowCommand}} cr:prune</code> and <code>{{flowCommand}} cr:import resource://Neos.Demo/Private/Content</code>
MSG, Status::WARNING());
}

// TODO adjust to 9.0
$availableSitePackages = join(', ', $availableSitePackagesToBeImported);
return new Health(<<<MSG
No Neos site was created. To import from one of the available site packages ($availableSitePackages) follow the steps from the documentation.
MSG, Status::WARNING());
$firstAvailableSitePackageKey = array_shift($availableSitePackagesToBeImported);
return new Health(sprintf(
'No Neos site was created. To import the site from %1$s you can run <code>{{flowCommand}} site:importall --package-key %1$s</code>.%2$s',
$firstAvailableSitePackageKey,
$availableSitePackagesToBeImported === [] ? '' : sprintf(' Or import one of the other available site packages: %s', join(', ', $availableSitePackagesToBeImported))
), Status::WARNING());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImageHandlerService
public function __construct()
{
//
// FIXME: It seems there is this hack and in the image factory there is a hack too now (: https://github.com/neos/imagine/pull/11
// Hack. We instantiate the unproxied class without injected settings.
// This is to allow to still reconfigure the image driver, even if it is disabled.
// The "driver" Gd for Imagine must be enabled by settings, check Neos.Imagine.enabledDrivers. Or use ./flow setup:imagehandler
Expand Down