Remove PHPStan issues

Most were fixed, some were ignored on top level.
This commit is contained in:
Daniel Siepmann 2021-12-14 16:59:12 +01:00
parent a576709947
commit 29c31375a5
6 changed files with 230 additions and 514 deletions

View file

@ -75,6 +75,10 @@ class CategoryService
->execute(); ->execute();
while ($row = $res->fetch()) { while ($row = $res->fetch()) {
if (is_array($row) === false) {
continue;
}
$counter++; $counter++;
if ($counter > 10000) { if ($counter > 10000) {
$this->timeTracker->setTSlogMessage('EXT:dd_events: one or more recursive categories where found'); $this->timeTracker->setTSlogMessage('EXT:dd_events: one or more recursive categories where found');
@ -109,6 +113,10 @@ class CategoryService
->execute() ->execute()
->fetchAll(); ->fetchAll();
foreach ($rows as $row) { foreach ($rows as $row) {
if (is_array($row) === false) {
continue;
}
$list[] = $row['uid']; $list[] = $row['uid'];
} }

View file

@ -90,7 +90,11 @@ class Database
->execute() ->execute()
->fetchAll(); ->fetchAll();
return array_map(function (array $record) { return array_map(function ($record) {
if (is_array($record) === false) {
return '';
}
return $record['uid']; return $record['uid'];
}, $records); }, $records);
} }

View file

@ -3,14 +3,16 @@
namespace Wrm\Events\Service; namespace Wrm\Events\Service;
use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\DataHandling\SlugHelper; use TYPO3\CMS\Core\DataHandling\SlugHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException; use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Index\MetaDataRepository; use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
@ -30,117 +32,134 @@ use Wrm\Events\Domain\Repository\RegionRepository;
class DestinationDataImportService class DestinationDataImportService
{ {
/** /**
* @var * @var string
*/ */
protected $restUrl; private $restUrl;
/** /**
* @var * @var string
*/ */
protected $restLicenseKey; private $restLicenseKey;
/** /**
* @var * @var string
*/ */
protected $restType; private $restType;
/** /**
* @var * @var string
*/ */
protected $restLimit; private $restLimit;
/** /**
* @var * @var string
*/ */
protected $restMode; private $restMode;
/** /**
* @var * @var string
*/ */
protected $restTemplate; private $restTemplate;
/** /**
* @var * @var string
*/ */
protected $restExperience; private $restExperience;
/** /**
* @var * @var int
*/ */
protected $storagePid; private $storagePid;
/** /**
* @var * @var int
*/ */
protected $categoriesPid; private $regionUid;
/** /**
* @var * @var int
*/ */
protected $regionUid; private $categoriesPid;
/** /**
* @var * @var int
*/ */
protected $categoryParentUid; private $categoryParentUid;
/** /**
* @var * @var string
*/ */
protected $filesFolder; private $filesFolder;
/**
* @var
*/
protected $storage;
/** /**
* @var array * @var array
*/ */
protected $settings = []; private $settings = [];
/*
* @var
*/
protected $environment;
/** /**
* @var * @var Environment
*/ */
protected $tmpCurrentEvent; private $environment;
/** /**
* @var * @var Event
*/ */
protected $logger; private $tmpCurrentEvent;
/**
* @var Logger
*/
private $logger;
/** /**
* @var EventRepository * @var EventRepository
*/ */
protected $eventRepository; private $eventRepository;
/** /**
* @var RegionRepository * @var RegionRepository
*/ */
protected $regionRepository; private $regionRepository;
/** /**
* @var OrganizerRepository * @var OrganizerRepository
*/ */
protected $organizerRepository; private $organizerRepository;
/** /**
* @var DateRepository * @var DateRepository
*/ */
protected $dateRepository; private $dateRepository;
/** /**
* @var CategoryRepository * @var CategoryRepository
*/ */
protected $sysCategoriesRepository; private $sysCategoriesRepository;
/**
* @var FileRepository
*/
protected $fileRepository;
/** /**
* @var MetaDataRepository * @var MetaDataRepository
*/ */
protected $metaDataRepository; private $metaDataRepository;
/** /**
* @var ConfigurationManager * @var ConfigurationManager
*/ */
protected $configurationManager; private $configurationManager;
/** /**
* @var ObjectManager * @var ObjectManager
*/ */
protected $objectManager; private $objectManager;
/** /**
* @var PersistenceManager * @var PersistenceManager
*/ */
protected $persistenceManager; private $persistenceManager;
/** /**
* @var ResourceFactory * @var ResourceFactory
*/ */
protected $resourceFactory; private $resourceFactory;
/** /**
* ImportService constructor. * ImportService constructor.
@ -149,7 +168,6 @@ class DestinationDataImportService
* @param OrganizerRepository $organizerRepository * @param OrganizerRepository $organizerRepository
* @param DateRepository $dateRepository * @param DateRepository $dateRepository
* @param CategoryRepository $sysCategoriesRepository * @param CategoryRepository $sysCategoriesRepository
* @param FileRepository $fileRepository
* @param MetaDataRepository $metaDataRepository * @param MetaDataRepository $metaDataRepository
* @param ConfigurationManager $configurationManager * @param ConfigurationManager $configurationManager
* @param PersistenceManager $persistenceManager * @param PersistenceManager $persistenceManager
@ -163,7 +181,6 @@ class DestinationDataImportService
OrganizerRepository $organizerRepository, OrganizerRepository $organizerRepository,
DateRepository $dateRepository, DateRepository $dateRepository,
CategoryRepository $sysCategoriesRepository, CategoryRepository $sysCategoriesRepository,
FileRepository $fileRepository,
MetaDataRepository $metaDataRepository, MetaDataRepository $metaDataRepository,
ConfigurationManager $configurationManager, ConfigurationManager $configurationManager,
PersistenceManager $persistenceManager, PersistenceManager $persistenceManager,
@ -176,7 +193,6 @@ class DestinationDataImportService
$this->organizerRepository = $organizerRepository; $this->organizerRepository = $organizerRepository;
$this->dateRepository = $dateRepository; $this->dateRepository = $dateRepository;
$this->sysCategoriesRepository = $sysCategoriesRepository; $this->sysCategoriesRepository = $sysCategoriesRepository;
$this->fileRepository = $fileRepository;
$this->metaDataRepository = $metaDataRepository; $this->metaDataRepository = $metaDataRepository;
$this->configurationManager = $configurationManager; $this->configurationManager = $configurationManager;
$this->persistenceManager = $persistenceManager; $this->persistenceManager = $persistenceManager;
@ -198,18 +214,16 @@ class DestinationDataImportService
$this->restLimit = $this->settings['destinationData']['restLimit']; $this->restLimit = $this->settings['destinationData']['restLimit'];
$this->restMode = $this->settings['destinationData']['restMode']; $this->restMode = $this->settings['destinationData']['restMode'];
$this->restTemplate = $this->settings['destinationData']['restTemplate']; $this->restTemplate = $this->settings['destinationData']['restTemplate'];
$this->sysCategoriesPid = $this->settings['destinationData']['categoriesPid']; $this->categoriesPid = (int) $this->settings['destinationData']['categoriesPid'];
$this->categoryParentUid = $this->settings['destinationData']['categoryParentUid']; $this->categoryParentUid = (int) $this->settings['destinationData']['categoryParentUid'];
} }
/** public function import(
* @param $restExperience string $restExperience,
* @param $storagePid int $storagePid,
* @param $regionUid int $regionUid,
* @param $filesFolder string $filesFolder
*/ ): int {
public function import($restExperience, $storagePid, $regionUid, $filesFolder)
{
$this->restExperience = $restExperience; $this->restExperience = $restExperience;
$this->storagePid = $storagePid; $this->storagePid = $storagePid;
$this->regionUid = $regionUid; $this->regionUid = $regionUid;
@ -235,20 +249,32 @@ class DestinationDataImportService
$restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&mode=' . $this->restMode . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate; $restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&mode=' . $this->restMode . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate;
$this->logger->info('Try to get data from ' . $restUrl); $this->logger->info('Try to get data from ' . $restUrl);
if ($jsonResponse = json_decode(file_get_contents($restUrl), true)) { try {
$this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items'); $fetchedData = $this->fetchData($restUrl);
return $this->processData($jsonResponse); } catch (\Exception $e) {
} else {
$this->logger->error('Could not receive data.'); $this->logger->error('Could not receive data.');
return 1; return 1;
} }
return $this->processData($fetchedData);
} }
/** private function fetchData(string $restUrl): array
* @param $data {
* @return int $jsonContent = file_get_contents($restUrl);
*/ if (is_string($jsonContent) === false) {
public function processData($data) throw new \Exception('Could not receive data.', 1639495835);
}
$jsonResponse = json_decode($jsonContent, true);
if (is_array($jsonResponse) === false) {
throw new \Exception('Could not receive data.', 1639495835);
}
$this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items');
return $jsonResponse;
}
public function processData(array $data): int
{ {
$this->logger->info('Processing json ' . count($data['items'])); $this->logger->info('Processing json ' . count($data['items']));
@ -265,9 +291,7 @@ class DestinationDataImportService
$this->tmpCurrentEvent->setLanguageUid(-1); $this->tmpCurrentEvent->setLanguageUid(-1);
// Set selected Region // Set selected Region
if ($selectedRegion !== null) { $this->tmpCurrentEvent->setRegion($selectedRegion);
$this->tmpCurrentEvent->setRegion($selectedRegion);
}
// Set Title // Set Title
$this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254)); $this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254));
@ -339,9 +363,17 @@ class DestinationDataImportService
* *
* @param array $categories * @param array $categories
*/ */
protected function setCategories(array $categories) private function setCategories(array $categories): void
{ {
$sysParentCategory = $this->sysCategoriesRepository->findByUid($this->categoryParentUid); $sysParentCategory = $this->sysCategoriesRepository->findByUid($this->categoryParentUid);
if (!$sysParentCategory instanceof Category) {
$this->logger->warning(
'Could not fetch system parent category by uid.',
['uid' => $this->categoryParentUid]
);
return;
}
foreach ($categories as $categoryTitle) { foreach ($categories as $categoryTitle) {
$tmpSysCategory = $this->sysCategoriesRepository->findOneByTitle($categoryTitle); $tmpSysCategory = $this->sysCategoriesRepository->findOneByTitle($categoryTitle);
if (!$tmpSysCategory) { if (!$tmpSysCategory) {
@ -349,7 +381,7 @@ class DestinationDataImportService
$tmpSysCategory = $this->objectManager->get(Category::class); $tmpSysCategory = $this->objectManager->get(Category::class);
$tmpSysCategory->setTitle($categoryTitle); $tmpSysCategory->setTitle($categoryTitle);
$tmpSysCategory->setParent($sysParentCategory); $tmpSysCategory->setParent($sysParentCategory);
$tmpSysCategory->setPid($this->sysCategoriesPid); $tmpSysCategory->setPid($this->categoriesPid);
$this->sysCategoriesRepository->add($tmpSysCategory); $this->sysCategoriesRepository->add($tmpSysCategory);
$this->tmpCurrentEvent->addCategory($tmpSysCategory); $this->tmpCurrentEvent->addCategory($tmpSysCategory);
} else { } else {
@ -358,15 +390,10 @@ class DestinationDataImportService
} }
} }
/** private function setDates(
* @param array $timeIntervals
* @TODO: split into functions
*/
protected function setDates(
array $timeIntervals, array $timeIntervals,
bool $canceled bool $canceled
) { ): void {
// @TODO: does not seem to work --> // @TODO: does not seem to work -->
//$currentEventDates = $this->tmpCurrentEvent->getDates(); //$currentEventDates = $this->tmpCurrentEvent->getDates();
//$this->tmpCurrentEvent->removeAllDates($currentEventDates); //$this->tmpCurrentEvent->removeAllDates($currentEventDates);
@ -406,14 +433,17 @@ class DestinationDataImportService
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz'])); $start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
$until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz'])); $until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz']));
for ($i = strtotime($start->format('l'), $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 day', $i)) { $i = (int) strtotime($start->format('l'), $start->getTimestamp());
while ($i !== 0 && $i <= $until->getTimestamp()) {
$i = (int) strtotime('+1 day', $i);
if ($i >= $today) { if ($i >= $today) {
$eventStart = new \DateTime(); $eventStart = new \DateTime();
$eventStart->setTimestamp($i); $eventStart->setTimestamp($i);
$eventStart->setTime($start->format('H'), $start->format('i')); $eventStart->setTime((int) $start->format('H'), (int) $start->format('i'));
$eventEnd = new \DateTime(); $eventEnd = new \DateTime();
$eventEnd->setTimestamp($i); $eventEnd->setTimestamp($i);
$eventEnd->setTime($until->format('H'), $until->format('i')); $eventEnd->setTime((int) $until->format('H'), (int) $until->format('i'));
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData( $this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
$eventStart, $eventStart,
$eventEnd, $eventEnd,
@ -433,10 +463,10 @@ class DestinationDataImportService
if ($i >= $today) { if ($i >= $today) {
$eventStart = new \DateTime(); $eventStart = new \DateTime();
$eventStart->setTimestamp($i); $eventStart->setTimestamp($i);
$eventStart->setTime($start->format('H'), $start->format('i')); $eventStart->setTime((int) $start->format('H'), (int) $start->format('i'));
$eventEnd = new \DateTime(); $eventEnd = new \DateTime();
$eventEnd->setTimestamp($i); $eventEnd->setTimestamp($i);
$eventEnd->setTime($until->format('H'), $until->format('i')); $eventEnd->setTime((int) $until->format('H'), (int) $until->format('i'));
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData( $this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
$eventStart, $eventStart,
$eventEnd, $eventEnd,
@ -451,10 +481,7 @@ class DestinationDataImportService
$this->logger->info('Finished setup dates'); $this->logger->info('Finished setup dates');
} }
/** private function setOrganizer(array $addresses): void
* @param array $addresses
*/
protected function setOrganizer(array $addresses)
{ {
foreach ($addresses as $address) { foreach ($addresses as $address) {
if ($address['rel'] == "organizer") { if ($address['rel'] == "organizer") {
@ -482,7 +509,7 @@ class DestinationDataImportService
/** /**
* @param array $event * @param array $event
*/ */
protected function setAddress(array $event) private function setAddress(array $event): void
{ {
$this->tmpCurrentEvent->setName($event['name'] ?? ''); $this->tmpCurrentEvent->setName($event['name'] ?? '');
$this->tmpCurrentEvent->setStreet($event['street'] ?? ''); $this->tmpCurrentEvent->setStreet($event['street'] ?? '');
@ -496,7 +523,7 @@ class DestinationDataImportService
/** /**
* @param array $media * @param array $media
*/ */
protected function setSocial(array $media) private function setSocial(array $media): void
{ {
foreach ($media as $link) { foreach ($media as $link) {
if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook") { if ($link['rel'] == "socialmedia" && $link['value'] == "Facebook") {
@ -514,33 +541,29 @@ class DestinationDataImportService
/** /**
* @param array $media * @param array $media
*/ */
protected function setTickets(array $media) private function setTickets(array $media): void
{ {
foreach ($media as $link) { foreach ($media as $link) {
if ($link['rel'] == "ticket") { if ($link['rel'] == "ticket") {
$this->tmpCurrentEvent->setTicket($link['url']); $this->tmpCurrentEvent->setTicket($link['url']);
break; break;
} elseif ($link['rel'] == "booking" && !$this->multi_array_key_exists('ticket', $media)) { } elseif ($link['rel'] == "booking" && !$this->multiArrayKeyExists('ticket', $media)) {
$this->tmpCurrentEvent->setTicket($link['url']); $this->tmpCurrentEvent->setTicket($link['url']);
break; break;
} elseif ($link['rel'] == "PRICE_KARTENLINK" && !$this->multi_array_key_exists('ticket', $media) && !$this->multi_array_key_exists('booking', $media)) { } elseif ($link['rel'] == "PRICE_KARTENLINK" && !$this->multiArrayKeyExists('ticket', $media) && !$this->multiArrayKeyExists('booking', $media)) {
$this->tmpCurrentEvent->setTicket($link['url']); $this->tmpCurrentEvent->setTicket($link['url']);
} }
} }
} }
/** private function multiArrayKeyExists(string $needle, array $haystack): bool
* @param string $needle
* @param array $haystack
*/
protected function multi_array_key_exists($needle, $haystack)
{ {
foreach ($haystack as $key => $value) { foreach ($haystack as $key => $value) {
if ($needle == $key) { if ($needle == $key) {
return true; return true;
} }
if (is_array($value)) { if (is_array($value)) {
if ($this->multi_array_key_exists($needle, $value) == true) { if ($this->multiArrayKeyExists($needle, $value) == true) {
return true; return true;
} }
} }
@ -548,21 +571,13 @@ class DestinationDataImportService
return false; return false;
} }
/** private function setLatLng(string $lat, string $lng): void
* @param string $lat
* @param string $lng
*/
protected function setLatLng(string $lat, string $lng)
{ {
$this->tmpCurrentEvent->setLatitude($lat); $this->tmpCurrentEvent->setLatitude($lat);
$this->tmpCurrentEvent->setLongitude($lng); $this->tmpCurrentEvent->setLongitude($lng);
} }
/** private function setTexts(array $texts): void
* Set Texts
* @param Array $texts
*/
protected function setTexts(array $texts)
{ {
foreach ($texts as $text) { foreach ($texts as $text) {
if ($text['rel'] == "details" && $text['type'] == "text/plain") { if ($text['rel'] == "details" && $text['type'] == "text/plain") {
@ -577,19 +592,14 @@ class DestinationDataImportService
} }
} }
/** private function getOrCreateEvent(string $globalId, string $title): Event
* Load File
* @param String $globalId
* @param String $title
*/
protected function getOrCreateEvent(string $globalId, string $title)
{ {
$event = $this->eventRepository->findOneByGlobalId($globalId); $event = $this->eventRepository->findOneByGlobalId($globalId);
if ($event) { if ($event instanceof Event) {
// Global ID is found and events gets updated $this->logger->info(
$event = $this->eventRepository->findOneByGlobalId($globalId); 'Found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database'
$this->logger->info('Found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database'); );
return $event; return $event;
} }
@ -601,25 +611,29 @@ class DestinationDataImportService
$event->setCategories(new ObjectStorage()); $event->setCategories(new ObjectStorage());
$this->eventRepository->add($event); $this->eventRepository->add($event);
$this->persistenceManager->persistAll(); $this->persistenceManager->persistAll();
$this->logger->info('Not found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database. Created new one.'); $this->logger->info(
'Not found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database.'
. ' Created new one.'
);
return $event; return $event;
} }
/** private function setAssets(array $assets): void
* @param array $assets
*/
protected function setAssets(array $assets)
{ {
$this->logger->info("Set assets"); $this->logger->info("Set assets");
$storage = $this->resourceFactory->getDefaultStorage();
if (!$storage instanceof ResourceStorage) {
$this->logger->error('No default storage defined. Cancel import.');
exit();
}
$error = false; $error = false;
foreach ($assets as $media_object) { foreach ($assets as $media_object) {
if ($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") { if ($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") {
$this->storage = $this->resourceFactory->getDefaultStorage();
$orgFileUrl = urldecode($media_object['url']); $orgFileUrl = urldecode($media_object['url']);
$orgFileNameSanitized = $this->storage->sanitizeFileName( $orgFileNameSanitized = $storage->sanitizeFileName(
basename( basename(
urldecode($media_object['url']) urldecode($media_object['url'])
) )
@ -627,15 +641,12 @@ class DestinationDataImportService
$this->logger->info('File attached:' . $orgFileUrl); $this->logger->info('File attached:' . $orgFileUrl);
$this->logger->info('File attached sanitized:' . $orgFileNameSanitized); $this->logger->info('File attached sanitized:' . $orgFileNameSanitized);
//die();
if ($this->storage == null) {
$this->logger->error('No default storage defined. Cancel import.');
die();
}
$targetFilePath = $this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder
. $orgFileNameSanitized;
// Check if file already exists // Check if file already exists
if (file_exists($this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder . $orgFileNameSanitized)) {
if (file_exists($targetFilePath)) {
$this->logger->info('File already exists'); $this->logger->info('File already exists');
} else { } else {
$this->logger->info("File don't exist " . $orgFileNameSanitized); $this->logger->info("File don't exist " . $orgFileNameSanitized);
@ -645,12 +656,13 @@ class DestinationDataImportService
$this->logger->info('Adding file ' . $file); $this->logger->info('Adding file ' . $file);
try { try {
$targetFolder = $this->storage->getFolder($this->filesFolder); $targetFolder = $storage->getFolder($this->filesFolder);
} catch (FolderDoesNotExistException $e) { } catch (FolderDoesNotExistException $e) {
$targetFolder = $this->storage->createFolder($this->filesFolder); $targetFolder = $storage->createFolder($this->filesFolder);
} }
$this->storage->addFile($this->environment->getPublicPath() . "/uploads/tx_events/" . $file, $targetFolder); $tempFilePath = $this->environment->getPublicPath() . "/uploads/tx_events/" . $file;
$storage->addFile($tempFilePath, $targetFolder);
} else { } else {
$error = true; $error = true;
} }
@ -662,9 +674,27 @@ class DestinationDataImportService
// TODO: How to delete file references? // TODO: How to delete file references?
} else { } else {
$this->logger->info('No relation found'); $this->logger->info('No relation found');
$file = $this->storage->getFile($this->filesFolder . $orgFileNameSanitized); $fileIdentifier = $this->filesFolder . $orgFileNameSanitized;
$this->metaDataRepository->update($file->getUid(), array('title' => $media_object['value'], 'description' => $media_object['description'], 'alternative' => 'DD Import')); $file = $storage->getFile($fileIdentifier);
$this->createFileRelations($file->getUid(), 'tx_events_domain_model_event', $this->tmpCurrentEvent->getUid(), 'images', $this->storagePid); if (!$file instanceof File) {
$this->logger->warning('Could not find file.', [$fileIdentifier]);
continue;
}
$this->metaDataRepository->update(
$file->getUid(),
[
'title' => $media_object['value'],
'description' => $media_object['description'],
'alternative' => 'DD Import'
]
);
$this->createFileRelations(
$file->getUid(),
'tx_events_domain_model_event',
$this->tmpCurrentEvent->getUid(),
'images',
$this->storagePid
);
} }
} }
} }
@ -672,12 +702,7 @@ class DestinationDataImportService
} }
} }
/** private function loadFile(string $file): string
* Load File
* @param string $file
* @return string
*/
protected function loadFile($file)
{ {
$directory = $this->environment->getPublicPath() . "/uploads/tx_events/"; $directory = $this->environment->getPublicPath() . "/uploads/tx_events/";
$filename = basename($file); $filename = basename($file);
@ -688,20 +713,16 @@ class DestinationDataImportService
return $filename; return $filename;
} }
$this->logger->error('Cannot load file ' . $file); $this->logger->error('Cannot load file ' . $file);
return false; return '';
} }
/** private function createFileRelations(
* Build relations for FAL int $uid_local,
* @param int $uid_local string $tablenames,
* @param string $tablenames int $uid_foreign,
* @param int $uid_foreign string $fieldname,
* @param string $fieldname int $storagePid
* @param string $storagePid ): bool {
* @return bool
*/
protected function createFileRelations($uid_local, $tablenames, $uid_foreign, $fieldname, $storagePid)
{
$newId = 'NEW1234'; $newId = 'NEW1234';
$data = array(); $data = array();
@ -733,11 +754,7 @@ class DestinationDataImportService
return false; return false;
} }
/** private function doSlugUpdate(): void
* Performs slug update
* @return bool
*/
protected function doSlugUpdate()
{ {
$this->logger->info('Update slugs'); $this->logger->info('Update slugs');
@ -748,7 +765,8 @@ class DestinationDataImportService
$GLOBALS['TCA']['tx_events_domain_model_event']['columns']['slug']['config'] $GLOBALS['TCA']['tx_events_domain_model_event']['columns']['slug']['config']
); );
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_events_domain_model_event'); $connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_events_domain_model_event');
$queryBuilder = $connection->createQueryBuilder(); $queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll(); $queryBuilder->getRestrictions()->removeAll();
@ -763,6 +781,10 @@ class DestinationDataImportService
->execute(); ->execute();
while ($record = $statement->fetch()) { while ($record = $statement->fetch()) {
if (is_array($record) === false) {
continue;
}
$queryBuilder = $connection->createQueryBuilder(); $queryBuilder = $connection->createQueryBuilder();
$queryBuilder->update('tx_events_domain_model_event') $queryBuilder->update('tx_events_domain_model_event')
->where( ->where(
@ -775,28 +797,25 @@ class DestinationDataImportService
$queryBuilder->getSQL(); $queryBuilder->getSQL();
$queryBuilder->execute(); $queryBuilder->execute();
} }
return true;
} }
/** /**
* Fetch the value for requested attribute. * Fetch the boolean value for requested attribute.
* *
* Returns first if multiple attributes with same key exist. * Returns first if multiple attributes with same key exist.
* Casts "true" and "false" to true and false. * Casts "true" and "false" to true and false.
* Return null in case no attribute value could exists.
*/ */
private function getAttributeValue( private function getAttributeValue(
array $event, array $event,
string $attributeKey string $attributeKey
) { ): bool {
$attributes = array_filter($event['attributes'] ?? [], function (array $attribute) use ($attributeKey) { $attributes = array_filter($event['attributes'] ?? [], function (array $attribute) use ($attributeKey) {
$currentKey = $attribute['key'] ?? ''; $currentKey = $attribute['key'] ?? '';
return $currentKey === $attributeKey; return $currentKey === $attributeKey;
}); });
if ($attributes === []) { if ($attributes === []) {
return null; return false;
} }
$value = $attributes[0]['value'] ?? null; $value = $attributes[0]['value'] ?? null;
@ -808,6 +827,6 @@ class DestinationDataImportService
return false; return false;
} }
return $value; return (bool) $value;
} }
} }

View file

@ -35,6 +35,8 @@ Tasks
* Removed outdated stuff from Documentation. * Removed outdated stuff from Documentation.
* Fixed nearly all PHPStan issues.
Deprecation Deprecation
----------- -----------

View file

@ -1,54 +1,24 @@
parameters: parameters:
ignoreErrors: ignoreErrors:
- -
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" message: "#^Parameter \\#1 \\$restExperience of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects string, mixed given\\.$#"
count: 1 count: 1
path: Classes/Domain/Repository/CategoryRepository.php path: Classes/Command/DestinationDataImportCommand.php
- -
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" message: "#^Parameter \\#2 \\$storagePid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int, mixed given\\.$#"
count: 1 count: 1
path: Classes/Domain/Repository/DateRepository.php path: Classes/Command/DestinationDataImportCommand.php
- -
message: "#^Cannot call method fetch\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" message: "#^Parameter \\#3 \\$regionUid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int, mixed given\\.$#"
count: 1 count: 1
path: Classes/Extbase/AddSpecialProperties.php path: Classes/Command/DestinationDataImportCommand.php
- -
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" message: "#^Parameter \\#4 \\$filesFolder of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects string, mixed given\\.$#"
count: 1 count: 1
path: Classes/Extbase/AddSpecialProperties.php path: Classes/Command/DestinationDataImportCommand.php
-
message: "#^Cannot access offset 'uid' on mixed\\.$#"
count: 3
path: Classes/Service/CategoryService.php
-
message: "#^Cannot call method fetch\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
count: 1
path: Classes/Service/CategoryService.php
-
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
count: 1
path: Classes/Service/CategoryService.php
-
message: "#^Parameter \\#1 \\$idList of method Wrm\\\\Events\\\\Service\\\\CategoryService\\:\\:getChildrenCategoriesRecursive\\(\\) expects string, mixed given\\.$#"
count: 1
path: Classes/Service/CategoryService.php
-
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
count: 2
path: Classes/Service/Cleanup/Database.php
-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(array\\)\\: mixed given\\.$#"
count: 1
path: Classes/Service/Cleanup/Database.php
- -
message: "#^Call to method deleteFile\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Storage\\.$#" message: "#^Call to method deleteFile\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Storage\\.$#"
@ -66,302 +36,7 @@ parameters:
path: Classes/Service/Cleanup/Files.php path: Classes/Service/Cleanup/Files.php
- -
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#" message: "#^Parameter \\#3 \\$uid_foreign of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:createFileRelations\\(\\) expects int, int\\|null given\\.$#"
count: 1
path: Classes/Service/Cleanup/Files.php
-
message: "#^Access to an undefined property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$sysCategoriesPid\\.$#"
count: 2
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface\\:\\:getUid\\(\\)\\.$#"
count: 2
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot access offset 'global_id' on mixed\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot access offset 'items' on mixed\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot access offset 'uid' on mixed\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot call method fetch\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot call method sanitizeFileName\\(\\) on TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceStorage\\|null\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:getAttributeValue\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:getOrCreateEvent\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) has parameter \\$filesFolder with no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) has parameter \\$regionUid with no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) has parameter \\$restExperience with no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) has parameter \\$storagePid with no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:loadFile\\(\\) should return string but returns false\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:multi_array_key_exists\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:processData\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setAddress\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setAssets\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setCategories\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setDates\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setLatLng\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setOrganizer\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setSocial\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setTexts\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:setTickets\\(\\) has no return type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\$data\\)\\: Unexpected token \"\\$data\", expected type at offset 18$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\$filesFolder\\)\\: Unexpected token \"\\$filesFolder\", expected type at offset 99$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\$regionUid\\)\\: Unexpected token \"\\$regionUid\", expected type at offset 74$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\$restExperience\\)\\: Unexpected token \"\\$restExperience\", expected type at offset 18$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\$storagePid\\)\\: Unexpected token \"\\$storagePid\", expected type at offset 48$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^PHPDoc tag @var has invalid value \\(\\)\\: Unexpected token \"\\\\n \", expected type at offset 15$#"
count: 15
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$hour of method DateTime\\:\\:setTime\\(\\) expects int, string given\\.$#"
count: 4
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$parent of method TYPO3\\\\CMS\\\\Extbase\\\\Domain\\\\Model\\\\Category\\:\\:setParent\\(\\) expects TYPO3\\\\CMS\\\\Extbase\\\\Domain\\\\Model\\\\Category, Wrm\\\\Events\\\\Domain\\\\Model\\\\Category\\|null given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$timestamp of method DateTime\\:\\:setTimestamp\\(\\) expects int, int\\|false given\\.$#"
count: 2
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$baseTimestamp of function strtotime expects int\\|null, int\\|false given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$minute of method DateTime\\:\\:setTime\\(\\) expects int, string given\\.$#"
count: 4
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$minute of method DateTime\\:\\:setTime\\(\\) expects int, string given\\.$#"
count: 4
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Parameter \\#2 \\$now of function strtotime expects int, int\\|false given\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$categoriesPid has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$categoryParentUid has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$environment has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$filesFolder has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$logger has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$regionUid has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restExperience has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restLicenseKey has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restLimit has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restMode has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restTemplate has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restType has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$restUrl has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$storage has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$storagePid has no type specified\\.$#"
count: 1
path: Classes/Service/DestinationDataImportService.php
-
message: "#^Property Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:\\$tmpCurrentEvent has no type specified\\.$#"
count: 1 count: 1
path: Classes/Service/DestinationDataImportService.php path: Classes/Service/DestinationDataImportService.php

View file

@ -8,3 +8,11 @@ parameters:
checkMissingIterableValueType: false checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
ignoreErrors:
- "#^Call to an undefined method Doctrine\\\\DBAL\\\\Result\\:\\:fetch\\(\\)\\.$#"
- "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
- "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#"
- "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
- "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#"
- "#^Cannot call method fetch\\(\\) on Doctrine\\\\DBAL\\\\Driver\\\\ResultStatement\\|int\\.$#"
- "#^Cannot call method fetch\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#"