-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from jweiland-net/typo3_13_compatibility
Typo3 13 compatibility
- Loading branch information
Showing
78 changed files
with
2,067 additions
and
3,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ jobs: | |
|
||
matrix: | ||
php: | ||
- '8.1' | ||
- '8.2' | ||
- '8.3' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Backend\Preview; | ||
|
||
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer; | ||
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem; | ||
use TYPO3\CMS\Core\Service\FlexFormService; | ||
use TYPO3\CMS\Core\View\ViewFactoryData; | ||
use TYPO3\CMS\Core\View\ViewFactoryInterface; | ||
use TYPO3\CMS\Core\View\ViewInterface; | ||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
|
||
/** | ||
* Add plugin preview for EXT:weather2 | ||
*/ | ||
class Weather2PluginPreview extends StandardContentPreviewRenderer | ||
{ | ||
private const PREVIEW_TEMPLATE = 'EXT:weather2/Resources/Private/Templates/PluginPreview/Weather2.html'; | ||
|
||
private const ALLOWED_PLUGINS = [ | ||
'weather2_currentweather', | ||
'weather2_weatheralert', | ||
]; | ||
|
||
public function __construct( | ||
protected FlexFormService $flexFormService, | ||
protected ViewFactoryInterface $viewFactory, | ||
) {} | ||
|
||
public function renderPageModulePreviewContent(GridColumnItem $item): string | ||
{ | ||
$ttContentRecord = $item->getRecord(); | ||
if (!$this->isValidPlugin($ttContentRecord)) { | ||
return ''; | ||
} | ||
|
||
$view = $this->viewFactory->create( | ||
new ViewFactoryData( | ||
templatePathAndFilename: self::PREVIEW_TEMPLATE, | ||
), | ||
); | ||
$view->assignMultiple($ttContentRecord); | ||
|
||
$this->addPluginName($view, $ttContentRecord); | ||
|
||
// Add data from column pi_flexform | ||
$piFlexformData = $this->getPiFlexformData($ttContentRecord); | ||
if ($piFlexformData !== []) { | ||
$view->assign('pi_flexform_transformed', $piFlexformData); | ||
} | ||
|
||
return $view->render(); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $ttContentRecord | ||
*/ | ||
protected function isValidPlugin(array $ttContentRecord): bool | ||
{ | ||
if (!isset($ttContentRecord['CType'])) { | ||
return false; | ||
} | ||
|
||
if (!in_array($ttContentRecord['CType'], self::ALLOWED_PLUGINS, true)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $ttContentRecord | ||
*/ | ||
protected function addPluginName(ViewInterface $view, array $ttContentRecord): void | ||
{ | ||
$langKey = sprintf( | ||
'plugin.%s.title', | ||
str_replace('weather2_', '', $ttContentRecord['CType']), | ||
); | ||
|
||
$view->assign( | ||
'pluginName', | ||
LocalizationUtility::translate('LLL:EXT:weather2/Resources/Private/Language/locallang_db.xlf:' . $langKey), | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $ttContentRecord | ||
* @return array<string, mixed> | ||
*/ | ||
protected function getPiFlexformData(array $ttContentRecord): array | ||
{ | ||
$data = []; | ||
if (!empty($ttContentRecord['pi_flexform'] ?? '')) { | ||
$data = $this->flexFormService->convertFlexFormContentToArray($ttContentRecord['pi_flexform']); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Command; | ||
|
||
use JWeiland\Weather2\Service\DeutscherWetterdienstAlertService; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class DeutscherWetterdienstCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly DeutscherWetterdienstAlertService $alertService, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Fetch and process weather alerts from Deutscher Wetterdienst') | ||
->setHelp('Calls the Deutscher Wetterdienst api and saves response in weather2 format into database') | ||
->addArgument( | ||
'selectedWarnCells', | ||
InputArgument::REQUIRED, | ||
'Fetch alerts for selected cities (e.g. Pforzheim)', | ||
) | ||
->addArgument( | ||
'recordStoragePage', | ||
InputArgument::REQUIRED, | ||
'Record storage page (optional)', | ||
) | ||
->addArgument( | ||
'pageIdsToClear', | ||
InputArgument::OPTIONAL, | ||
'Clear cache for pages (comma separated list with IDs)', | ||
); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$output->writeln('<info>Starting to fetch warn cell data...</info>'); | ||
try { | ||
$this->alertService->fetchAndStoreAlerts($input, $output); | ||
$output->writeln('<info>Warn alert data has been successfully updated.</info>'); | ||
|
||
return Command::SUCCESS; | ||
} catch (\Throwable $exception) { | ||
$output->writeln(sprintf('<error>Failed to process weather alerts: %s</error>', $exception->getMessage())); | ||
|
||
return Command::FAILURE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Command; | ||
|
||
use JWeiland\Weather2\Service\DeutscherWetterdienstWarncellService; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class DeutscherWetterdienstWarnCellCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly DeutscherWetterdienstWarncellService $warnCellService, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setHelp( | ||
'Calls the Deutscher Wetterdienst api and saves warn cells into database. Required before using DeutscherWetterdienstCommand!', | ||
); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$output->writeln('<info>Starting to fetch warn cell data...</info>'); | ||
|
||
try { | ||
$this->warnCellService->fetchAndStoreWarnCells($output); | ||
$output->writeln('<info>Warn cell data has been successfully updated.</info>'); | ||
return Command::SUCCESS; | ||
} catch (\Throwable $e) { | ||
$output->writeln(sprintf('<error>Error: %s</error>', $e->getMessage())); | ||
return Command::FAILURE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Command; | ||
|
||
use JWeiland\Weather2\Service\WeatherServiceInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class OpenWeatherMapCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly WeatherServiceInterface $weatherService, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setHelp('Calls the api of openweathermap.org and saves response into database') | ||
->addArgument('name', InputArgument::REQUIRED, 'Name') | ||
->addArgument('city', InputArgument::REQUIRED, 'City name (e.g. Munich)') | ||
->addArgument('country', InputArgument::REQUIRED, 'Country Code (e.g. DE)') | ||
->addArgument('apiKey', InputArgument::REQUIRED, 'API-Key') | ||
->addArgument( | ||
'pageIdsToClear', | ||
InputArgument::OPTIONAL, | ||
'Clear cache for pages (comma separated list with IDs)', | ||
) | ||
->addArgument('recordStoragePage', InputArgument::OPTIONAL, 'Record storage page (optional)'); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$output->writeln('<info>Starting OpenWeatherMap data fetch...</info>'); | ||
|
||
try { | ||
$arguments = $this->getArgumentsFromInput($input); | ||
$this->weatherService->processWeatherData($arguments, $output); | ||
$output->writeln('<info>Weather data successfully updated!</info>'); | ||
|
||
return Command::SUCCESS; | ||
} catch (\Throwable $e) { | ||
$this->logger->error('Error fetching weather data: ' . $e->getMessage()); | ||
$output->writeln('<error>' . $e->getMessage() . '</error>'); | ||
return Command::FAILURE; | ||
} | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
private function getArgumentsFromInput(InputInterface $input): array | ||
{ | ||
return [ | ||
'name' => $input->getArgument('name'), | ||
'city' => $input->getArgument('city'), | ||
'country' => $input->getArgument('country'), | ||
'apiKey' => $input->getArgument('apiKey'), | ||
'recordStoragePage' => (int)$input->getArgument('recordStoragePage'), | ||
'pageIdsToClear' => $input->getArgument('pageIdsToClear') ?? '', | ||
]; | ||
} | ||
} |
Oops, something went wrong.