From 71101e5bc864bfb4de7e7c7c70148207c2bbdd04 Mon Sep 17 00:00:00 2001 From: Tomasz Strojny Date: Fri, 28 Aug 2020 15:19:55 +0200 Subject: [PATCH 1/6] Initial leave git repo in plugins --- src/Console/InstallCommand.php | 12 ++++++++++++ src/Manager/BaseManager.php | 18 ++++++++++++++++++ src/Manager/PluginManager.php | 4 +++- src/Manager/ThemeManager.php | 4 +++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 18207b6..e0f7a56 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -110,6 +110,12 @@ public function setOutput(OutputInterface $output) $this->composer->setOutput($output); } + public function setWithGitDirectory(bool $withGitDirectory) + { + $this->pluginManager->setWithGitDirectory($withGitDirectory); + $this->themeManager->setWithGitDirectory($withGitDirectory); + } + /** * Configure the command options. * @@ -140,6 +146,11 @@ protected function configure() InputOption::VALUE_OPTIONAL, 'Specify from where to fetch template files (git remote)', '' + )->addOption( + 'with-git-directory', + null, + InputOption::VALUE_NONE, + 'Specify whether or not to delete .git directories' ); } @@ -163,6 +174,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->setOutput($output); + $this->setWithGitDirectory($input->getOption('with-git-directory')); $this->force = $input->getOption('force'); diff --git a/src/Manager/BaseManager.php b/src/Manager/BaseManager.php index 41b6346..0e796b0 100644 --- a/src/Manager/BaseManager.php +++ b/src/Manager/BaseManager.php @@ -29,6 +29,11 @@ class BaseManager */ protected $php; + /** + * @var bool + */ + protected $withGitDirectory = false; + public function __construct() { $this->artisan = new Artisan(); @@ -46,4 +51,17 @@ public function setPhp(string $php = 'php') $this->php = $php; $this->artisan->setPhp($php); } + + /** + * Set if remove .git directories or not + */ + public function setWithGitDirectory(bool $withGitDirectory = false) + { + $this->withGitDirectory = $withGitDirectory; + } + + public function isWithGitDirectory(): bool + { + return $this->withGitDirectory; + } } diff --git a/src/Manager/PluginManager.php b/src/Manager/PluginManager.php index 8f7f285..db9cae7 100644 --- a/src/Manager/PluginManager.php +++ b/src/Manager/PluginManager.php @@ -140,7 +140,9 @@ public function install(string $pluginDeclaration) throw new RuntimeException('Error while cloning plugin repo: ' . $e->getMessage()); } - $this->removeGitRepo($this->getDirPath($pluginDeclaration)); + if(!$this->isWithGitDirectory()) { + $this->removeGitRepo($this->getDirPath($pluginDeclaration)); + } } /** diff --git a/src/Manager/ThemeManager.php b/src/Manager/ThemeManager.php index b6cb067..c0be58c 100644 --- a/src/Manager/ThemeManager.php +++ b/src/Manager/ThemeManager.php @@ -92,7 +92,9 @@ public function install(string $themeDeclaration) throw new RuntimeException('Error while cloning theme repo: ' . $e->getMessage()); } - $this->removeGitRepo($themeDir); + if(!$this->isWithGitDirectory()) { + $this->removeGitRepo($themeDir); + } return true; } From f9905dafbdb2f74b68dd531c753f4c58cb4bd72d Mon Sep 17 00:00:00 2001 From: Daniel Zlotnik Date: Wed, 23 Dec 2020 15:15:18 +0000 Subject: [PATCH 2/6] add withGitDirectory to october.yaml --- src/Console/InstallCommand.php | 38 ++++++++++++++++------------------ src/Downloader/OctoberCms.php | 8 +++---- templates/october.yaml | 1 + 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index e0f7a56..176b794 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -146,11 +146,6 @@ protected function configure() InputOption::VALUE_OPTIONAL, 'Specify from where to fetch template files (git remote)', '' - )->addOption( - 'with-git-directory', - null, - InputOption::VALUE_NONE, - 'Specify whether or not to delete .git directories' ); } @@ -174,25 +169,24 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->setOutput($output); - $this->setWithGitDirectory($input->getOption('with-git-directory')); - + $this->force = $input->getOption('force'); - + $this->firstRun = ! $this->dirExists($this->path('bootstrap')) || $this->force; - + if ($input->getOption('templates-from')) { $remote = $input->getOption('templates-from'); $this->fetchTemplateFiles($remote); } - + $this->makeConfig(); - + if ( ! empty($php = $input->getOption('php'))) { $this->setPhp($php); } - + $this->gitignore = new Gitignore($this->getGitignore()); - + $this->write('Downloading latest October CMS...'); try { (new OctoberCms())->download($this->force); @@ -200,23 +194,27 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->write($e->getMessage(), 'comment'); } catch (Throwable $e) { $this->write($e->getMessage(), 'error'); - + return false; } - + $this->write('Patching composer.json...'); $this->patchComposerJson(); - + $this->write('Installing composer dependencies...'); $this->composer->install(); - + $this->write('Setting up config files...'); $this->writeConfig($this->force); - + $this->prepareDatabase(); - + $this->write('Migrating database...'); $this->artisan->call('october:up'); + + if (isset($this->config->git['withGitDirectory'])) { + $this->setWithGitDirectory($this->config->git['withGitDirectory']); + } $themeDeclaration = false; try { @@ -224,7 +222,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } catch (RuntimeException $e) { $this->write('No theme to install', 'comment'); } - + if ($themeDeclaration) { $this->write('Installing Theme...'); try { diff --git a/src/Downloader/OctoberCms.php b/src/Downloader/OctoberCms.php index dd77191..868bb30 100644 --- a/src/Downloader/OctoberCms.php +++ b/src/Downloader/OctoberCms.php @@ -55,7 +55,7 @@ public function download($force = false) */ protected function fetchZip() { - $response = (new Client)->get('https://github.com/octobercms/october/archive/1.0.zip'); + $response = (new Client)->get('https://github.com/octobercms/october/archive/1.1.zip'); file_put_contents($this->zipFile, $response->getBody()); return $this; @@ -84,7 +84,7 @@ protected function extract() */ protected function fetchHtaccess() { - $contents = file_get_contents('https://raw.githubusercontent.com/octobercms/october/1.0/.htaccess'); + $contents = file_get_contents('https://raw.githubusercontent.com/octobercms/october/1.1/.htaccess'); file_put_contents(getcwd() . DS . '.htaccess', $contents); return $this; @@ -106,7 +106,7 @@ protected function setMaster() $contents = preg_replace_callback( '/october\/(?:rain|system|backend|cms)":\s"([^"]+)"/m', function ($treffer) { - return str_replace($treffer[1], '~1.0', $treffer[0]); + return str_replace($treffer[1], '~1.1', $treffer[0]); }, $contents ); @@ -129,7 +129,7 @@ protected function cleanUp() @unlink($this->zipFile); $directory = getcwd(); - $source = $directory . DS . 'october-1.0'; + $source = $directory . DS . 'october-1.1'; (new Process(sprintf('mv %s %s', $source . '/*', $directory)))->run(); (new Process(sprintf('rm -rf %s', $source)))->run(); diff --git a/templates/october.yaml b/templates/october.yaml index 42e7aad..5919d5a 100644 --- a/templates/october.yaml +++ b/templates/october.yaml @@ -24,6 +24,7 @@ git: excludePlugins: false # Even exclude plugins from your repo. Private plugins will be # checkout out again during each "install" run. Be careful! # Manual changes to these plugins will be overwritten. + withGitDirectory: false # Keep .git in plugins # deployment: # user: hostinguser From 17b8aad9dd8d9acf5f4950d69fb7b64b16961eec Mon Sep 17 00:00:00 2001 From: Daniel Zlotnik Date: Wed, 23 Dec 2020 15:47:30 +0000 Subject: [PATCH 3/6] fix lines --- src/Console/InstallCommand.php | 52 ++++++++++++++++++---------------- src/Downloader/OctoberCms.php | 10 +++---- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 176b794..eaa51a6 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -164,29 +164,29 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - if ( ! class_exists('ZipArchive')) { + if (!class_exists('ZipArchive')) { throw new RuntimeException('The Zip PHP extension is not installed. Please install it and try again.'); } $this->setOutput($output); - + $this->force = $input->getOption('force'); - - $this->firstRun = ! $this->dirExists($this->path('bootstrap')) || $this->force; - + + $this->firstRun = !$this->dirExists($this->path('bootstrap')) || $this->force; + if ($input->getOption('templates-from')) { $remote = $input->getOption('templates-from'); $this->fetchTemplateFiles($remote); } - + $this->makeConfig(); - - if ( ! empty($php = $input->getOption('php'))) { + + if (!empty($php = $input->getOption('php'))) { $this->setPhp($php); } - + $this->gitignore = new Gitignore($this->getGitignore()); - + $this->write('Downloading latest October CMS...'); try { (new OctoberCms())->download($this->force); @@ -194,24 +194,24 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->write($e->getMessage(), 'comment'); } catch (Throwable $e) { $this->write($e->getMessage(), 'error'); - + return false; } - + $this->write('Patching composer.json...'); $this->patchComposerJson(); - + $this->write('Installing composer dependencies...'); $this->composer->install(); - + $this->write('Setting up config files...'); $this->writeConfig($this->force); - + $this->prepareDatabase(); - + $this->write('Migrating database...'); $this->artisan->call('october:up'); - + if (isset($this->config->git['withGitDirectory'])) { $this->setWithGitDirectory($this->config->git['withGitDirectory']); } @@ -222,7 +222,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } catch (RuntimeException $e) { $this->write('No theme to install', 'comment'); } - + if ($themeDeclaration) { $this->write('Installing Theme...'); try { @@ -312,14 +312,16 @@ public function installPlugins($pluginsDeclarations) { foreach ($pluginsDeclarations as $pluginDeclaration) { $pluginInstalled = $this->pluginManager->isInstalled($pluginDeclaration); - $installPlugin = ! $pluginInstalled; + $installPlugin = !$pluginInstalled; list($update, $vendor, $plugin, $remote, $branch) = $this->pluginManager->parseDeclaration($pluginDeclaration); - if ($pluginInstalled && ($update || ! $this->gitignore->hasPluginHeader($vendor, $plugin))) { + if ($pluginInstalled && ($update || !$this->gitignore->hasPluginHeader($vendor, $plugin))) { if ($pluginInstalled && $remote) { - $this->write("Removing ${vendor}.${plugin} directory to re-download the newest version...", - 'comment'); + $this->write( + "Removing ${vendor}.${plugin} directory to re-download the newest version...", + 'comment' + ); $this->pluginManager->removeDir($pluginDeclaration); $installPlugin = true; @@ -409,7 +411,7 @@ protected function copyReadme() protected function cleanup() { - if ( ! $this->firstRun) { + if (!$this->firstRun) { return; } @@ -427,7 +429,7 @@ public function prepareDatabase() // If SQLite database does not exist, create it if ($this->config->database['connection'] === 'sqlite') { $path = $this->config->database['database']; - if ( ! $this->fileExists($path) && is_dir(dirname($path))) { + if (!$this->fileExists($path) && is_dir(dirname($path))) { $this->write("Creating $path ..."); touch($path); } @@ -441,7 +443,7 @@ public function prepareDatabase() */ protected function patchComposerJson() { - if ( ! $this->fileExists('composer.json')) { + if (!$this->fileExists('composer.json')) { $this->write('Failed to locate composer.json in local directory', 'error'); return; diff --git a/src/Downloader/OctoberCms.php b/src/Downloader/OctoberCms.php index 868bb30..83f89f7 100644 --- a/src/Downloader/OctoberCms.php +++ b/src/Downloader/OctoberCms.php @@ -55,7 +55,7 @@ public function download($force = false) */ protected function fetchZip() { - $response = (new Client)->get('https://github.com/octobercms/october/archive/1.1.zip'); + $response = (new Client)->get('https://github.com/octobercms/october/archive/1.0.zip'); file_put_contents($this->zipFile, $response->getBody()); return $this; @@ -84,7 +84,7 @@ protected function extract() */ protected function fetchHtaccess() { - $contents = file_get_contents('https://raw.githubusercontent.com/octobercms/october/1.1/.htaccess'); + $contents = file_get_contents('https://raw.githubusercontent.com/octobercms/october/1.0/.htaccess'); file_put_contents(getcwd() . DS . '.htaccess', $contents); return $this; @@ -106,7 +106,7 @@ protected function setMaster() $contents = preg_replace_callback( '/october\/(?:rain|system|backend|cms)":\s"([^"]+)"/m', function ($treffer) { - return str_replace($treffer[1], '~1.1', $treffer[0]); + return str_replace($treffer[1], '~1.0', $treffer[0]); }, $contents ); @@ -129,7 +129,7 @@ protected function cleanUp() @unlink($this->zipFile); $directory = getcwd(); - $source = $directory . DS . 'october-1.1'; + $source = $directory . DS . 'october-1.0'; (new Process(sprintf('mv %s %s', $source . '/*', $directory)))->run(); (new Process(sprintf('rm -rf %s', $source)))->run(); @@ -161,4 +161,4 @@ protected function alreadyInstalled($force) return ! $force && is_dir(getcwd() . DS . 'bootstrap') && is_dir(getcwd() . DS . 'modules'); } -} +} \ No newline at end of file From 6bb2298165e8a9d5903754434c31a3486f08c04d Mon Sep 17 00:00:00 2001 From: Daniel Zlotnik Date: Wed, 23 Dec 2020 15:54:24 +0000 Subject: [PATCH 4/6] prettier --- src/Console/InstallCommand.php | 20 +++++++++----------- src/Downloader/OctoberCms.php | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index eaa51a6..d78ba8b 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -164,7 +164,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - if (!class_exists('ZipArchive')) { + if ( ! class_exists('ZipArchive')) { throw new RuntimeException('The Zip PHP extension is not installed. Please install it and try again.'); } @@ -172,7 +172,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->force = $input->getOption('force'); - $this->firstRun = !$this->dirExists($this->path('bootstrap')) || $this->force; + $this->firstRun = ! $this->dirExists($this->path('bootstrap')) || $this->force; if ($input->getOption('templates-from')) { $remote = $input->getOption('templates-from'); @@ -181,7 +181,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->makeConfig(); - if (!empty($php = $input->getOption('php'))) { + if ( ! empty($php = $input->getOption('php'))) { $this->setPhp($php); } @@ -312,16 +312,14 @@ public function installPlugins($pluginsDeclarations) { foreach ($pluginsDeclarations as $pluginDeclaration) { $pluginInstalled = $this->pluginManager->isInstalled($pluginDeclaration); - $installPlugin = !$pluginInstalled; + $installPlugin = ! $pluginInstalled; list($update, $vendor, $plugin, $remote, $branch) = $this->pluginManager->parseDeclaration($pluginDeclaration); - if ($pluginInstalled && ($update || !$this->gitignore->hasPluginHeader($vendor, $plugin))) { + if ($pluginInstalled && ($update || ! $this->gitignore->hasPluginHeader($vendor, $plugin))) { if ($pluginInstalled && $remote) { - $this->write( - "Removing ${vendor}.${plugin} directory to re-download the newest version...", - 'comment' - ); + $this->write( "Removing ${vendor}.${plugin} directory to re-download the newest version...", + 'comment'); $this->pluginManager->removeDir($pluginDeclaration); $installPlugin = true; @@ -411,7 +409,7 @@ protected function copyReadme() protected function cleanup() { - if (!$this->firstRun) { + if ( ! $this->firstRun) { return; } @@ -443,7 +441,7 @@ public function prepareDatabase() */ protected function patchComposerJson() { - if (!$this->fileExists('composer.json')) { + if ( ! $this->fileExists('composer.json')) { $this->write('Failed to locate composer.json in local directory', 'error'); return; diff --git a/src/Downloader/OctoberCms.php b/src/Downloader/OctoberCms.php index 83f89f7..dd77191 100644 --- a/src/Downloader/OctoberCms.php +++ b/src/Downloader/OctoberCms.php @@ -161,4 +161,4 @@ protected function alreadyInstalled($force) return ! $force && is_dir(getcwd() . DS . 'bootstrap') && is_dir(getcwd() . DS . 'modules'); } -} \ No newline at end of file +} From 28a7f0c7c98c583c8c5325b2af59813cf645bbd6 Mon Sep 17 00:00:00 2001 From: Daniel Zlotnik Date: Wed, 23 Dec 2020 15:56:22 +0000 Subject: [PATCH 5/6] fix prettier --- src/Console/InstallCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index d78ba8b..570d599 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -318,7 +318,7 @@ public function installPlugins($pluginsDeclarations) if ($pluginInstalled && ($update || ! $this->gitignore->hasPluginHeader($vendor, $plugin))) { if ($pluginInstalled && $remote) { - $this->write( "Removing ${vendor}.${plugin} directory to re-download the newest version...", + $this->write("Removing ${vendor}.${plugin} directory to re-download the newest version...", 'comment'); $this->pluginManager->removeDir($pluginDeclaration); @@ -427,7 +427,7 @@ public function prepareDatabase() // If SQLite database does not exist, create it if ($this->config->database['connection'] === 'sqlite') { $path = $this->config->database['database']; - if (!$this->fileExists($path) && is_dir(dirname($path))) { + if ( ! $this->fileExists($path) && is_dir(dirname($path))) { $this->write("Creating $path ..."); touch($path); } From 825e068008e6176e1379e368c6197bb15e6a72c5 Mon Sep 17 00:00:00 2001 From: Daniel Zlotnik Date: Wed, 23 Dec 2020 16:38:21 +0000 Subject: [PATCH 6/6] withGitDirectory -> keepRepo --- README.md | 1 + src/Console/InstallCommand.php | 4 ++-- templates/october.yaml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 45cd856..d13ff0b 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ database: git: deployment: gitlab + keepRepo: false # Keep .git in plugins # deployment: # Automatically configure the Envoy file for GitLab deployments # user: hostinguser diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 570d599..e91dd48 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -212,8 +212,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->write('Migrating database...'); $this->artisan->call('october:up'); - if (isset($this->config->git['withGitDirectory'])) { - $this->setWithGitDirectory($this->config->git['withGitDirectory']); + if (isset($this->config->git['keepRepo'])) { + $this->setWithGitDirectory($this->config->git['keepRepo']); } $themeDeclaration = false; diff --git a/templates/october.yaml b/templates/october.yaml index 5919d5a..0d61384 100644 --- a/templates/october.yaml +++ b/templates/october.yaml @@ -24,7 +24,7 @@ git: excludePlugins: false # Even exclude plugins from your repo. Private plugins will be # checkout out again during each "install" run. Be careful! # Manual changes to these plugins will be overwritten. - withGitDirectory: false # Keep .git in plugins + keepRepo: false # Keep .git in plugins # deployment: # user: hostinguser