prestaconcept / PrestaSitemapBundle

A symfony bundle that provides tools to build a rich application sitemap. The main goals are : simple, no databases, various namespace (eg. google image), respect constraints etc.
MIT License
355 stars 102 forks source link

S3 compliant #322

Closed lbcd closed 8 months ago

lbcd commented 11 months ago

Description
Is it possible to push file on S3 / Minio storage ? Could be interfaced using flysystem

yann-eugone commented 11 months ago

Hi, thank you for the idea.

There is no such feature within the bundle itself, but you can easily do it on your own. You can register an event listener at the very end of the dump command, then send your files to S3, something like this:

<?php

declare(strict_types=1);

namespace App\Sitemap;

use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: ConsoleEvents::TERMINATE, method: 'onConsoleTerminate')]
final class SendSitemapToCdnListener
{
    public function onConsoleTerminate(ConsoleTerminateEvent $event): void
    {
        if ($event->getCommand()?->getName() !== 'presta:sitemaps:dump') {
            return;
        }

        $files = \glob(__DIR__ . '/../../public/sitemap.*');
        // todo send $files to your CDN
    }
}
yann-eugone commented 8 months ago

Might end in a documentation section, if someone experienced such feature on a project But I'm not sure we will ever do something like this IN the bundle