mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Merge branch '3.8'
Conflicts: lib/Alchemy/Phrasea/Command/CreateCollection.php lib/Alchemy/Phrasea/Controller/Admin/Databox.php lib/Alchemy/Phrasea/Controller/Root/Login.php lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php lib/Alchemy/Phrasea/Model/Entities/AuthFailure.php lib/Alchemy/Phrasea/Model/Entities/LazaretAttribute.php lib/Alchemy/Phrasea/Model/Entities/LazaretCheck.php lib/Alchemy/Phrasea/Model/Entities/SessionModule.php lib/Alchemy/Phrasea/Model/Entities/ValidationData.php lib/Alchemy/Phrasea/Model/Repositories/BasketRepository.php lib/conf.d/Doctrine/Entities.Session.dcm.yml lib/conf.d/Doctrine/Entities.StoryWZ.dcm.yml lib/conf.d/Doctrine/Entities.UsrList.dcm.yml lib/conf.d/Doctrine/Entities.UsrListEntry.dcm.yml lib/conf.d/Doctrine/Entities.UsrListOwner.dcm.yml lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php tests/Alchemy/Tests/Phrasea/SearchEngine/SphinxSearchEngineTest.php
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
namespace Alchemy\Phrasea\Command;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\Phrasea\Core\Event\CollectionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -62,5 +64,7 @@ class CreateCollection extends Command
|
||||
$this->container['manipulator.acl']->resetAdminRights(array_map(function ($id) use ($app) {
|
||||
return \User_Adapter::getInstance($id, $app);
|
||||
}, array_keys(\User_Adapter::get_sys_admins($this->container))));
|
||||
|
||||
$this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Controller\Admin;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\CollectionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -806,6 +808,8 @@ class Databox implements ControllerProviderInterface
|
||||
}
|
||||
}
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($collection));
|
||||
|
||||
return $app->redirectPath('admin_display_collection', ['bas_id' => $collection->get_base_id(), 'success' => 1, 'reload-tree' => 1]);
|
||||
} catch (\Exception $e) {
|
||||
return $app->redirectPath('admin_database_submit_collection', ['databox_id' => $databox_id, 'error' => 'error']);
|
||||
|
@@ -56,7 +56,7 @@ class Subdefs implements ControllerProviderInterface
|
||||
|
||||
if ($delete_subdef) {
|
||||
|
||||
$delete_subef = explode('_', $delete_subdef);
|
||||
$delete_subef = explode('_', $delete_subdef, 2);
|
||||
$group = $delete_subef[0];
|
||||
$name = $delete_subef[1];
|
||||
$subdefs = $databox->get_subdef_structure();
|
||||
@@ -78,10 +78,10 @@ class Subdefs implements ControllerProviderInterface
|
||||
|
||||
$options = [];
|
||||
|
||||
$post_sub_ex = explode('_', $post_sub);
|
||||
$post_sub_ex = explode('_', $post_sub, 2);
|
||||
|
||||
$group = array_shift($post_sub_ex);
|
||||
$name = implode('_', $post_sub_ex);
|
||||
$group = $post_sub_ex[0];
|
||||
$name = $post_sub_ex[1];
|
||||
|
||||
$class = $request->request->get($post_sub . '_class');
|
||||
$downloadable = $request->request->get($post_sub . '_downloadable');
|
||||
|
@@ -1032,8 +1032,6 @@ class Login implements ControllerProviderInterface
|
||||
$response = $this->generateAuthResponse($app, $app['browser'], $request->request->get('redirect'));
|
||||
$response->headers->clearCookie('invite-usr-id');
|
||||
|
||||
$app['acl']->get($user)->inject_rights();
|
||||
|
||||
if ($request->cookies->has('postlog') && $request->cookies->get('postlog') == '1') {
|
||||
if (!$user->is_guest() && $request->cookies->has('invite-usr_id')) {
|
||||
if ($user->get_id() != $inviteUsrId = $request->cookies->get('invite-usr_id')) {
|
||||
|
29
lib/Alchemy/Phrasea/Core/Event/CollectionCreateEvent.php
Normal file
29
lib/Alchemy/Phrasea/Core/Event/CollectionCreateEvent.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||
|
||||
class CollectionCreateEvent extends SfEvent
|
||||
{
|
||||
private $collection;
|
||||
|
||||
public function __construct(\collection $collection)
|
||||
{
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
}
|
@@ -23,4 +23,6 @@ final class PhraseaEvents
|
||||
const API_LOAD_START = 'api.load.start';
|
||||
const API_LOAD_END = 'api.load.end';
|
||||
const API_RESULT = 'api.result';
|
||||
|
||||
const COLLECTION_CREATE = 'collection.create';
|
||||
}
|
||||
|
@@ -23,24 +23,38 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['phraseanet.SE'] = $app->share(function ($app) {
|
||||
|
||||
$engineClass = $app['conf']->get(['main', 'search-engine', 'type']);
|
||||
$engineOptions = $app['conf']->get(['main', 'search-engine', 'options']);
|
||||
|
||||
if (!class_exists($engineClass) || $engineClass instanceof SearchEngineInterface) {
|
||||
throw new InvalidArgumentException(sprintf('%s is not valid SearchEngineInterface', $engineClass));
|
||||
}
|
||||
|
||||
return $engineClass::create($app, $engineOptions);
|
||||
return $app['phraseanet.SE.engine-class']::create($app, $engineOptions);
|
||||
});
|
||||
|
||||
$app['phraseanet.SE.logger'] = $app->share(function (Application $app) {
|
||||
return new SearchEngineLogger($app);
|
||||
});
|
||||
|
||||
$app['phraseanet.SE.engine-class'] = $app->share(function ($app) {
|
||||
$engineClass = $app['conf']->get(['main', 'search-engine', 'type']);
|
||||
|
||||
if (!class_exists($engineClass) || $engineClass instanceof SearchEngineInterface) {
|
||||
throw new InvalidArgumentException(sprintf('%s is not valid SearchEngineInterface', $engineClass));
|
||||
}
|
||||
|
||||
return $engineClass;
|
||||
});
|
||||
|
||||
$app['phraseanet.SE.subscriber'] = $app->share(function ($app) {
|
||||
return $app['phraseanet.SE.engine-class']::createSubscriber($app);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
}
|
||||
$app['dispatcher'] = $app->share(
|
||||
$app->extend('dispatcher', function ($dispatcher, Application $app) {
|
||||
$dispatcher->addSubscriber($app['phraseanet.SE.subscriber']);
|
||||
|
||||
return $dispatcher;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Repositories;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Basket;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
|
@@ -508,6 +508,16 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
return $html ;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return PhraseaEngineSubscriber
|
||||
*/
|
||||
public static function createSubscriber(Application $app)
|
||||
{
|
||||
return new PhraseaEngineSubscriber($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Phrasea;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\CollectionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\Event\PostAuthenticate;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class PhraseaEngineSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function onAuthenticate(PostAuthenticate $event)
|
||||
{
|
||||
$event->getUser()->ACL()->inject_rights();
|
||||
}
|
||||
|
||||
public function onCollectionCreate(CollectionCreateEvent $event)
|
||||
{
|
||||
$sql = 'SELECT u.usr_id, c.session_id
|
||||
FROM (usr u, Sessions s, basusr b)
|
||||
LEFT JOIN cache c ON (c.usr_id = u.usr_id)
|
||||
WHERE u.model_of = 0 AND u.usr_login NOT LIKE "(#deleted%"
|
||||
AND b.base_id = :base_id AND b.usr_id = u.usr_id AND b.actif=1
|
||||
AND s.usr_id = u.usr_id';
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':base_id' => $event->getCollection()->get_base_id()));
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$initialized = false;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$user = \User_Adapter::getInstance($row['usr_id'], $this->app);
|
||||
$user->ACL()->inject_rights();
|
||||
if (null !== $row['session_id']) {
|
||||
if (!$initialized) {
|
||||
$this->app['phraseanet.SE']->initialize();
|
||||
$initialized = true;
|
||||
}
|
||||
phrasea_clear_cache($row['session_id']);
|
||||
phrasea_close_session($row['session_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
PhraseaEvents::POST_AUTHENTICATE => array('onAuthenticate', 0),
|
||||
PhraseaEvents::COLLECTION_CREATE => array('onCollectionCreate', 0),
|
||||
);
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
||||
|
||||
@@ -232,6 +233,13 @@ interface SearchEngineInterface
|
||||
*/
|
||||
public function clearAllCache(\DateTime $date = null);
|
||||
|
||||
/**
|
||||
* Returns a subscriber
|
||||
*
|
||||
* @return EventSubscriberInterface
|
||||
*/
|
||||
public static function createSubscriber(Application $app);
|
||||
|
||||
/**
|
||||
* Creates the adapter.
|
||||
*
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\Phrasea\SphinxSearchEngineSubscriber;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
@@ -573,6 +574,16 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return SphinxSearchEngineSubscriber
|
||||
*/
|
||||
public static function createSubscriber(Application $app)
|
||||
{
|
||||
return new SphinxSearchEngineSubscriber();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Phrasea;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class SphinxSearchEngineSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
@@ -427,14 +427,14 @@
|
||||
<td style="padding-right: 5px;">
|
||||
<div class="input-prepend">
|
||||
<span class="add-on"><i class="icon-calendar"></i></span>
|
||||
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_min" placeholder="YYYY/MM/DD" style="margin: 0;position: relative; z-index: 10001;" />
|
||||
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_min" placeholder="{% trans %}YYYY/MM/DD{% endtrans %}" style="margin: 0;position: relative; z-index: 10001;" />
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ 'phraseanet::time:: a' | trans }}</td>
|
||||
<td>
|
||||
<div class="input-prepend">
|
||||
<span class="add-on"><i class="icon-calendar"></i></span>
|
||||
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_max" placeholder="YYYY/MM/DD" style="margin: 0;position: relative; z-index: 10001;" />
|
||||
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_max" placeholder="{% trans %}YYYY/MM/DD{% endtrans %}" style="margin: 0;position: relative; z-index: 10001;" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@@ -27,6 +27,7 @@ class PhraseaEngineTest extends SearchEngineAbstractTest
|
||||
public function initialize()
|
||||
{
|
||||
self::$searchEngine = PhraseaEngine::create(self::$DI['app']);
|
||||
self::$searchEngineClass = 'Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine';
|
||||
}
|
||||
|
||||
protected function updateIndex(array $stemms = [])
|
||||
|
@@ -10,6 +10,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
{
|
||||
protected $options;
|
||||
protected static $searchEngine;
|
||||
protected static $searchEngineClass;
|
||||
protected static $initialized = false;
|
||||
|
||||
public function setUp()
|
||||
@@ -764,6 +765,12 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateSubscriber()
|
||||
{
|
||||
$classname = self::$searchEngineClass;
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $classname::createSubscriber(self::$DI['app']));
|
||||
}
|
||||
|
||||
abstract public function initialize();
|
||||
|
||||
abstract public function testAutocomplete();
|
||||
|
@@ -72,6 +72,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
self::$searchd->run();
|
||||
|
||||
self::$searchEngine = SphinxSearchEngine::create($app, $app['conf']->get(['main', 'search-engine', 'options']));
|
||||
self::$searchEngineClass = 'Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine';
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
|
Reference in New Issue
Block a user