diff --git a/blt/src/Blt/Plugin/Commands/GryphonCommands.php b/blt/src/Blt/Plugin/Commands/GryphonCommands.php index e968833ba..3e6571154 100644 --- a/blt/src/Blt/Plugin/Commands/GryphonCommands.php +++ b/blt/src/Blt/Plugin/Commands/GryphonCommands.php @@ -3,6 +3,8 @@ namespace Gryphon\Blt\Plugin\Commands; use Acquia\Blt\Robo\BltTasks; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Yaml\Yaml; /** * Class GryphonCommands. @@ -81,4 +83,89 @@ public function roleReport($role) fclose($out); } + /** + * Provisioning a site. + * + * @command gryphon:provision + * @description This is command to populate URLs by scafoliding the multisite and designating URLs on Acquia. + */ + public function provision($sitename): void { + if (empty($sitename)) { + $this->say('Sitename cannot be empty. Exiting'); + return; + } + + // Define environment types + $env_types = ['dev', 'test', 'prod']; + + foreach ($env_types as $env_type) { + $sitename_env = $sitename . '-' . $env_type; + + // Checks to see if domain name is in use. + if ($this->checkForARecord($sitename_env)) { + $this->say('A Record present in NetDB. Cannot proceed with provision until aliases released.'); + } + //Outputs alias for NetDB. + $this->say('A Record not present. Site name is free to use.'); + $this->say('Alias for NetDB: ' . $sitename_env); + $this->addDomainsToAcquia($sitename, $env_type, $sitename_env); +// $this->postMultiSiteInit($sitename); + + } + } + + /** + * @param $domain + * + * @return bool + */ + private function checkForARecord($domain): bool { + return !empty(dns_get_record($domain . '.stanford.edu', DNS_A)); + } + + /** + * Adds domains to Acquia + * + * @param $sitename_env + * + * @return void + */ + private function addDomainsToAcquia($sitename, $env_type, $sitename_env): void { + $condition = $this->ask("Do you want to add the domain to acquia? (yes/no)", "yes"); + + if (strtolower($condition) === 'yes') { + $this->say("Running the specific function..."); + $this->gryphonAddDomain($env_type, $sitename_env . '.stanford.edu'); + $this->addToBltYml($sitename); + $this->scaffoldingMultisite(); + } else { + $this->say("Skipped running the specific function."); + } + } + + private function scaffoldingMultisite(): void { + $gryphon = new GryphonHooksCommands(); + $gryphon->postMultiSiteInit(); + } + + /** + * @return void + * + * @command gryphon:yaml + * @description This is command to show provision URLs. + */ + private function addToBltYml($sitename) { + $bltYAML = __DIR__ . "/../../../../blt.yml"; + + if (!file_exists($bltYAML)){ + $this->say('No BLT yaml file to edit.'); + return; + } + + $yamlContentsBlt = Yaml::parseFile($bltYAML); + $yamlContentsBlt['multisites'][] = $sitename; + sort($yamlContentsBlt['multisites']); + $newMultisiteYaml = Yaml::dump($yamlContentsBlt, 10, 2); + $this->taskWriteToFile($bltYAML)->text($newMultisiteYaml)->run(); + } }