Files
Phraseanet/lib/Alchemy/Phrasea/Collection/CollectionRepositoryRegistry.php
aynsix 5cdf473c7f PHRAS-1972: Account Page, Allow a Phraseanet User to delete his account and associated datas (#2918)
* allow user to delete account

* generate translation and add checkbox in the windows confirmation

* change text an configuration key

* update delete account fonctionality

* rename variable

* write in explicite condition

* merge yarn.lock

* regenerate translation
2019-04-08 14:25:17 +02:00

117 lines
2.9 KiB
PHP

<?php
/**
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Collection;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
class CollectionRepositoryRegistry
{
private $baseIdMap = null;
/**
* @var Application
*/
private $application;
/**
* @var CollectionRepository[]
*/
private $repositories = array();
/**
* @var CollectionReferenceRepository
*/
private $referenceRepository;
/**
* @var CollectionRepositoryFactory
*/
private $repositoryFactory;
/**
* @param Application $app
* @param CollectionRepositoryFactory $collectionRepositoryFactory
* @param CollectionReferenceRepository $referenceRepository
*/
public function __construct(
Application $app,
CollectionRepositoryFactory $collectionRepositoryFactory,
CollectionReferenceRepository $referenceRepository
) {
$this->application = $app;
$this->repositoryFactory = $collectionRepositoryFactory;
$this->referenceRepository = $referenceRepository;
}
/**
* @param $databoxId
* @return CollectionRepository
*/
public function getRepositoryByDatabox($databoxId)
{
if (!isset($this->repositories[$databoxId])) {
$this->repositories[$databoxId] = $this->repositoryFactory->createRepositoryForDatabox($databoxId);
}
return $this->repositories[$databoxId];
}
/**
* @param int $baseId
* @return CollectionRepository
* @throws \OutOfBoundsException if no repository was found for the given baseId.
*/
public function getRepositoryByBase($baseId)
{
if ($this->baseIdMap === null) {
$this->loadBaseIdMap();
}
if (isset($this->baseIdMap[$baseId])) {
return $this->getRepositoryByDatabox($this->baseIdMap[$baseId]);
}
throw new \OutOfBoundsException('No repository available for given base [baseId: ' . $baseId . ' ].');
}
public function getBaseIdMap()
{
if ($this->baseIdMap === null) {
$this->loadBaseIdMap();
}
return $this->baseIdMap;
}
public function purgeRegistry()
{
$this->baseIdMap = null;
$appBox = $this->application->getApplicationBox();
\phrasea::reset_baseDatas($appBox);
\phrasea::reset_sbasDatas($appBox);
}
private function loadBaseIdMap()
{
$references = $this->referenceRepository->findAll();
$this->baseIdMap = [];
foreach ($references as $reference) {
$this->baseIdMap[$reference->getBaseId()] = $reference->getDataboxId();
}
}
}