diff --git a/composer.json b/composer.json index 2cc482629ae8a627bdf4b82382470b0a0bf2c587..c0d4b93db353a9bcf2dc1179187763c6f9863ec5 100644 --- a/composer.json +++ b/composer.json @@ -8,14 +8,20 @@ "authors": [ { "name": "Jürgen Haas", - "email": "juergen@paragon-es.de", - "homepage": "https://www.paragon-es.de", + "email": "juergen.haas@lakedrops.com", + "homepage": "https://www.lakedrops.com", + "role": "Drupal Expert" + }, + { + "name": "Daniel Speicher", + "email": "daniel.speicher@lakedrops.com", + "homepage": "https://www.lakedrops.com", "role": "Drupal Expert" }, { "name": "Richard Papp", - "email": "richard.papp@boromino.com", - "homepage": "http://www.boromino.com", + "email": "richard.papp@lakedrops.com", + "homepage": "https://www.lakedrops.com", "role": "Drupal Expert" } ], @@ -32,7 +38,15 @@ }, "require-dev": { "composer/composer": "^1||^2", - "phpunit/phpunit": "^8.4" + "drupal/coder": "^8.3", + "phpunit/phpunit": "^9.5", + "roave/security-advisories": "dev-master", + "squizlabs/php_codesniffer": "^3.7" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/Handler.php b/src/Handler.php index 61c3fdcd1b1f812112b57dd2a8dba4f71dbce4af..3b817f5a776965d8dc5838faf46ae23b9d347d2f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -2,14 +2,12 @@ namespace LakeDrops\DorgFlow; -use Exception; -use GitElephant\Command\ResetCommand; use GitElephant\Repository; use LakeDrops\Component\Composer\BaseHandler; use Symfony\Component\Filesystem\Filesystem; /** - * Class Handler. + * Handler class for the Dorgflow plugin. * * @package LakeDrops\DorgFlow */ @@ -50,10 +48,10 @@ class Handler extends BaseHandler { $installationManager = $this->composer->getInstallationManager(); foreach ([ - 'projects' => 'git.drupal.org:project', - 'drupalspoons' => 'gitlab.com:drupalspoons', - 'selfhosted' => FALSE, - ] as $type => $url) { + 'projects' => 'git.drupal.org:project', + 'drupalspoons' => 'gitlab.com:drupalspoons', + 'selfhosted' => FALSE, + ] as $type => $url) { if ($this->config->readValue($type) === NULL) { continue; } @@ -86,7 +84,9 @@ class Handler extends BaseHandler { } $path = $installationManager->getInstallPath($package); $this->io->write("- $project => $path", TRUE); + $this->keepObjects($project); $this->prepareWorkingDirectory($path, $projectname, $version, $fullUrl); + $this->restoreObjects($project); } } } @@ -112,11 +112,12 @@ class Handler extends BaseHandler { try { $origin = $repository->getRemote('origin', FALSE); - if ($origin && $origin->getFetchURL() === $uri) { + if ($origin->getFetchURL() === $uri) { // Already setup correctly. return; } - } catch (Exception $ex) { + } + catch (\Exception $ex) { // Ignore the exception and conitue setup. } @@ -177,12 +178,13 @@ class Handler extends BaseHandler { $repository = Repository::open($path); try { $origin = $repository->getRemote($remote, FALSE); - if ($origin && $origin->getFetchURL() === $uri) { + if ($origin->getFetchURL() === $uri) { // Already setup correctly. $this->io->write('Already available.'); return; } - } catch (Exception $ex) { + } + catch (\Exception $ex) { // Ignore the exception and conitue setup. } $repository->addRemote($remote, $uri); @@ -190,4 +192,40 @@ class Handler extends BaseHandler { $this->io->write('Successfully added issue fork.'); } + /** + * Move files and directories to keep to the /tmp directory. + * + * @param string $project + * The project name. + */ + private function keepObjects(string $project): void { + if ($objects = $this->config->readValue(['keep', $project])) { + $fs = new Filesystem(); + foreach ($objects as $id => $object) { + if (file_exists($object)) { + $this->io->write(' - keeping ' . $object); + $fs->rename($object, '/tmp/dorgflow-keep-' . $id, TRUE); + } + } + } + } + + /** + * Move files and directories to keep from the /tmp directory. + * + * @param string $project + * The project name. + */ + private function restoreObjects(string $project): void { + if ($objects = $this->config->readValue(['keep', $project])) { + $fs = new Filesystem(); + foreach ($objects as $id => $object) { + if (file_exists('/tmp/dorgflow-keep-' . $id)) { + $this->io->write(' - restoring ' . $object); + $fs->rename('/tmp/dorgflow-keep-' . $id, $object, TRUE); + } + } + } + } + }