PHRAS-773 #time 5h

added some events to allow port of MT bo-report plugin
This commit is contained in:
Jean-Yves Gaulier
2015-10-20 16:47:13 +02:00
committed by Benoît Burnichon
parent e00937f2ea
commit bcf8f7d056
41 changed files with 1114 additions and 12 deletions

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class AccessPeriodChangedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class AccessToBaseGrantedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class AccessToBaseRevokedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class AccessToSbasGrantedEvent extends AclEvent
{
public function getSbasId()
{
return $this->args['sbas_id'];
}
}

View File

@@ -0,0 +1,42 @@
<?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\Core\Event\Acl;
use Symfony\Component\EventDispatcher\Event;
use ACL;
abstract class AclEvent extends Event
{
/** @var ACL */
private $acl;
/**@var array|null $args supplemental parameters specific to an inherited event class */
protected $args;
/**
* @param ACL $acl
* @param array|null $args
*/
public function __construct(ACL $acl, array $args = null)
{
$this->acl = $acl;
$this->args = $args;
}
/**
* @return ACL
*/
public function getAcl()
{
return $this->acl;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
final class AclEvents
{
const SYSADMIN_CHANGED = 'acl.syadmin_changed';
const ACCESS_TO_BASE_REVOKED = 'acl.access_to_base_revoked';
const ACCESS_TO_BASE_GRANTED = 'acl.acces_to_base_granted';
const ACCESS_TO_SBAS_GRANTED = 'acl.acces_to_sbas_granted';
const RIGHTS_TO_BASE_CHANGED = 'acl.rights_to_base_changed';
const RIGHTS_TO_SBAS_CHANGED = 'acl.rights_to_sbas_changed';
const DOWNLOAD_QUOTAS_ON_BASE_REMOVED = 'acl.download_quotas_on_base_removed';
const DOWNLOAD_QUOTAS_RESET = 'acl.download_quotas_reset';
const DOWNLOAD_QUOTAS_ON_BASE_CHANGED = 'acl.download_quotas_on_base_changed';
const MASKS_ON_BASE_CHANGED = 'acl.masks_on_base_changed';
const ACCESS_PERIOD_CHANGED = 'acl.access_period_changed';
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class DownloadQuotasOnBaseChangedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
public function getRemainingDownloads()
{
return $this->args['remain_dwnld'];
}
public function getMonthDownloadMax()
{
return $this->args['month_dwnld_max'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class DownloadQuotasOnBaseRemovedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class DownloadQuotasResetEvent extends AclEvent
{
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class MasksOnBaseChangedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class RightsToBaseChangedEvent extends AclEvent
{
public function getBaseId()
{
return $this->args['base_id'];
}
public function getRights()
{
return $this->args['rights'];
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class RightsToSbasChangedEvent extends AclEvent
{
public function getSbasId()
{
return $this->args['sbas_id'];
}
public function getRights()
{
return $this->args['rights'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Acl;
class SysadminChangedEvent extends AclEvent
{
public function isSysadmin()
{
return $this->args['is_sysadmin'];
}
}

View File

@@ -15,15 +15,23 @@ use Symfony\Component\EventDispatcher\Event;
abstract class CollectionEvent extends Event
{
/** @var \collection $collection */
private $collection;
/** @var array|null $args */
protected $args;
public function __construct(\collection $collection)
/**
* @param \collection|null $collection
* @param array|null $args
*/
public function __construct($collection, array $args = null)
{
$this->collection = $collection;
$this->args = $args;
}
/**
* @return \collection
* @return \collection|null
*/
public function getCollection()
{

View File

@@ -14,5 +14,12 @@ namespace Alchemy\Phrasea\Core\Event\Collection;
final class CollectionEvents
{
const CREATED = 'collection.created';
const DISABLED = 'collection.disabled';
const EMPTIED = 'collection.emptied';
const ENABLED = 'collection.enabled';
const LABEL_CHANGED = 'collection.label_changed';
const MOUNTED = 'collection.mounted';
const NAME_CHANGED = 'collection.name_changed';
const SETTINGS_CHANGED = 'collection.settings_changed';
const UNMOUNTED = 'collection.unmounted';
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class DisabledEvent extends CollectionEvent
{
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class EmptiedEvent extends CollectionEvent
{
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class EnabledEvent extends CollectionEvent
{
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class LabelChangedEvent extends CollectionEvent
{
public function getLng()
{
return $this->args['lng'];
}
public function getLabelBefore()
{
return $this->args['label_before'];
}
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class MountedEvent extends CollectionEvent
{
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class SettingsChangedEvent extends CollectionEvent
{
public function getSettingsBefore()
{
return $this->args['settings_before'];
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Collection;
class UnmountedEvent extends CollectionEvent
{
public function getCollId()
{
return $this->args['coll_id'];
}
public function getCollName()
{
return $this->args['coll_name'];
}
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class CreatedEvent extends DataboxEvent
{
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Alchemy\Phrasea\Core\Event\Databox;
use Symfony\Component\EventDispatcher\Event;
class DataboxEvent extends Event
{
/** @var \databox|null $databox */
private $databox;
/** @var array|null $args supplemental parameters specific to an inherited event class */
protected $args;
/**
* @param \databox|null $databox
* @param array|null $args
*/
public function __construct($databox, array $args = null)
{
$this->databox = $databox;
$this->args = $args;
}
public function getDatabox()
{
return $this->databox;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
final class DataboxEvents
{
const UNMOUNTED = 'databox.unmounted';
const CREATED = 'databox.created';
const MOUNTED = 'databox.mounted';
const DELETED = 'databox.deleted';
const STRUCTURE_CHANGED = 'databox.structure_changed';
const THESAURUS_CHANGED = 'databox.thesaurus_changed';
const REINDEX_ASKED = 'databox.reindex_asked';
const TOU_CHANGED = 'databox.tou_changed';
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class DeletedEvent extends DataboxEvent
{
public function getDbName()
{
return $this->args['dbname'];
}
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class MountedEvent extends DataboxEvent
{
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class ReindexAskedEvent extends DataboxEvent
{
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class StructureChangedEvent extends DataboxEvent
{
public function getDomBefore()
{
return $this->args['dom_before'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class ThesaurusChangedEvent extends DataboxEvent
{
public function getDomBefore()
{
return $this->args['dom_before'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class TouChangedEvent extends DataboxEvent
{
public function getTouBefore()
{
return $this->args['tou_before'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\Databox;
class UnmountedEvent extends DataboxEvent
{
public function getDbName()
{
return $this->args['dbname'];
}
}

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\User;
class CreatedEvent extends UserEvent
{
}

View File

@@ -0,0 +1,39 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\User;
class DeletedEvent extends UserEvent
{
/**
* @return int
*/
public function getUserId()
{
return $this->args['user_id'];
}
/**
* @return string
*/
public function getLogin()
{
return $this->args['login'];
}
/**
* @return string
*/
public function getEmailAddress()
{
return $this->args['email'];
}
}

View File

@@ -0,0 +1,40 @@
<?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\Core\Event\User;
use Alchemy\Phrasea\Model\Entities\User as UserEntity;
use Symfony\Component\EventDispatcher\Event;
use ACL;
abstract class UserEvent extends Event
{
/** @var UserEntity |null $user */
private $user;
/** @var array|null $args */
protected $args;
/**
* @param UserEntity |null $user
* @param array|null $args
*/
public function __construct(UserEntity $user, Array $args = null)
{
$this->user = $user;
$this->args = $args;
}
public function getUser()
{
return $this->user;
}
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 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\User;
final class UserEvents
{
const DELETED = 'user.deleted';
const CREATED = 'user.created';
}

View File

@@ -38,7 +38,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface
});
$app['manipulator.user'] = $app->share(function ($app) {
return new UserManipulator($app['model.user-manager'], $app['auth.password-encoder'], $app['geonames.connector'], $app['repo.users'], $app['random.low']);
return new UserManipulator($app['model.user-manager'], $app['auth.password-encoder'], $app['geonames.connector'], $app['repo.users'], $app['random.low'], $app['dispatcher']);
});
$app['manipulator.token'] = $app->share(function ($app) {

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Model\Manipulator;
use Alchemy\Geonames\Connector as GeonamesConnector;
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
use Alchemy\Phrasea\Core\Event\User\CreatedEvent;
use Alchemy\Phrasea\Model\Entities\UserNotificationSetting;
use Alchemy\Phrasea\Model\Entities\UserQuery;
use Alchemy\Phrasea\Model\Entities\UserSetting;
@@ -24,6 +25,11 @@ use RandomLib\Generator;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Alchemy\Phrasea\Core\Event\User\UserEvents;
use Alchemy\Phrasea\Core\Event\User\DeletedEvent;
/**
* Manages common operations for the users.
*/
@@ -39,14 +45,18 @@ class UserManipulator implements ManipulatorInterface
private $generator;
/** @var EntityRepository */
private $repository;
/** @var EventDispatcherInterface */
private $dispatcher;
public function __construct(UserManager $manager, PasswordEncoderInterface $passwordEncoder, GeonamesConnector $connector, EntityRepository $repo, Generator $generator)
public function __construct(UserManager $manager, PasswordEncoderInterface $passwordEncoder, GeonamesConnector $connector, EntityRepository $repo, Generator $generator, EventDispatcherInterface $dispatcher)
{
$this->manager = $manager;
$this->generator = $generator;
$this->passwordEncoder = $passwordEncoder;
$this->geonamesConnector = $connector;
$this->repository = $repo;
$this->dispatcher = $dispatcher;
}
/**
@@ -71,6 +81,13 @@ class UserManipulator implements ManipulatorInterface
$user->setAdmin($admin);
$this->manager->update($user);
$this->dispatcher->dispatch(
UserEvents::CREATED,
new CreatedEvent(
$user
)
);
return $user;
}
@@ -81,11 +98,28 @@ class UserManipulator implements ManipulatorInterface
*/
public function delete($users)
{
/** @var User $user */
foreach ($this->makeTraversable($users) as $user) {
$old_id = $user->getId();
$old_login = $user->getLogin();
$old_email = $user->getEmail();
$user->setDeleted(true);
$user->setEmail(null);
$this->manager->delete($user);
$this->dispatcher->dispatch(
UserEvents::DELETED,
new DeletedEvent(
null,
array(
'user_id'=>$old_id,
'login'=>$old_login,
'email'=>$old_email
)
)
);
}
}

View File

@@ -14,6 +14,20 @@ use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\DBAL\DBALException;
use Alchemy\Phrasea\Model\RecordInterface;
use Alchemy\Phrasea\Core\Event\Acl\AclEvents;
use Alchemy\Phrasea\Core\Event\Acl\AccessPeriodChangedEvent;
use Alchemy\Phrasea\Core\Event\Acl\AccessToBaseGrantedEvent;
use Alchemy\Phrasea\Core\Event\Acl\AccessToBaseRevokedEvent;
use Alchemy\Phrasea\Core\Event\Acl\AccessToSbasGrantedEvent;
use Alchemy\Phrasea\Core\Event\Acl\DownloadQuotasOnBaseChangedEvent;
use Alchemy\Phrasea\Core\Event\Acl\DownloadQuotasOnBaseRemovedEvent;
use Alchemy\Phrasea\Core\Event\Acl\DownloadQuotasResetEvent;
use Alchemy\Phrasea\Core\Event\Acl\MasksOnBaseChangedEvent;
use Alchemy\Phrasea\Core\Event\Acl\RightsToBaseChangedEvent;
use Alchemy\Phrasea\Core\Event\Acl\RightsToSbasChangedEvent;
use Alchemy\Phrasea\Core\Event\Acl\SysadminChangedEvent;
class ACL implements cache_cacheableInterface
{
@@ -780,6 +794,16 @@ class ACL implements cache_cacheableInterface
$this->app['manipulator.user']->demote($this->user);
}
$this->app['dispatcher']->dispatch(
AclEvents::SYSADMIN_CHANGED,
new SysadminChangedEvent(
$this,
array(
'is_sysadmin'=>$boolean
)
)
);
return $this;
}
@@ -1123,6 +1147,16 @@ class ACL implements cache_cacheableInterface
if (!$stmt_del->execute([':base_id' => $base_id, ':usr_id' => $usr_id])) {
throw new Exception('Error while deleteing some rights');
}
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_TO_BASE_REVOKED,
new AccessToBaseRevokedEvent(
$this,
array(
'base_id'=>$base_id
)
)
);
}
$stmt_del->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
@@ -1167,6 +1201,16 @@ class ACL implements cache_cacheableInterface
$stmt_upd = $this->app->getApplicationBox()->get_connection()->prepare($sql_upd);
foreach ($to_update as $base_id) {
$stmt_upd->execute([':usr_id' => $usr_id, ':base_id' => $base_id]);
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_TO_BASE_GRANTED,
new AccessToBaseGrantedEvent(
$this,
array(
'base_id'=>$base_id
)
)
);
}
$stmt_upd->closeCursor();
@@ -1192,6 +1236,16 @@ class ACL implements cache_cacheableInterface
if (!$this->has_access_to_sbas($sbas_id)) {
try {
$stmt_ins->execute([':sbas_id' => $sbas_id, ':usr_id' => $usr_id]);
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_TO_SBAS_GRANTED,
new AccessToSbasGrantedEvent(
$this,
array(
'sbas_id'=>$sbas_id
)
)
);
} catch (DBALException $e) {
}
@@ -1254,6 +1308,17 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::RIGHTS_TO_BASE_CHANGED,
new RightsToBaseChangedEvent(
$this,
array(
'base_id'=>$base_id,
'rights'=>$rights
)
)
);
return $this;
}
@@ -1318,6 +1383,17 @@ class ACL implements cache_cacheableInterface
$stmt_up->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
$this->app['dispatcher']->dispatch(
AclEvents::RIGHTS_TO_SBAS_CHANGED,
new RightsToSbasChangedEvent(
$this,
array(
'sbas_id'=>$sbas_id,
'rights'=>$rights
)
)
);
return $this;
}
@@ -1339,6 +1415,16 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::DOWNLOAD_QUOTAS_ON_BASE_REMOVED,
new DownloadQuotasOnBaseRemovedEvent(
$this,
array(
'base_id'=>$base_id
)
)
);
return $this;
}
@@ -1361,6 +1447,13 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::DOWNLOAD_QUOTAS_RESET,
new DownloadQuotasResetEvent(
$this
)
);
return $this;
}
@@ -1391,6 +1484,18 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::DOWNLOAD_QUOTAS_ON_BASE_CHANGED,
new DownloadQuotasOnBaseChangedEvent(
$this,
array(
'base_id'=>$base_id,
'remain_dwnld'=>$restes,
'month_dwnld_max'=>$droits
)
)
);
return $this;
}
@@ -1563,6 +1668,16 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::MASKS_ON_BASE_CHANGED,
new MasksOnBaseChangedEvent(
$this,
array(
'base_id'=>$base_id
)
)
);
return $this;
}
@@ -1624,6 +1739,16 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_LIMITS_BAS);
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_PERIOD_CHANGED,
new AccessPeriodChangedEvent(
$this,
array(
'base_id'=>$base_id
)
)
);
return $this;
}

View File

@@ -10,10 +10,6 @@
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\Collection\CollectionEvent;
use Alchemy\Phrasea\Core\Event\Collection\CollectionEvents;
use Alchemy\Phrasea\Core\Event\Collection\CreatedEvent;
use Alchemy\Phrasea\Core\Event\Collection\NameChangedEvent;
use Alchemy\Phrasea\Core\Thumbnail\ThumbnailedElement;
use Alchemy\Phrasea\Core\Thumbnail\ThumbnailManager;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
@@ -21,6 +17,18 @@ use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\DBAL\Driver\Connection;
use Symfony\Component\HttpFoundation\File\File;
use Alchemy\Phrasea\Core\Event\Collection\CollectionEvent;
use Alchemy\Phrasea\Core\Event\Collection\CollectionEvents;
use Alchemy\Phrasea\Core\Event\Collection\CreatedEvent;
use Alchemy\Phrasea\Core\Event\Collection\NameChangedEvent;
use Alchemy\Phrasea\Core\Event\Collection\EmptiedEvent;
use Alchemy\Phrasea\Core\Event\Collection\EnabledEvent;
use Alchemy\Phrasea\Core\Event\Collection\DisabledEvent;
use Alchemy\Phrasea\Core\Event\Collection\MountedEvent;
use Alchemy\Phrasea\Core\Event\Collection\UnmountedEvent;
use Alchemy\Phrasea\Core\Event\Collection\SettingsChangedEvent;
use Alchemy\Phrasea\Core\Event\Collection\LabelChangedEvent;
class collection implements cache_cacheableInterface, ThumbnailedElement
{
protected $base_id;
@@ -157,6 +165,13 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
$this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
$this->app['dispatcher']->dispatch(
CollectionEvents::ENABLED,
new EnabledEvent(
$this
)
);
return $this;
}
@@ -186,6 +201,13 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
$this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure');
$this->app['dispatcher']->dispatch(
CollectionEvents::DISABLED,
new DisabledEvent(
$this
)
);
return $this;
}
@@ -208,6 +230,13 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
unset($record);
}
$this->app['dispatcher']->dispatch(
CollectionEvents::EMPTIED,
new EmptiedEvent(
$this
)
);
return $this;
}
@@ -273,6 +302,8 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
public function set_name($name)
{
$old_name = $this->get_name();
$name = trim(strip_tags($name));
if ($name === '')
@@ -290,7 +321,13 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
phrasea::reset_baseDatas($this->databox->get_appbox());
$this->dispatch(CollectionEvents::NAME_CHANGED, new NameChangedEvent($this));
$this->dispatch(
CollectionEvents::NAME_CHANGED,
new NameChangedEvent(
$this,
array("name_before"=>$old_name)
)
);
return $this;
}
@@ -301,6 +338,8 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
}
$old_label = $this->labels[$code];
$sql = "UPDATE coll SET label_$code = :label
WHERE coll_id = :coll_id";
$stmt = $this->get_connection()->prepare($sql);
@@ -313,6 +352,14 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
phrasea::reset_baseDatas($this->databox->get_appbox());
$this->app['dispatcher']->dispatch(
CollectionEvents::LABEL_CHANGED,
new LabelChangedEvent(
$this,
array("lng"=>$code, "label_before"=>$old_label)
)
);
return $this;
}
@@ -528,6 +575,8 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
public function set_prefs(DOMDocument $dom)
{
$old_prefs = $this->get_prefs();
$this->prefs = $dom->saveXML();
$sql = "UPDATE coll SET prefs = :prefs WHERE coll_id = :coll_id";
@@ -537,6 +586,16 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
$this->delete_data_from_cache();
$this->app['dispatcher']->dispatch(
CollectionEvents::SETTING_CHANGED,
new SettingsChangedEvent(
$this,
array(
'settings_before'=>$old_prefs
)
)
);
return $this->prefs;
}
@@ -557,6 +616,9 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
public function unmount_collection(Application $app)
{
$old_coll_id = $this->get_coll_id();
$old_name = $this->get_name();
$params = [':base_id' => $this->get_base_id()];
$query = $app['phraseanet.user-query'];
@@ -589,6 +651,17 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
phrasea::reset_baseDatas($app['phraseanet.appbox']);
$app['dispatcher']->dispatch(
CollectionEvents::UNMOUNTED,
new UnmountedEvent(
null, // the coll is not available anymore
array(
'coll_id'=>$old_coll_id,
'coll_name'=>$old_name
)
)
);
return $this;
}
@@ -654,7 +727,12 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
$collection->set_admin($new_bas, $user);
}
$app['dispatcher']->dispatch(CollectionEvents::CREATED, new CreatedEvent($collection));
$app['dispatcher']->dispatch(
CollectionEvents::CREATED,
new CreatedEvent(
$collection
)
);
return $collection;
}
@@ -710,8 +788,15 @@ class collection implements cache_cacheableInterface, ThumbnailedElement
phrasea::reset_baseDatas($databox->get_appbox());
$coll = self::get_from_base_id($app, $new_bas);
$coll->set_admin($new_bas, $user);
$collection = self::get_from_base_id($app, $new_bas);
$collection->set_admin($new_bas, $user);
$app['dispatcher']->dispatch(
CollectionEvents::MOUNTED,
new MountedEvent(
$collection
)
);
return $new_bas;
}

View File

@@ -26,6 +26,17 @@ use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Translation\TranslatorInterface;
use Alchemy\Phrasea\Core\Event\Databox\DataboxEvents;
use Alchemy\Phrasea\Core\Event\Databox\CreatedEvent;
use Alchemy\Phrasea\Core\Event\Databox\DeletedEvent;
use Alchemy\Phrasea\Core\Event\Databox\MountedEvent;
use Alchemy\Phrasea\Core\Event\Databox\ReindexAskedEvent;
use Alchemy\Phrasea\Core\Event\Databox\StructureChangedEvent;
use Alchemy\Phrasea\Core\Event\Databox\ThesaurusChangedEvent;
use Alchemy\Phrasea\Core\Event\Databox\TouChangedEvent;
use Alchemy\Phrasea\Core\Event\Databox\UnmountedEvent;
class databox extends base implements ThumbnailedElement
{
@@ -401,6 +412,8 @@ class databox extends base implements ThumbnailedElement
public function unmount_databox()
{
$old_dbname = $this->get_dbname();
foreach ($this->get_collections() as $collection) {
$collection->unmount_collection($this->app);
}
@@ -457,6 +470,16 @@ class databox extends base implements ThumbnailedElement
$this->get_appbox()->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->app['dispatcher']->dispatch(
DataboxEvents::UNMOUNTED,
new UnmountedEvent(
null,
array(
'dbname'=>$old_dbname
)
)
);
return;
}
@@ -554,6 +577,13 @@ class databox extends base implements ThumbnailedElement
$data_template, $app['conf']->get(['main', 'storage', 'subdefs'])
);
$app['dispatcher']->dispatch(
DataboxEvents::CREATED,
new CreatedEvent(
$databox
)
);
return $databox;
}
@@ -613,6 +643,13 @@ class databox extends base implements ThumbnailedElement
cache_databox::update($app, $databox->get_sbas_id(), 'structure');
$app['dispatcher']->dispatch(
DataboxEvents::MOUNTED,
new MountedEvent(
$databox
)
);
return $databox;
}
@@ -682,6 +719,8 @@ class databox extends base implements ThumbnailedElement
public function delete()
{
$old_dbname = $this->get_dbname();
$sql = 'DROP DATABASE `' . $this->get_dbname() . '`';
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
@@ -689,6 +728,16 @@ class databox extends base implements ThumbnailedElement
$this->get_appbox()->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->app['dispatcher']->dispatch(
DataboxEvents::DELETED,
new DeletedEvent(
null,
array(
'dbname'=>$old_dbname
)
)
);
return;
}
@@ -801,6 +850,7 @@ class databox extends base implements ThumbnailedElement
*/
public function saveStructure(DOMDocument $dom_struct)
{
$old_structure = $this->get_dom_structure();
$dom_struct->documentElement
->setAttribute("modification_date", $now = date("YmdHis"));
@@ -828,6 +878,16 @@ class databox extends base implements ThumbnailedElement
cache_databox::update($this->app, $this->id, 'structure');
$this->app['dispatcher']->dispatch(
DataboxEvents::STRUCTURE_CHANGED,
new StructureChangedEvent(
$this,
array(
'dom_before'=>$old_structure
)
)
);
return $this;
}
@@ -854,6 +914,7 @@ class databox extends base implements ThumbnailedElement
public function saveThesaurus(DOMDocument $dom_thesaurus)
{
$old_thesaurus = $this->get_dom_thesaurus();
$dom_thesaurus->documentElement->setAttribute("modification_date", $now = date("YmdHis"));
$this->thesaurus = $dom_thesaurus->saveXML();
@@ -864,6 +925,16 @@ class databox extends base implements ThumbnailedElement
$stmt->closeCursor();
$this->delete_data_from_cache(databox::CACHE_THESAURUS);
$this->app['dispatcher']->dispatch(
DataboxEvents::THESAURUS_CHANGED,
new ThesaurusChangedEvent(
$this,
array(
'dom_before'=>$old_thesaurus,
)
)
);
return $this;
}
@@ -1037,6 +1108,13 @@ class databox extends base implements ThumbnailedElement
$stmt->bindValue(':token', PhraseaTokens::TO_INDEX, PDO::PARAM_INT);
$stmt->execute();
$this->app['dispatcher']->dispatch(
DataboxEvents::REINDEX_ASKED,
new ReindexAskedEvent(
$this
)
);
return $this;
}
@@ -1389,6 +1467,8 @@ class databox extends base implements ThumbnailedElement
public function update_cgus($locale, $terms, $reset_date)
{
$old_tou = $this->get_cgus();
$terms = str_replace(["\r\n", "\n", "\r"], ['', '', ''], strip_tags($terms, '<p><strong><a><ul><ol><li><h1><h2><h3><h4><h5><h6>'));
$sql = 'UPDATE pref SET value = :terms ';
@@ -1403,6 +1483,16 @@ class databox extends base implements ThumbnailedElement
$this->cgus = null;
$this->delete_data_from_cache(self::CACHE_CGUS);
$this->app['dispatcher']->dispatch(
DataboxEvents::TOU_CHANGED,
new TouChangedEvent(
$this,
array(
'tou_before'=>$old_tou,
)
)
);
return $this;
}