Skip to content

Commit

Permalink
Automated code fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
becw committed Oct 25, 2022
1 parent c98897c commit 5569bfc
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'];
Expand Down
50 changes: 18 additions & 32 deletions src/TheBuild/Acquia/AcquiaTask.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,40 @@
<?php
/**
* @file AcquiaTask.php
*
* Abastract base task for creating Acquia Cloud API tasks.
*
* Loads the Acquia Cloud credentials from a JSON file and constructs
* authenticated requests against the Cloud API.
*
* This class will use the credentials file at ~/.acquia/cloudapi.conf if none
* is provided in the task call:
*
* @code
* <exampleTask credentialsFile="artifacts/cloudapi.conf" />
* @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;

/**
* Email address associated with the Acquia Cloud access. This value is set
* from the credentials file.
*
* @var string
*/
protected $mail;

/**
* Secure key associated with the Acquia Cloud access. This value is set from
* the credentials file.
*
* @var string
*/
protected $key;

/**
* The Acquia Cloud API endpoint. This code is specific to version 1 of the
* API.
*
* @var string
*/
protected $endpoint = 'https://cloudapi.acquia.com/v1';
Expand All @@ -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);
Expand All @@ -80,22 +63,23 @@ 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.');
}
}

/**
* 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);

Expand All @@ -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) {
Expand All @@ -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);
}

}
Loading

0 comments on commit 5569bfc

Please sign in to comment.