From 32f314391e481ada46b06cf3c8f33fe139c87659 Mon Sep 17 00:00:00 2001 From: DACHCOM Bot Date: Thu, 5 Dec 2024 14:42:40 +0000 Subject: [PATCH] [CS] Refactor --- src/Builder/ExtJsDataBuilder.php | 20 +++++++++---- src/Command/FetchSocialPostsCommand.php | 11 ++++++++ .../ConnectorDefinitionInterface.php | 11 ++++++++ .../ConnectorEngineConfigurationInterface.php | 11 ++++++++ .../ConnectorFeedConfigurationInterface.php | 11 ++++++++ src/Connector/SocialPostBuilderInterface.php | 11 ++++++++ src/Controller/Admin/LogController.php | 15 ++++++++-- src/Controller/Admin/SettingsController.php | 23 +++++++++++---- .../Admin/Traits/ConnectResponseTrait.php | 11 ++++++++ src/Controller/Admin/WallsController.php | 16 +++++++++-- .../Compiler/ConnectorDefinitionPass.php | 12 +++++++- src/DependencyInjection/Configuration.php | 11 ++++++++ .../SocialDataExtension.php | 15 ++++++++-- src/Dto/AbstractData.php | 11 ++++++++ src/Dto/BuildConfig.php | 11 ++++++++ src/Dto/FetchData.php | 11 ++++++++ src/Dto/FilterData.php | 11 ++++++++ src/Dto/TransformData.php | 11 ++++++++ src/Event/SocialPostBuildConfigureEvent.php | 11 ++++++++ src/Event/SocialPostBuildEvent.php | 11 ++++++++ src/EventListener/Admin/AssetListener.php | 11 ++++++++ src/EventListener/EntityDeletionListener.php | 13 ++++++++- src/EventListener/FeedPostListener.php | 11 ++++++++ .../Maintenance/CleanUpLogsTask.php | 13 ++++++++- .../Maintenance/CleanUpOldSocialPostsTask.php | 14 +++++++++- .../Maintenance/FetchSocialPostsTask.php | 14 +++++++++- src/Exception/BuildException.php | 12 +++++++- src/Exception/ConnectException.php | 11 ++++++++ src/Factory/SocialPostFactory.php | 11 ++++++++ src/Factory/SocialPostFactoryInterface.php | 13 ++++++++- src/Form/Admin/Type/TagCollectionType.php | 12 +++++++- src/Form/Admin/Type/TagType.php | 12 +++++++- .../Component/ConnectorEngineChoiceType.php | 12 +++++++- .../Wall/Component/PimcoreRelationType.php | 11 ++++++++ .../Admin/Type/Wall/FeedCollectionType.php | 12 +++++++- src/Form/Admin/Type/Wall/FeedType.php | 11 ++++++++ src/Form/Admin/Type/Wall/WallType.php | 12 +++++++- src/Form/Traits/ExtJsTagTransformTrait.php | 12 +++++++- src/Logger/Logger.php | 11 ++++++++ src/Logger/LoggerInterface.php | 13 ++++++++- src/Logger/MonologEntryHandler.php | 13 ++++++++- .../ProviderContextConsoleProcessor.php | 11 ++++++++ src/Manager/ConnectorManager.php | 19 ++++++++++--- src/Manager/ConnectorManagerInterface.php | 11 ++++++++ src/Manager/FeedPostManager.php | 13 ++++++++- src/Manager/FeedPostManagerInterface.php | 13 ++++++++- src/Manager/LogManager.php | 13 ++++++++- src/Manager/LogManagerInterface.php | 13 ++++++++- src/Manager/SocialPostManager.php | 21 ++++++++++++-- src/Manager/SocialPostManagerInterface.php | 13 ++++++++- src/Manager/WallManager.php | 13 ++++++++- src/Manager/WallManagerInterface.php | 13 ++++++++- src/Model/ConnectorEngine.php | 11 ++++++++ src/Model/ConnectorEngineInterface.php | 11 ++++++++ src/Model/Feed.php | 13 ++++++++- src/Model/FeedInterface.php | 11 ++++++++ src/Model/LogEntry.php | 11 ++++++++ src/Model/LogEntryInterface.php | 11 ++++++++ src/Model/SocialPostInterface.php | 11 ++++++++ src/Model/Tag.php | 11 ++++++++ src/Model/TagInterface.php | 11 ++++++++ src/Model/Wall.php | 11 ++++++++ src/Model/WallInterface.php | 11 ++++++++ src/Processor/SocialPostBuilderProcessor.php | 28 +++++++++++++++---- src/Registry/ConnectorDefinitionRegistry.php | 11 ++++++++ .../ConnectorDefinitionRegistryInterface.php | 11 ++++++++ src/Repository/ConnectorEngineRepository.php | 11 ++++++++ .../ConnectorEngineRepositoryInterface.php | 11 ++++++++ src/Repository/LogRepository.php | 11 ++++++++ src/Repository/LogRepositoryInterface.php | 12 +++++++- src/Repository/SocialPostRepository.php | 17 +++++++---- .../SocialPostRepositoryInterface.php | 11 ++++++++ src/Repository/WallRepository.php | 11 ++++++++ src/Repository/WallRepositoryInterface.php | 11 ++++++++ src/Service/ConnectorService.php | 11 ++++++++ src/Service/ConnectorServiceInterface.php | 11 ++++++++ src/Service/EnvironmentService.php | 11 ++++++++ src/Service/EnvironmentServiceInterface.php | 11 ++++++++ src/Service/LockService.php | 12 +++++++- src/Service/LockServiceInterface.php | 11 ++++++++ src/Service/StatisticService.php | 11 ++++++++ src/Service/StatisticServiceInterface.php | 11 ++++++++ src/SocialDataBundle.php | 13 ++++++++- src/SocialDataEvents.php | 13 +++++++-- src/Tool/Install.php | 13 ++++++++- 85 files changed, 994 insertions(+), 64 deletions(-) diff --git a/src/Builder/ExtJsDataBuilder.php b/src/Builder/ExtJsDataBuilder.php index 3e822a6..231d4c2 100644 --- a/src/Builder/ExtJsDataBuilder.php +++ b/src/Builder/ExtJsDataBuilder.php @@ -1,7 +1,19 @@ connectorManager->getAllConnectorDefinitions(true); foreach ($allConnectorDefinitions as $connectorDefinitionName => $connectorDefinition) { - $engineConfiguration = []; $isInstalled = $connectorDefinition->engineIsLoaded(); @@ -168,8 +177,8 @@ protected function generateFeedStore(): array $feedStore = []; foreach ($this->connectorManager->getAllActiveConnectorDefinitions() as $connectorDefinitionName => $connectorDefinition) { $feedStore[] = [ - 'label' => ucFirst($connectorDefinitionName), - 'connectorName' => ucFirst($connectorDefinitionName), + 'label' => ucfirst($connectorDefinitionName), + 'connectorName' => ucfirst($connectorDefinitionName), 'connectorEngine' => $connectorDefinition->getConnectorEngine()->getId(), 'iconCls' => sprintf('pimcore_icon_social_data_connector_%s', strtolower($connectorDefinitionName)) ]; @@ -196,7 +205,6 @@ protected function getExtJSSerializerContext(): array return $data instanceof ConnectorEngineInterface ? $data->getId() : null; }, 'configuration' => function ($data) { - if ($data instanceof ConnectorFeedConfigurationInterface) { return $this->serializer->normalize($data); } diff --git a/src/Command/FetchSocialPostsCommand.php b/src/Command/FetchSocialPostsCommand.php index c064b3c..07074a4 100644 --- a/src/Command/FetchSocialPostsCommand.php +++ b/src/Command/FetchSocialPostsCommand.php @@ -1,5 +1,16 @@ isValid()) { return $this->adminJson([ 'success' => false, - 'message' => sprintf('Error while processing backend configuration for %s":
%s', - $connectorName, join('
', $this->extJsDataBuilder->generateFormErrorList($form)) + 'message' => sprintf( + 'Error while processing backend configuration for %s":
%s', + $connectorName, + join('
', $this->extJsDataBuilder->generateFormErrorList($form)) ) ]); } diff --git a/src/Controller/Admin/Traits/ConnectResponseTrait.php b/src/Controller/Admin/Traits/ConnectResponseTrait.php index ef18e1b..e533ab0 100644 --- a/src/Controller/Admin/Traits/ConnectResponseTrait.php +++ b/src/Controller/Admin/Traits/ConnectResponseTrait.php @@ -1,5 +1,16 @@ adminJson($response); } - } diff --git a/src/DependencyInjection/Compiler/ConnectorDefinitionPass.php b/src/DependencyInjection/Compiler/ConnectorDefinitionPass.php index e8ca4db..e7a1e82 100644 --- a/src/DependencyInjection/Compiler/ConnectorDefinitionPass.php +++ b/src/DependencyInjection/Compiler/ConnectorDefinitionPass.php @@ -1,5 +1,16 @@ findTaggedServiceIds('social_data.connector_definition', true) as $id => $tags) { $connectorDefinition = $container->getDefinition($id); foreach ($tags as $attributes) { - if (!isset($attributes['identifier'])) { throw new InvalidConfigurationException(sprintf('You need to define a valid identifier for connector "%s"', $id)); } elseif (!isset($attributes['socialPostBuilder'])) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b3c9795..bb46c53 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,5 +1,16 @@ enabled === false) { - $this->lockService->unLock(self::LOCK_ID); + $this->lockService->unLock(self::LOCK_ID); + return; } diff --git a/src/EventListener/Maintenance/FetchSocialPostsTask.php b/src/EventListener/Maintenance/FetchSocialPostsTask.php index 5c8d260..ca219d6 100644 --- a/src/EventListener/Maintenance/FetchSocialPostsTask.php +++ b/src/EventListener/Maintenance/FetchSocialPostsTask.php @@ -1,9 +1,20 @@ enabled === false) { $this->lockService->unLock(self::LOCK_ID); + return; } diff --git a/src/Exception/BuildException.php b/src/Exception/BuildException.php index dfe62b4..bc02815 100644 --- a/src/Exception/BuildException.php +++ b/src/Exception/BuildException.php @@ -1,8 +1,18 @@ addModelTransformer( new CallbackTransformer( function ($tags) { - if (!$tags instanceof PersistentCollection) { return $tags; } diff --git a/src/Form/Admin/Type/TagType.php b/src/Form/Admin/Type/TagType.php index b9b87b9..727d10e 100644 --- a/src/Form/Admin/Type/TagType.php +++ b/src/Form/Admin/Type/TagType.php @@ -1,5 +1,16 @@ false, 'active' => true, 'choices' => function (Options $options) { - $connectorEngines = []; foreach ($this->connectorManager->getAllActiveConnectorDefinitions() as $connectorDefinition) { $connectorEngines[] = $connectorDefinition->getConnectorEngine(); diff --git a/src/Form/Admin/Type/Wall/Component/PimcoreRelationType.php b/src/Form/Admin/Type/Wall/Component/PimcoreRelationType.php index e17bdb8..feb967b 100644 --- a/src/Form/Admin/Type/Wall/Component/PimcoreRelationType.php +++ b/src/Form/Admin/Type/Wall/Component/PimcoreRelationType.php @@ -1,5 +1,16 @@ addModelTransformer( new CallbackTransformer( function ($feeds) { - if (!$feeds instanceof PersistentCollection) { return $feeds; } diff --git a/src/Form/Admin/Type/Wall/FeedType.php b/src/Form/Admin/Type/Wall/FeedType.php index 2838c22..af2a67d 100644 --- a/src/Form/Admin/Type/Wall/FeedType.php +++ b/src/Form/Admin/Type/Wall/FeedType.php @@ -1,5 +1,16 @@ logManager->update($logEntry); } -} \ No newline at end of file +} diff --git a/src/Logger/ProviderContextConsoleProcessor.php b/src/Logger/ProviderContextConsoleProcessor.php index f4acd90..7a91909 100644 --- a/src/Logger/ProviderContextConsoleProcessor.php +++ b/src/Logger/ProviderContextConsoleProcessor.php @@ -1,5 +1,16 @@ getAllConnectorDefinitions(true), static function (ConnectorDefinitionInterface $connectorDefinition) { return $connectorDefinition->engineIsLoaded() && $connectorDefinition->isConnected(); - }); + } + ); } public function getAllConnectorDefinitions(bool $loadEngine = false): array @@ -34,7 +46,6 @@ public function getAllConnectorDefinitions(bool $loadEngine = false): array $allConnectorDefinitions = $this->connectorDefinitionRegistry->getAll(); foreach ($allConnectorDefinitions as $connectorDefinitionName => $connectorDefinition) { - if (!in_array($connectorDefinitionName, $this->availableConnectors, true)) { continue; } diff --git a/src/Manager/ConnectorManagerInterface.php b/src/Manager/ConnectorManagerInterface.php index 2b9f096..22d4cd6 100644 --- a/src/Manager/ConnectorManagerInterface.php +++ b/src/Manager/ConnectorManagerInterface.php @@ -1,5 +1,16 @@ getAssets(); - /** + /* * 1. Check if asset exists with property * 2. If not, check if asset exists in current path definition to avoid duplicate path issues */ @@ -218,6 +229,7 @@ protected function assertImageData(string $posterUrl): ?array $content = $this->getAssetDataFromUrl($posterUrl); } catch (\Throwable $e) { $this->logger->error(sprintf('Could not load asset data from url "%s". Error: %s', $posterUrl, $e->getMessage())); + return null; } @@ -225,11 +237,13 @@ protected function assertImageData(string $posterUrl): ?array $imageData = getimagesizefromstring($content); } catch (\Throwable $e) { $this->logger->error(sprintf('Could not determinate asset data as image from url "%s". Error: %s', $posterUrl, $e->getMessage())); + return null; } if (!is_array($imageData)) { $this->logger->error(sprintf('Could not extract image data from url "%s". Maybe it is not a valid image?', $posterUrl)); + return null; } @@ -237,6 +251,7 @@ protected function assertImageData(string $posterUrl): ?array if ($imageType !== 'image') { $this->logger->error(sprintf('Asset should be type of "image" but is type of "%s".', $imageType)); + return null; } @@ -246,6 +261,7 @@ protected function assertImageData(string $posterUrl): ?array $extension = image_type_to_extension($imageData[2]); } catch (\Exception $e) { $this->logger->error(sprintf('Could not determinate image extension from url "%s".', $posterUrl)); + return null; } @@ -258,6 +274,7 @@ protected function assertImageData(string $posterUrl): ?array if ($width <= 1 && $height <= 1) { $this->logger->warning(sprintf('Image width (%dpx) and height (%dpx) are too mall to import from url "%s".', $width, $height, $posterUrl)); + return null; } diff --git a/src/Manager/SocialPostManagerInterface.php b/src/Manager/SocialPostManagerInterface.php index 5353f6d..47d1ea8 100644 --- a/src/Manager/SocialPostManagerInterface.php +++ b/src/Manager/SocialPostManagerInterface.php @@ -1,5 +1,16 @@ lockService->isLocked(LockServiceInterface::SOCIAL_POST_BUILD_PROCESS_ID)) { $this->logger->debug(sprintf('Process %s already has been started', LockServiceInterface::SOCIAL_POST_BUILD_PROCESS_ID)); + return; } @@ -49,6 +60,7 @@ public function process(bool $forceProcessing, ?int $wallId): void $walls = $this->wallManager->getById($wallId); if (!$walls instanceof WallInterface) { $this->logger->error(sprintf('Wall with id %d not found', $wallId)); + return; } } else { @@ -84,6 +96,7 @@ protected function processWall(WallInterface $wall, bool $forceProcessing): void $this->socialPostManager->checkWallStoragePaths($wall); } catch (\Exception $e) { $this->logger->error(sprintf($e->getMessage()), [$wall]); + return; } @@ -143,7 +156,6 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig } foreach ($fetchData->getFetchedEntities() as $entry) { - // 2 filter $filterData = $this->dispatchSocialPostBuildCycle('filter', $connectorName, $buildConfig, $postBuilder, [ 'transferredData' => $entry @@ -159,11 +171,13 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig if ($filteredElement === null) { $this->logger->debug(sprintf('Element%s has been removed during filter process', empty($filteredId) ? '' : sprintf(' "%s"', $filteredId)), $logContext); + continue; } if (empty($filteredId)) { $this->logger->error(sprintf('Could not resolve social post id'), $logContext); + continue; } @@ -171,12 +185,14 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig if (!$preFetchedSocialPostEntity instanceof Concrete) { $this->logger->error(sprintf('Could not resolve pre-fetched social post for entity with id "%s"', $filteredId), $logContext); + continue; } /* @phpstan-ignore-next-line */ if (!$preFetchedSocialPostEntity instanceof SocialPostInterface) { $this->logger->error(sprintf('Could not resolve pre-fetched social post for entity with id "%s"', $filteredId), $logContext); + continue; } @@ -185,6 +201,7 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig sprintf('Social post %s (%d) already has been processed', $preFetchedSocialPostEntity->getSocialId(), $preFetchedSocialPostEntity->getId()), $logContext ); + continue; } @@ -201,6 +218,7 @@ protected function loadFeedPosts(string $connectorName, BuildConfig $buildConfig $transformedEntry = $transformData->getTransformedElement(); if (!$transformedEntry instanceof SocialPostInterface) { $this->logger->debug(sprintf('Element "%s" has been removed during transform process', $filteredId), $logContext); + continue; } @@ -217,7 +235,6 @@ protected function dispatchSocialPostBuildCycle( SocialPostBuilderInterface $socialPostBuilder, ?array $transferredData = null ): ?AbstractData { - $buildDataTransferObject = null; $logContext = [$buildConfig->getFeed()]; @@ -254,7 +271,6 @@ protected function dispatchSocialPostBuildCycle( $this->eventDispatcher->dispatch($postEvent, constant($postEventName)); $buildDataTransferObject = $postEvent->getData(); - } catch (BuildException $e) { $this->logger->error(sprintf('[Build Error] %s', $e->getMessage()), $logContext); } catch (\Throwable $e) { diff --git a/src/Registry/ConnectorDefinitionRegistry.php b/src/Registry/ConnectorDefinitionRegistry.php index 1eefe37..99f72f6 100644 --- a/src/Registry/ConnectorDefinitionRegistry.php +++ b/src/Registry/ConnectorDefinitionRegistry.php @@ -1,5 +1,16 @@ getDao()->getTableName(); $listing->onCreateQueryBuilder(function (QueryBuilder $query) use ($joinWallTagTables, $joinFeedTagTables, $aliasFrom) { - $query ->join($aliasFrom, 'social_data_feed_post', 'fp', 'fp.post_id = id') ->join($aliasFrom, 'social_data_feed', 'f', 'f.id = fp.feed_id'); @@ -218,15 +228,12 @@ public function deleteOutdatedSocialPosts(int $expireDays, bool $deletePoster = /** @var Concrete $socialPost */ foreach ($listing->getObjects() as $socialPost) { - try { - if ($deletePoster === true && $socialPost instanceof SocialPostInterface && $socialPost->getPoster() instanceof Asset) { $socialPost->getPoster()->delete(); } $socialPost->delete(); - } catch (\Exception $e) { // fail silently } diff --git a/src/Repository/SocialPostRepositoryInterface.php b/src/Repository/SocialPostRepositoryInterface.php index 87bd42e..9f098ff 100644 --- a/src/Repository/SocialPostRepositoryInterface.php +++ b/src/Repository/SocialPostRepositoryInterface.php @@ -1,5 +1,16 @@