diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index cd6a391596..d142e5b27a 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -1057,7 +1057,7 @@ class V1Controller extends Controller $searchView = $this->buildSearchView($this->doSearch($request)); - $subdefTransformer = new SubdefTransformer(); + $subdefTransformer = new SubdefTransformer($this->app['acl'], $this->getAuthenticatedUser(), new PermalinkTransformer()); $recordTransformer = new RecordTransformer($subdefTransformer, new TechnicalDataTransformer()); $storyTransformer = new StoryTransformer($subdefTransformer, $recordTransformer); $compositeTransformer = new V1SearchCompositeResultTransformer($recordTransformer, $storyTransformer); @@ -1269,20 +1269,20 @@ class V1Controller extends Controller */ private function resolveSearchIncludes(Request $request) { - if (!$request->attributes->get('_extended', false)) { - return []; + if ($request->attributes->get('_extended', false)) { + return [ + 'results.stories.records.subdefs', + 'results.stories.records.metadata', + 'results.stories.records.caption', + 'results.stories.records.status', + 'results.records.subdefs', + 'results.records.metadata', + 'results.records.caption', + 'results.records.status', + ]; } - return [ - 'results.stories.records.subdefs', - 'results.stories.records.metadata', - 'results.stories.records.caption', - 'results.stories.records.status', - 'results.records.subdefs', - 'results.records.metadata', - 'results.records.caption', - 'results.records.status', - ]; + return []; } /** @@ -1293,16 +1293,16 @@ class V1Controller extends Controller */ private function resolveSearchRecordsIncludes(Request $request) { - if (!$request->attributes->get('_extended', false)) { - return []; + if ($request->attributes->get('_extended', false)) { + return [ + 'results.subdefs', + 'results.metadata', + 'results.caption', + 'results.status', + ]; } - return [ - 'results.subdefs', - 'results.metadata', - 'results.caption', - 'results.status', - ]; + return []; } /** diff --git a/lib/Alchemy/Phrasea/Databox/Caption/CaptionDataRepositoryFactory.php b/lib/Alchemy/Phrasea/Databox/Caption/CaptionDataRepositoryFactory.php new file mode 100644 index 0000000000..12faab9deb --- /dev/null +++ b/lib/Alchemy/Phrasea/Databox/Caption/CaptionDataRepositoryFactory.php @@ -0,0 +1,43 @@ +connectionProvider = $connectionProvider; + $this->cache = $cache; + } + + public function createRepositoryFor($databoxId) + { + return new CachedCaptionDataRepository( + new DbalCaptionDataRepository($this->connectionProvider->getConnection($databoxId)), + $this->cache, + sprintf('databox[%d]:', $databoxId) + ); + } +} diff --git a/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepository.php b/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepository.php index eb9cee0a77..e66de9b226 100644 --- a/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepository.php +++ b/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepository.php @@ -10,8 +10,6 @@ namespace Alchemy\Phrasea\Databox\Caption; -use Assert\Assertion; - class CaptionRepository { /** diff --git a/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepositoryFactory.php b/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepositoryFactory.php deleted file mode 100644 index d48ab0e395..0000000000 --- a/lib/Alchemy/Phrasea/Databox/Caption/CaptionRepositoryFactory.php +++ /dev/null @@ -1,60 +0,0 @@ -connectionProvider = $connectionProvider; - $this->cache = $cache; - $this->captionFactoryProvider = $captionFactoryProvider; - } - - public function createRepositoryFor($databoxId) - { - $connection = $this->connectionProvider->getConnection($databoxId); - - $dbalRepository = new DbalCaptionDataRepository($connection); - $dataRepository = new CachedCaptionDataRepository($dbalRepository, $this->cache, sprintf('databox[%d]:', $databoxId)); - - $provider = $this->captionFactoryProvider; - $factory = $provider($databoxId); - - if (!is_callable($factory)) { - throw new \UnexpectedValueException(sprintf( - 'Caption factory is expected to be callable, got %s', - is_object($factory) ? get_class($factory) : gettype($factory) - )); - } - - return new CaptionRepository($dataRepository, $factory); - } -} diff --git a/lib/Alchemy/Phrasea/Databox/Caption/CaptionServiceProvider.php b/lib/Alchemy/Phrasea/Databox/Caption/CaptionServiceProvider.php index bc5cbee3bf..3f63153e33 100644 --- a/lib/Alchemy/Phrasea/Databox/Caption/CaptionServiceProvider.php +++ b/lib/Alchemy/Phrasea/Databox/Caption/CaptionServiceProvider.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Databox\Caption; use Alchemy\Phrasea\Controller\LazyLocator; +use Alchemy\Phrasea\Databox\ClosureDataboxBoundRepositoryFactory; use Alchemy\Phrasea\Databox\DataboxBoundRepositoryProvider; use Alchemy\Phrasea\Databox\DataboxConnectionProvider; use Alchemy\Phrasea\Record\RecordReference; @@ -29,13 +30,26 @@ class CaptionServiceProvider implements ServiceProviderInterface }; }); + $app['provider.data_repo.caption'] = $app->share(function (Application $app) { + return new DataboxBoundRepositoryProvider(new CaptionDataRepositoryFactory( + new DataboxConnectionProvider($app['phraseanet.appbox']), + $app['cache'] + )); + }); + $app['provider.repo.caption'] = $app->share(function (Application $app) { - $connectionProvider = new DataboxConnectionProvider($app['phraseanet.appbox']); - $factoryProvider = $app['provider.factory.caption']; + return new DataboxBoundRepositoryProvider( + new ClosureDataboxBoundRepositoryFactory(function ($databoxId) use ($app) { + /** @var CaptionDataRepository $dataRepository */ + $dataRepository = $app['provider.data_repo.caption']->getRepositoryForDatabox($databoxId); + $captionFactoryProvider = $app['provider.factory.caption']; - $repositoryFactory = new CaptionRepositoryFactory($connectionProvider, $app['cache'], $factoryProvider); - - return new DataboxBoundRepositoryProvider($repositoryFactory); + return new CaptionRepository( + $dataRepository, + $captionFactoryProvider($databoxId) + ); + }) + ); }); $app['service.caption'] = $app->share(function (Application $app) { @@ -45,6 +59,6 @@ class CaptionServiceProvider implements ServiceProviderInterface public function boot(Application $app) { - $app['dispatcher']->addSubscriber(new CaptionCacheInvalider(new LazyLocator($app, 'provider.repo.caption'))); + $app['dispatcher']->addSubscriber(new CaptionCacheInvalider(new LazyLocator($app, 'provider.data_repo.caption'))); } } diff --git a/lib/Alchemy/Phrasea/Databox/ClosureDataboxBoundRepositoryFactory.php b/lib/Alchemy/Phrasea/Databox/ClosureDataboxBoundRepositoryFactory.php new file mode 100644 index 0000000000..88776f4bb5 --- /dev/null +++ b/lib/Alchemy/Phrasea/Databox/ClosureDataboxBoundRepositoryFactory.php @@ -0,0 +1,31 @@ +factory = $factory; + } + + public function createRepositoryFor($databoxId) + { + $factory = $this->factory; + + return $factory($databoxId); + } +}