src/Logging/Media/CloudAclInodeLog.php line 28

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Media/AclInodeLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Media;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use App\Entity\Cloud\AclInode;
  9. use App\Entity\Cloud\Inode;
  10. use App\Logging\Tools;
  11. use App\Logging\DeletionContextLogger;
  12. use App\Services\LogTools;
  13. class CloudAclInodeLog
  14. {
  15.     private array $pendingLogArgs = [];
  16.     public function __construct(ManagerRegistry $doctrineTranslatorInterface $translatorLogTools $logToolsDeletionContextLogger $contextLoggerTools $tools)
  17.     {
  18.         $this->em $doctrine->getManager();
  19.         $this->logTools $logTools;
  20.         $this->contextLogger $contextLogger;
  21.         $this->tools $tools;
  22.         $this->translator $translator;
  23.         $this->nc $this->translator->trans('none_provided');
  24.     }
  25.     public function logCreation(AclInode $aclInode)
  26.     {
  27.         $inode $aclInode->getInode();
  28.         if ($inode === null) return [];
  29.         $pendingLogArgs = [];
  30.         //----------------------------------------------------------------------
  31.         // Fetch eventual info stored in the object
  32.         $loggingData $this->logTools->handleLoggingData($aclInode);
  33.         $info $loggingData['info'];
  34.         $specialAuthor $loggingData['special_author'];
  35.         $ignore $loggingData['ignore'];
  36.         if ($ignore) return $pendingLogArgs;
  37.         //----------------------------------------------------------------------
  38.         // Init base log args
  39.         // This does not contain action
  40.         $args $this->initArgs($inode$loggingData);
  41.         //----------------------------------------------------------------------
  42.         if ($inode->isFolder())
  43.             $action "inode_folder_share";
  44.         else
  45.             $action "inode_file_share";
  46.         $sharer $aclInode->getSharer() !== null $aclInode->getSharer()->display() : $this->nc;
  47.         $receiver $this->nc;
  48.         if ($aclInode->getAccess() !== null)
  49.         {
  50.             $receiver $aclInode->getAccess()->display();
  51.         }
  52.         else
  53.         {
  54.             if ($aclInode->getFunction() !== null)
  55.             {
  56.                 $receiver $aclInode->getFunction()->display();
  57.             }
  58.         }
  59.         $info $this->translator->trans('shared_by_with', array(
  60.             "%sharer%"            =>    $sharer,
  61.             "%receiver%"        =>    $receiver,
  62.         ), 'messages');
  63.         $args["action"] = $action;
  64.         $args["info"] = $info;
  65.         $pendingLogArgs[] = $args;
  66.         return $pendingLogArgs;
  67.     }
  68.     public function logChanges(AclInode $aclInode$changes)
  69.     {
  70.         $pendingLogArgs = [];
  71.         return $pendingLogArgs;
  72.     }
  73.     public function logRemoval(AclInode $aclInode)
  74.     {
  75.         $pendingLogArgs = [];
  76.         $cachedData $this->contextLogger->getContext($aclInode);
  77.         if ($cachedData === null || empty($cachedData))
  78.         {
  79.             // Nothing to do here
  80.             return $pendingLogArgs;
  81.         }
  82.         if (!array_key_exists('inode'$cachedData) || $cachedData['inode'] === null)
  83.         {
  84.             return $pendingLogArgs;
  85.         }
  86.         $inode $cachedData['inode'];
  87.         //----------------------------------------------------------------------
  88.         // Fetch eventual info skeletond in the object
  89.         $loggingData $this->logTools->handleLoggingData($aclInode);
  90.         $info $loggingData['info'];
  91.         $specialAuthor $loggingData['special_author'];
  92.         $ignore $loggingData['ignore'];
  93.         if ($ignore) return $pendingLogArgs;
  94.         //----------------------------------------------------------------------
  95.         // Init base log args
  96.         // This does not contain action
  97.         $args $this->initArgs($inode$loggingData);
  98.         //----------------------------------------------------------------------
  99.         if ($inode->isFolder())
  100.             $action "inode_folder_unshare";
  101.         else
  102.             $action "inode_file_unshare";
  103.         $sharer $cachedData['sharer'] !== null $cachedData['sharer']->display() : $this->nc;
  104.         $receiver $this->nc;
  105.         if ($cachedData['access'] !== null)
  106.         {
  107.             $receiver $cachedData['access']->display();
  108.         }
  109.         else
  110.         {
  111.             if ($cachedData['accessFunction'] !== null)
  112.             {
  113.                 $receiver $cachedData['accessFunction']->display();
  114.             }
  115.         }
  116.         $info $this->translator->trans('shared_by_with', array(
  117.             "%sharer%"            =>    $sharer,
  118.             "%receiver%"        =>    $receiver,
  119.         ), 'messages');
  120.         $args["action"] = $action;
  121.         $args["info"] = $info;
  122.         $pendingLogArgs[] = $args;
  123.         return $pendingLogArgs;
  124.     }
  125.     private function initArgs(Inode $inode$loggingData)
  126.     {
  127.         $societyGroup $inode->getSocietyGroup();
  128.         $args = array(
  129.             "object_id"                    =>    $inode->getId(),
  130.             "object_bundle"                =>    "Cloud",
  131.             "object_entity"                =>    "Inode",
  132.             "object_display"            =>    $inode->display(),
  133.             "society_group"                =>    $societyGroup,
  134.             "info"                        =>    $loggingData['info'],
  135.             "special_author"            =>    $loggingData['special_author'],
  136.         );
  137.         return $args;
  138.     }
  139. }