mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Getting collection calls access_restriction which is not properly cached.
Remove use of cache in AccessRestriction and use instance memory cache instead. Beware static keyword declares variable static for the class, not the instance
This commit is contained in:
@@ -730,11 +730,7 @@ class ACL implements cache_cacheableInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$ret[$base_id] = collection::getByBaseId($this->app, $base_id);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
$ret[$base_id] = $collection;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -335,7 +335,7 @@ class appbox extends base
|
||||
/**
|
||||
* @return AccessRestriction
|
||||
*/
|
||||
private function getAccessRestriction()
|
||||
public function getAccessRestriction()
|
||||
{
|
||||
return $this->app['conf.restrictions'];
|
||||
}
|
||||
|
@@ -188,52 +188,73 @@ class collection implements ThumbnailedElement, cache_cacheableInterface
|
||||
));
|
||||
}
|
||||
|
||||
$repository = self::getRepository($app, $reference->getDataboxId());
|
||||
$collection = $repository->find($reference->getCollectionId());
|
||||
return self::getAvailableCollection($app, $reference->getDataboxId(), $reference->getCollectionId());
|
||||
}
|
||||
|
||||
if (!$collection) {
|
||||
throw new Exception_Databox_CollectionNotFound(sprintf(
|
||||
"Collection with base_id %s could not be found",
|
||||
$base_id
|
||||
));
|
||||
}
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param databox $databox
|
||||
* @param int $collectionId
|
||||
* @return collection
|
||||
*/
|
||||
public static function getByCollectionId(Application $app, databox $databox, $collectionId)
|
||||
{
|
||||
assert(is_int($collectionId));
|
||||
|
||||
if (!$app['conf.restrictions']->isCollectionAvailable($collection)) {
|
||||
return self::getAvailableCollection($app, $databox->get_sbas_id(), $collectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @return \Alchemy\Phrasea\Core\Configuration\AccessRestriction
|
||||
*/
|
||||
private static function getAccessRestriction(Application $app)
|
||||
{
|
||||
return $app['conf.restrictions'];
|
||||
}
|
||||
|
||||
private static function assertCollectionIsAvailable(Application $app, collection $collection)
|
||||
{
|
||||
if (!self::getAccessRestriction($app)->isCollectionAvailable($collection)) {
|
||||
throw new Exception_Databox_CollectionNotFound(sprintf(
|
||||
'Collection `%d` is not available here.',
|
||||
$collection->get_base_id()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return collection
|
||||
*/
|
||||
private static function getByDataboxIdAndCollectionId(Application $app, $databoxId, $collectionId)
|
||||
{
|
||||
$repository = self::getRepository($app, $databoxId);
|
||||
$collection = $repository->find($collectionId);
|
||||
|
||||
if (!$collection) {
|
||||
throw new Exception_Databox_CollectionNotFound(sprintf(
|
||||
"Collection '%d' on databox '%d' could not be found",
|
||||
$collectionId,
|
||||
$databoxId
|
||||
));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param databox $databox
|
||||
* @param int $coll_id
|
||||
* @param Application $app
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return collection
|
||||
*/
|
||||
public static function getByCollectionId(Application $app, databox $databox, $coll_id)
|
||||
private static function getAvailableCollection(Application $app, $databoxId, $collectionId)
|
||||
{
|
||||
assert(is_int($coll_id));
|
||||
|
||||
$repository = self::getRepository($app, $databox->get_sbas_id());
|
||||
$collection = $repository->find($coll_id);
|
||||
|
||||
if (!$collection) {
|
||||
throw new Exception_Databox_CollectionNotFound(sprintf(
|
||||
"Collection with collection ID %d could not be found",
|
||||
$coll_id
|
||||
));
|
||||
}
|
||||
|
||||
if (!$app['conf.restrictions']->isCollectionAvailable($collection)) {
|
||||
throw new Exception_Databox_CollectionNotFound(sprintf(
|
||||
'Collection `%d` is not available here.',
|
||||
$collection->get_base_id()
|
||||
));
|
||||
}
|
||||
$collection = self::getByDataboxIdAndCollectionId($app, $databoxId, $collectionId);
|
||||
self::assertCollectionIsAvailable($app, $collection);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
Reference in New Issue
Block a user