src/Logging/Media/CloudInodeLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Media/InodeLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Media;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Cloud\Inode;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class CloudInodeLog
  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(Inode $inode)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($inode);
  25.         $info $loggingData['info'];
  26.         $specialAuthor $loggingData['special_author'];
  27.         $ignore $loggingData['ignore'];
  28.         if ($ignore) return $pendingLogArgs;
  29.         //----------------------------------------------------------------------
  30.         // Init base log args
  31.         // This does not contain action
  32.         $args $this->initArgs($inode$loggingData);
  33.         //----------------------------------------------------------------------
  34.         if ($inode->isFolder())
  35.             $action "inode_folder_add";
  36.         else
  37.             $action "inode_file_add";
  38.         $args["action"] = $action;
  39.         $args["new_value"] = $inode->display();
  40.         $pendingLogArgs[] = $args;
  41.         return $pendingLogArgs;
  42.     }
  43.     public function logChanges(Inode $inode$changes)
  44.     {
  45.         $pendingLogArgs = [];
  46.         //----------------------------------------------------------------------
  47.         // Fetch eventual info skeletond in the object
  48.         $loggingData $this->logTools->handleLoggingData($inode);
  49.         $info $loggingData['info'];
  50.         $specialAuthor $loggingData['special_author'];
  51.         $ignore $loggingData['ignore'];
  52.         if ($ignore) return $pendingLogArgs;
  53.         //----------------------------------------------------------------------
  54.         // Init base log args
  55.         // This does not contain action
  56.         $args $this->initArgs($inode$loggingData);
  57.         //----------------------------------------------------------------------
  58.         if ($inode->isFolder())
  59.             $action "inode_folder_edit";
  60.         else
  61.             $action "inode_file_edit";
  62.         $basicChanges = array(
  63.             "name",
  64.         );
  65.         $basicBoolChanges = array(
  66.         );
  67.         $dateChanges = array(
  68.         );
  69.         $labelChanges = array(
  70.         );
  71.         // Method getLogLabel() should be defined for these objects/entities
  72.         $objectChanges = array(
  73.             "parent",
  74.         );
  75.         // See what changed and log (members first)
  76.         foreach ($changes as $key => $change)
  77.         {
  78.             // Something to skip ?
  79.             if (false)
  80.             {
  81.                 continue;
  82.             }
  83.             $name $this->logTools->camelToSnakeCase($key);
  84.             $args["action"]    = $action."_".$name;
  85.             $before $change[0];
  86.             $after $change[1];
  87.             if (in_array($key$basicChanges))
  88.             {
  89.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  90.                 continue;
  91.             }
  92.             if (in_array($key$basicBoolChanges))
  93.             {
  94.                 $pendingLogArgs[] = $this->tools->handleBasicBoolChanges($args$before$after);
  95.                 continue;
  96.             }
  97.             if (in_array($key$dateChanges))
  98.             {
  99.                 // Display d/m/Y H:i => Add a fourth param true to handleDateChanges
  100.                 // dateChanges can be null
  101.                 $changeLogs $this->tools->handleDateChanges($args$before$after);
  102.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  103.                 continue;
  104.             }
  105.             if (in_array($key$labelChanges))
  106.             {
  107.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  108.                 continue;
  109.             }
  110.             if (in_array($key$objectChanges))
  111.             {
  112.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  113.                 continue;
  114.             }
  115.         }
  116.         return $pendingLogArgs;
  117.     }
  118.     public function logRemoval(Inode $inode)
  119.     {
  120.         $pendingLogArgs = [];
  121.         //----------------------------------------------------------------------
  122.         // Fetch eventual info skeletond in the object
  123.         $loggingData $this->logTools->handleLoggingData($inode);
  124.         $info $loggingData['info'];
  125.         $specialAuthor $loggingData['special_author'];
  126.         $ignore $loggingData['ignore'];
  127.         if ($ignore) return $pendingLogArgs;
  128.         //----------------------------------------------------------------------
  129.         // Init base log args
  130.         // This does not contain action
  131.         $args $this->initArgs($inode$loggingData);
  132.         //----------------------------------------------------------------------
  133.         if ($inode->isFolder())
  134.             $action "inode_folder_delete";
  135.         else
  136.             $action "inode_file_delete";
  137.         $args["action"] = $action;
  138.         $args["old_value"] = $inode->display();
  139.         $pendingLogArgs[] = $args;
  140.         return $pendingLogArgs;
  141.     }
  142.     private function initArgs(Inode $inode$loggingData)
  143.     {
  144.         $societyGroup $inode->getSocietyGroup();
  145.         $args = array(
  146.             "object_id"                    =>    $inode->getId(),
  147.             "object_bundle"                =>    "Cloud",
  148.             "object_entity"                =>    "Inode",
  149.             "object_display"            =>    $inode->display(),
  150.             "society_group"                =>    $societyGroup,
  151.             "info"                        =>    $loggingData['info'],
  152.             "special_author"            =>    $loggingData['special_author'],
  153.         );
  154.         return $args;
  155.     }
  156. }