Skip to content

Commit

Permalink
Merge pull request #58 from jweiland-net/typo3_13_compatibility
Browse files Browse the repository at this point in the history
Typo3 13 compatibility
  • Loading branch information
hojalatheef authored Dec 12, 2024
2 parents 53c40fa + 1292bb0 commit 54ab0c2
Show file tree
Hide file tree
Showing 78 changed files with 2,067 additions and 3,068 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:

matrix:
php:
- '8.1'
- '8.2'
- '8.3'

Expand Down
1 change: 1 addition & 0 deletions Build/phpunit/UnitTestsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
if (!getenv('TYPO3_PATH_ROOT')) {
putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/'));
}

if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/'));
}
Expand Down
56 changes: 0 additions & 56 deletions Classes/Ajax/DeutscherWetterdienstWarnCellSearch.php

This file was deleted.

109 changes: 109 additions & 0 deletions Classes/Backend/Preview/Weather2PluginPreview.php
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;
}
}
64 changes: 64 additions & 0 deletions Classes/Command/DeutscherWetterdienstCommand.php
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;
}
}
}
47 changes: 47 additions & 0 deletions Classes/Command/DeutscherWetterdienstWarnCellCommand.php
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;
}
}
}
77 changes: 77 additions & 0 deletions Classes/Command/OpenWeatherMapCommand.php
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') ?? '',
];
}
}
Loading

0 comments on commit 54ab0c2

Please sign in to comment.