diff --git a/src/Application.php b/src/Application.php index f41e41d0..b6932754 100644 --- a/src/Application.php +++ b/src/Application.php @@ -85,6 +85,7 @@ public function createCommands($context = 'default') { $commands[] = new \Civi\Cv\Command\ScriptCommand(); $commands[] = new \Civi\Cv\Command\CoreCheckReqCommand(); $commands[] = new \Civi\Cv\Command\CoreInstallCommand(); + $commands[] = new \Civi\Cv\Command\CoreDownloadCommand(); $commands[] = new \Civi\Cv\Command\CoreUninstallCommand(); } return $commands; diff --git a/src/Command/CoreDownloadCommand.php b/src/Command/CoreDownloadCommand.php new file mode 100644 index 00000000..ea15788c --- /dev/null +++ b/src/Command/CoreDownloadCommand.php @@ -0,0 +1,91 @@ +setName('core:download') + ->setDescription('Download a CiviCRM release') + ->addOption('cms', '', InputOption::VALUE_REQUIRED, 'Specify the CMS') + ->addOption('release', '', InputOption::VALUE_REQUIRED, 'Specify the release') + ->addOption('l10n', '', InputOption::VALUE_NONE, 'Download localization files') + ->setHelp(' +Dowload the Drupal release of CiviCRM + +$ cv core:download drupal +'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + + if(is_dir('civicrm')){ + $output->writeln('Refusing to download CiviCRM. civicrm directory already exists here'); + exit; + } + + + $this->cacheDir = "{$_SERVER['HOME']}/.cache/cv"; + + if(!($release = $input->getOption('release'))){ + $release = $this->getLatestRelease(); + } + $cms = $input->getOption('cms'); + + $ext = in_array($cms, ['wordpress', 'joomla']) ? 'zip' : 'tar.gz'; + + $tarName = "civicrm-{$release}-{$cms}.{$ext}"; + + if(!file_exists("{$this->cacheDir}/{$tarName}")){ + $this->cacheTar($tarName, $output); + } + $output->writeln("Extracting {$tarName}..."); + if($ext == 'zip'){ + exec("unzip {$this->cacheDir}/{$tarName}"); + }else{ + exec("tar -xf {$this->cacheDir}/{$tarName}"); + } + + if($input->getOption('l10n')){ + $l10nTarName = "civicrm-{$release}-l10n.tar.gz"; + if(!file_exists("{$this->cacheDir}/{$l10nTarName}")){ + $this->cacheTar($l10nTarName, $output); + } + $output->writeln("Extracting {$l10nTarName}..."); + if ($cms == 'wordpress') { + exec("tar -xf {$this->cacheDir}/{$l10nTarName} -C civicrm"); + } else { + exec("tar -xf {$this->cacheDir}/{$l10nTarName}"); + } + + } + } + + protected function cacheTar($tarName, OutputInterface $output){ + + if(!is_dir($this->cacheDir)){ + mkdir($this->cacheDir); + } + $output->writeln("Dowloading {$tarName}..."); + file_put_contents("{$this->cacheDir}/{$tarName}", file_get_contents("https://download.civicrm.org/{$tarName}")); + } + + protected function getLatestRelease(){ + $latest = file_get_contents('https://latest.civicrm.org/stable.php'); + if(!$latest){ + Throw new \Exception('Error looking up latest release'); + } + return $latest; + } + +}