Skip to content

Commit

Permalink
Merge pull request #109 from acquia/develop
Browse files Browse the repository at this point in the history
ACMS-1906: Merge develop in main
  • Loading branch information
rajeshreeputra authored Jul 24, 2023
2 parents 7ad0a07 + 9b67dc2 commit 5a3f5c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/Commands/SiteInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
protected function configure() :void {
protected function configure(): void {
$this->setName("site:install")
->setDescription("A wrapper command for drush site:install command.")
->setDefinition([
Expand Down Expand Up @@ -119,7 +119,7 @@ protected function configure() :void {
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) :int {
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$args = [];
if (!$input->getOption('without-product-info')) {
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output) :int
* @param \Symfony\Component\Console\Output\OutputInterface $output
* A Symfony console output object.
*/
protected function postSiteInstall(string $bundle, OutputInterface $output) :void {
protected function postSiteInstall(string $bundle, OutputInterface $output): void {
$output->writeln("");
$formatter = $this->getHelper('formatter');
$infoMessage = "[OK] Thank you for choosing Acquia CMS. We've successfully setup your project using bundle: `$bundle`.";
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Process/Commands/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getCommand(array $commands): array {
$uri = $this->input->getParameterOption('--uri');
$commands = parent::getCommand($commands);
if ($uri) {
$commands = array_merge($commands, ['--uri=' . $uri]);
$commands = array_unique(array_merge($commands, ['--uri=' . $uri]));
}
return $commands;
}
Expand Down
35 changes: 18 additions & 17 deletions src/Helpers/Task/InstallTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function configure(
InputInterface $input,
OutputInterface $output,
string $bundle,
string $site_uri) :void {
string $site_uri): void {
$this->bundle = $bundle;
$this->input = $input;
$this->output = $output;
Expand All @@ -213,39 +213,40 @@ public function configure(
* @param array $args
* An array of params argument to pass.
*/
public function run(array $args) :void {
public function run(array $args): void {
$this->print("Installing Site:", 'headline');
$staretkit_name = 'Existing Site';
$starterkitName = 'Existing Site';
if (isset($this->starterKits[$this->bundle])) {
$staretkit_name = $this->starterKits[$this->bundle]['name'];
$starterkitName = $this->starterKits[$this->bundle]['name'];
}
$this->siteInstall->execute([
'no-interaction' => $this->input->getOption('no-interaction'),
'name' => $staretkit_name,
]);
$siteInstallArgs = array_filter($this->input->getOptions()) + [
'name' => $starterkitName,
];

$this->siteInstall->execute($siteInstallArgs);

// Add user selected starter-kit to state.
$command = array_merge([
"state:set",
"acquia_cms.starter_kit",
], [$this->bundle]);
$this->drushCommand->prepare($command)->run();
$bundle_modules = $this->buildInformation['modules'] ?? [];
$modules_list = JsonParser::installPackages($bundle_modules);
// Get User password from shared factory.
$password = SharedFactory::getData('password');
$bundleModules = $this->buildInformation['modules'] ?? [];
// Get User password from shared factory or from option argument.
$password = $siteInstallArgs['account-pass'] ?? SharedFactory::getData('password');
$this->print("User name: admin, User password: $password", 'info');
$this->print("Enabling modules for the starter-kit:", 'headline');
$isDemoContent = FALSE;
if ($key = array_search('acquia_cms_starter', $modules_list)) {
$modulesList = JsonParser::installPackages($bundleModules);
if ($key = array_search('acquia_cms_starter', $modulesList)) {
// Remove acquia_cms_starter module in the list of modules to install.
// Because we install this module separately in the last.
unset($modules_list[$key]);
unset($modulesList[$key]);
$isDemoContent = TRUE;
}
// Enable modules.
$this->enableModules->execute([
'modules' => $modules_list,
'modules' => $modulesList,
'keys' => $args['keys'],
]);

Expand All @@ -266,7 +267,7 @@ public function run(array $args) :void {
$siteStudioOrgKey = $args['keys']['SITESTUDIO_ORG_KEY'] ?? '';
// Trigger Site Studio Package import, if acquia_cms_site_studio module
// is there in active bundle.
if (in_array('acquia_cms_site_studio', $modules_list)) {
if (in_array('acquia_cms_site_studio', $modulesList)) {
if (!(($siteStudioApiKey && $siteStudioOrgKey) || (getenv('SITESTUDIO_API_KEY') && getenv('SITESTUDIO_ORG_KEY')))) {
$this->print("Skipped importing Site Studio Packages." .
PHP_EOL .
Expand Down Expand Up @@ -312,7 +313,7 @@ public function run(array $args) :void {
* @param string $type
* Type of styling the message.
*/
protected function print(string $message, string $type) :void {
protected function print(string $message, string $type): void {
$this->output->writeln($this->style($message, $type));
}

Expand Down
48 changes: 43 additions & 5 deletions src/Helpers/Task/Steps/SiteInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ class SiteInstall {
*/
public $drushCommand;

/**
* Site name.
*
* @var string
*/
public string $siteName;

/**
* Account password.
*
* @var string
*/
protected string $password;

/**
* Constructs an object.
*
Expand All @@ -25,6 +39,8 @@ class SiteInstall {
*/
public function __construct(Drush $drush) {
$this->drushCommand = $drush;
SharedFactory::setData('password');
$this->password = SharedFactory::getData('password');
}

/**
Expand All @@ -33,17 +49,39 @@ public function __construct(Drush $drush) {
* @param array $args
* An array of params argument to pass.
*/
public function execute(array $args = []) :int {
SharedFactory::setData('password');
$siteInstallCommand = $args['command'] ?? [
public function execute(array $args = []): int {
// Handle the account password.
if (array_key_exists('account-pass', $args)) {
$this->password = $args['account-pass'];
unset($args['account-pass']);
}

$this->siteName = array_key_exists('site-name', $args) ?
$args['site-name'] : $args['name'];
unset($args['name']);
unset($args['site-name']);

// Prepare site install command data.
$siteInstallCommand = [
"site:install",
"minimal",
"--site-name=" . $args['name'],
"--account-pass=" . SharedFactory::getData('password'),
"--site-name=$this->siteName",
"--account-pass=$this->password",
];
// Iterate arguments i.e options to prepare for site install.
foreach ($args as $key => $value) {
if (!in_array($key, [
'without-product-info',
'no-interaction',
])) {
$siteInstallCommand[] = "--" . $key . "=" . $value;
}
}
// Option no-interation then add suffix --yes to the command.
if (isset($args['no-interaction']) && $args['no-interaction']) {
$siteInstallCommand = array_merge($siteInstallCommand, ["--yes"]);
}

return $this->drushCommand->prepare($siteInstallCommand)->run();
}

Expand Down

0 comments on commit 5a3f5c9

Please sign in to comment.