mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
merge master into branch
This commit is contained in:
@@ -1248,9 +1248,12 @@ class ACL implements cache_cacheableInterface
|
||||
|
||||
}
|
||||
}
|
||||
$this->app->getApplicationBox()->get_databox($sbas_id)->clearCache(databox::CACHE_COLLECTIONS);
|
||||
}
|
||||
$stmt_ins->closeCursor();
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
|
||||
// $this->delete_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1365,7 +1368,10 @@ class ACL implements cache_cacheableInterface
|
||||
$stmt->execute([':sbas_id' => $sbas_id, ':usr_id' => $this->user->getId()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->app->getApplicationBox()->get_databox($sbas_id)->clearCache(databox::CACHE_COLLECTIONS);
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
|
||||
// $this->delete_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
||||
|
||||
$this->app['dispatcher']->dispatch(
|
||||
AclEvents::RIGHTS_TO_SBAS_CHANGED,
|
||||
|
@@ -597,6 +597,9 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
|
||||
$this->getReferenceRepository()->save($this->reference);
|
||||
$this->collectionRepositoryRegistry->purgeRegistry();
|
||||
|
||||
// clear the trivial cache of databox->get_collections()
|
||||
$this->get_databox()->clearCache(databox::CACHE_COLLECTIONS);
|
||||
|
||||
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
|
||||
|
||||
$this->dispatch(CollectionEvents::DISABLED, new DisabledEvent($this));
|
||||
@@ -614,6 +617,9 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
|
||||
$this->getReferenceRepository()->save($this->reference);
|
||||
$this->collectionRepositoryRegistry->purgeRegistry();
|
||||
|
||||
// clear the trivial cache of databox->get_collections()
|
||||
$this->get_databox()->clearCache(databox::CACHE_COLLECTIONS);
|
||||
|
||||
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
|
||||
|
||||
$this->dispatch(CollectionEvents::ENABLED, new EnabledEvent($this));
|
||||
|
@@ -576,18 +576,35 @@ class databox extends base implements ThumbnailedElement
|
||||
parent::delete_data_from_cache($option);
|
||||
}
|
||||
|
||||
/*
|
||||
* trivial cache to speed-up get_collections() which does sql
|
||||
*/
|
||||
private $_collection_unique_ids = null;
|
||||
private $_collections = null;
|
||||
|
||||
public function clearCache($what)
|
||||
{
|
||||
switch($what) {
|
||||
case self::CACHE_COLLECTIONS:
|
||||
$this->_collection_unique_ids = $this->_collections = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_collection_unique_ids()
|
||||
{
|
||||
$collectionsIds = [];
|
||||
if($this->_collection_unique_ids === null) {
|
||||
$this->_collection_unique_ids = [];
|
||||
|
||||
foreach ($this->get_collections() as $collection) {
|
||||
$collectionsIds[] = $collection->get_base_id();
|
||||
foreach ($this->get_collections() as $collection) {
|
||||
$this->_collection_unique_ids[] = $collection->get_base_id();
|
||||
}
|
||||
}
|
||||
|
||||
return $collectionsIds;
|
||||
return $this->_collection_unique_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -595,15 +612,20 @@ class databox extends base implements ThumbnailedElement
|
||||
*/
|
||||
public function get_collections()
|
||||
{
|
||||
/** @var CollectionRepositoryRegistry $repositoryRegistry */
|
||||
$repositoryRegistry = $this->app['repo.collections-registry'];
|
||||
$repository = $repositoryRegistry->getRepositoryByDatabox($this->get_sbas_id());
|
||||
if($this->_collections === null) {
|
||||
/** @var CollectionRepositoryRegistry $repositoryRegistry */
|
||||
$repositoryRegistry = $this->app['repo.collections-registry'];
|
||||
$repository = $repositoryRegistry->getRepositoryByDatabox($this->get_sbas_id());
|
||||
|
||||
return array_filter($repository->findAll(), function (collection $collection) {
|
||||
return $collection->is_active();
|
||||
});
|
||||
$this->_collections = array_filter($repository->findAll(), function (collection $collection) {
|
||||
return $collection->is_active();
|
||||
});
|
||||
}
|
||||
|
||||
return $this->_collections;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return collection|null
|
||||
*/
|
||||
|
@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Assert\Assertion;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Guzzle\Http\Url;
|
||||
|
||||
class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
@@ -380,13 +381,14 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
* @param Application $app
|
||||
* @param databox $databox
|
||||
* @param media_subdef[] $subdefs
|
||||
* @throws DBALException
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \InvalidArgumentException|Exception
|
||||
*/
|
||||
public static function createMany(Application $app, databox $databox, $subdefs)
|
||||
{
|
||||
$databoxId = $databox->get_sbas_id();
|
||||
$recordIds = [];
|
||||
/** @var media_subdef[] $uniqSubdefs */
|
||||
$uniqSubdefs = [];
|
||||
|
||||
foreach ($subdefs as $media_subdef) {
|
||||
if ($media_subdef->get_sbas_id() !== $databoxId) {
|
||||
@@ -397,12 +399,17 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
));
|
||||
}
|
||||
|
||||
$recordIds[] = $media_subdef->get_record_id();
|
||||
// keep unique record_id, to fetch records and find if some are missing
|
||||
$recordIds[$media_subdef->get_record_id()] = $media_subdef->get_record_id();
|
||||
|
||||
// keep unique subdefs so we don't try to generate the same twice
|
||||
// (even if we could since it's catched)
|
||||
$uniqSubdefs[$media_subdef->get_subdef_id()] = $media_subdef;
|
||||
}
|
||||
|
||||
// find records
|
||||
$databoxRecords = $databox->getRecordRepository()->findByRecordIds($recordIds);
|
||||
|
||||
/** @var record_adapter[] $records */
|
||||
$records = array_combine(
|
||||
array_map(function (record_adapter $record) {
|
||||
return $record->getRecordId();
|
||||
@@ -410,7 +417,8 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
$databoxRecords
|
||||
);
|
||||
|
||||
if (count(array_unique($recordIds)) !== count($records)) {
|
||||
// check if some records are missing
|
||||
if (count($recordIds) !== count($records)) {
|
||||
throw new \RuntimeException('Some records are missing');
|
||||
}
|
||||
|
||||
@@ -418,7 +426,7 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($subdefs as $media_subdef) {
|
||||
foreach ($uniqSubdefs as $media_subdef) {
|
||||
$data[] = [
|
||||
'subdef_id' => $media_subdef->get_subdef_id(),
|
||||
'token' => $generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS),
|
||||
@@ -426,20 +434,22 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$databox->get_connection()->transactional(function (Connection $connection) use ($data) {
|
||||
$sql = "INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label)\n"
|
||||
. " VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)";
|
||||
$databox->get_connection()->transactional(function (Connection $connection) use ($data) {
|
||||
$sql = "INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label)\n"
|
||||
. " VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)";
|
||||
|
||||
$statement = $connection->prepare($sql);
|
||||
$statement = $connection->prepare($sql);
|
||||
|
||||
foreach ($data as $params) {
|
||||
foreach ($data as $params) {
|
||||
try {
|
||||
$statement->execute($params);
|
||||
}
|
||||
});
|
||||
} catch (Exception $e) {
|
||||
throw new RuntimeException('Permalink already exists', $e->getCode(), $e);
|
||||
}
|
||||
catch(UniqueConstraintViolationException $e) {
|
||||
// we ignore this because somebody else might have created this plink
|
||||
// between the test of "to be created" and here
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user