Skip to content
Open
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
30 changes: 29 additions & 1 deletion Classes/CreateProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use SUDHAUS7\Sudhaus7Wizard\Events\BeforeClonedTreeInsertEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\BeforeContentCloneEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\BeforeSiteConfigWriteEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\BeforeSiteSettingsWriteEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\BeforeUserCreationUCDefaultsEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\CalcualteMountpointNameEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\CalculateBackendUserGroupNameEvent;
Expand Down Expand Up @@ -90,6 +91,11 @@ final class CreateProcess implements LoggerAwareInterface
*/
public array $siteConfig = [];

/**
* @var array<array-key, mixed>
*/
public array $siteSettings = [];

/**
* @var array<array-key, mixed>
*/
Expand Down Expand Up @@ -1719,6 +1725,10 @@ private function finalYaml(): void
$this->eventDispatcher->dispatch($event);
$this->siteConfig = $event->getSiteconfig();

$event = new BeforeSiteSettingsWriteEvent($this->siteSettings, $this);
$this->eventDispatcher->dispatch($event);
$this->siteSettings = $event->getSettings();

// Fallback to ensure a site folder in case of a failing preg_replace on slug generation
if ($identifier === null) {
$entryPoint = 'autogenerated-' . $this->getSiteRootId();
Expand All @@ -1727,7 +1737,9 @@ private function finalYaml(): void

$this->calculatedSiteconfigIdentifier = $identifier;

GeneralUtility::makeInstance(SiteWriter::class)->write($identifier, $this->siteConfig);
$siteWriter = GeneralUtility::makeInstance(SiteWriter::class);
$siteWriter->write($identifier, $this->siteConfig);
$siteWriter->writeSettings($identifier, $this->siteSettings);
}

/**
Expand All @@ -1746,6 +1758,22 @@ public function setSiteConfig(array $siteConfig): void
$this->siteConfig = $siteConfig;
}

/**
* @return array<string, mixed>
*/
public function getSiteSettings(): array
{
return $this->siteSettings;
}

/**
* @param array<string, mixed> $siteSettings
*/
public function setSiteSettings(array $siteSettings): void
{
$this->siteSettings = $siteSettings;
}

/**
* @return string[]
*/
Expand Down
55 changes: 55 additions & 0 deletions Classes/Events/BeforeSiteSettingsWriteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the TYPO3 project.
*
* @author Frank Berger <fberger@sudhaus7.de>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace SUDHAUS7\Sudhaus7Wizard\Events;

use SUDHAUS7\Sudhaus7Wizard\CreateProcess;
use SUDHAUS7\Sudhaus7Wizard\Interfaces\WizardEventInterface;
use SUDHAUS7\Sudhaus7Wizard\Traits\EventTrait;

final class BeforeSiteSettingsWriteEvent implements WizardEventInterface
{
use EventTrait;

protected CreateProcess $createProcess;

/**
* @var array<array-key, mixed>
*/
protected array $settings;

/**
* @param array<array-key, mixed> $settings
*/
public function __construct(array $settings, CreateProcess $createProcess)
{
$this->createProcess = $createProcess;
$this->settings = $settings;
}

/**
* @return array<array-key, mixed>
*/
public function getSettings(): array
{
return $this->settings;
}

/**
* @param array<array-key, mixed> $settings
*/
public function setSettings(array $settings): void
{
$this->settings = $settings;
}
}
65 changes: 65 additions & 0 deletions Classes/Events/LoadInitialSiteSettingsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the TYPO3 project.
*
* @author Frank Berger <fberger@sudhaus7.de>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace SUDHAUS7\Sudhaus7Wizard\Events;

use SUDHAUS7\Sudhaus7Wizard\CreateProcess;
use SUDHAUS7\Sudhaus7Wizard\Interfaces\WizardEventInterface;
use SUDHAUS7\Sudhaus7Wizard\Traits\EventTrait;

final class LoadInitialSiteSettingsEvent implements WizardEventInterface
{
use EventTrait;

protected CreateProcess $createProcess;

protected mixed $pageId;
/**
* @var array<array-key, mixed>
*/
protected array $settings;

/**
* @param array<array-key, mixed> $settings
*/
public function __construct(mixed $pageId, array $settings, CreateProcess $createProcess)
{
$this->pageId = $pageId;
$this->createProcess = $createProcess;
$this->settings = $settings;
}

/**
* @return mixed
*/
public function getPageId(): mixed
{
return $this->pageId;
}

/**
* @return array<array-key, mixed>
*/
public function getSettings(): array
{
return $this->settings;
}

/**
* @param array<array-key, mixed> $settings
*/
public function setSettings(array $settings): void
{
$this->settings = $settings;
}
}
7 changes: 7 additions & 0 deletions Classes/Services/AbstractCreateProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use SUDHAUS7\Sudhaus7Wizard\CreateProcess;
use SUDHAUS7\Sudhaus7Wizard\Domain\Model\Creator;
use SUDHAUS7\Sudhaus7Wizard\Events\LoadInitialSiteConfigEvent;
use SUDHAUS7\Sudhaus7Wizard\Events\LoadInitialSiteSettingsEvent;
use SUDHAUS7\Sudhaus7Wizard\Interfaces\WizardProcessInterface;
use SUDHAUS7\Sudhaus7Wizard\Sources\LocalDatabase;
use SUDHAUS7\Sudhaus7Wizard\Sources\SourceInterface;
Expand Down Expand Up @@ -59,11 +60,17 @@ public function get(Creator $creator, ?LoggerInterface $logger = null): CreatePr
}
$pid = $creator->getSourcepid();
$siteconfig = $task->getSource()->getSiteConfig($pid);
$settings = $task->getSource()->getSiteSettings($pid);

// wanted to do this early to have more control over where the source is loaded
$event = new LoadInitialSiteConfigEvent($pid, $siteconfig, $task);
GeneralUtility::makeInstance(EventDispatcher::class)->dispatch($event);
$task->setSiteConfig($event->getSiteconfig());

$event = new LoadInitialSiteSettingsEvent($pid, $settings, $task);
GeneralUtility::makeInstance(EventDispatcher::class)->dispatch($event);
$task->setSiteSettings($event->getSettings());

return $task;
}
}
17 changes: 16 additions & 1 deletion Classes/Sources/LocalDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ public function getSiteConfig(mixed $id): array
return $this->siteconfig;
}

/**
* @return array<array-key, mixed>
*/
public function getSiteSettings(mixed $id): array
{
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
try {
$site = $siteFinder->getSiteByRootPageId((int)$id);
return $site->getSettings()->getAll();
} catch (SiteNotFoundException|\Exception $e) {
$this->logger?->debug($e->getMessage(), [$id]);
}
return [];
}

public function ping(): void
{
$db = $this->connectionPool->getConnectionByName('Default');
Expand Down Expand Up @@ -269,7 +284,7 @@ public function handleFile(array $sysFile, string $newIdentifier): array
'sys_file',
['identifier' => $newIdentifier]
);
return $res->fetchAssociative() ?: [];
return $res->fetchAssociative() ?: $sysFile;
}

$this->logger?->notice('cp ' . Environment::getPublicPath() . '/fileadmin' . $sysFile['identifier'] . ' ' . Environment::getPublicPath() . '/fileadmin' . $newIdentifier);
Expand Down
13 changes: 13 additions & 0 deletions Classes/Sources/RestWizardServerSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ public function getSiteConfig(mixed $id): array
return $this->siteconfig;
}

/**
* @inheritDoc
* @throws \Exception
*/
public function getSiteSettings(mixed $id): array
{
$result = $this->getAPI()->request('/sitesettings/' . $id);
if (is_array($result) && $result !== []) {
return $result;
}
return [];
}

/**
* @inheritDoc
*/
Expand Down
9 changes: 9 additions & 0 deletions Classes/Sources/SourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function getCreator(): Creator;
*/
public function getSiteConfig(mixed $id): array;

/**
* Returns the Site Settings as an array
*
* @param mixed $id
*
* @return array<array-key, mixed>
*/
public function getSiteSettings(mixed $id): array;

/**
* @param array<array-key, mixed> $where
*/
Expand Down
26 changes: 26 additions & 0 deletions Tests/Functional/Wizard/WizardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use SBUERK\TYPO3\Testing\TestCase\FunctionalTestCase;
use SUDHAUS7\Sudhaus7Wizard\Cli\RunCommand;
use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\CMS\Core\Configuration\Event\SiteConfigurationChangedEvent;
use TYPO3\CMS\Core\Configuration\SiteWriter;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;
Expand Down Expand Up @@ -112,4 +114,28 @@ public function wizardGeneratesNewSite(): void
self::assertIsArray($site->getAttribute('dependencies'));
self::assertEquals(['sudhaus7/template'], $site->getAttribute('dependencies'));
}

#[Test]
#[Group('not-postgres')]
public function wizardGeneratesNewSiteWithSettings(): void
{
/** @var SiteWriter $siteWriter */
$siteWriter = $this->get(SiteWriter::class);
$siteWriter->writeSettings('acme', ['my_setting' => 'my_value']);
$this->get(\Psr\EventDispatcher\EventDispatcherInterface::class)->dispatch(new SiteConfigurationChangedEvent('acme'));
$this->get('cache.core')->flush();

$tester = new CommandTester($this->get(RunCommand::class));
$tester->execute([
'mode' => 'next',
]);

$tester->assertCommandIsSuccessful($tester->getDisplay());

/** @var SiteFinder $siteFinder */
$siteFinder = $this->get(SiteFinder::class);
$site = $siteFinder->getSiteByIdentifier('readytemplate');
self::assertInstanceOf(Site::class, $site);
self::assertEquals('my_value', $site->getSettings()->get('my_setting'));
}
}