Commit 34a4606e authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Factorisation pour la suppression du cache doctrine des affectations, plus...

Factorisation pour la suppression du cache doctrine des affectations, plus propre et centralisé dans un service.
parent 23e40074
Loading
Loading
Loading
Loading
Loading
+3 −6
Changes for module/Administration/src/Command/SynchronisationCommand.php: 3 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Administration\Command;

use Application\Provider\Role\RoleProvider;
use Application\Service\Traits\AffectationServiceAwareTrait;
use Doctrine\Common\Cache\FilesystemCache;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -19,9 +20,7 @@ use UnicaenImport\Processus\Traits\ImportProcessusAwareTrait;
class SynchronisationCommand extends Command
{
    use ImportProcessusAwareTrait;

    protected FilesystemCache $doctrineCache;

    use AffectationServiceAwareTrait;

    protected function configure(): void
    {
@@ -56,9 +55,7 @@ class SynchronisationCommand extends Command
            $io->writeln("Fin du job '" . $job . "'");
            //Suppresion du cache des affectations
            $io->writeln("Suppression du cache doctrine des affectations");

            $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');

            $this->getServiceAffectation()->deleteCacheAffectation();
        }

        return Command::SUCCESS;
+1 −2
Changes for module/Administration/src/Command/SynchronisationCommandFactory.php: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -23,10 +23,9 @@ class SynchronisationCommandFactory
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null): SynchronisationCommand
    {
        $doctrineCache = $container->get('doctrine.cache.filesystem');

        $command = new SynchronisationCommand;
        $command->setProcessusImport($container->get(ImportProcessus::class));
        $command->setDoctrineCache($doctrineCache);

        /* Injectez vos dépendances ICI */

+4
Changes for module/Application/config/droits.config.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -221,6 +221,10 @@ return [
    'service_manager' => [
        'invokables' => [
            Service\PerimetreService::class => Service\PerimetreService::class,

        ],
        'factories' => [
            Service\AffectationService::class => Service\Factory\AffectationServiceFactory::class,
        ],
    ],
    'form_elements'   => [
+5 −5
Changes for module/Application/src/Controller/DroitsController.php: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ class DroitsController extends AbstractController
            if ($form->isValid()) {
                try {
                    $this->getServiceRole()->save($role);
                    $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
                    $this->getServiceAffectation()->deleteCacheAffectation();
                    $form->get('id')->setValue($role->getId()); // transmet le nouvel ID
                } catch (\Exception $e) {
                    $errors[] = $this->translate($e);
@@ -118,7 +118,7 @@ class DroitsController extends AbstractController
        $title = "Suppression du rôle";
        $form  = $this->makeFormSupprimer(function () use ($role) {
            $this->getServiceRole()->delete($role);
            $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
            $this->getServiceAffectation()->deleteCacheAffectation();
            $this->getSessionContainer()->offsetUnset('privileges' . $this->getServiceContext()->getAnnee()->getId());
        });

@@ -168,7 +168,7 @@ class DroitsController extends AbstractController
                if ($role) $this->roleRemovePrivilege($role, $privilege);
            break;
        }
        $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
        $this->getServiceAffectation()->deleteCacheAffectation();

        return compact('role', 'privilege');
    }
@@ -254,7 +254,7 @@ class DroitsController extends AbstractController
                }
            }
        }
        $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
        $this->getServiceAffectation()->deleteCacheAffectation();

        return compact('form', 'title', 'errors');
    }
@@ -270,7 +270,7 @@ class DroitsController extends AbstractController
        $form = $this->makeFormSupprimer(function () use ($affectation) {
            $this->getServiceAffectation()->delete($affectation);
        });
        $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
        $this->getServiceAffectation()->deleteCacheAffectation();

        return compact('affectation', 'title', 'form');
    }
+16
Changes for module/Application/src/Service/AffectationService.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Application\Service;

use Application\Entity\Db\Role;
use Application\Provider\Role\RoleProvider;
use Application\Service\Traits\SourceServiceAwareTrait;
use Application\Entity\Db\Affectation;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Lieu\Entity\Db\Structure;
@@ -24,6 +26,8 @@ class AffectationService extends AbstractEntityService
    use SourceServiceAwareTrait;
    use StructureServiceAwareTrait;

    protected FilesystemCache $doctrineCache;


    /**
     * retourne la classe des entités
@@ -106,4 +110,16 @@ class AffectationService extends AbstractEntityService
        return $qb;
    }

    public function setDoctrineCache(FilesystemCache $doctrineCache):affectationService
    {
        $this->doctrineCache = $doctrineCache;

        return $this;
    }

    public function deleteCacheAffectation():void
    {
        $this->doctrineCache->delete(str_replace('\\', '_', RoleProvider::class) . '_affectations');
    }

}
 No newline at end of file
Loading