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

[WIP][FEATURE] Site Creator #1018

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
40 changes: 40 additions & 0 deletions Classes/Command/CreateSiteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\Command;

use BK2K\BootstrapPackage\SiteCreator\Service\SiteCreatorService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Core\Bootstrap;

class CreateSiteCommand extends Command
{
protected SiteCreatorService $siteCreatorService;

public function __construct(
SiteCreatorService $siteCreatorService,
string $name = null
) {
$this->siteCreatorService = $siteCreatorService;
parent::__construct($name);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
Bootstrap::initializeBackendAuthentication();
Bootstrap::initializeLanguageObject();

Check failure on line 34 in Classes/Command/CreateSiteCommand.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Call to an undefined static method TYPO3\CMS\Core\Core\Bootstrap::initializeLanguageObject().

Check failure on line 34 in Classes/Command/CreateSiteCommand.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Call to an undefined static method TYPO3\CMS\Core\Core\Bootstrap::initializeLanguageObject().

Check failure on line 34 in Classes/Command/CreateSiteCommand.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Call to an undefined static method TYPO3\CMS\Core\Core\Bootstrap::initializeLanguageObject().

Check failure on line 34 in Classes/Command/CreateSiteCommand.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Call to an undefined static method TYPO3\CMS\Core\Core\Bootstrap::initializeLanguageObject().

$this->siteCreatorService->createSiteSetup();

return 0;
}
}
86 changes: 86 additions & 0 deletions Classes/SiteCreator/Dto/AbstractEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Dto;

/**
* AbstractEntity
*/
abstract class AbstractEntity
{
protected string $table;
protected ?string $parentStorage = null;

public string $id;
public ?Page $parent = null;
public array $parameterBag = [];

public function __construct(string $id = null)
{
if (!isset($this->table)) {
throw new \RuntimeException('Extending Entity needs to set $table.', 1622491079);
}
$this->id = $id ?? uniqid('NEW_CONTENT');
}

public function toDataHandler(): array
{
if ($this->parent !== null) {
$this->parameterBag['pid'] = $this->parent->id;
if ($this->parentStorage !== null) {
$key = array_search($this, $this->parent->{$this->parentStorage}, true);

Check failure on line 38 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 38 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 38 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 38 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.
if ($key !== 0) {
$this->parameterBag['pid'] = '-' . $this->parent->{$this->parentStorage}[((int) $key - 1)]->id;

Check failure on line 40 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 40 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 40 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.

Check failure on line 40 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Variable property access on BK2K\BootstrapPackage\SiteCreator\Dto\Page.
}
}
} else {
$this->parameterBag['pid'] = 0;
}

$relations = $this->getDataHandlerRelations();

$data = [];
$data[$this->table][$this->id] = $this->parameterBag;

return array_merge_recursive($data, $relations);
}

protected function getDataHandlerRelations(): array
{
$relations = [];

foreach ($this->parameterBag as $parameter => $parameterValue) {
if (!isset($GLOBALS['TCA'][$this->table]['columns'][$parameter])) {
continue;
}
$fieldConfig = $GLOBALS['TCA'][$this->table]['columns'][$parameter]['config'];
if ($fieldConfig['type'] === 'inline') {
$foreignTable = $fieldConfig['foreign_table'];
$foreignField = $fieldConfig['foreign_field'];
$recordUids = [];
foreach ($parameterValue as $record => $recordData) {
$recordId = $recordData['id'] ?? uniqid('NEW_RECORD');
$recordUids[] = $recordId;
unset($recordData['id']);
if (!strpos($this->parameterBag['pid'], '-') === 0) {

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Only booleans are allowed in a negated boolean, int<0, max>|false given.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Strict comparison using === between bool and 0 will always evaluate to false.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Only booleans are allowed in a negated boolean, int<0, max>|false given.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Strict comparison using === between bool and 0 will always evaluate to false.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Only booleans are allowed in a negated boolean, int<0, max>|false given.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Strict comparison using === between bool and 0 will always evaluate to false.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Only booleans are allowed in a negated boolean, int<0, max>|false given.

Check failure on line 72 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Strict comparison using === between bool and 0 will always evaluate to false.
$recordData['pid'] = $this->parameterBag['pid'];
} else {
$recordData['pid'] = $this->parent->id;

Check failure on line 75 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.2)

Cannot access property $id on BK2K\BootstrapPackage\SiteCreator\Dto\Page|null.

Check failure on line 75 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (^13, 8.3)

Cannot access property $id on BK2K\BootstrapPackage\SiteCreator\Dto\Page|null.

Check failure on line 75 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.2)

Cannot access property $id on BK2K\BootstrapPackage\SiteCreator\Dto\Page|null.

Check failure on line 75 in Classes/SiteCreator/Dto/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Build PHP (14.0.x-dev, 8.3)

Cannot access property $id on BK2K\BootstrapPackage\SiteCreator\Dto\Page|null.
}
$recordData[$foreignField] = $this->id;
$relations[$foreignTable][$recordId] = $recordData;
}
$this->parameterBag[$parameter] = implode(',', $recordUids);
}
}

return $relations;
}
}
20 changes: 20 additions & 0 deletions Classes/SiteCreator/Dto/ContentBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Dto;

/**
* ContentBlock
*/
class ContentBlock extends AbstractEntity
{
protected string $table = 'tt_content';
protected ?string $parentStorage = 'contentBlocks';
}
41 changes: 41 additions & 0 deletions Classes/SiteCreator/Dto/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Dto;

/**
* Page
*/
class Page extends AbstractEntity
{
protected string $table = 'pages';
protected ?string $parentStorage = 'pages';

public array $pages = [];
public array $templates = [];
public array $contentBlocks = [];

public function toDataHandler(): array
{
$data = parent::toDataHandler();

foreach ($this->pages as $childPage) {
$data = array_merge_recursive($data, $childPage->toDataHandler());
}
foreach ($this->templates as $template) {
$data = array_merge_recursive($data, $template->toDataHandler());
}
foreach ($this->contentBlocks as $contentBlock) {
$data = array_merge_recursive($data, $contentBlock->toDataHandler());
}

return $data;
}
}
31 changes: 31 additions & 0 deletions Classes/SiteCreator/Dto/Site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Dto;

/**
* Site
*/
class Site
{
public string $title;
public string $description;
public array $pages = [];

public function toDataHandler(): array
{
$data = [];
foreach ($this->pages as $page) {
$data = array_merge_recursive($data, $page->toDataHandler());
}

return $data;
}
}
20 changes: 20 additions & 0 deletions Classes/SiteCreator/Dto/Template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Dto;

/**
* Template
*/
class Template extends AbstractEntity
{
protected string $table = 'sys_template';
protected ?string $parentStorage = 'templates';
}
32 changes: 32 additions & 0 deletions Classes/SiteCreator/Factory/ContentBlockFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Factory;

use BK2K\BootstrapPackage\SiteCreator\Dto\ContentBlock;

class ContentBlockFactory
{
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): ContentBlock
{
$contentBlock = new ContentBlock();
if (isset($data['id'])) {
$contentBlock->id = $data['id'];
unset($data['id']);
}
$contentBlock->parameterBag = $data;

return $contentBlock;
}
}
65 changes: 65 additions & 0 deletions Classes/SiteCreator/Factory/PageFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Factory;

use BK2K\BootstrapPackage\SiteCreator\Dto\Page;

class PageFactory
{
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): Page
{
$page = new Page();

if (isset($data['id'])) {
$page->id = $data['id'];
unset($data['id']);
}

if (isset($data['pages'])) {
foreach ($data['pages'] as $childPageData) {
$childPage = self::fromArray($childPageData);
$childPage->parent = $page;
$page->pages[] = $childPage;
}
unset($data['pages']);
}

if (isset($data['templates'])) {
foreach ($data['templates'] as $templateData) {
$template = TemplateFactory::fromArray($templateData);
$template->parent = $page;
$page->templates[] = $template;
}
unset($data['templates']);
}

if (isset($data['contentBlocks'])) {
foreach ($data['contentBlocks'] as $contentBlockData) {
$contentBlock = ContentBlockFactory::fromArray($contentBlockData);
$contentBlock->parent = $page;
$page->contentBlocks[] = $contentBlock;
}
unset($data['contentBlocks']);
}

if (!isset($data['hidden'])) {
$data['hidden'] = 0;
}

$page->parameterBag = $data;

return $page;
}
}
32 changes: 32 additions & 0 deletions Classes/SiteCreator/Factory/SiteFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage\SiteCreator\Factory;

use BK2K\BootstrapPackage\SiteCreator\Dto\Site;

class SiteFactory
{
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): Site
{
$site = new Site();
$site->title = $data['title'];
$site->description = $data['description'];
foreach ($data['pages'] as $page) {
$site->pages[] = PageFactory::fromArray($page);
}

return $site;
}
}
Loading
Loading