diff --git a/defaults/standard/modules/the_build_utility/the_build_utility.install b/defaults/standard/modules/the_build_utility/the_build_utility.install index 913472f4..62fcd118 100644 --- a/defaults/standard/modules/the_build_utility/the_build_utility.install +++ b/defaults/standard/modules/the_build_utility/the_build_utility.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the-build utility module. */ -use Drupal\user\Entity\User; -use Drupal\user\RoleInterface; use Drupal\shortcut\Entity\Shortcut; /** @@ -57,18 +55,14 @@ function the_build_utility_install() { $install = ['admin_toolbar', 'admin_toolbar_tools', 'config_split', 'devel', 'workbench', 'workbench_tabs']; \Drupal::service('module_installer')->install($install); - // Remove any entity dependencies so we can uninstall modules. - - // Begin Comment module. - // Remove the comment fields. + // Remove comment fields so that comment module can be uninstalled. $fields = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['type' => 'comment']); foreach ($fields as $field) { $field->delete(); } - // Remove state setting. + // Remove state variable from comment module. \Drupal::state()->delete('comment.node_comment_statistics_scale'); - // End Comment module. // Uninstall the modules from the standard profile that we don't want. $uninstall = ['automated_cron', 'big_pipe', 'comment', 'contact', 'history', 'search', 'tour']; diff --git a/src/TheBuild/Acquia/AcquiaTask.php b/src/TheBuild/Acquia/AcquiaTask.php index 8ae3b18c..718aba3b 100644 --- a/src/TheBuild/Acquia/AcquiaTask.php +++ b/src/TheBuild/Acquia/AcquiaTask.php @@ -1,36 +1,16 @@ - * @endcode - * - * Extending classes may also set the 'endpoint' property if it is necessary to - * use the v2 API instead of v1. - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild\Acquia; -use BuildException; -use HTTP_Request2; -use PhingFile; - +/** + * + */ abstract class AcquiaTask extends \Task { /** * Required. The Acquia Cloud credentials file containing a json array with * 'mail' and 'key' values. + * * @var \PhingFile */ protected $credentialsFile; @@ -38,6 +18,7 @@ abstract class AcquiaTask extends \Task { /** * Email address associated with the Acquia Cloud access. This value is set * from the credentials file. + * * @var string */ protected $mail; @@ -45,6 +26,7 @@ abstract class AcquiaTask extends \Task { /** * Secure key associated with the Acquia Cloud access. This value is set from * the credentials file. + * * @var string */ protected $key; @@ -52,6 +34,7 @@ abstract class AcquiaTask extends \Task { /** * The Acquia Cloud API endpoint. This code is specific to version 1 of the * API. + * * @var string */ protected $endpoint = 'https://cloudapi.acquia.com/v1'; @@ -65,11 +48,11 @@ abstract class AcquiaTask extends \Task { protected function loadCredentials() { if (empty($this->mail) || empty($this->key)) { if (empty($this->credentialsFile)) { - $this->credentialsFile = new PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf'); + $this->credentialsFile = new \PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf'); } if (!file_exists($this->credentialsFile) || !is_readable($this->credentialsFile)) { - throw new BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available."); + throw new \BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available."); } $contents = file_get_contents($this->credentialsFile); @@ -80,7 +63,7 @@ protected function loadCredentials() { } if (empty($this->mail) || empty($this->key)) { - throw new BuildException('Missing Acquia Cloud API credentials.'); + throw new \BuildException('Missing Acquia Cloud API credentials.'); } } @@ -88,14 +71,15 @@ protected function loadCredentials() { * Build an HTTP request object against the Acquia Cloud API. * * @param $path - * @return HTTP_Request2 + * + * @return \HTTP_Request2 */ protected function createRequest($path) { $this->loadCredentials(); $uri = $this->endpoint . '/' . ltrim($path, '/'); - $request = new HTTP_Request2($uri); + $request = new \HTTP_Request2($uri); $request->setConfig('follow_redirects', TRUE); $request->setAuth($this->mail, $this->key); @@ -106,7 +90,9 @@ protected function createRequest($path) { * Example of how to query the Acquia Cloud API. * * @param $path + * * @return string + * * @throws \HTTP_Request2_Exception */ protected function getApiResponseBody($path) { @@ -118,12 +104,12 @@ protected function getApiResponseBody($path) { } /** - * @param PhingFile $file + * @param \PhingFile $file * @throws \IOException * @throws \NullPointerException */ - public function setCredentialsFile(PhingFile $file) { - $this->credentialsFile = new PhingFile($file); + public function setCredentialsFile(\PhingFile $file) { + $this->credentialsFile = new \PhingFile($file); } } diff --git a/src/TheBuild/Acquia/GetLatestBackupTask.php b/src/TheBuild/Acquia/GetLatestBackupTask.php index 96f2a0b3..e6ca136f 100644 --- a/src/TheBuild/Acquia/GetLatestBackupTask.php +++ b/src/TheBuild/Acquia/GetLatestBackupTask.php @@ -1,32 +1,18 @@ - * - * - * - * @endcode - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild\Acquia; -use BuildException; -use PhingFile; - - +/** + * + */ class GetLatestBackupTask extends AcquiaTask { /** * Directory for storing downloaded database backups. * * Required parameter. - * @var PhingFile + * + * @var \PhingFile */ protected $dir; @@ -38,6 +24,7 @@ class GetLatestBackupTask extends AcquiaTask { * This also appears in a site's server names, as 'sitename.REALM.hosting.acquia.com'. * * Required parameter. + * * @var string */ protected $realm; @@ -46,6 +33,7 @@ class GetLatestBackupTask extends AcquiaTask { * The Acquia Cloud site account name. * * Required parameter. + * * @var string */ protected $site; @@ -55,6 +43,7 @@ class GetLatestBackupTask extends AcquiaTask { * a site has RA or other additional environments. * * Required parameter. + * * @var string */ protected $env; @@ -65,6 +54,7 @@ class GetLatestBackupTask extends AcquiaTask { * running Drupal multisites. * * Optional parameter; defaults to matching $site. + * * @var string */ protected $database; @@ -75,6 +65,7 @@ class GetLatestBackupTask extends AcquiaTask { * and the newest backup will be downloaded. * * Optional parameter. + * * @var int */ protected $maxAge = 24; @@ -83,6 +74,7 @@ class GetLatestBackupTask extends AcquiaTask { * Name of a property to populate with the path to the latest database backup. * * Optional parameter. + * * @var string */ protected $propertyName; @@ -90,7 +82,8 @@ class GetLatestBackupTask extends AcquiaTask { /** * Where to store the JSON list of database backups downloaded from the Acquia * Cloud API. This is set to 'backups.json' in the directory specified by $dir. - * @var PhingFile + * + * @var \PhingFile */ protected $backupsFile; @@ -108,7 +101,7 @@ public function main() { // Store the Acquia Cloud API JSON database backup records in our backups // directory. - $this->backupsFile = new PhingFile($this->dir, "backups-{$this->site}-{$this->database}-{$this->env}.json"); + $this->backupsFile = new \PhingFile($this->dir, "backups-{$this->site}-{$this->database}-{$this->env}.json"); // Check the database backup records for entries within our time window. $backups = $this->getCurrentBackupRecords(); @@ -117,7 +110,7 @@ public function main() { $downloaded_backups = []; foreach ($backups as $backup) { $filename = basename($backup['path']); - $file = new PhingFile($this->dir, $filename); + $file = new \PhingFile($this->dir, $filename); if ($file->exists()) { $downloaded_backups[] = $backup; @@ -149,12 +142,12 @@ public function main() { // This means that we didn't have a current record in our backups json, and the Acquia Cloud API returned empty or // malformed JSON. if (empty($newest_backup)) { - throw new BuildException('Failed to find a backup record.'); + throw new \BuildException('Failed to find a backup record.'); } // Download the backup if it does not yet exist on the filesystem. $filename = basename($newest_backup['path']); - $file = new PhingFile($this->dir, $filename); + $file = new \PhingFile($this->dir, $filename); if (!$file->exists()) { $this->log("Downloading the backup to " . $file->getAbsolutePath()); $this->downloadBackup($newest_backup, $file); @@ -174,14 +167,15 @@ public function main() { * Download a backup from Acquia Cloud. * * @param array $backup - * @param PhingFile $destination + * @param \PhingFile $destination + * * @throws \HTTP_Request2_Exception * @throws \HTTP_Request2_LogicException */ - protected function downloadBackup(array $backup, PhingFile $destination) { + protected function downloadBackup(array $backup, \PhingFile $destination) { $stream = fopen($destination->getAbsolutePath(), 'wb'); if (!$stream) { - throw new BuildException('Can not write to ' . $destination->getAbsolutePath()); + throw new \BuildException('Can not write to ' . $destination->getAbsolutePath()); } // Use an HTTP_Request2 with the Observer pattern in order to download large @@ -197,18 +191,19 @@ protected function downloadBackup(array $backup, PhingFile $destination) { $response = $request->send(); fclose($stream); - $this->log("Downloaded " . $response->getHeader('content-length')/1000000 . "MB to " . $destination->getAbsolutePath()); + $this->log("Downloaded " . $response->getHeader('content-length') / 1000000 . "MB to " . $destination->getAbsolutePath()); } /** * Get backup records that are within the desired time window. + * * @return array */ protected function getCurrentBackupRecords() { try { $backups = $this->getBackupRecords($this->backupsFile); } - catch (BuildException $e) { + catch (\BuildException $e) { $backups = []; } @@ -232,8 +227,10 @@ protected function getCurrentBackupRecords() { * sorted from oldest to newest. * * @param $file + * * @return array - * @throws BuildException + * + * @throws \BuildException */ protected function getBackupRecords($file) { if ($file->exists()) { @@ -244,8 +241,10 @@ protected function getBackupRecords($file) { if (isset($backups[0]['started'])) { // Sort the backups by start time so that the newest is always last. - usort($backups, function($a, $b) { - if ($a['started'] == $b['started']) { return 0; } + usort($backups, function ($a, $b) { + if ($a['started'] == $b['started']) { + return 0; + } return ($a['started'] < $b['started']) ? -1 : 1; }); @@ -253,16 +252,16 @@ protected function getBackupRecords($file) { } elseif (count($backups) === 0) { // The site might not have been backed up yet. - throw new BuildException('No Acquia Cloud backups found: ' . $file->getCanonicalPath()); + throw new \BuildException('No Acquia Cloud backups found: ' . $file->getCanonicalPath()); } } - throw new BuildException('Acquia Cloud backup records could not be loaded from JSON: ' . $file->getCanonicalPath()); + throw new \BuildException('Acquia Cloud backup records could not be loaded from JSON: ' . $file->getCanonicalPath()); } /** * Download the latest list of backup records from the Acquia Cloud API. */ - protected function downloadBackupRecords(PhingFile $backups_file) { + protected function downloadBackupRecords(\PhingFile $backups_file) { $json = $this->getApiResponseBody("/sites/{$this->realm}:{$this->site}/envs/{$this->env}/dbs/{$this->database}/backups.json"); $writer = new \FileWriter($backups_file); @@ -273,6 +272,7 @@ protected function downloadBackupRecords(PhingFile $backups_file) { * Format the backup time to display in log messages. * * @param $backup + * * @return string */ protected function formatBackupTime($backup) { @@ -287,21 +287,45 @@ protected function formatBackupTime($backup) { public function setRealm($value) { $this->realm = $value; } + + /** + * + */ public function setSite($value) { $this->site = $value; } + + /** + * + */ public function setEnv($value) { $this->env = $value; } + + /** + * + */ public function setDatabase($value) { $this->database = $value; } + + /** + * + */ public function setDir($value) { - $this->dir = new PhingFile($value); + $this->dir = new \PhingFile($value); } + + /** + * + */ public function setMaxAge($value) { $this->maxAge = (int) $value; } + + /** + * + */ public function setPropertyName($value) { $this->propertyName = $value; } @@ -312,7 +336,7 @@ public function setPropertyName($value) { protected function validate() { foreach (['dir', 'realm', 'site', 'env'] as $attribute) { if (empty($this->$attribute)) { - throw new BuildException("$attribute attribute is required.", $this->location); + throw new \BuildException("$attribute attribute is required.", $this->location); } } } diff --git a/src/TheBuild/CopyPropertiesTask.php b/src/TheBuild/CopyPropertiesTask.php index 5d8c2379..6032ae10 100644 --- a/src/TheBuild/CopyPropertiesTask.php +++ b/src/TheBuild/CopyPropertiesTask.php @@ -1,22 +1,10 @@ - * @endcode - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild; -use BuildException; -use StringHelper; - - +/** + * + */ class CopyPropertiesTask extends \Task { /** @@ -30,19 +18,18 @@ class CopyPropertiesTask extends \Task { * Prefix for properties to create/update. */ protected $toPrefix = ''; - + /** * @var bool * Whether to overwrite the existing properties. */ - protected $override = true; + protected $override = TRUE; /** * @var string */ protected $propertyMethod = 'setProperty'; - /** * Copy properties. */ @@ -62,26 +49,24 @@ public function main() { } } - /** * Verify that the required attributes are set. */ public function validate() { if (empty($this->fromPrefix)) { - throw new BuildException("fromPrefix attribute is required.", $this->location); + throw new \BuildException("fromPrefix attribute is required.", $this->location); } if (empty($this->toPrefix)) { - throw new BuildException("toPrefix attribute is required.", $this->location); + throw new \BuildException("toPrefix attribute is required.", $this->location); } } - /** * @param string $prefix */ public function setFromPrefix($prefix) { - if (!StringHelper::endsWith(".", $prefix)) { + if (!\StringHelper::endsWith(".", $prefix)) { $prefix .= "."; } @@ -92,7 +77,7 @@ public function setFromPrefix($prefix) { * @param string $prefix */ public function setToPrefix($prefix) { - if (!StringHelper::endsWith(".", $prefix)) { + if (!\StringHelper::endsWith(".", $prefix)) { $prefix .= "."; } diff --git a/src/TheBuild/ForeachKeyTask.php b/src/TheBuild/ForeachKeyTask.php index 98a06351..fd9516ce 100644 --- a/src/TheBuild/ForeachKeyTask.php +++ b/src/TheBuild/ForeachKeyTask.php @@ -1,22 +1,10 @@ - * @endcode - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild; -use BuildException; -use StringHelper; - - +/** + * + */ class ForeachKeyTask extends \Task { /** @@ -73,8 +61,8 @@ public function main() { $this->validate(); $this->callee->setTarget($this->target); - $this->callee->setInheritAll(true); - $this->callee->setInheritRefs(true); + $this->callee->setInheritAll(TRUE); + $this->callee->setInheritRefs(TRUE); // Extract matching keys from the properties array. $keys = []; @@ -82,7 +70,7 @@ public function main() { foreach ($project->getProperties() as $name => $value) { if (strpos($name, $this->prefix) === 0) { $property_children = substr($name, strlen($this->prefix)); - list($key, $property_grandchildren) = explode('.', $property_children, 2); + [$key, $property_grandchildren] = explode('.', $property_children, 2); $keys[$key] = $key; } } @@ -93,12 +81,12 @@ public function main() { // Iterate over each extracted key. foreach ($keys as $key => $prefix) { $prop = $this->callee->createProperty(); - $prop->setOverride(true); + $prop->setOverride(TRUE); $prop->setName($this->keyParam); $prop->setValue($key); $prop = $this->callee->createProperty(); - $prop->setOverride(true); + $prop->setOverride(TRUE); $prop->setName($this->prefixParam); $prop->setValue($this->prefix); @@ -106,24 +94,22 @@ public function main() { } } - /** * Verify that the required attributes are set. */ public function validate() { foreach (['prefix', 'target', 'keyParam', 'prefixParam'] as $attribute) { if (empty($this->$attribute)) { - throw new BuildException("$attribute attribute is required.", $this->location); + throw new \BuildException("$attribute attribute is required.", $this->location); } } } - /** * @param string $value */ public function setPrefix($value) { - if (!StringHelper::endsWith(".", $value)) { + if (!\StringHelper::endsWith(".", $value)) { $value .= "."; } diff --git a/src/TheBuild/IncludeResourceTask.php b/src/TheBuild/IncludeResourceTask.php index a3a75215..d13f0266 100644 --- a/src/TheBuild/IncludeResourceTask.php +++ b/src/TheBuild/IncludeResourceTask.php @@ -1,17 +1,10 @@ log("Replacing existing resource '" . $this->dest->getPath() . "'"); if ($this->dest->delete(TRUE) === FALSE) { - throw new BuildException("Failed to delete existing destination '$this->dest'"); + throw new \BuildException("Failed to delete existing destination '$this->dest'"); } } @@ -88,60 +80,56 @@ public function main() { } } - /** * Verify that the required attributes are set. */ public function validate() { if (!in_array($this->mode, ['symlink', 'copy'])) { - throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location); + throw new \BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location); } if (empty($this->source) || empty($this->dest)) { - throw new BuildException("Both the 'source' and 'dest' attributes are required."); + throw new \BuildException("Both the 'source' and 'dest' attributes are required."); } } - /** * Set the artifact mode. * * @param $mode - * Use 'symlink' to link resources, and 'copy' to copy them. + * Use 'symlink' to link resources, and 'copy' to copy them. */ public function setMode($mode) { $this->mode = $mode; } - /** * Set the source of the resource to include. * * @param \PhingFile $source */ - public function setSource(PhingFile $source) { + public function setSource(\PhingFile $source) { if (!$source->exists()) { - throw new BuildException("resource '$source' is not available'"); + throw new \BuildException("resource '$source' is not available'"); } $this->source = $source; } - /** * Set the destination for the resource. - * @param PhingFile $dest + * + * @param \PhingFile $dest */ - public function setDest(PhingFile $dest) { + public function setDest(\PhingFile $dest) { $this->dest = $dest; } /** - * @param boolean $relative + * @param bool $relative */ - public function setRelative($relative) - { - $this->relative = $relative; + public function setRelative($relative) { + $this->relative = $relative; } } diff --git a/src/TheBuild/MenuInputRequest.php b/src/TheBuild/MenuInputRequest.php index 2bed0974..4c0b683f 100644 --- a/src/TheBuild/MenuInputRequest.php +++ b/src/TheBuild/MenuInputRequest.php @@ -1,37 +1,37 @@ options = array_values($options); } + /** + * + */ public function getPrompt() { $prompt = $this->prompt . $this->getPromptChar() . "\r\n"; foreach ($this->options as $i => $option) { @@ -40,10 +40,16 @@ public function getPrompt() { return $prompt; } + /** + * + */ public function isInputValid() { return (isset($this->options[$this->input])); } + /** + * + */ public function getInput() { return $this->options[$this->input]; } diff --git a/src/TheBuild/SelectOneTask.php b/src/TheBuild/SelectOneTask.php index 2b65d71a..34bad40e 100644 --- a/src/TheBuild/SelectOneTask.php +++ b/src/TheBuild/SelectOneTask.php @@ -1,30 +1,10 @@ - * - * - * @endcode - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild; -use BuildException; -use Project; - - +/** + * + */ class SelectOneTask extends \Task { /** @@ -44,24 +24,23 @@ class SelectOneTask extends \Task { * Required. Property to populate with the selected value. */ protected $propertyName = ''; - + /** * @var string * Message to display to the user when more than one key is available. */ protected $message = 'Select one:'; - /** * Select menu. */ public function main() { $this->validate(); - + $project = $this->getProject(); if ($existing_value = $this->project->getProperty($this->propertyName)) { - $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO); + $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", \Project::MSG_INFO); return; } @@ -78,7 +57,7 @@ public function main() { } elseif (count($keys) == 1) { $value = current($keys); - $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO); + $this->log("Using {$this->propertyName} = '{$value}' (one value found)", \Project::MSG_INFO); } if ($value) { @@ -86,14 +65,13 @@ public function main() { } } - /** * Verify that the required attributes are set. */ public function validate() { foreach (['list', 'propertyName'] as $attribute) { if (empty($this->$attribute)) { - throw new BuildException("$attribute attribute is required.", $this->location); + throw new \BuildException("$attribute attribute is required.", $this->location); } } } diff --git a/src/TheBuild/SelectPropertyKeyTask.php b/src/TheBuild/SelectPropertyKeyTask.php index dc5a30f8..f15f903e 100644 --- a/src/TheBuild/SelectPropertyKeyTask.php +++ b/src/TheBuild/SelectPropertyKeyTask.php @@ -1,30 +1,10 @@ - * @endcode - * - * @copyright 2018 Palantir.net, Inc. - */ namespace TheBuild; -use BuildException; -use StringHelper; -use Project; - - +/** + * + */ class SelectPropertyKeyTask extends \Task { /** @@ -38,7 +18,7 @@ class SelectPropertyKeyTask extends \Task { * Required. Property to populate with the selected value. */ protected $propertyName = ''; - + /** * @var string * Message to display to the user when more than one key is available. @@ -50,7 +30,6 @@ class SelectPropertyKeyTask extends \Task { */ protected $omitKeys = []; - /** * Copy properties. */ @@ -59,7 +38,7 @@ public function main() { $project = $this->getProject(); if ($existing_value = $this->project->getProperty($this->propertyName)) { - $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO); + $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", \Project::MSG_INFO); return; } @@ -68,7 +47,7 @@ public function main() { foreach ($project->getProperties() as $name => $value) { if (strpos($name, $this->prefix) === 0) { $property_children = substr($name, strlen($this->prefix)); - list($key, $property_grandchildren) = explode('.', $property_children, 2); + [$key, $property_grandchildren] = explode('.', $property_children, 2); $keys[$key] = $key; } } @@ -87,10 +66,10 @@ public function main() { } elseif (count($keys) == 1) { $value = current($keys); - $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO); + $this->log("Using {$this->propertyName} = '{$value}' (one value found)", \Project::MSG_INFO); } else { - $this->log("No properties found with prefix '{$this->prefix}'", Project::MSG_WARN); + $this->log("No properties found with prefix '{$this->prefix}'", \Project::MSG_WARN); } if ($value) { @@ -98,24 +77,22 @@ public function main() { } } - /** * Verify that the required attributes are set. */ public function validate() { foreach (['prefix', 'propertyName'] as $attribute) { if (empty($this->$attribute)) { - throw new BuildException("$attribute attribute is required.", $this->location); + throw new \BuildException("$attribute attribute is required.", $this->location); } } } - /** * @param string $value */ public function setPrefix($value) { - if (!StringHelper::endsWith(".", $value)) { + if (!\StringHelper::endsWith(".", $value)) { $value .= "."; }