kematjaya/backup-bundle

1.1.1 2022-10-01 11:45 UTC

This package is auto-updated.

Last update: 2024-03-29 04:19:13 UTC


README

  1. installation
composer require kematjaya/backup-bundle
  1. setting
## config/packages/backup.yaml

backup:
    name: postgresql
    location: '%kernel.project_dir%/var/backup'
  1. usage
php bin/console database:dump
  1. insert event
// save log to database

namespace App\EventListener;

use App\Repository\BackupRepository;
use Kematjaya\BackupBundle\Event\AfterDumpEvent;
use Kematjaya\BackupBundle\Event\BackupEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Description of BackupEventListener
 *
 * @author apple
 */
class BackupEventListener implements EventSubscriberInterface 
{
    
    private BackupRepository $backupRepository;
    
    public function __construct(BackupRepository $backupRepository) 
    {
        $this->backupRepository = $backupRepository;
    }
    
    public static function getSubscribedEvents():array 
    {
        return [
            BackupEvents::AFTER_DUMP => "saveLog"
        ];
    }

    public function saveLog(AfterDumpEvent $evt):void
    {
        $this->backupRepository->create($evt->getFileName());
    }
}