<?php
//----------------------------------------------------------------------
// src/Logging/Media/AclInodeLog.php
//----------------------------------------------------------------------
namespace App\Logging\Media;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Entity\Cloud\AclInode;
use App\Entity\Cloud\Inode;
use App\Logging\Tools;
use App\Logging\DeletionContextLogger;
use App\Services\LogTools;
class CloudAclInodeLog
{
private array $pendingLogArgs = [];
public function __construct(ManagerRegistry $doctrine, TranslatorInterface $translator, LogTools $logTools, DeletionContextLogger $contextLogger, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->logTools = $logTools;
$this->contextLogger = $contextLogger;
$this->tools = $tools;
$this->translator = $translator;
$this->nc = $this->translator->trans('none_provided');
}
public function logCreation(AclInode $aclInode)
{
$inode = $aclInode->getInode();
if ($inode === null) return [];
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($aclInode);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($inode, $loggingData);
//----------------------------------------------------------------------
if ($inode->isFolder())
$action = "inode_folder_share";
else
$action = "inode_file_share";
$sharer = $aclInode->getSharer() !== null ? $aclInode->getSharer()->display() : $this->nc;
$receiver = $this->nc;
if ($aclInode->getAccess() !== null)
{
$receiver = $aclInode->getAccess()->display();
}
else
{
if ($aclInode->getFunction() !== null)
{
$receiver = $aclInode->getFunction()->display();
}
}
$info = $this->translator->trans('shared_by_with', array(
"%sharer%" => $sharer,
"%receiver%" => $receiver,
), 'messages');
$args["action"] = $action;
$args["info"] = $info;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logChanges(AclInode $aclInode, $changes)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
public function logRemoval(AclInode $aclInode)
{
$pendingLogArgs = [];
$cachedData = $this->contextLogger->getContext($aclInode);
if ($cachedData === null || empty($cachedData))
{
// Nothing to do here
return $pendingLogArgs;
}
if (!array_key_exists('inode', $cachedData) || $cachedData['inode'] === null)
{
return $pendingLogArgs;
}
$inode = $cachedData['inode'];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($aclInode);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($inode, $loggingData);
//----------------------------------------------------------------------
if ($inode->isFolder())
$action = "inode_folder_unshare";
else
$action = "inode_file_unshare";
$sharer = $cachedData['sharer'] !== null ? $cachedData['sharer']->display() : $this->nc;
$receiver = $this->nc;
if ($cachedData['access'] !== null)
{
$receiver = $cachedData['access']->display();
}
else
{
if ($cachedData['accessFunction'] !== null)
{
$receiver = $cachedData['accessFunction']->display();
}
}
$info = $this->translator->trans('shared_by_with', array(
"%sharer%" => $sharer,
"%receiver%" => $receiver,
), 'messages');
$args["action"] = $action;
$args["info"] = $info;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(Inode $inode, $loggingData)
{
$societyGroup = $inode->getSocietyGroup();
$args = array(
"object_id" => $inode->getId(),
"object_bundle" => "Cloud",
"object_entity" => "Inode",
"object_display" => $inode->display(),
"society_group" => $societyGroup,
"info" => $loggingData['info'],
"special_author" => $loggingData['special_author'],
);
return $args;
}
}