Merge pull request #1391 from bburnichon/master

try improve tests stability
This commit is contained in:
Benoît Burnichon
2015-06-05 15:14:06 +02:00
32 changed files with 201 additions and 156 deletions

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller;
class LazyLocator
{
/** @var \Pimple */
private $pimple;
private $serviceId;
/**
* @param \Pimple $pimple
* @param string $serviceId
*/
public function __construct(\Pimple $pimple, $serviceId)
{
$this->pimple = $pimple;
$this->serviceId = $serviceId;
}
public function __invoke()
{
return $this->pimple->offsetGet($this->serviceId);
}
}

View File

@@ -13,10 +13,12 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\CollectionController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;
class Collection implements ControllerProviderInterface, ServiceProviderInterface
{
@@ -26,9 +28,7 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
{
$app['controller.admin.collection'] = $app->share(function (PhraseaApplication $app) {
return (new CollectionController($app))
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
;
});
}
@@ -40,10 +40,12 @@ class Collection implements ControllerProviderInterface, ServiceProviderInterfac
public function connect(Application $app)
{
$controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) {
$app['firewall']->requireAccessToModule('admin')
->requireRightOnBase($app['request']->attributes->get('bas_id'), 'canadmin');
$controllers->before(function (Request $request) use ($firewall) {
$firewall
->requireAccessToModule('admin')
->requireRightOnBase($request->attributes->get('bas_id'), 'canadmin');
});
$controllers->get('/{bas_id}/', 'controller.admin.collection:getCollection')

View File

@@ -46,9 +46,10 @@ class ConnectedUsers implements ControllerProviderInterface, ServiceProviderInte
public function connect(Application $app)
{
$controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) {
$app['firewall']->requireAccessToModule('Admin');
$controllers->before(function () use ($firewall) {
$firewall->requireAccessToModule('Admin');
});
$controllers->get('/', 'controller.admin.connected-users:listConnectedUsers')

View File

@@ -13,6 +13,8 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\DashboardController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
@@ -20,13 +22,14 @@ use Silex\ServiceProviderInterface;
class Dashboard implements ControllerProviderInterface, ServiceProviderInterface
{
use ControllerProviderTrait;
public function register(Application $app)
{
$app['controller.admin.dashboard'] = $app->share(function (PhraseaApplication $app) {
return (new DashboardController($app))
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
;
});
}
@@ -36,11 +39,11 @@ class Dashboard implements ControllerProviderInterface, ServiceProviderInterface
public function connect(Application $app)
{
/** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
$controllers = $this->createCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($app) {
$app['firewall']->requireAdmin();
$controllers->before(function () use ($firewall) {
$firewall->requireAdmin();
});
$controllers->get('/', 'controller.admin.dashboard:slash')

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Admin\DataboxController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Alchemy\Phrasea\Security\Firewall;
use Silex\Application;
@@ -28,9 +29,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.admin.databox'] = $app->share(function (PhraseaApplication $app) {
return (new DataboxController($app))
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Admin;
use Alchemy\Phrasea\Controller\Admin\UserController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
use Silex\ControllerProviderInterface;
@@ -25,12 +26,8 @@ class Users implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.admin.users'] = $app->share(function () use ($app) {
return (new UserController($app))
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
;
});
}

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\DatafileController;
use Alchemy\Phrasea\Controller\LazyLocator;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
@@ -25,9 +26,8 @@ class Datafiles implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.datafiles'] = $app->share(function (PhraseaApplication $app) {
return (new DatafileController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) {
return $app['phraseanet.file-serve'];
});
->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\PermalinkController;
use Silex\Application;
use Silex\ControllerCollection;
@@ -25,9 +26,8 @@ class Permalink implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.permalink'] = $app->share(function (PhraseaApplication $app) {
return (new PermalinkController($app, $app['phraseanet.appbox'], $app['acl'], $app['authentication']))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) {
return $app['phraseanet.file-serve'];
});
->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\DoDownloadController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -26,13 +27,10 @@ class DoDownload implements ControllerProviderInterface, ServiceProviderInterfac
{
$app['controller.prod.do-download'] = $app->share(function (PhraseaApplication $app) {
return (new DoDownloadController($app))
->setDelivererLocator(function () use ($app) {
return $app['phraseanet.file-serve'];
})
->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
->setDispatcher($app['dispatcher'])
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
});
->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\EditController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -28,9 +29,7 @@ class Edit implements ControllerProviderInterface, ServiceProviderInterface
return (new EditController($app))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDispatcher($app['dispatcher'])
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\ExportController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -27,12 +28,8 @@ class Export implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.export'] = $app->share(function (PhraseaApplication $app) {
return (new ExportController($app))
->setDispatcher($app['dispatcher'])
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
})
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
})
->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\LazaretController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -27,18 +28,10 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.lazaret'] = $app->share(function (PhraseaApplication $app) {
return (new LazaretController($app))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDelivererLocator(function () use ($app) {
return $app['phraseanet.file-serve'];
})
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
->setDelivererLocator(new LazyLocator($app, 'phraseanet.file-serve'))
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\OrderController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -27,12 +28,8 @@ class Order implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.order'] = $app->share(function (PhraseaApplication $app) {
return (new OrderController($app))
->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\PushController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -28,12 +29,8 @@ class Push implements ControllerProviderInterface, ServiceProviderInterface
return (new PushController($app))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setUserQueryFactory(function () use ($app) {
return $app['phraseanet.user-query'];
})
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setUserQueryFactory(new LazyLocator($app, 'phraseanet.user-query'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\QueryController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -26,12 +27,8 @@ class Query implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.prod.query'] = $app->share(function (PhraseaApplication $app) {
return (new QueryController($app))
->setSearchEngineLocator(function () use ($app) {
return $app['phraseanet.SE'];
})
->setSearchEngineLoggerLocator(function () use ($app) {
return $app['phraseanet.SE.logger'];
})
->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
->setSearchEngineLoggerLocator(new LazyLocator($app, 'phraseanet.SE.logger'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\RecordController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -26,12 +27,8 @@ class Record implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.prod.records'] = $app->share(function (PhraseaApplication $app) {
return (new RecordController($app))
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setSearchEngineLocator(function () use ($app) {
return $app['phraseanet.SE'];
})
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\StoryController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -27,9 +28,7 @@ class Story implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.story'] = $app->share(function (PhraseaApplication $app) {
return (new StoryController($app))
->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\ToolsController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -27,12 +28,8 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface
$app['controller.prod.tools'] = $app->share(function (PhraseaApplication $app) {
return (new ToolsController($app))
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\TooltipController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -26,9 +27,7 @@ class Tooltip implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.prod.tooltip'] = $app->share(function (PhraseaApplication $app) {
return (new TooltipController($app))
->setSearchEngineLocator(function () use ($app) {
return $app['phraseanet.SE'];
})
->setSearchEngineLocator(new LazyLocator($app, 'phraseanet.SE'))
;
});
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Controller\Prod\UploadController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
@@ -26,23 +27,13 @@ class Upload implements ControllerProviderInterface, ServiceProviderInterface
{
$app['controller.prod.upload'] = $app->share(function (PhraseaApplication $app) {
return (new UploadController($app))
->setBorderManagerLocator(function () use ($app) {
return $app['border-manager'];
})
->setBorderManagerLocator(new LazyLocator($app, 'border-manager'))
->setDispatcher($app['dispatcher'])
->setDataboxLoggerLocator($app['phraseanet.logger'])
->setEntityManagerLocator(function () use ($app) {
return $app['orm.em'];
})
->setFileSystemLocator(function () use ($app) {
return $app['filesystem'];
})
->setTemporaryFileSystemLocator(function () use ($app) {
return $app['temporary-filesystem'];
})
->setSubDefinitionSubstituerLocator(function () use ($app) {
return $app['subdef.substituer'];
})
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setFileSystemLocator(new LazyLocator($app, 'filesystem'))
->setTemporaryFileSystemLocator(new LazyLocator($app, 'temporary-filesystem'))
->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer'))
;
});
}

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Root;
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Alchemy\Phrasea\ControllerProvider\Root\Login;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
@@ -37,9 +38,7 @@ class Account implements ControllerProviderInterface
public function connect(Application $app)
{
$app['account.controller'] = $this
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
$controllers = $this->createAuthenticatedCollection($app);

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Authentication\Exception\NotAuthenticatedException;
use Alchemy\Phrasea\Authentication\Exception\AuthenticationException;
use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Authentication\Provider\ProviderInterface;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Core\Event\LogoutEvent;
use Alchemy\Phrasea\Core\Event\PreAuthenticate;
use Alchemy\Phrasea\Core\Event\PostAuthenticate;
@@ -99,9 +100,8 @@ class Login implements ControllerProviderInterface
$controllers = $app['controllers_factory'];
$app['login.controller'] = $this
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
;
$controllers->before(function (Request $request) use ($app) {
if ($request->getPathInfo() == $app->path('homepage')) {

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Model\Entities\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -25,9 +26,7 @@ abstract class AbstractNotificationSubscriber implements EventSubscriberInterfac
public function __construct(Application $app)
{
$this->app = $app;
$this->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
$this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
}
protected function shouldSendNotificationFor(User $user, $type)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\SearchEngine\SearchEngineLogger;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
@@ -25,7 +26,6 @@ use Alchemy\Phrasea\SearchEngine\Elastic\Search\FacetsResponse;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryCompiler;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus;
use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngineSubscriber;
use Elasticsearch\Client;
use Hoa\Compiler;
use Hoa\File;
@@ -33,6 +33,8 @@ use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class SearchEngineServiceProvider implements ServiceProviderInterface
{
@@ -106,13 +108,24 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
return new RecordHelper($app['phraseanet.appbox']);
});
$app['elasticsearch.indexer_subscriber'] = $app->share(function ($app) {
return new IndexerSubscriber($app['elasticsearch.indexer']);
});
$app['dispatcher'] = $app
->share($app->extend('dispatcher', function (EventDispatcherInterface $dispatcher, $app) {
$subscriber = new IndexerSubscriber(new LazyLocator($app, 'elasticsearch.indexer'));
$dispatcher->addSubscriber($subscriber);
$app['dispatcher'] = $app->share($app->extend('dispatcher', function ($dispatcher, $app) {
$dispatcher->addSubscriber($app['elasticsearch.indexer_subscriber']);
$listener = array($subscriber, 'flushQueue');
// Add synchronous flush when used in CLI.
if (isset($app['console'])) {
foreach (array_keys($subscriber->getSubscribedEvents()) as $eventName) {
$dispatcher->addListener($eventName, $listener, -10);
}
return $dispatcher;
}
$dispatcher->addListener(KernelEvents::TERMINATE, $listener);
return $dispatcher;
}));

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\TaskManager\Job\FtpJob;
use Alchemy\Phrasea\TaskManager\Job\ArchiveJob;
use Alchemy\Phrasea\TaskManager\Job\BridgeJob;
@@ -75,9 +76,8 @@ class TasksServiceProvider implements ServiceProviderInterface
return [
(new FtpJob($app['translator'], $app['dispatcher'], $logger))
->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
}),
->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'))
,
new ArchiveJob($app['translator'], $app['dispatcher'], $logger),
new IndexerJob($app['translator'], $app['dispatcher'], $logger),
new BridgeJob($app['translator'], $app['dispatcher'], $logger),

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate;
@@ -38,9 +39,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
public function __construct(Application $app, Request $Request)
{
parent::__construct($app, $Request);
$this->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
$this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
$this->users = explode(';', $Request->get('users'));

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Helper\Helper;
use Alchemy\Phrasea\Notification\Receiver;
@@ -38,9 +39,7 @@ class Manage extends Helper
{
parent::__construct($app, $Request);
$this->setDelivererLocator(function () use ($app) {
return $app['notification.deliverer'];
});
$this->setDelivererLocator(new LazyLocator($app, 'notification.deliverer'));
}
/**

View File

@@ -19,21 +19,55 @@ use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\RecordSubDefinitionCreatedEvent;
use Alchemy\Phrasea\Core\Event\Record\Structure\RecordStructureEvent;
use Alchemy\Phrasea\Core\Event\Record\Structure\RecordStructureEvents;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\RecordQueuer;
use Elasticsearch\Client;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Subscribe to events changing index.
* Be careful, this does not flush queue on its own, and flushQueue should be added as listener separately.
*/
class IndexerSubscriber implements EventSubscriberInterface
{
/** @var callable|Indexer */
private $indexer;
public function __construct(Indexer $indexer)
/**
* @param callable|Indexer $indexer The indexer locator
*/
public function __construct($indexer)
{
if (!$indexer instanceof Indexer && !is_callable($indexer)) {
throw new \InvalidArgumentException(sprintf(
'Expects $indexer to be a callable or %s, got %s.',
Indexer::class,
is_object($indexer) ? get_class($indexer) : gettype($indexer)
));
}
$this->indexer = $indexer;
}
/** @return Indexer */
public function getIndexer()
{
if ($this->indexer instanceof Indexer) {
return $this->indexer;
}
$indexer = call_user_func($this->indexer);
if (!$indexer instanceof Indexer) {
throw new \LogicException(sprintf(
'Expects locator to return instance of %s, got %s.',
Indexer::class,
is_object($indexer) ? get_class($indexer) : gettype($indexer)
));
}
$this->indexer = $indexer;
return $this->indexer;
}
public static function getSubscribedEvents()
{
return [
@@ -50,20 +84,19 @@ class IndexerSubscriber implements EventSubscriberInterface
RecordEvents::STATUS_CHANGED => 'onRecordChange',
RecordEvents::SUB_DEFINITION_CREATED => 'onRecordChange',
RecordEvents::MEDIA_SUBSTITUTED => 'onRecordChange',
KernelEvents::TERMINATE => 'onKernelTerminate',
];
}
public function onStructureChange(RecordStructureEvent $event)
{
$databox = $event->getDatabox();
$this->indexer->migrateMappingForDatabox($databox);
$this->getIndexer()->migrateMappingForDatabox($databox);
}
public function onCollectionChange(CollectionEvent $event)
{
$collection = $event->getCollection();
$this->indexer->scheduleRecordsFromCollectionForIndexing($collection);
$this->getIndexer()->scheduleRecordsFromCollectionForIndexing($collection);
}
public function onRecordChange(RecordEvent $event)
@@ -72,18 +105,17 @@ class IndexerSubscriber implements EventSubscriberInterface
return;
}
$record = $event->getRecord();
$this->indexer->indexRecord($record);
$this->getIndexer()->indexRecord($record);
}
public function onRecordDelete(RecordDeletedEvent $event)
{
$record = $event->getRecord();
$this->indexer->deleteRecord($record);
$this->getIndexer()->deleteRecord($record);
}
public function onKernelTerminate(PostResponseEvent $event)
public function flushQueue()
{
// TODO flush queue synchronously in CLI (think task manager)
$this->indexer->flushQueue();
$this->getIndexer()->flushQueue();
}
}

View File

@@ -28,6 +28,9 @@ class databox_field implements cache_cacheableInterface
{
protected $id;
/** @var Application */
protected $app;
/**
* @var databox
*/
@@ -208,17 +211,22 @@ class databox_field implements cache_cacheableInterface
{
$cache_key = 'field_' . $id;
$instance_id = $databox->get_sbas_id() . '_' . $id;
if ( ! isset(self::$_instance[$instance_id]) || (self::$_instance[$instance_id] instanceof self) === false) {
if (! isset(self::$_instance[$instance_id])) {
try {
self::$_instance[$instance_id] = $databox->get_data_from_cache($cache_key);
$field = $databox->get_data_from_cache($cache_key);
if (!$field instanceof self) {
trigger_error('Cache type returned mismatch', E_WARNING);
throw new \Exception('Retrieved $field value is invalid');
}
} catch (\Exception $e) {
self::$_instance[$instance_id] = new self($app, $databox, $id);
$databox->set_data_to_cache(self::$_instance[$instance_id], $cache_key);
$field = new self($app, $databox, $id);
$databox->set_data_to_cache($field, $cache_key);
}
self::$_instance[$instance_id] = $field;
}
self::$_instance[$instance_id]->app = $app;
return self::$_instance[$instance_id];
$field =& self::$_instance[$instance_id];
$field->app = $app;
return $field;
}
public function hydrate(Application $app)

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# stoping iptable
sudo service iptables-persistent stop
sudo service iptables-persistent flush
source ~/.bashrc

View File

@@ -128,7 +128,7 @@ sudo service php5-fpm restart
sudo service nginx restart
# stoping iptable
sudo service iptables-persistent stop
sudo service iptables-persistent flush
# reload bash
source ~/.bashrc

View File

@@ -25,6 +25,7 @@ mysql -uroot -ptoor -e '
SET @@global.sql_mode= STRICT_ALL_TABLES;
SET @@global.max_allowed_packet= 33554432;
SET @@global.wait_timeout= 999999;
DROP SCHEMA IF EXISTS ab_test;DROP SCHEMA IF EXISTS db_test;
CREATE SCHEMA IF NOT EXISTS ab_test;CREATE SCHEMA IF NOT EXISTS db_test;
'
if ! ./bin/developer system:uninstall > /dev/null 2>&1