Skip to content
Snippets Groups Projects
Commit c56602a1 authored by Adam G-H's avatar Adam G-H
Browse files

Make it an event

parent ec1a0e11
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,6 @@ services:
automatic_updates.updater:
class: Drupal\automatic_updates\Updater
arguments: ['@state', '@string_translation','@package_manager.beginner', '@package_manager.stager', '@package_manager.cleaner', '@package_manager.committer', '@event_dispatcher', '@automatic_updates.path_locator']
# Package Manager service decorators.
automatic_updates.cleaner:
class: Drupal\automatic_updates\ComposerStager\Cleaner
decorates: package_manager.cleaner
......@@ -16,15 +14,12 @@ services:
- '%site.path%'
- '@automatic_updates.path_locator'
properties: { _serviceId: package_manager.cleaner }
automatic_updates.committer:
class: Drupal\automatic_updates\ComposerStager\Committer
decorates: package_manager.committer
public: false
automatic_updates.update_refresh_subscriber:
class: Drupal\automatic_updates\Event\UpdateRefreshSubscriber
arguments:
- '@automatic_updates.committer.inner'
- '@update.manager'
properties: { _serviceId: package_manager.committer }
tags:
- { name: event_subscriber, priority: 1000 }
automatic_updates.excluded_paths_subscriber:
class: Drupal\automatic_updates\Event\ExcludedPathsSubscriber
arguments: ['%app.root%', '%site.path%', '@file_system', '@stream_wrapper_manager']
......
......@@ -57,4 +57,13 @@ final class AutomaticUpdatesEvents {
*/
const PRE_COMMIT = 'automatic_updates.pre_commit';
/**
* Name of the event fired when a staged update has been committed.
*
* @Event
*
* @var string
*/
const POST_COMMIT = 'automatic_updates.post_commit';
}
<?php
namespace Drupal\automatic_updates\ComposerStager;
namespace Drupal\automatic_updates\Event;
use Drupal\automatic_updates\AutomaticUpdatesEvents;
use Drupal\update\UpdateManagerInterface;
use PhpTuf\ComposerStager\Domain\CommitterInterface;
use PhpTuf\ComposerStager\Domain\Output\ProcessOutputCallbackInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Defines a committer service that clears stored update data.
* Clears stale update data once a staged update has been committed.
*/
class Committer implements CommitterInterface {
/**
* The decorated committer service.
*
* @var \PhpTuf\ComposerStager\Domain\CommitterInterface
*/
protected $decorated;
class UpdateRefreshSubscriber implements EventSubscriberInterface {
/**
* The update manager service.
......@@ -26,23 +19,19 @@ class Committer implements CommitterInterface {
protected $updateManager;
/**
* Constructs a Committer object.
* Constructs an UpdateRefreshSubscriber object.
*
* @param \PhpTuf\ComposerStager\Domain\CommitterInterface $decorated
* The decorated committer service.
* @param \Drupal\update\UpdateManagerInterface $update_manager
* The update manager service.
*/
public function __construct(CommitterInterface $decorated, UpdateManagerInterface $update_manager) {
$this->decorated = $decorated;
public function __construct(UpdateManagerInterface $update_manager) {
$this->updateManager = $update_manager;
}
/**
* {@inheritdoc}
* Clears stale update data.
*/
public function commit(string $stagingDir, string $activeDir, ?array $exclusions = [], ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120): void {
$this->decorated->commit($stagingDir, $activeDir, $exclusions, $callback, $timeout);
public function clearData(): void {
$this->updateManager->refreshUpdateData();
update_storage_clear();
}
......@@ -50,8 +39,10 @@ class Committer implements CommitterInterface {
/**
* {@inheritdoc}
*/
public function directoryExists(string $stagingDir): bool {
return $this->decorated->directoryExists($stagingDir);
public static function getSubscribedEvents() {
return [
AutomaticUpdatesEvents::POST_COMMIT => 'clearData',
];
}
}
......@@ -234,6 +234,7 @@ class Updater {
/** @var \Drupal\automatic_updates\Event\PreCommitEvent $event */
$event = $this->dispatchUpdateEvent(new PreCommitEvent(), AutomaticUpdatesEvents::PRE_COMMIT);
$this->committer->commit($this->pathLocator->getStageDirectory(), $this->pathLocator->getActiveDirectory(), $this->getExclusions($event));
$this->dispatchUpdateEvent(new UpdateEvent(), AutomaticUpdatesEvents::POST_COMMIT);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment