Skip to content

Commit

Permalink
ACMS-000: Fixed conflicts and minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkhode1 committed Nov 21, 2023
1 parent 03ddd55 commit 7a3887f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/drs_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ jobs:
run: ../orca/bin/ci/install.sh
- name: Before script
run: ../orca/bin/ci/before_script.sh
- name: Script
run: ./tests/ci/script.sh
- name: Run PHPUnit tests
run: |
composer install
./vendor/bin/phpunit tests
- name: After script
run: |
../orca/bin/ci/after_success.sh
Expand Down
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ composer require acquia/drupal-recommended-settings
+ use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector;
```

## Steps to use Acquia Drupal Recommended Settings with BLT.
- Create an Settings object & call generate method.
# Quick examples.
## Generate settings for a given site.
```
<?php
Expand All @@ -63,30 +63,56 @@ composer require acquia/drupal-recommended-settings
*/
use Acquia\Drupal\RecommendedSettings\Settings;
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
// Create settings object.
$siteUri = "site1";
$settings = new Settings(DRUPAL_ROOT, $siteUri);
try {
// Call generate method.
$settings->generate();
} catch (SettingsException $e) {
echo $e->getMessage();
}
```

## Generate settings for a given site passing database credentials.

```
<?php
/**
* @file
* Include DRS settings.
*/
use Acquia\Drupal\RecommendedSettings\Settings;
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
// Create settings object.
$settings = new Settings(DRUPAL_ROOT, 'site-uri');
$siteUri = "site1";
$settings = new Settings(DRUPAL_ROOT, $siteUri);
// Database details.
$dbSpec = [
'drupal' => [
'db' => [
// Database name.
'database' => 'drupal',
// Mysql database login username.
'username' => 'drupal',
// Mysql database login password.
'password' => 'drupal',
// Mysql host.
'host' => 'localhost',
// Mysql port.
'port' => '3306',
],
],
];
// Call generate method with database details.
$settings->generate($dbSpec);
try {
// Call generate method passing database details.
$settings->generate($dbSpec);
} catch (SettingsException $e) {
echo $e->getMessage();
}
```

# License
Expand Down
7 changes: 5 additions & 2 deletions src/Helpers/HashGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Acquia\Drupal\RecommendedSettings\Helpers;

use Acquia\Drupal\RecommendedSettings\Common\RandomString;
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;

/**
* Class to generate salt hash.
Expand All @@ -16,6 +17,8 @@ class HashGenerator {
* Given directory.
* @param mixed $io
* Given io object to print message to terminal.
*
* @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException
*/
public static function generate(string $directory, $io): void {
try {
Expand All @@ -30,8 +33,8 @@ public static function generate(string $directory, $io): void {
$io->write("<fg=white;bg=cyan;options=bold>[notice]</> Hash salt already exists.");
}
}
catch (\RuntimeException $e) {
$io->write("<fg=white;bg=red;options=bold>[error]</> " . $e->getMessage());
catch (\Exception $e) {
throw new SettingsException($e);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Acquia\Drupal\RecommendedSettings;

use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
use Acquia\Drupal\RecommendedSettings\Helpers\HashGenerator;
use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
Expand Down Expand Up @@ -93,7 +94,7 @@ public function onPostPackageEvent(PackageEvent $event) {
/**
* Includes Acquia recommended settings post composer update/install command.
*
* @throws \Exception
* @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException
*/
public function onPostCmdEvent() {
// Only install the template files, if the drupal-recommended-settings
Expand All @@ -104,7 +105,7 @@ public function onPostCmdEvent() {
$settings = new Settings($this->getDrupalRoot());
$settings->generate();
}
catch (\Exception $e) {
catch (SettingsException $e) {
$this->io->write("<fg=white;bg=red;options=bold>[error]</> " . $e->getMessage());
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Acquia\Drupal\RecommendedSettings\Config\ConfigInitializer;
use Acquia\Drupal\RecommendedSettings\Config\SettingsConfig;
use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
use Acquia\Drupal\RecommendedSettings\Helpers\Filesystem;

/**
Expand Down Expand Up @@ -96,8 +97,11 @@ protected function copySiteSettings(): bool {
*
* @param array $overrideData
* An array of data to override.
*
* @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException
*/
public function generate(array $overrideData = []): void {
try {
$site = $this->site;
$this->copyGlobalSettings();
$this->copySiteSettings();
Expand Down Expand Up @@ -137,6 +141,10 @@ public function generate(array $overrideData = []): void {
// The config directory for given site must exists, otherwise Drupal will
// add database credentials to settings.php.
$this->fileSystem->ensureDirectoryExists($this->drupalRoot . "/../config/$site");
} catch (\Exception $e) {
throw new SettingsException($e);
}

}

/**
Expand Down
19 changes: 0 additions & 19 deletions tests/ci/script.sh

This file was deleted.

0 comments on commit 7a3887f

Please sign in to comment.