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

Compatibility with TYPO3 13 #14

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
23 changes: 17 additions & 6 deletions Classes/Backend/ButtonBar/YamlExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
* Class YamlExportButton
Expand Down Expand Up @@ -71,8 +72,10 @@ public function __invoke(ModifyButtonBarEvent $event): void
// Add button directly to array instead of using ->getButtonBar as this needs too much memory
$buttons[$options['buttonBarPosition']][$options['index']][] = $button;
}
// @todo: Load Javascript with native ES6 modules instead of RequireJs (which is deprecated)
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/YamlConfiguration/Backend');

if (isset($button)) { // include JavaScript only if a button was created
$this->pageRenderer->loadJavaScriptModule('@supseven/yaml-configuration/Backend.js');
}

// Persist final buttons configuration
$event->setButtons($buttons);
Expand Down Expand Up @@ -111,11 +114,19 @@ protected function isButtonEnabled(string $table): bool
*/
protected function isApplicableTable(string $table): bool
{
if (!array_key_exists('table', $this->getRequest()->getQueryParams())) {
return false;
$typo3Version = VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version());
if ($typo3Version < 13000000) { // old check befor TYPO3 v13
if (!array_key_exists('table', $this->getRequest()->getQueryParams())) {
return false;
}
return ($this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/module/web/list') &&
($this->getRequest()->getQueryParams()['table'] === $table);
}
return ($this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/module/web/list') &&
($this->getRequest()->getQueryParams()['table'] === $table);

return (
$this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/record/edit'
&& isset($this->getRequest()->getQueryParams()['edit'][$table])
);
}

private function getRequest(): ServerRequestInterface
Expand Down
10 changes: 5 additions & 5 deletions Classes/Command/AbstractTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ protected function getColumnNames(): array
$result = $this->queryBuilderForTable($table)
->select('*')
->from($table)
->execute()
->fetch();
->executeQuery()
->fetchAssociative();
if ($result) {
$columnNames = \array_keys($result);
$this->tableColumnCache[$table] = $columnNames;
} else {
$result = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$result = $result->getSchemaManager()->listTableColumns($table);
foreach ($result as $columnName => $columnProperties) {
$columnNames[] = $columnName;
$result = $result->getSchemaInformation()->introspectTable($table)->getColumns();
foreach ($result as $columnProperties) {
$columnNames[] = $columnProperties->getName();
}
$this->tableColumnCache[$table] = $columnNames;
}
Expand Down
8 changes: 4 additions & 4 deletions Classes/Command/ExportTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class ExportTableCommand extends AbstractTableCommand
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->setSkipColumns(GeneralUtility::trimExplode(',', $input->getOption('skip-columns'), true));
$this->setExplodeColumns(GeneralUtility::trimExplode(',', $input->getOption('explode-columns'), true));
$this->setSkipColumns(GeneralUtility::trimExplode(',', $input->getOption('skip-columns') ?? '', true));
$this->setExplodeColumns(GeneralUtility::trimExplode(',', $input->getOption('explode-columns') ?? '', true));
if ($input->getOption('use-only-columns')) {
$this->setUseOnlyColumns(GeneralUtility::trimExplode(',', $input->getOption('use-only-columns'), true));
}
Expand Down Expand Up @@ -188,7 +188,7 @@ protected function configure(): void
* @param OutputInterface $output
* @return int|void|null
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// Output information about the command
Expand Down Expand Up @@ -271,7 +271,7 @@ protected function exportTable(SymfonyStyle $io): void
)
)
)
->execute();
->executeQuery();
$usergroupsTitles = [];
foreach ($usergroups as $singleUserGroup) {
$usergroupsTitles[] = $singleUserGroup['title'];
Expand Down
4 changes: 2 additions & 2 deletions Classes/Command/ImportTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
* @param OutputInterface $output
* @return int|void|null
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$this->informationalHeader($io, $input);
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function importData(SymfonyStyle $io): void
)
);
}
$row = $row->where(...$whereClause)->execute()->fetch();
$row = $row->where(...$whereClause)->executeQuery()->fetchAssociative();
}
if ($row) {
// Update row as the matched row exists in the table
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/YamlExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function export(ServerRequestInterface $request): ResponseInterface
]);
}

$output = '';
$output = [];
$returnValue = 0;
$pathAndFileName = ExtensionManagementUtility::extPath($this->config['extensionName']) . $this->config['path'] . $this->config['table'] . '.yaml';

Expand Down
7 changes: 7 additions & 0 deletions Configuration/JavaScriptModules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'imports' => [
'@supseven/yaml-configuration/' => 'EXT:yaml_configuration/Resources/Public/JavaScript/',
],
];
36 changes: 18 additions & 18 deletions Resources/Public/JavaScript/Backend.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Notification from "@typo3/backend/notification.js";

(function() {
var httpRequest;
document.getElementsByClassName('t3js-yaml-export')[0].addEventListener('click', makeRequest);
Expand All @@ -20,29 +22,27 @@
if (httpRequest.status === 200) {
var _response = JSON.parse(httpRequest.response);

Notification(_response)
notify(_response)
} else {
console.log("error");
}
}
}

function Notification(response) {
require(['TYPO3/CMS/Backend/Notification'], function(Notification) {
switch (response.status) {
case 1:
Notification.warning(response.title, response.message);
break;
case 255:
Notification.notice(response.title, response.message);
break;
case 500:
Notification.error(response.title, response.message);
break;
default:
Notification.success(response.title, response.message);
break;
}
});
function notify(response) {
switch (response.status) {
case 1:
Notification.warning(response.title, response.message);
break;
case 255:
Notification.notice(response.title, response.message);
break;
case 500:
Notification.error(response.title, response.message);
break;
default:
Notification.success(response.title, response.message);
break;
}
}
})();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
}
],
"require": {
"typo3/cms-core": "^11 || ^12",
"symfony/yaml": "2.6 - 4.99 || ^5 || ^6"
"typo3/cms-core": "^12 || ^13",
"symfony/yaml": "^5 || ^6 || ^7"
},
"extra": {
"typo3/cms": {
Expand Down