Skip to content

Commit

Permalink
Add a lot of logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Aug 30, 2024
1 parent 2814efc commit 521a53b
Show file tree
Hide file tree
Showing 26 changed files with 556 additions and 29 deletions.
5 changes: 5 additions & 0 deletions config/services/enqueuer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<argument type="service" id="webgriffe_sylius_active_campaign_plugin.command_bus"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.contact"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.enqueuer.connection"
class="Webgriffe\SyliusActiveCampaignPlugin\Enqueuer\ConnectionEnqueuer">
<argument type="service" id="webgriffe_sylius_active_campaign_plugin.command_bus"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.connection"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.enqueuer.ecommerce_customer"
Expand All @@ -22,20 +24,23 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_customer"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="webgriffe_sylius_active_campaign.factory.channel_customer"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.enqueuer.ecommerce_order"
class="Webgriffe\SyliusActiveCampaignPlugin\Enqueuer\EcommerceOrderEnqueuer">
<argument type="service" id="webgriffe_sylius_active_campaign_plugin.command_bus"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_order"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.enqueuer.webhook"
class="Webgriffe\SyliusActiveCampaignPlugin\Enqueuer\WebhookEnqueuer">
<argument type="service" id="webgriffe_sylius_active_campaign_plugin.command_bus"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.webhook"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.generator.channel_hostname_url"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
</service>
</services>
</container>
13 changes: 13 additions & 0 deletions config/services/message_handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.contact"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.contact"/>
<argument type="service" id="sylius.repository.customer"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -15,12 +16,14 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.contact"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.contact"/>
<argument type="service" id="sylius.repository.customer"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.message_handler.contact.remove"
class="Webgriffe\SyliusActiveCampaignPlugin\MessageHandler\Contact\ContactRemoveHandler">
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.contact"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand Down Expand Up @@ -61,6 +64,7 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.connection"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.connection"/>
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -69,12 +73,14 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.connection"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.connection"/>
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.message_handler.connection.remove"
class="Webgriffe\SyliusActiveCampaignPlugin\MessageHandler\Connection\ConnectionRemoveHandler">
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.connection"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -86,6 +92,7 @@
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="webgriffe_sylius_active_campaign.factory.channel_customer"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -95,12 +102,14 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_customer"/>
<argument type="service" id="sylius.repository.customer"/>
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.message_handler.ecommerce_customer.remove"
class="Webgriffe\SyliusActiveCampaignPlugin\MessageHandler\EcommerceCustomer\EcommerceCustomerRemoveHandler">
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_customer"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -109,6 +118,7 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.ecommerce_order"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_order"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -117,12 +127,14 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.mapper.ecommerce_order"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_order"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

<service id="webgriffe.sylius_active_campaign_plugin.message_handler.ecommerce_order.remove"
class="Webgriffe\SyliusActiveCampaignPlugin\MessageHandler\EcommerceOrder\EcommerceOrderRemoveHandler">
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.ecommerce_order"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>

Expand All @@ -132,6 +144,7 @@
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.client.active_campaign.webhook"/>
<argument type="service" id="sylius.repository.channel"/>
<argument type="service" id="webgriffe.sylius_active_campaign_plugin.generator.channel_hostname_url"/>
<argument type="service" id="monolog.logger.webgriffe_sylius_active_campaign_plugin"/>
<tag name="messenger.message_handler"/>
</service>
</services>
Expand Down
27 changes: 27 additions & 0 deletions src/Enqueuer/ConnectionEnqueuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webgriffe\SyliusActiveCampaignPlugin\Enqueuer;

use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Client\ActiveCampaignResourceClientInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Message\Connection\ConnectionCreate;
Expand All @@ -18,16 +19,33 @@ public function __construct(
private MessageBusInterface $messageBus,
private ActiveCampaignResourceClientInterface $activeCampaignConnectionClient,
private EntityManagerInterface $entityManager,
private ?LoggerInterface $logger = null,
) {
if ($this->logger === null) {
trigger_deprecation(
'webgriffe/sylius-active-campaign-plugin',
'v0.12.2',
'The logger argument is mandatory.',
);
}
}

public function enqueue($channel): void
{
/** @var string|int|null $channelId */
$channelId = $channel->getId();
Assert::notNull($channelId, 'The channel id should not be null');
$this->logger?->debug(sprintf(
'Starting enqueuing connection for channel "%s".',
$channelId,
));
$activeCampaignConnectionId = $channel->getActiveCampaignId();
if ($activeCampaignConnectionId !== null) {
$this->logger?->debug(sprintf(
'Channel "%s" has an already valued ActiveCampaign id "%s", so we have to update the connection.',
$channelId,
$activeCampaignConnectionId,
));
$this->messageBus->dispatch(new ConnectionUpdate($channelId, $activeCampaignConnectionId));

return;
Expand All @@ -44,11 +62,20 @@ public function enqueue($channel): void
$activeCampaignConnectionId = $connection->getId();
$channel->setActiveCampaignId($activeCampaignConnectionId);
$this->entityManager->flush();
$this->logger?->debug(sprintf(
'Found an ActiveCampaign connection with id "%s" for given channel "%s", the id has been stored and we have to update the connection.',
$activeCampaignConnectionId,
$channelId,
));

$this->messageBus->dispatch(new ConnectionUpdate($channelId, $activeCampaignConnectionId));

return;
}
$this->logger?->debug(sprintf(
'No connection found for given channel "%s", we have to create the connection.',
$channelId,
));

$this->messageBus->dispatch(new ConnectionCreate($channelId));
}
Expand Down
27 changes: 27 additions & 0 deletions src/Enqueuer/ContactEnqueuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webgriffe\SyliusActiveCampaignPlugin\Enqueuer;

use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Client\ActiveCampaignResourceClientInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Message\Contact\ContactCreate;
Expand All @@ -18,16 +19,33 @@ public function __construct(
private MessageBusInterface $messageBus,
private ActiveCampaignResourceClientInterface $activeCampaignContactClient,
private EntityManagerInterface $entityManager,
private ?LoggerInterface $logger = null,
) {
if ($this->logger === null) {
trigger_deprecation(
'webgriffe/sylius-active-campaign-plugin',
'v0.12.2',
'The logger argument is mandatory.',
);
}
}

public function enqueue($customer): void
{
/** @var string|int|null $customerId */
$customerId = $customer->getId();
Assert::notNull($customerId, 'The customer id should not be null');
$this->logger?->debug(sprintf(
'Starting enqueuing contact for customer "%s".',
$customerId,
));
$activeCampaignContactId = $customer->getActiveCampaignId();
if ($activeCampaignContactId !== null) {
$this->logger?->debug(sprintf(
'Customer "%s" has an already valued ActiveCampaign id "%s", so we have to update the contact.',
$customerId,
$activeCampaignContactId,
));
$this->messageBus->dispatch(new ContactUpdate($customerId, $activeCampaignContactId));

return;
Expand All @@ -41,11 +59,20 @@ public function enqueue($customer): void
$activeCampaignContactId = $contact->getId();
$customer->setActiveCampaignId($activeCampaignContactId);
$this->entityManager->flush();
$this->logger?->debug(sprintf(
'Customer "%s" has an already valued ActiveCampaign id "%s", so we have to update the contact.',
$customerId,
$activeCampaignContactId,
));

$this->messageBus->dispatch(new ContactUpdate($customerId, $activeCampaignContactId));

return;
}
$this->logger?->debug(sprintf(
'No contact found for given customer "%s", we have to create the contact.',
$customerId,
));

$this->messageBus->dispatch(new ContactCreate($customerId));
}
Expand Down
31 changes: 31 additions & 0 deletions src/Enqueuer/EcommerceCustomerEnqueuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webgriffe\SyliusActiveCampaignPlugin\Enqueuer;

use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Client\ActiveCampaignResourceClientInterface;
Expand All @@ -24,7 +25,15 @@ public function __construct(
private ActiveCampaignResourceClientInterface $activeCampaignEcommerceCustomerClient,
private EntityManagerInterface $entityManager,
private FactoryInterface $channelCustomerFactory,
private ?LoggerInterface $logger = null,
) {
if ($this->logger === null) {
trigger_deprecation(
'webgriffe/sylius-active-campaign-plugin',
'v0.12.2',
'The logger argument is mandatory.',
);
}
}

public function enqueue($customer, $channel): void
Expand All @@ -35,9 +44,20 @@ public function enqueue($customer, $channel): void
/** @var string|int|null $channelId */
$channelId = $channel->getId();
Assert::notNull($channelId, 'The channel id should not be null');
$this->logger?->debug(sprintf(
'Starting enqueuing ecommerce customer for customer "%s" and channel "%s".',
$customerId,
$channelId,
));

$channelCustomer = $customer->getChannelCustomerByChannel($channel);
if ($channelCustomer !== null) {
$this->logger?->debug(sprintf(
'Customer "%s" has an already valued ActiveCampaign id "%s" for channel "%s", so we have to update the ecommerce customer.',
$customerId,
$channelCustomer->getActiveCampaignId(),
$channelId,
));
$this->messageBus->dispatch(new EcommerceCustomerUpdate($customerId, $channelCustomer->getActiveCampaignId(), $channelId));

return;
Expand All @@ -63,11 +83,22 @@ public function enqueue($customer, $channel): void
$this->entityManager->persist($channelCustomer);
$customer->addChannelCustomer($channelCustomer);
$this->entityManager->flush();
$this->logger?->debug(sprintf(
'Found an ActiveCampaign ecommerce customer with id "%s" for given customer "%s" and channel "%s", the id has been stored and we have to update the ecommerce customer.',
$activeCampaignEcommerceCustomerId,
$customerId,
$channelId,
));

$this->messageBus->dispatch(new EcommerceCustomerUpdate($customerId, $activeCampaignEcommerceCustomerId, $channelId));

return;
}
$this->logger?->debug(sprintf(
'No ecommerce customer found for given customer "%s" and channel "%s", we have to create the ecommerce customer.',
$customerId,
$channelId,
));

$this->messageBus->dispatch(new EcommerceCustomerCreate($customerId, $channelId));
}
Expand Down
Loading

0 comments on commit 521a53b

Please sign in to comment.