From afc715538fbc9d8bb55681428f73e7a16c5cdbce Mon Sep 17 00:00:00 2001 From: Michael McAndrew Date: Wed, 31 Oct 2018 14:43:33 +0000 Subject: [PATCH 1/2] quick and dirty cv core:download --- src/Application.php | 1 + src/Command/CoreDownloadCommand.php | 86 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/Command/CoreDownloadCommand.php 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..e956ce8d --- /dev/null +++ b/src/Command/CoreDownloadCommand.php @@ -0,0 +1,86 @@ +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}..."); + 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; + } + +} From 44ef9009e744caeedd179c7a49e270c504add8cb Mon Sep 17 00:00:00 2001 From: Michael McAndrew Date: Wed, 31 Oct 2018 14:56:54 +0000 Subject: [PATCH 2/2] extract wordpress l10n files to the correct directory --- src/Command/CoreDownloadCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Command/CoreDownloadCommand.php b/src/Command/CoreDownloadCommand.php index e956ce8d..ea15788c 100644 --- a/src/Command/CoreDownloadCommand.php +++ b/src/Command/CoreDownloadCommand.php @@ -62,7 +62,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->cacheTar($l10nTarName, $output); } $output->writeln("Extracting {$l10nTarName}..."); - exec("tar -xf {$this->cacheDir}/{$l10nTarName}"); + if ($cms == 'wordpress') { + exec("tar -xf {$this->cacheDir}/{$l10nTarName} -C civicrm"); + } else { + exec("tar -xf {$this->cacheDir}/{$l10nTarName}"); + } + } }