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

Working on TYPO3 12 LTS compatibility #209

Draft
wants to merge 16 commits into
base: main
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
echo "Running unit tests";
echo;
echo;
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --testsuite unit;
.Build/bin/phpunit --bootstrap .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php --testsuite unit;
fi

- >
Expand All @@ -63,7 +63,7 @@ jobs:
echo "Running functional tests";
echo;
echo;
find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; .Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTestsBootstrap.php {}';
find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; .Build/bin/phpunit --bootstrap .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php {}';
fi

- >
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
echo "Running unit tests";
echo;
echo;
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --log-junit .Log/junit/unit_$VERSION.xml --coverage-php .Log/coverage/unit_$VERSION.cov --testsuite unit;
.Build/bin/phpunit --bootstrap .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php --log-junit .Log/junit/unit_$VERSION.xml --coverage-php .Log/coverage/unit_$VERSION.cov --testsuite unit;
fi

if [ -d "Tests/Functional" ]; then
Expand Down
3 changes: 2 additions & 1 deletion Classes/Aggregate/AbstractInlineContentAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected function getAvailableInlineFields()
continue;
}
foreach ($configuration['tca'] as $field => $fieldConfiguration) {
if ('inline' === $fieldConfiguration['config']['type']
if (isset($fieldConfiguration['config']['type'])
&& 'inline' === $fieldConfiguration['config']['type']
&& 'tt_content' === $fieldConfiguration['config']['foreign_table']
) {
if (empty($inlineFields[$table])) {
Expand Down
5 changes: 4 additions & 1 deletion Classes/Aggregate/AbstractOverridesAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ protected function addTableColumns(array $tableConfiguration)
return;
}

// allow new TCA parent structure which was introduced in mask 8
$allowedTableFields = array_merge($this->maskConfiguration[$this->table]['tca'], ['tx_mask_content_parent_uid' => []]);

$newTableFields = array_intersect_key(
$tableConfiguration['columns'],
$this->maskConfiguration[$this->table]['tca']
$allowedTableFields,
);
if (empty($newTableFields)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Aggregate/ContentElementIconAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function process()
<<<EOS
\$iconRegistry->registerIcon(
'$iconIdentifier',
\TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class,
\FriendsOfTYPO3\FontawesomeProvider\Imaging\IconProvider\FontawesomeIconProvider::class,
[
'name' => '$iconName',
]
Expand Down
3 changes: 2 additions & 1 deletion Classes/Aggregate/ContentRenderingAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ protected function addDataProcessing($table, array $fields)
$index = 10;
foreach ($fields as $field) {
if (empty($GLOBALS['TCA'][$table]['columns'][$field]['config']['type'])
|| 'inline' !== $GLOBALS['TCA'][$table]['columns'][$field]['config']['type']
|| ('inline' !== $GLOBALS['TCA'][$table]['columns'][$field]['config']['type']
&& 'file' !== $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'])
|| empty($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table'])
) {
continue;
Expand Down
11 changes: 6 additions & 5 deletions Classes/Aggregate/ExtensionConfigurationAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ protected function addComposerJson()
'type' => 'typo3-cms-extension',
'license' => 'GPL-2.0-or-later',
'require' => [
'typo3/cms-backend' => '^' . TYPO3_branch,
'typo3/cms-core' => '^' . TYPO3_branch,
'typo3/cms-extbase' => '^' . TYPO3_branch,
'typo3/cms-fluid' => '^' . TYPO3_branch,
'typo3/cms-frontend' => '^' . TYPO3_branch,
'typo3/cms-backend' => '^' . $this->typo3Version->getBranch(),
'typo3/cms-core' => '^' . $this->typo3Version->getBranch(),
'typo3/cms-extbase' => '^' . $this->typo3Version->getBranch(),
'typo3/cms-fluid' => '^' . $this->typo3Version->getBranch(),
'typo3/cms-frontend' => '^' . $this->typo3Version->getBranch(),
'friendsoftypo3/fontawesome-provider' => '^1.0',
],
'replace' => [
'typo3-ter/mask' => 'self.version',
Expand Down
41 changes: 30 additions & 11 deletions Classes/Aggregate/TcaAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* LICENSE file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

trait TcaAwareTrait
{
use LanguageAwareTrait;
Expand Down Expand Up @@ -86,17 +89,33 @@ protected function addFieldSqlDefinition(array $tableConfiguration, $field)
&& 'inline' === $this->maskConfiguration[$table]['tca'][$field]['config']['type']
&& 'tt_content' === $this->maskConfiguration[$table]['tca'][$field]['config']['foreign_table']
) {
$this->addSqlDefinition(
'tt_content',
$field . '_parent',
$definition
);
$this->addSqlDefinitions(
'tt_content',
[
'KEY ' . $field . '_parent' => '(' . $field . '_parent,pid,deleted)',
]
);
// allow new TCA parent structure which was introduced in mask 8
$maskVersion = preg_replace('/[^0-9\.]/', '', ExtensionManagementUtility::getExtensionVersion('mask'));
if (version_compare($maskVersion, '8.0.0', '>=')) {
$this->maskConfiguration['tt_content']['tx_mask_content_parent_uid'] = [
'config' => [
'type' => 'passthrough',
],
];
$this->addSqlDefinitions('tt_content', [
'tx_mask_content_parent_uid' => 'int(11) unsigned DEFAULT \'0\' NOT NULL',
'tx_mask_content_role' => 'varchar(255) DEFAULT \'\' NOT NULL',
'tx_mask_content_tablenames' => 'varchar(255) DEFAULT \'\' NOT NULL',
'KEY tx_mask_content_parent_uid' => '(tx_mask_content_parent_uid)',
]);
} else {
$this->addSqlDefinition(
'tt_content',
$field . '_parent',
$definition
);
$this->addSqlDefinitions(
'tt_content',
[
'KEY ' . $field . '_parent' => '(' . $field . '_parent,pid,deleted)',
]
);
}
}
}

Expand Down
30 changes: 6 additions & 24 deletions Classes/CodeGenerator/HtmlCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,16 @@
* LICENSE file that was distributed with this source code.
*/

use MASK\Mask\Domain\Repository\StorageRepository;
use MASK\Mask\Helper\FieldHelper;
use MASK\Mask\Definition\TableDefinitionCollection;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Generates the html and fluid for mask content elements
*/
class HtmlCodeGenerator
{
/**
* @var FieldHelper
*/
protected $fieldHelper;

/**
* @var StorageRepository
*/
protected $storageRepository;

public function __construct(StorageRepository $storageRepository = null, FieldHelper $fieldHelper = null)
public function __construct(protected TableDefinitionCollection $tableDefinitionCollection)
{
$this->storageRepository = $storageRepository ?: GeneralUtility::makeInstance(StorageRepository::class);

if (method_exists($this->storageRepository, 'getFormType')) {
$this->fieldHelper = $this->storageRepository;
} else {
$this->fieldHelper = $fieldHelper ?: GeneralUtility::makeInstance(FieldHelper::class, $this->storageRepository);
}
}

/**
Expand All @@ -57,7 +39,7 @@ public function __construct(StorageRepository $storageRepository = null, FieldHe
*/
public function generateHtml($key, $table = 'tt_content')
{
$storage = $this->storageRepository->loadElement('tt_content', $key);
$storage = $this->tableDefinitionCollection->loadElement('tt_content', $key)->toArray();
$html = '';
if (!empty($storage['tca'])) {
foreach ($storage['tca'] as $fieldKey => $fieldConfig) {
Expand All @@ -83,7 +65,7 @@ public function generateHtml($key, $table = 'tt_content')
*/
protected function generateFieldHtml($fieldKey, $elementKey, $table = 'tt_content', $datafield = 'data')
{
$formType = strtolower($this->fieldHelper->getFormType($fieldKey, $elementKey, $table));
$formType = strtolower((string)$this->tableDefinitionCollection->getFieldType($fieldKey, $table, $elementKey));
if (in_array($formType, ['linebreak', 'tab'], true)) {
return '';
}
Expand Down Expand Up @@ -161,11 +143,11 @@ protected function generateFieldHtml($fieldKey, $elementKey, $table = 'tt_conten
break;

case 'inline':
$inlineFields = $this->storageRepository->loadInlineFields($fieldKey);
$inlineFields = $this->tableDefinitionCollection->loadInlineFields($fieldKey, $elementKey);
$inlineFieldsHtml = '';
$datafieldInline = strtr($datafield, '.', '_');
if (!empty($inlineFields)) {
foreach ($inlineFields as $inlineField) {
foreach ($inlineFields->toArray() as $inlineField) {
$inlineFieldsHtml .= $this->generateFieldHtml($inlineField['maskKey'], $elementKey, $fieldKey, $datafieldInline . '_item.data');
}
}
Expand Down
101 changes: 60 additions & 41 deletions Classes/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
use IchHabRecht\MaskExport\FileCollection\PlainTextFileCollection;
use IchHabRecht\MaskExport\FileCollection\SqlFileCollection;
use MASK\Mask\Domain\Repository\StorageRepository;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Finder\Finder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
Expand Down Expand Up @@ -81,25 +86,35 @@ class ExportController extends ActionController
*/
protected $maskConfiguration;

public function __construct(StorageRepository $storageRepository)
{
protected ?ModuleTemplate $moduleTemplate = null;

public function __construct(
StorageRepository $storageRepository,
protected readonly PageRenderer $pageRenderer,
protected readonly ModuleTemplateFactory $moduleTemplateFactory
) {
$this->maskConfiguration = (array)$storageRepository->load();
}

/**
* @param string $vendorName
* @param string $extensionName
* @param array $elements
*/
public function listAction($vendorName = '', $extensionName = '', $elements = [])
public function setModuleTemplate(ModuleTemplate $moduleTemplate)
{
$this->moduleTemplate = $moduleTemplate;
}

public function listAction(
string $vendorName = '',
string $extensionName = '',
array $elements = []
): ResponseInterface {
$extensionName = $extensionName ?: $this->getExtensionName();
$vendorName = $vendorName ?: $this->getVendorName();
$elements = $elements ?: $this->getElements();

$files = $this->getFiles($vendorName, $extensionName, $elements);

$this->view->assignMultiple(
$moduleTemplate = $this->getModuleTemplate();
$moduleTemplate->setTitle('Mask Export');
$moduleTemplate->assignMultiple(
[
'composerMode' => Environment::isComposerMode(),
'vendorName' => $vendorName,
Expand All @@ -109,15 +124,17 @@ public function listAction($vendorName = '', $extensionName = '', $elements = []
'files' => $files,
]
);

$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/MaskExport/Toggler');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
return $moduleTemplate->renderResponse();
}

/**
* @param string $vendorName
* @param string $extensionName
* @param array $elements
*/
public function saveAction($vendorName = '', $extensionName = '', $elements = [])
{
public function saveAction(
string $vendorName = '',
string $extensionName = '',
array $elements = []
): ResponseInterface {
if (empty($vendorName)) {
$vendorName = $this->getVendorName();
} else {
Expand All @@ -135,22 +152,17 @@ public function saveAction($vendorName = '', $extensionName = '', $elements = []
$backendUser->writeUC();

$action = 'list';
if ($this->request->hasArgument('submit')) {
$submit = strtolower($this->request->getArgument('submit'));
if ($this->request->hasArgument('submitted')) {
$submit = strtolower($this->request->getArgument('submitted'));
if (in_array($submit, ['download', 'install'], true)) {
$action = $submit;
}
}

$this->forward($action, null, null, ['vendorName' => $vendorName, 'extensionName' => $extensionName, 'elements' => $elements]);
return new ForwardResponse($action);
}

/**
* @param string $vendorName
* @param string $extensionName
* @param array $elements
*/
public function downloadAction($vendorName, $extensionName, $elements)
public function downloadAction(string $vendorName, string $extensionName, array $elements): void
{
$files = $this->getFiles($vendorName, $extensionName, $elements);

Expand All @@ -174,25 +186,23 @@ public function downloadAction($vendorName, $extensionName, $elements)
exit;
}

/**
* @param string $vendorName
* @param string $extensionName
* @param array $elements
*/
public function installAction($vendorName, $extensionName, $elements)
public function installAction(string $vendorName, string $extensionName, array $elements): ResponseInterface
{
$paths = Extension::returnInstallPaths();
if (empty($paths['Local']) || !file_exists($paths['Local'])) {
throw new \RuntimeException('Local extension install path is missing', 1500061028);
if (Environment::isComposerMode()) {
$vendorFolder = strtolower($vendorName) . '/' . $extensionName;
$extensionPath = Environment::getComposerRootPath() . '/vendor/' . $vendorFolder;
} else {
$paths = Extension::returnInstallPaths();
if (empty($paths['Local']) || !file_exists($paths['Local'])) {
throw new \RuntimeException('Local extension install path is missing', 1500061028);
}
$extensionPath = $paths['Local'] . $extensionName;
}

$extensionPath = $paths['Local'] . $extensionName;
$files = $this->getFiles($vendorName, $extensionName, $elements);
$this->writeExtensionFilesToPath($files, $extensionPath);

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
if (!Environment::isComposerMode()) {
$managementService = $objectManager->get(ExtensionManagementService::class);
$managementService = GeneralUtility::makeInstance(ExtensionManagementService::class);
$managementService->reloadPackageInformation($extensionName);
$extension = $managementService->getExtension($extensionName);
$installInformation = $managementService->installExtension($extension);
Expand All @@ -211,17 +221,17 @@ public function installAction($vendorName, $extensionName, $elements)
);
}
} else {
$installUtility = $objectManager->get(InstallUtility::class);
$installUtility = GeneralUtility::makeInstance(InstallUtility::class);
$installUtility->reloadCaches();

$this->addFlashMessage(
'',
'Extension files of ' . $extensionName . ' were written successfully',
'Extension files were succesfully written to ' . $vendorFolder,
AbstractMessage::OK
);
}

$this->redirect('list');
return $this->redirect('list');
}

/**
Expand Down Expand Up @@ -542,4 +552,13 @@ protected function getBackendUser()
{
return $GLOBALS['BE_USER'];
}

protected function getModuleTemplate(): ModuleTemplate
{
if (!$this->moduleTemplate) {
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
}

return $this->moduleTemplate;
}
}
Loading