mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
Bust databox cache via repository
This commit is contained in:
@@ -146,9 +146,17 @@ class RepositoriesServiceProvider implements ServiceProviderInterface
|
|||||||
$app['repo.databoxes'] = $app->share(function (PhraseaApplication $app) {
|
$app['repo.databoxes'] = $app->share(function (PhraseaApplication $app) {
|
||||||
$factory = new DataboxFactory($app);
|
$factory = new DataboxFactory($app);
|
||||||
$appbox = $app->getApplicationBox();
|
$appbox = $app->getApplicationBox();
|
||||||
$repository = new DbalDataboxRepository($appbox->get_connection(), $factory);
|
|
||||||
|
|
||||||
return new CachingDataboxRepositoryDecorator($repository, $app['cache'], $appbox->get_cache_key($appbox::CACHE_LIST_BASES), $factory);
|
$repository = new CachingDataboxRepositoryDecorator(
|
||||||
|
new DbalDataboxRepository($appbox->get_connection(), $factory),
|
||||||
|
$app['cache'],
|
||||||
|
$appbox->get_cache_key($appbox::CACHE_LIST_BASES),
|
||||||
|
$factory
|
||||||
|
);
|
||||||
|
|
||||||
|
$factory->setDataboxRepository($repository);
|
||||||
|
|
||||||
|
return $repository;
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['repo.fields.factory'] = $app->protect(function (\databox $databox) use ($app) {
|
$app['repo.fields.factory'] = $app->protect(function (\databox $databox) use ($app) {
|
||||||
|
@@ -56,6 +56,13 @@ final class CachingDataboxRepositoryDecorator implements DataboxRepository
|
|||||||
return $databoxes;
|
return $databoxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save(\databox $databox)
|
||||||
|
{
|
||||||
|
$this->cache->delete($this->cacheKey);
|
||||||
|
|
||||||
|
$this->repository->save($databox);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \databox[] $databoxes
|
* @param \databox[] $databoxes
|
||||||
*/
|
*/
|
||||||
|
@@ -17,20 +17,33 @@ class DataboxFactory
|
|||||||
/** @var Application */
|
/** @var Application */
|
||||||
private $app;
|
private $app;
|
||||||
|
|
||||||
|
/** @var DataboxRepository */
|
||||||
|
private $databoxRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Application $app
|
||||||
|
*/
|
||||||
public function __construct(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param DataboxRepository $databoxRepository
|
||||||
|
*/
|
||||||
|
public function setDataboxRepository(DataboxRepository $databoxRepository)
|
||||||
|
{
|
||||||
|
$this->databoxRepository = $databoxRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
* @param array $raw
|
* @param array $raw
|
||||||
* @throws NotFoundHttpException when Databox could not be retrieved from Persistence layer
|
* @return \databox when Databox could not be retrieved from Persistence layer
|
||||||
* @return \databox
|
|
||||||
*/
|
*/
|
||||||
public function create($id, array $raw)
|
public function create($id, array $raw)
|
||||||
{
|
{
|
||||||
return new \databox($this->app, $id, $raw);
|
return new \databox($this->app, $id, $this->databoxRepository, $raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +56,7 @@ class DataboxFactory
|
|||||||
$databoxes = [];
|
$databoxes = [];
|
||||||
|
|
||||||
foreach ($rows as $id => $raw) {
|
foreach ($rows as $id => $raw) {
|
||||||
$databoxes[$id] = new \databox($this->app, $id, $raw);
|
$databoxes[$id] = new \databox($this->app, $id, $this->databoxRepository, $raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $databoxes;
|
return $databoxes;
|
||||||
|
@@ -21,4 +21,9 @@ interface DataboxRepository
|
|||||||
* @return \databox[]
|
* @return \databox[]
|
||||||
*/
|
*/
|
||||||
public function findAll();
|
public function findAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \databox $databox
|
||||||
|
*/
|
||||||
|
public function save(\databox $databox);
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,11 @@ final class DbalDataboxRepository implements DataboxRepository
|
|||||||
return $this->factory->createMany($this->fetchRows());
|
return $this->factory->createMany($this->fetchRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save(\databox $databox)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return false|array
|
* @return false|array
|
||||||
|
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Core\Connection\ConnectionSettings;
|
|||||||
use Alchemy\Phrasea\Core\PhraseaTokens;
|
use Alchemy\Phrasea\Core\PhraseaTokens;
|
||||||
use Alchemy\Phrasea\Core\Thumbnail\ThumbnailedElement;
|
use Alchemy\Phrasea\Core\Thumbnail\ThumbnailedElement;
|
||||||
use Alchemy\Phrasea\Core\Version\DataboxVersionRepository;
|
use Alchemy\Phrasea\Core\Version\DataboxVersionRepository;
|
||||||
|
use Alchemy\Phrasea\Databox\DataboxRepository;
|
||||||
use Alchemy\Phrasea\Databox\Record\RecordRepository;
|
use Alchemy\Phrasea\Databox\Record\RecordRepository;
|
||||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
@@ -74,23 +75,30 @@ class databox extends base implements ThumbnailedElement
|
|||||||
/** @var databox_subdefsStructure */
|
/** @var databox_subdefsStructure */
|
||||||
protected $subdef_struct;
|
protected $subdef_struct;
|
||||||
|
|
||||||
|
/** @var DataboxRepository */
|
||||||
|
private $databoxRepository;
|
||||||
/** @var RecordRepository */
|
/** @var RecordRepository */
|
||||||
private $recordRepository;
|
private $recordRepository;
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
private $labels = [];
|
private $labels = [];
|
||||||
|
/** @var int */
|
||||||
private $ord;
|
private $ord;
|
||||||
|
/** @var string */
|
||||||
private $viewname;
|
private $viewname;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Application $app
|
* @param Application $app
|
||||||
* @param int $sbas_id
|
* @param int $sbas_id
|
||||||
* @param array $row
|
* @param DataboxRepository $databoxRepository
|
||||||
|
* @param array $row
|
||||||
*/
|
*/
|
||||||
public function __construct(Application $app, $sbas_id, array $row)
|
public function __construct(Application $app, $sbas_id, DataboxRepository $databoxRepository, array $row)
|
||||||
{
|
{
|
||||||
assert(is_int($sbas_id));
|
assert(is_int($sbas_id));
|
||||||
assert($sbas_id > 0);
|
assert($sbas_id > 0);
|
||||||
|
|
||||||
|
$this->databoxRepository = $databoxRepository;
|
||||||
$this->id = $sbas_id;
|
$this->id = $sbas_id;
|
||||||
|
|
||||||
$connectionConfigs = phrasea::sbas_params($app);
|
$connectionConfigs = phrasea::sbas_params($app);
|
||||||
@@ -146,6 +154,7 @@ class databox extends base implements ThumbnailedElement
|
|||||||
cache_databox::update($this->app, $this->id, 'structure');
|
cache_databox::update($this->app, $this->id, 'structure');
|
||||||
|
|
||||||
$this->viewname = $viewname;
|
$this->viewname = $viewname;
|
||||||
|
$this->databoxRepository->save($this);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -192,14 +201,10 @@ class databox extends base implements ThumbnailedElement
|
|||||||
*/
|
*/
|
||||||
public function get_collection_unique_ids()
|
public function get_collection_unique_ids()
|
||||||
{
|
{
|
||||||
static $collectionsIds;
|
$collectionsIds = [];
|
||||||
|
|
||||||
if ($collectionsIds === null) {
|
foreach ($this->get_collections() as $collection) {
|
||||||
$collectionsIds = [];
|
$collectionsIds[] = $collection->get_base_id();
|
||||||
|
|
||||||
foreach ($this->get_collections() as $collection) {
|
|
||||||
$collectionsIds[] = $collection->get_base_id();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collectionsIds;
|
return $collectionsIds;
|
||||||
@@ -243,6 +248,8 @@ class databox extends base implements ThumbnailedElement
|
|||||||
|
|
||||||
$this->labels[$code] = $label;
|
$this->labels[$code] = $label;
|
||||||
|
|
||||||
|
$this->databoxRepository->save($this);
|
||||||
|
|
||||||
phrasea::reset_sbasDatas($this->app['phraseanet.appbox']);
|
phrasea::reset_sbasDatas($this->app['phraseanet.appbox']);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -841,6 +848,8 @@ class databox extends base implements ThumbnailedElement
|
|||||||
|
|
||||||
cache_databox::update($this->app, $this->id, 'structure');
|
cache_databox::update($this->app, $this->id, 'structure');
|
||||||
|
|
||||||
|
$this->databoxRepository->save($this);
|
||||||
|
|
||||||
$this->app['dispatcher']->dispatch(
|
$this->app['dispatcher']->dispatch(
|
||||||
DataboxEvents::STRUCTURE_CHANGED,
|
DataboxEvents::STRUCTURE_CHANGED,
|
||||||
new StructureChangedEvent(
|
new StructureChangedEvent(
|
||||||
@@ -871,6 +880,8 @@ class databox extends base implements ThumbnailedElement
|
|||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
$this->databoxRepository->save($this);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
protected $thesaurus;
|
protected $thesaurus;
|
||||||
@@ -888,6 +899,8 @@ class databox extends base implements ThumbnailedElement
|
|||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
$this->delete_data_from_cache(databox::CACHE_THESAURUS);
|
$this->delete_data_from_cache(databox::CACHE_THESAURUS);
|
||||||
|
|
||||||
|
$this->databoxRepository->save($this);
|
||||||
|
|
||||||
$this->app['dispatcher']->dispatch(
|
$this->app['dispatcher']->dispatch(
|
||||||
DataboxEvents::THESAURUS_CHANGED,
|
DataboxEvents::THESAURUS_CHANGED,
|
||||||
new ThesaurusChangedEvent(
|
new ThesaurusChangedEvent(
|
||||||
|
@@ -645,6 +645,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$data = json_decode(self::$DI['client']->getResponse()->getContent(), true);
|
$data = json_decode(self::$DI['client']->getResponse()->getContent(), true);
|
||||||
$this->assertTrue($data['success']);
|
$this->assertTrue($data['success']);
|
||||||
|
|
||||||
|
$base = $this->getApplication()->findDataboxById($base->get_sbas_id());
|
||||||
|
|
||||||
$this->assertEquals('frenchy label', $base->get_label('fr', false));
|
$this->assertEquals('frenchy label', $base->get_label('fr', false));
|
||||||
$this->assertEquals('', $base->get_label('en', false));
|
$this->assertEquals('', $base->get_label('en', false));
|
||||||
$this->assertEquals('Jaja label', $base->get_label('de', false));
|
$this->assertEquals('Jaja label', $base->get_label('de', false));
|
||||||
|
Reference in New Issue
Block a user