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

Issue #3230250 by phenaproxima, tedbow: Update Composer Stager to 0.2.0

parent d8384b58
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ services: ...@@ -11,7 +11,7 @@ services:
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
automatic_updates.beginner: automatic_updates.beginner:
class: Drupal\automatic_updates\ComposerStager\Beginner class: PhpTuf\ComposerStager\Domain\Beginner
arguments: arguments:
['@automatic_updates.file_copier', '@automatic_updates.file_system' ] ['@automatic_updates.file_copier', '@automatic_updates.file_system' ]
automatic_updates.stager: automatic_updates.stager:
...@@ -34,17 +34,18 @@ services: ...@@ -34,17 +34,18 @@ services:
class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierFactory class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierFactory
arguments: arguments:
- '@automatic_updates.symfony_exec_finder' - '@automatic_updates.symfony_exec_finder'
- '@automatic_updates.file_copier.php'
- '@automatic_updates.file_copier.rsync' - '@automatic_updates.file_copier.rsync'
- '@automatic_updates.file_copier.symfony'
automatic_updates.file_copier.rsync: automatic_updates.file_copier.rsync:
class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\RsyncFileCopier class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\RsyncFileCopier
arguments: arguments:
- '@automatic_updates.file_system' - '@automatic_updates.file_system'
- '@automatic_updates.rsync' - '@automatic_updates.rsync'
automatic_updates.file_copier.symfony: automatic_updates.file_copier.php:
class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\SymfonyFileCopier class: PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\PhpFileCopier
arguments: arguments:
- '@automatic_updates.symfony_file_system' - '@automatic_updates.file_system'
- '@automatic_updates.finder'
- '@automatic_updates.finder' - '@automatic_updates.finder'
automatic_updates.finder: automatic_updates.finder:
class: Symfony\Component\Finder\Finder class: Symfony\Component\Finder\Finder
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"php-tuf/composer-stager": "0.1.1" "php-tuf/composer-stager": "0.2.0"
}, },
"config": { "config": {
"platform": { "platform": {
......
<?php
namespace Drupal\automatic_updates\ComposerStager;
use PhpTuf\ComposerStager\Domain\BeginnerInterface;
use PhpTuf\ComposerStager\Domain\Output\ProcessOutputCallbackInterface;
use PhpTuf\ComposerStager\Exception\DirectoryAlreadyExistsException;
use PhpTuf\ComposerStager\Exception\DirectoryNotFoundException;
use PhpTuf\ComposerStager\Infrastructure\Filesystem\FilesystemInterface;
use PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierInterface;
/**
* An implementation of Composer Stager's Beginner which supports exclusions.
*
* @todo Remove this class when composer_stager implements this functionality.
*/
final class Beginner implements BeginnerInterface {
/**
* The file copier service.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierInterface
*/
private $fileCopier;
/**
* The file system service.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Filesystem\FilesystemInterface
*/
private $filesystem;
/**
* Constructs a Beginner object.
*
* @param \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierInterface $fileCopier
* The file copier service.
* @param \PhpTuf\ComposerStager\Infrastructure\Filesystem\FilesystemInterface $filesystem
* The file system service.
*/
public function __construct(FileCopierInterface $fileCopier, FilesystemInterface $filesystem) {
$this->fileCopier = $fileCopier;
$this->filesystem = $filesystem;
}
/**
* {@inheritdoc}
*/
public function begin(string $activeDir, string $stagingDir, ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120, array $exclusions = []): void {
if (!$this->filesystem->exists($activeDir)) {
throw new DirectoryNotFoundException($activeDir, 'The active directory does not exist at "%s"');
}
if ($this->filesystem->exists($stagingDir)) {
throw new DirectoryAlreadyExistsException($stagingDir, 'The staging directory already exists at "%s"');
}
$this->fileCopier->copy(
$activeDir,
$stagingDir,
$exclusions,
$callback,
$timeout
);
}
}
...@@ -60,6 +60,18 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface { ...@@ -60,6 +60,18 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
$this->streamWrapperManager = $stream_wrapper_manager; $this->streamWrapperManager = $stream_wrapper_manager;
} }
/**
* Reacts before staged updates are committed the active directory.
*
* @param \Drupal\automatic_updates\Event\PreCommitEvent $event
* The event object.
*/
public function preCommit(PreCommitEvent $event): void {
// Don't copy anything from the staging area's sites/default.
// @todo Make this a lot smarter in https://www.drupal.org/i/3228955.
$event->excludePath('sites/default');
}
/** /**
* Reacts to the beginning of an update process. * Reacts to the beginning of an update process.
* *
...@@ -136,6 +148,7 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface { ...@@ -136,6 +148,7 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() { public static function getSubscribedEvents() {
return [ return [
AutomaticUpdatesEvents::PRE_START => 'preStart', AutomaticUpdatesEvents::PRE_START => 'preStart',
AutomaticUpdatesEvents::PRE_COMMIT => 'preCommit',
]; ];
} }
......
...@@ -7,6 +7,7 @@ use Drupal\automatic_updates\Event\PreCommitEvent; ...@@ -7,6 +7,7 @@ use Drupal\automatic_updates\Event\PreCommitEvent;
use Drupal\automatic_updates\Event\PreStartEvent; use Drupal\automatic_updates\Event\PreStartEvent;
use Drupal\automatic_updates\Event\UpdateEvent; use Drupal\automatic_updates\Event\UpdateEvent;
use Drupal\automatic_updates\Exception\UpdateException; use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
...@@ -129,7 +130,10 @@ class Updater { ...@@ -129,7 +130,10 @@ class Updater {
* The absolute path for stage directory. * The absolute path for stage directory.
*/ */
public function getStageDirectory(): string { public function getStageDirectory(): string {
return realpath(static::getVendorDirectory() . '/..') . '/.automatic_updates_stage'; // @todo This should be unique, in order to support parallel runs, or
// multiple sites on the same server. Find a way to make it unique, and
// persistent for the entire lifetime of the update process.
return FileSystem::getOsTemporaryDirectory() . '/.automatic_updates_stage';
} }
/** /**
...@@ -165,7 +169,7 @@ class Updater { ...@@ -165,7 +169,7 @@ class Updater {
public function begin(): string { public function begin(): string {
$stage_key = $this->createActiveStage(); $stage_key = $this->createActiveStage();
$event = $this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_START); $event = $this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_START);
$this->beginner->begin(static::getActiveDirectory(), static::getStageDirectory(), NULL, 120, $this->getExclusions($event)); $this->beginner->begin(static::getActiveDirectory(), static::getStageDirectory(), $this->getExclusions($event));
return $stage_key; return $stage_key;
} }
...@@ -227,11 +231,12 @@ class Updater { ...@@ -227,11 +231,12 @@ class Updater {
* Commits the current update. * Commits the current update.
*/ */
public function commit(): void { public function commit(): void {
$this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_COMMIT); /** @var \Drupal\automatic_updates\Event\PreCommitEvent $event */
$event = $this->dispatchUpdateEvent(AutomaticUpdatesEvents::PRE_COMMIT);
// @todo Pass excluded paths into the committer once // @todo Pass excluded paths into the committer once
// https://github.com/php-tuf/composer-stager/pull/14 is in a tagged release // https://github.com/php-tuf/composer-stager/pull/14 is in a tagged release
// of Composer Stager. // of Composer Stager.
$this->committer->commit($this->getStageDirectory(), static::getActiveDirectory()); $this->committer->commit($this->getStageDirectory(), static::getActiveDirectory(), $this->getExclusions($event));
} }
/** /**
......
...@@ -13,7 +13,7 @@ class Beginner implements BeginnerInterface { ...@@ -13,7 +13,7 @@ class Beginner implements BeginnerInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function begin(string $activeDir, string $stagingDir, ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120): void { public function begin(string $activeDir, string $stagingDir, ?array $exclusions = [], ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120): void {
} }
} }
...@@ -30,7 +30,7 @@ class Committer implements CommitterInterface { ...@@ -30,7 +30,7 @@ class Committer implements CommitterInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function commit(string $stagingDir, string $activeDir, ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120): void { public function commit(string $stagingDir, string $activeDir, ?array $exclusions = [], ?ProcessOutputCallbackInterface $callback = NULL, ?int $timeout = 120): void {
} }
/** /**
......
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