commit 4dbc76688cff6cd1dd5065c55c42b11506fdf08a Author: Bart Feenstra Date: Sun Oct 13 19:19:17 2013 +0200 1972304 diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 9b0ef4c..4c321f1 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -411,7 +411,8 @@ function install_begin_request(&$install_state) { // Register a module handler for managing enabled modules. $container - ->register('module_handler', 'Drupal\Core\Extension\ModuleHandler'); + ->register('module_handler', 'Drupal\Core\Extension\ModuleHandler') + ->addArgument(new Reference('event_dispatcher')); // Register the Guzzle HTTP client for fetching translation files from a // remote translation server such as localization.drupal.org. diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index 9cd8f5a..17f7101 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -89,10 +89,12 @@ protected function registerModuleHandler(ContainerBuilder $container) { if ($container->getParameter('kernel.environment') == 'install') { // During installation we use the non-cached version. $container->register('module_handler', 'Drupal\Core\Extension\ModuleHandler') + ->addArgument(new Reference('event_dispatcher')) ->addArgument('%container.modules%'); } else { $container->register('module_handler', 'Drupal\Core\Extension\CachedModuleHandler') + ->addArgument(new Reference('event_dispatcher')) ->addArgument('%container.modules%') ->addArgument(new Reference('state')) ->addArgument(new Reference('cache.bootstrap')); diff --git a/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php index d458665..3d0c723 100644 --- a/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php +++ b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php @@ -9,6 +9,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; +use Symfony\Component\DependencyInjection\Reference; /** * ServiceProvider class for update.php service overrides. @@ -33,6 +34,7 @@ public function register(ContainerBuilder $container) { ->register('config.storage', 'Drupal\Core\Config\FileStorage') ->addArgument(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); $container->register('module_handler', 'Drupal\Core\Extension\UpdateModuleHandler') + ->addArgument(new Reference('event_dispatcher')) ->addArgument('%container.modules%'); $container ->register("cache_factory", 'Drupal\Core\Cache\MemoryBackendFactory'); diff --git a/core/lib/Drupal/Core/Extension/CachedModuleHandler.php b/core/lib/Drupal/Core/Extension/CachedModuleHandler.php index 6e09432..88ad8a6 100644 --- a/core/lib/Drupal/Core/Extension/CachedModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/CachedModuleHandler.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Extension; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; @@ -39,8 +41,8 @@ class CachedModuleHandler extends ModuleHandler implements CachedModuleHandlerIn /** * Constructs a new CachedModuleHandler object. */ - public function __construct(array $module_list = array(), KeyValueStoreInterface $state, CacheBackendInterface $bootstrap_cache) { - parent::__construct($module_list); + public function __construct(EventDispatcherInterface $dispatcher, KeyValueStoreInterface $state, CacheBackendInterface $bootstrap_cache, array $module_list = array()) { + parent::__construct($dispatcher, $module_list); $this->state = $state; $this->bootstrapCache = $bootstrap_cache; } diff --git a/core/lib/Drupal/Core/Extension/HookEvent.php b/core/lib/Drupal/Core/Extension/HookEvent.php new file mode 100644 index 0000000..2d2b9a4 --- /dev/null +++ b/core/lib/Drupal/Core/Extension/HookEvent.php @@ -0,0 +1,48 @@ +return[] = $value; + } + + /** + * Returns the collected return values from all listeners to this hook event. + * @return array + */ + public function getReturn() { + return $this->return; + } + +} + diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 92cf2a4..d91150b 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Extension; use Drupal\Component\Graph\Graph; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Yaml\Parser; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; @@ -65,8 +66,17 @@ class ModuleHandler implements ModuleHandlerInterface { protected $alterFunctions; /** + * Event dispatcher to use for hook events. + * + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + protected $dispatcher; + + /** * Constructs a ModuleHandler object. * + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher + * The event dispatcher that should be used for firing hook events. * @param array $module_list * An associative array whose keys are the names of installed modules and * whose values are the module filenames. This is normally the @@ -75,7 +85,8 @@ class ModuleHandler implements ModuleHandlerInterface { * @see \Drupal\Core\DrupalKernel * @see \Drupal\Core\CoreServiceProvider */ - public function __construct(array $module_list = array()) { + public function __construct(EventDispatcherInterface $dispatcher, array $module_list = array()) { + $this->dispatcher = $dispatcher; $this->moduleList = $module_list; } @@ -289,6 +300,16 @@ public function invokeAll($hook, $args = array()) { $return[] = $result; } } + $event = new HookEvent($hook, $args); + $this->dispatcher->dispatch("hook.{$hook}", $event); + foreach ($event->getReturn() as $result) { + if (is_array($result)) { + $return = NestedArray::mergeDeep($return, $result); + } + else { + $return[] = $result; + } + } } return $return; diff --git a/core/modules/history/history.module b/core/modules/history/history.module index a3842fc..89d474d 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -120,15 +120,6 @@ function history_write($nid, $account = NULL) { } /** - * Implements hook_cron(). - */ -function history_cron() { - db_delete('history') - ->condition('timestamp', HISTORY_READ_LIMIT, '<') - ->execute(); -} - -/** * Implements hook_node_delete(). */ function history_node_delete(EntityInterface $node) { diff --git a/core/modules/history/history.services.yml b/core/modules/history/history.services.yml new file mode 100644 index 0000000..d042b5c --- /dev/null +++ b/core/modules/history/history.services.yml @@ -0,0 +1,4 @@ +services: + history.cron: + class: Drupal\history\EventSubscriber\CoreSubscriber + arguments: ['@database'] diff --git a/core/modules/history/lib/Drupal/history/EventSubscriber/CronSubscriber.php b/core/modules/history/lib/Drupal/history/EventSubscriber/CronSubscriber.php new file mode 100644 index 0000000..90a6192 --- /dev/null +++ b/core/modules/history/lib/Drupal/history/EventSubscriber/CronSubscriber.php @@ -0,0 +1,53 @@ +connection = $connection; + } + + /** + * {@inheritdoc} + */ + static function getSubscribedEvents() { + $events['hook.cron'][] = array('cleanHistory', 30); + + return $events; + } + + /** + * Clear out old history events. + * + * @param \Drupal\Core\Extension\HookEvent $event + * The event to process. + */ + public function cleanHistory(HookEvent $event) { + $this->connection->delete('history') + ->condition('timestamp', HISTORY_READ_LIMIT, '<') + ->execute(); + } +} +