src/Logging/Security/AclLog.php line 17

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Security/AclLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Security;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Security\Acl;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class AclLog
  11. {
  12.     private array $pendingLogArgs = [];
  13.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsTools $tools)
  14.     {
  15.         $this->em $doctrine->getManager();
  16.         $this->logTools $logTools;
  17.         $this->tools $tools;
  18.     }
  19.     public function logCreation(Acl $acl)
  20.     {
  21.         if ($this->societyGroupIsNotLoggable($acl)) return [];
  22.         $pendingLogArgs = [];
  23.         $function $acl->getFunction();
  24.         if ($function === null) return $pendingLogArgs;
  25.         //----------------------------------------------------------------------
  26.         // Fetch eventual info stored in the object
  27.         $loggingData $this->logTools->handleLoggingData($acl);
  28.         $info $loggingData['info'];
  29.         $specialAuthor $loggingData['special_author'];
  30.         $ignore $loggingData['ignore'];
  31.         if ($ignore) return $pendingLogArgs;
  32.         //----------------------------------------------------------------------
  33.         // Init base log args
  34.         // This does not contain action
  35.         $args $this->initArgs($acl$loggingData);
  36.         //----------------------------------------------------------------------
  37.         $action "acl_change_permission";
  38.         $args["action"] = $action;
  39.         $pendingLogArgs[] = $args;
  40.         return $pendingLogArgs;
  41.     }
  42.     public function logChanges(Acl $acl$changes)
  43.     {
  44.         if ($this->societyGroupIsNotLoggable($acl)) return [];
  45.         $pendingLogArgs = [];
  46.         $function $acl->getFunction();
  47.         if ($function === null) return $pendingLogArgs;
  48.         //----------------------------------------------------------------------
  49.         // Fetch eventual info skeletond in the object
  50.         $loggingData $this->logTools->handleLoggingData($acl);
  51.         $info $loggingData['info'];
  52.         $specialAuthor $loggingData['special_author'];
  53.         $ignore $loggingData['ignore'];
  54.         if ($ignore) return $pendingLogArgs;
  55.         //----------------------------------------------------------------------
  56.         // Init base log args
  57.         // This does not contain action
  58.         $args $this->initArgs($acl$loggingData);
  59.         //----------------------------------------------------------------------
  60.         $action "acl_change_permission";
  61.         $args["action"] = $action;
  62.         $pendingLogArgs[] = $args;
  63.         return $pendingLogArgs;
  64.     }
  65.     public function logRemoval(Acl $acl)
  66.     {
  67.         $pendingLogArgs = [];
  68.         return $pendingLogArgs;
  69.     }
  70.     // SocietyGroup creation => Objects are being created at the same time
  71.     // but the SocietyGroup itself has not been flushed
  72.     private function societyGroupIsNotLoggable(Acl $acl)
  73.     {
  74.         $user $this->logTools->getCurrentUser();
  75.         $societyGroup $user->getSocietyGroup();
  76.         if ($societyGroup === null || empty($societyGroup->getId()))
  77.         {
  78.             return true;
  79.         }
  80.         return false;
  81.     }
  82.     private function initArgs(Acl $acl$loggingData)
  83.     {
  84.         $user $this->logTools->getCurrentUser();
  85.         $societyGroup $user->getSocietyGroup();
  86.         $function $acl->getFunction()->getName();
  87.         $functionDisplay $function " : ";
  88.         if ($acl->getValue())
  89.         {
  90.             $oldValue "non";
  91.             $newValue "oui";
  92.         }
  93.         else
  94.         {
  95.             $oldValue "oui";
  96.             $newValue "non";
  97.         }
  98.         $args = array(
  99.             "object_id"                    =>    $acl->getId(),
  100.             "object_bundle"                =>    "Security",
  101.             "object_entity"                =>    "Acl",
  102.             "object_display"            =>    $acl->getPermission()->getTranslation(),
  103.             "old_value"                    =>    $functionDisplay $oldValue,
  104.             "new_value"                    =>    $functionDisplay $newValue,
  105.             "society_group"                =>    $societyGroup,
  106.             "society"                    =>    null,
  107.             "info"                        =>    $loggingData['info'],
  108.             "special_author"            =>    $loggingData['special_author'],
  109.         );
  110.         return $args;
  111.     }
  112. }