Skip to content

Commit

Permalink
Fixes #704: Improve upgrade path for older versions of BLT. (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash authored Dec 5, 2016
1 parent 21df33f commit b55e1b4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion phing/tasks/blt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --include-from=${blt.update.ignore-existing-file} --ignore-existing" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>

<target name="update" depends="blt:rsync-template, blt:update-composer, blt:update-yml, blt:update-delta" hidden="true">
<target name="update" depends="blt:rsync-template, blt:update-composer, blt:update-yml, blt:update-delta, cleanup" hidden="true">

<phingcall target="install-alias">
<property name="create_alias" value="true"/>
Expand Down
3 changes: 3 additions & 0 deletions scripts/blt/remove-deprecated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rm -rf scripts/git-hooks
rm -rf scripts/release-notes
rm -rf scripts/tugboat
rm -f blt.sh
rm -f project.yml
rm -f project.local.yml
rm -f example.project.local.yml
rm -f readme/acsf-setup.md
rm -f readme/architecture.md
rm -f readme/best-practices.md
Expand Down
115 changes: 96 additions & 19 deletions src/Update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ class Updater {
* @var \Symfony\Component\Filesystem\Filesystem*/
protected $fs;

/**
* @var string
*/
protected $composerJsonFilepath;

/**
* Updater constructor.
*
* @param string $update_class
* The name of the class containing the update methods to be executed.
*/
public function __construct($update_class = 'Acquia\Blt\Update\Updates') {
$this->output = new ConsoleOutput();
$this->output->setFormatter(new OutputFormatter(TRUE));
AnnotationRegistry::registerFile(__DIR__ . '/../Annotations/Update.php');
$this->annotationsReader = new IndexedReader(new AnnotationReader());
$this->updateClassName = $update_class;
$this->fs = new Filesystem();
$this->composerJsonFilepath = $this->repoRoot . '/composer.json';
}

/**
* Returns $this->repoRoot.
*
Expand Down Expand Up @@ -71,21 +92,6 @@ public function getFileSystem() {
return $this->fs;
}

/**
* Updater constructor.
*
* @param string $update_class
* The name of the class containing the update methods to be executed.
*/
public function __construct($update_class = 'Acquia\Blt\Update\Updates') {
$this->output = new ConsoleOutput();
$this->output->setFormatter(new OutputFormatter(TRUE));
AnnotationRegistry::registerFile(__DIR__ . '/../Annotations/Update.php');
$this->annotationsReader = new IndexedReader(new AnnotationReader());
$this->updateClassName = $update_class;
$this->fs = new Filesystem();
}

/**
* Executes an array of updates.
*
Expand Down Expand Up @@ -226,9 +232,8 @@ public static function executeCommand($command, $cwd = NULL, $display_output = T
* @return bool
* TRUE if patch was removed, otherwise FALSE.
*/
public function removePatch($package, $url) {
$composer_json_filepath = $this->repoRoot . '/composer.json';
$composer_json = json_decode(file_get_contents($composer_json_filepath), TRUE);
public function removeComposerPatch($package, $url) {
$composer_json = $this->getComposerJson();
if (!empty($composer_json['extra']['patches'][$package])) {
foreach ($composer_json['extra']['patches'][$package] as $key => $patch_url) {
if ($patch_url == $url) {
Expand All @@ -237,7 +242,56 @@ public function removePatch($package, $url) {
if (empty($composer_json['extra']['patches'][$package])) {
unset($composer_json['extra']['patches'][$package]);
}
file_put_contents($composer_json_filepath, json_encode($composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$this->writeComposerJson($composer_json);

return TRUE;
}
}
}
return FALSE;
}

/**
* Removes a repository from composer.json using the repository url[
*
* @param string $repo_url
* The url property of the repository to remove.
*
* @return bool
* TRUE if repo was removed, otherwise false.
*/
public function removeComposerRepository($repo_url) {
$composer_json = $this->getComposerJson();
if (!empty($composer_json['repositories'])) {
foreach ($composer_json['repositories'] as $key => $repo) {
$url = $repo['url'];
if ($repo_url == $url) {
unset($composer_json['repositories'][$key]);
$this->writeComposerJson($composer_json);

return TRUE;
}
}
}
return FALSE;
}

/**
* Removes a repository from composer.json using the repository url[
*
* @param string $script_key
* The key of the scripts to remove. E.g., post-create-project-cmd.
*
* @return bool
* TRUE if script was removed, otherwise false.
*/
public function removeComposerScript($script_key) {
$composer_json = $this->getComposerJson();
if (!empty($composer_json['scripts'])) {
foreach ($composer_json['scripts'] as $key => $script) {
if ($script_key == $key) {
unset($composer_json['scripts'][$key]);
$this->writeComposerJson($composer_json);

return TRUE;
}
Expand All @@ -246,6 +300,29 @@ public function removePatch($package, $url) {
return FALSE;
}

/**
* Returns composer.json content.
*
* @return array
* The contents of composer.json.
*/
public function getComposerJson() {
$composer_json = json_decode(file_get_contents($this->composerJsonFilepath), TRUE);

return $composer_json;
}

/**
* Writes an array to composer.json.
*
* @param array $contents
* The new contents of composer.json.
*/
public function writeComposerJson($contents) {
file_put_contents($this->composerJsonFilepath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}


/**
* Moves a file from one location to another, relative to repo root.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Update/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Updater $updater) {
* )
*/
public function update_851() {
$this->updater->removePatch("drupal/features", "https://www.drupal.org/files/issues/features-2808303-2.patch");
$this->updater->removeComposerPatch("drupal/features", "https://www.drupal.org/files/issues/features-2808303-2.patch");
}

/**
Expand All @@ -51,7 +51,9 @@ public function update_860() {
// Delete symlink to hooks directory. Individual git hooks are now symlinked, not the entire directory.
$this->updater->deleteFile('.git/hooks');
$this->updater->getOutput()->writeln('.git/hooks was deleted. Please re-run setup:git-hooks to install git hooks locally.');
}

$this->updater->removeComposerRepository('https://github.com/mortenson/composer-patches');
$this->updater->removeComposerScript('post-create-project-cmd');
}

}

0 comments on commit b55e1b4

Please sign in to comment.