Installation
composer require common-gateway/pdd-bundle
Add the bundle to your config/bundles.php:
return [
// ...
CommonGateway\PddBundle\PddBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console config:dump-reference CommonGateway\PddBundle\Configuration
Update config/packages/common_gateway_pdd.yaml with your OpenWoo/Open Index API credentials and endpoint URLs.
First Synchronization Trigger a manual sync via CLI:
php bin/console pdd:sync
Or via a controller:
use CommonGateway\PddBundle\Command\SyncCommand;
$syncCommand = new SyncCommand();
$syncCommand->run(new ArrayInput([]), new NullOutput());
Querying Data Use the provided repository to fetch synchronized objects:
$publication = $this->getDoctrine()
->getRepository(CommonGateway\PddBundle\Entity\Publication::class)
->findByTitle('Example Publication');
// In a Twig template or controller
$publication = $this->getDoctrine()
->getRepository(CommonGateway\PddBundle\Entity\Publication::class)
->findOneBy(['uuid' => 'your-publication-uuid']);
return $this->render('publication/show.html.twig', [
'publication' => $publication,
]);
Scheduled Synchronization Use Laravel’s task scheduling to automate syncs (e.g., daily at 2 AM):
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('pdd:sync')->dailyAt('02:00');
}
Event-Driven Updates Listen for sync completion events to trigger downstream actions:
// src/EventListener/PddSyncListener.php
namespace App\EventListener;
use CommonGateway\PddBundle\Event\SyncCompletedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PddSyncListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
SyncCompletedEvent::class => 'onSyncCompleted',
];
}
public function onSyncCompleted(SyncCompletedEvent $event)
{
// Notify admins, update caches, etc.
}
}
Bulk Operations Use Doctrine batch processing for large datasets:
$em = $this->getDoctrine()->getManager();
$publications = $em->getRepository(Publication::class)->findAll();
foreach (array_chunk($publications, 50) as $chunk) {
$em->createQueryBuilder()
->update(Publication::class, 'p')
->set('p.isProcessed', ':value')
->setParameter('value', true)
->where('p IN (:chunk)')
->setParameter('chunk', $chunk)
->getQuery()
->execute();
}
Custom Fields Mapping
Extend the Publication entity to include custom fields from OpenWoo:
// src/Entity/PublicationExtension.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use CommonGateway\PddBundle\Entity\Publication;
#[ORM\Entity]
class PublicationExtension
{
#[ORM\OneToOne(targetEntity: Publication::class, inversedBy: 'extension')]
#[ORM\JoinColumn(name: 'publication_id', referencedColumnName: 'id')]
private Publication $publication;
#[ORM\Column(nullable: true)]
private ?string $customField = null;
// Getters/setters...
}
API Rate Limiting
Configure HTTP client retries and rate limits in config/packages/common_gateway_pdd.yaml:
clients:
openwoo:
timeout: 30
retries: 3
delay: 1000
max_concurrency: 5
Search Integration Use the bundle’s search service to query Open Index:
$results = $this->get('common_gateway_pdd.search')
->search('query', ['category' => 'publications']);
UUID Conflicts
SyncCommand:
// Override the command to merge duplicates
$command = new SyncCommand();
$command->setDuplicateHandler(function ($existing, $new) {
// Custom merge logic
return $existing;
});
Doctrine Mismatches
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
API Deprecations
Enable Verbose Logging
Add to config/packages/monolog.yaml:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
Then filter for common_gateway_pdd in logs.
Inspect Sync Payloads
Dump raw API responses in SyncCommand:
// In a custom command class
$this->logger->debug('Raw API response:', [
'response' => $client->getResponse()->getContent(),
]);
Validate Entities Use Symfony’s validator to catch malformed data:
$errors = $validator->validate($publication);
if (count($errors) > 0) {
throw new \RuntimeException('Validation failed: ' . (string) $errors);
}
Partial Syncs
Use the lastSyncAt field to resume interrupted syncs:
$lastSync = $this->getDoctrine()
->getRepository(Publication::class)
->findOneBy([], ['updatedAt' => 'DESC']);
$command->setLastSyncDate($lastSync ? $lastSync->getUpdatedAt() : null);
Webhook Integration Expose a webhook endpoint to receive real-time updates from OpenWoo:
// src/Controller/PddWebhookController.php
namespace App\Controller;
use CommonGateway\PddBundle\Event\WebhookReceivedEvent;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class PddWebhookController extends AbstractController
{
public function __invoke(Request $request, EventDispatcherInterface $dispatcher)
{
$dispatcher->dispatch(new WebhookReceivedEvent($request->getContent()));
return new Response('OK');
}
}
Route it in config/routes.yaml:
pdd_webhook:
path: /api/pdd/webhook
controller: App\Controller\PddWebhookController
methods: [POST]
Testing Mock the HTTP client for unit tests:
// tests/Unit/PddBundleTest.php
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
$mockClient = new MockHttpClient([
new MockResponse('{"data": [...]}', ['http_code' => 200]),
]);
$container->set('common_gateway_pdd.client.openwoo', $mockClient);
Performance
$message = new SyncPublicationsMessage();
$this->messageBus->dispatch($message);
How can I help you explore Laravel packages today?