diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AccessPeriodChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessPeriodChangedEvent.php new file mode 100644 index 0000000000..65470721e4 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessPeriodChangedEvent.php @@ -0,0 +1,20 @@ +args['base_id']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseGrantedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseGrantedEvent.php new file mode 100644 index 0000000000..f4f096dfc2 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseGrantedEvent.php @@ -0,0 +1,20 @@ +args['base_id']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseRevokedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseRevokedEvent.php new file mode 100644 index 0000000000..ae42357e44 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToBaseRevokedEvent.php @@ -0,0 +1,20 @@ +args['base_id']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToSbasGrantedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToSbasGrantedEvent.php new file mode 100644 index 0000000000..58ecd90d52 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AccessToSbasGrantedEvent.php @@ -0,0 +1,20 @@ +args['sbas_id']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvent.php new file mode 100644 index 0000000000..867e5a1bed --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvent.php @@ -0,0 +1,42 @@ +acl = $acl; + $this->args = $args; + } + + /** + * @return ACL + */ + public function getAcl() + { + return $this->acl; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvents.php b/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvents.php new file mode 100644 index 0000000000..8eff5f7266 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/AclEvents.php @@ -0,0 +1,27 @@ +args['base_id']; + } + + public function getRemainingDownloads() + { + return $this->args['remain_dwnld']; + } + + public function getMonthDownloadMax() + { + return $this->args['month_dwnld_max']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasOnBaseRemovedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasOnBaseRemovedEvent.php new file mode 100644 index 0000000000..64860e4a3c --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasOnBaseRemovedEvent.php @@ -0,0 +1,20 @@ +args['base_id']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasResetEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasResetEvent.php new file mode 100644 index 0000000000..30967ecb28 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/DownloadQuotasResetEvent.php @@ -0,0 +1,16 @@ +args['base_id']; + } +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToBaseChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToBaseChangedEvent.php new file mode 100644 index 0000000000..f4e313372d --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToBaseChangedEvent.php @@ -0,0 +1,25 @@ +args['base_id']; + } + + public function getRights() + { + return $this->args['rights']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToSbasChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToSbasChangedEvent.php new file mode 100644 index 0000000000..279be1769c --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/RightsToSbasChangedEvent.php @@ -0,0 +1,25 @@ +args['sbas_id']; + } + + public function getRights() + { + return $this->args['rights']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Acl/SysadminChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Acl/SysadminChangedEvent.php new file mode 100644 index 0000000000..f4c9563f3c --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Acl/SysadminChangedEvent.php @@ -0,0 +1,20 @@ +args['is_sysadmin']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvent.php b/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvent.php index 358a77d45a..5cef52fae2 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvent.php @@ -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() { diff --git a/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvents.php b/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvents.php index 205cf5cf76..ec8cbccd24 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvents.php +++ b/lib/Alchemy/Phrasea/Core/Event/Collection/CollectionEvents.php @@ -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'; } diff --git a/lib/Alchemy/Phrasea/Core/Event/Collection/DisabledEvent.php b/lib/Alchemy/Phrasea/Core/Event/Collection/DisabledEvent.php new file mode 100644 index 0000000000..46fe8882d3 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Collection/DisabledEvent.php @@ -0,0 +1,16 @@ +args['lng']; + } + + public function getLabelBefore() + { + return $this->args['label_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Collection/MountedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Collection/MountedEvent.php new file mode 100644 index 0000000000..15792d7dfd --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Collection/MountedEvent.php @@ -0,0 +1,16 @@ +args['settings_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Collection/UnmountedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Collection/UnmountedEvent.php new file mode 100644 index 0000000000..461ba0645e --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Collection/UnmountedEvent.php @@ -0,0 +1,25 @@ +args['coll_id']; + } + + public function getCollName() + { + return $this->args['coll_name']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/CreatedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Databox/CreatedEvent.php new file mode 100644 index 0000000000..2384437806 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/CreatedEvent.php @@ -0,0 +1,16 @@ +databox = $databox; + $this->args = $args; + } + + public function getDatabox() + { + return $this->databox; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/DataboxEvents.php b/lib/Alchemy/Phrasea/Core/Event/Databox/DataboxEvents.php new file mode 100644 index 0000000000..40b5aa13ea --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/DataboxEvents.php @@ -0,0 +1,24 @@ +args['dbname']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/MountedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Databox/MountedEvent.php new file mode 100644 index 0000000000..68f487b0fb --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/MountedEvent.php @@ -0,0 +1,16 @@ +args['dom_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/ThesaurusChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Databox/ThesaurusChangedEvent.php new file mode 100644 index 0000000000..2990eac048 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/ThesaurusChangedEvent.php @@ -0,0 +1,20 @@ +args['dom_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/TouChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Databox/TouChangedEvent.php new file mode 100644 index 0000000000..f93c107504 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/TouChangedEvent.php @@ -0,0 +1,20 @@ +args['tou_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Databox/UnmountedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Databox/UnmountedEvent.php new file mode 100644 index 0000000000..c82fd95fda --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Databox/UnmountedEvent.php @@ -0,0 +1,20 @@ +args['dbname']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/User/CreatedEvent.php b/lib/Alchemy/Phrasea/Core/Event/User/CreatedEvent.php new file mode 100644 index 0000000000..d130e14810 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/User/CreatedEvent.php @@ -0,0 +1,16 @@ +args['user_id']; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->args['login']; + } + + /** + * @return string + */ + public function getEmailAddress() + { + return $this->args['email']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/User/UserEvent.php b/lib/Alchemy/Phrasea/Core/Event/User/UserEvent.php new file mode 100644 index 0000000000..ecfa47de61 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/User/UserEvent.php @@ -0,0 +1,40 @@ +user = $user; + $this->args = $args; + } + + public function getUser() + { + return $this->user; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/User/UserEvents.php b/lib/Alchemy/Phrasea/Core/Event/User/UserEvents.php new file mode 100644 index 0000000000..5add592edc --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/User/UserEvents.php @@ -0,0 +1,18 @@ +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) { diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php index eb02187d14..ff712488a7 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php @@ -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 + ) + ) + ); } } diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 556e69bcfe..d567fe8157 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -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; } diff --git a/lib/classes/collection.php b/lib/classes/collection.php index d3c7516f10..ddce82cb5f 100644 --- a/lib/classes/collection.php +++ b/lib/classes/collection.php @@ -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::SETTINGS_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; } diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 3cb258dc23..40d9fda99e 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -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, '