Skip to content

Commit

Permalink
Use Akeneo Logger everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGrimmChester committed Oct 24, 2024
1 parent 00a7478 commit b00c7f9
Show file tree
Hide file tree
Showing 50 changed files with 140 additions and 135 deletions.
10 changes: 5 additions & 5 deletions src/Checker/Product/IsProductProcessableChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class IsProductProcessableChecker implements IsProductProcessableCheckerIn
private const ONE_VARIATION_AXIS = 1;

public function __construct(
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private ApiConnectionProviderInterface $apiConnectionProvider,
private FamilyVariantRetrieverInterface $familyVariantRetriever,
) {
Expand All @@ -25,13 +25,13 @@ public function check(array $resource): bool
{
try {
if ('' === $resource['code'] || null === $resource['code']) {
$this->logger->warning('Skipping product import because the code is missing.', ['resource' => $resource]);
$this->akeneoLogger->warning('Skipping product import because the code is missing.', ['resource' => $resource]);

return false;
}

if (!isset($resource['family'])) {
$this->logger->warning('Skipping product import because the family is missing.', ['resource' => $resource]);
$this->akeneoLogger->warning('Skipping product import because the family is missing.', ['resource' => $resource]);

return false;
}
Expand All @@ -44,7 +44,7 @@ public function check(array $resource): bool
$numberOfVariationAxis > self::ONE_VARIATION_AXIS &&
$this->apiConnectionProvider->get()->getAxeAsModel() === AkeneoAxesEnum::FIRST
) {
$this->logger->debug('Skipping product import because the parent is null and it has more than one variation axis.', ['resource' => $resource]);
$this->akeneoLogger->debug('Skipping product import because the parent is null and it has more than one variation axis.', ['resource' => $resource]);

return false;
}
Expand All @@ -54,7 +54,7 @@ public function check(array $resource): bool
$numberOfVariationAxis === 2 &&
$this->apiConnectionProvider->get()->getAxeAsModel() !== AkeneoAxesEnum::FIRST
) {
$this->logger->debug('Skipping product import because the parent is null, and it has more than one variation axis.', ['resource' => $resource]);
$this->akeneoLogger->debug('Skipping product import because the parent is null, and it has more than one variation axis.', ['resource' => $resource]);

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/AbstractImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractImportCommand extends Command
protected PipelineInterface $pipeline;

public function __construct(
protected LoggerInterface $logger,
protected LoggerInterface $akeneoLogger,
protected PayloadFactoryInterface $payloadFactory,
private PipelineFactoryInterface $pipelineFactory,
string $name = null,
Expand Down Expand Up @@ -57,14 +57,14 @@ protected function preExecute(): void
throw new CommandLockedException(Messages::commandAlreadyRunning());
}

$this->logger->notice(static::$defaultName ?? '');
$this->akeneoLogger->notice(static::$defaultName ?? '');

$this->pipeline = $this->pipelineFactory->create();
}

protected function postExecute(): void
{
$this->logger->notice(Messages::endOfCommand(static::$defaultName ?? ''));
$this->akeneoLogger->notice(Messages::endOfCommand(static::$defaultName ?? ''));
$this->release();
}
}
6 changes: 3 additions & 3 deletions src/Command/BatchImportAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BatchImportAssetsCommand extends AbstractBatchCommand

public function __construct(
private ClientFactoryInterface $clientFactory,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private BatchAssetTask $batchAssetTask,
) {
parent::__construct(self::$defaultName);
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$batchPayload = new AssetPayload($this->clientFactory->createFromApiCredentials());
$batchPayload->setIds($ids);
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BatchImportAssociationTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BatchImportAssociationTypesCommand extends AbstractBatchCommand

public function __construct(
private ClientFactoryInterface $clientFactory,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private BatchAssociationTypesTask $batchAssociationTypesTask,
) {
parent::__construct(self::$defaultName);
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$batchPayload = new AssociationTypePayload($this->clientFactory->createFromApiCredentials());
$batchPayload->setIds($ids);
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BatchImportAttributesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BatchImportAttributesCommand extends AbstractBatchCommand

public function __construct(
private ClientFactoryInterface $clientFactory,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private BatchAttributesTask $attributesTask,
) {
parent::__construct(self::$defaultName);
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$attributePayload = new AttributePayload($this->clientFactory->createFromApiCredentials());
$attributePayload->setIds($ids);
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BatchImportCategoriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BatchImportCategoriesCommand extends AbstractBatchCommand

public function __construct(
private ClientFactoryInterface $clientFactory,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private BatchCategoriesTask $task,
) {
parent::__construct(self::$defaultName);
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$payload = new CategoryPayload($this->clientFactory->createFromApiCredentials());
$payload->setIds($ids);
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BatchImportProductModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class BatchImportProductModelsCommand extends AbstractBatchCommand
public function __construct(
private ClientFactoryInterface $clientFactory,
private BatchProductModelTask $batchProductModelTask,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
) {
parent::__construct(self::$defaultName);
}
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$productModelPayload = new ProductModelPayload($this->clientFactory->createFromApiCredentials());
$productModelPayload->setIds($ids);
Expand Down
6 changes: 3 additions & 3 deletions src/Command/BatchImportProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BatchImportProductsCommand extends AbstractBatchCommand

public function __construct(
private ClientFactoryInterface $clientFactory,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private BatchProductsTask $batchProductGroupsTask,
) {
parent::__construct(self::$defaultName);
Expand All @@ -37,8 +37,8 @@ protected function execute(
Assert::string($input->getArgument('ids'));
$ids = explode(',', $input->getArgument('ids'));

$this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->logger->debug(self::$defaultName, ['batched_ids' => $ids]);
$this->akeneoLogger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->debug(self::$defaultName, ['batched_ids' => $ids]);

$productModelPayload = new ProductPayload($this->clientFactory->createFromApiCredentials());
$productModelPayload->setIds($ids);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportAssociationTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ImportAssociationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ImportAssociationsCommand extends Command
public function __construct(
private ClientFactoryInterface $clientFactory,
private AssociateProductsTask $associateProductsTask,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
) {
parent::__construct(self::$defaultName);
}
Expand All @@ -49,12 +49,12 @@ protected function execute(
return 0;
}

$this->logger->notice(self::$defaultName);
$this->akeneoLogger->notice(self::$defaultName);

$payload = new AssociationPayload($this->clientFactory->createFromApiCredentials());
$this->associateProductsTask->__invoke($payload);

$this->logger->notice(Messages::endOfCommand(self::$defaultName));
$this->akeneoLogger->notice(Messages::endOfCommand(self::$defaultName));
$this->release();

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportAttributesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportCategoriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportProductModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ImportProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postExecute();
} catch (CommandLockedException $commandLockedException) {
$this->logger->warning($commandLockedException->getMessage());
$this->akeneoLogger->warning($commandLockedException->getMessage());

return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Creator/AttributeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
private RepositoryInterface $productAttributeRepository,
private AkeneoAttributeToSyliusAttributeTransformerInterface $akeneoAttributeToSyliusAttributeTransformer,
private AttributeTypeMatcher $attributeTypeMatcher,
private LoggerInterface $logger,
private LoggerInterface $akeneoLogger,
private ExcludedAttributesProviderInterface $excludedAttributesProvider,
private EditionCheckerInterface $editionChecker,
private ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
Expand Down Expand Up @@ -77,7 +77,7 @@ public function create(array $resource): AttributeInterface

return $attribute;
} catch (UnsupportedAttributeTypeException $unsupportedAttributeTypeException) {
$this->logger->warning(sprintf(
$this->akeneoLogger->warning(sprintf(
'%s: %s',
$resource['code'],
$unsupportedAttributeTypeException->getMessage(),
Expand Down Expand Up @@ -123,14 +123,14 @@ private function getOrCreateEntity(string $attributeCode, TypeMatcherInterface $

$attribute->setCode($attributeCode);
$this->entityManager->persist($attribute);
$this->logger->info(Messages::hasBeenCreated('Attribute', (string) $attribute->getCode()));
$this->akeneoLogger->info(Messages::hasBeenCreated('Attribute', (string) $attribute->getCode()));

return $attribute;
}

$this->migrateType($attribute, $attributeType);

$this->logger->info(Messages::hasBeenUpdated('Attribute', (string) $attribute->getCode()));
$this->akeneoLogger->info(Messages::hasBeenUpdated('Attribute', (string) $attribute->getCode()));

return $attribute;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Handler/Task/SymfonyMessengerTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SymfonyMessengerTaskHandler implements TaskHandlerInterface

public function __construct(
protected EntityManagerInterface $entityManager,
protected LoggerInterface $logger,
protected LoggerInterface $akeneoLogger,
private MessageBusInterface $bus,
private BatchMessageFactoryInterface $batchMessageFactory,
) {
Expand Down Expand Up @@ -65,7 +65,7 @@ private function handleByPage(
$identifiers[] = $item['code'] ?? $item['identifier'];

if (0 === $count % $payload->getBatchSize()) {
$this->logger->notice('Batching', ['codes' => $identifiers]);
$this->akeneoLogger->notice('Batching', ['codes' => $identifiers]);
$this->batch($payload, $items);
$items = [];
$identifiers = [];
Expand Down Expand Up @@ -96,7 +96,7 @@ private function handleByCursor(
$identifiers[] = $item['code'] ?? $item['identifier'];

if (0 === $count % $payload->getBatchSize()) {
$this->logger->notice('Batching', ['codes' => $identifiers]);
$this->akeneoLogger->notice('Batching', ['codes' => $identifiers]);
$this->batch($payload, $items);
$items = [];
$identifiers = [];
Expand Down
10 changes: 5 additions & 5 deletions src/Handler/Task/SymfonyProcessTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SymfonyProcessTaskHandler implements TaskHandlerInterface
public function __construct(
protected EntityManagerInterface $entityManager,
protected ProcessManagerInterface $processManager,
protected LoggerInterface $logger,
protected LoggerInterface $akeneoLogger,
private string $projectDir,
private PayloadBatchTaskProvider $payloadBatchTaskProvider,
private BatchTaskProvider $batchTaskProvider,
Expand Down Expand Up @@ -61,7 +61,7 @@ public function batch(
$isTtySupported = Process::isTtySupported();
$process->setTty($isTtySupported);
$this->processManager->addProcess($process);
$this->logger->info('Added batch process', [
$this->akeneoLogger->info('Added batch process', [
'ids' => $ids,
]);

Expand Down Expand Up @@ -128,7 +128,7 @@ public function handle(
}

if ($count > 0 && count($ids) > 0 && $pipelinePayload->isBatchingAllowed() && $pipelinePayload->getProcessAsSoonAsPossible() && $pipelinePayload->allowParallel()) {
$this->logger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[(is_countable($ids) ? \count($ids) : 0) - 1]]);
$this->akeneoLogger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[(is_countable($ids) ? \count($ids) : 0) - 1]]);
$this->batch($pipelinePayload, $ids);
$this->processManager->waitForAllProcesses();

Expand Down Expand Up @@ -184,7 +184,7 @@ private function handleByPage(
if ($payload->isBatchingAllowed() &&
$payload->getProcessAsSoonAsPossible() &&
0 === $count % $payload->getBatchSize()) {
$this->logger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->batch($payload, $ids);
$ids = [];
}
Expand Down Expand Up @@ -215,7 +215,7 @@ private function handleByCursor(
if ($payload->isBatchingAllowed() &&
$payload->getProcessAsSoonAsPossible() &&
0 === $count % $payload->getBatchSize()) {
$this->logger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->akeneoLogger->notice('Batching', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]);
$this->batch($payload, $ids);
$ids = [];
}
Expand Down
Loading

0 comments on commit b00c7f9

Please sign in to comment.