From fcd38353fbfee1204363b53169a160b72f2619b2 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 3 May 2016 16:15:42 +0300 Subject: [PATCH 1/3] Do not create __apps dir. Fixes #332, Fixes #290 --- .../ExecuteCoreUpgradeScriptsCommand.php | 20 +++++++++++++------ src/Utils/Checkpoint.php | 11 +++++++++- src/Utils/FilesystemHelper.php | 14 +++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Command/ExecuteCoreUpgradeScriptsCommand.php b/src/Command/ExecuteCoreUpgradeScriptsCommand.php index dd4ad008..3f8a56f7 100644 --- a/src/Command/ExecuteCoreUpgradeScriptsCommand.php +++ b/src/Command/ExecuteCoreUpgradeScriptsCommand.php @@ -22,6 +22,8 @@ namespace Owncloud\Updater\Command; +use Owncloud\Updater\Utils\Checkpoint; +use Owncloud\Updater\Utils\FilesystemHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -48,9 +50,12 @@ protected function configure(){ protected function execute(InputInterface $input, OutputInterface $output){ $locator = $this->container['utils.locator']; + /** @var FilesystemHelper $fsHelper */ $fsHelper = $this->container['utils.filesystemhelper']; $registry = $this->container['utils.registry']; $fetcher = $this->container['utils.fetcher']; + /** @var Checkpoint $checkpoint */ + $checkpoint = $this->container['utils.checkpoint']; $installedVersion = implode('.', $locator->getInstalledVersion()); $registry->set('installedVersion', $installedVersion); @@ -96,15 +101,18 @@ protected function execute(InputInterface $input, OutputInterface $output){ $fsHelper->copyr($tmpDir . '/config/config.php', $oldSourcesDir . '/config/config.php'); try { - $fsHelper->move($oldSourcesDir . '/apps', $oldSourcesDir . '/__apps'); - $fsHelper->mkdir($oldSourcesDir . '/apps'); + $appDirectories = $fsHelper->scandirFiltered($oldSourcesDir . '/apps'); + foreach ($appDirectories as $appDirectory){ + $fsHelper->rmdirr($oldSourcesDir . '/apps/' . $appDirectory); + } $plain = $this->occRunner->run('upgrade'); - $fsHelper->removeIfExists($oldSourcesDir . '/apps'); - $fsHelper->move($oldSourcesDir . '/__apps', $oldSourcesDir . '/apps'); $output->writeln($plain); } catch (ProcessFailedException $e){ - $fsHelper->removeIfExists($oldSourcesDir . '/apps'); - $fsHelper->move($oldSourcesDir . '/__apps', $oldSourcesDir . '/apps'); + $lastCheckpointId = $checkpoint->getLastCheckpointId(); + if ($lastCheckpointId){ + $lastCheckpointPath = $checkpoint->getCheckpointPath($lastCheckpointId); + $fsHelper->copyr($lastCheckpointPath . '/apps', $oldSourcesDir . '/apps', false); + } if ($e->getProcess()->getExitCode() != 3){ throw ($e); } diff --git a/src/Utils/Checkpoint.php b/src/Utils/Checkpoint.php index 21ced1d2..21f8a5b2 100644 --- a/src/Utils/Checkpoint.php +++ b/src/Utils/Checkpoint.php @@ -151,6 +151,15 @@ public function checkpointExists($checkpointId){ return in_array($checkpointId, $this->getAllCheckpointIds()); } + /** + * Get the most recent checkpoint Id + * @return bool + */ + public function getLastCheckpointId(){ + $allCheckpointIds = $this->getAllCheckpointIds(); + return count($allCheckpointIds) > 0 ? end($allCheckpointIds) : false; + } + /** * Return array of all checkpoint ids * @return array @@ -189,7 +198,7 @@ public function getCheckpointPath($checkpointId){ /** * Produce an error on non-existing checkpoints * @param string $checkpointId id of checkpoint - * @throws UnexpectedValueException if there is no checkpoint with this id + * @throws \UnexpectedValueException if there is no checkpoint with this id */ private function assertCheckpointExists($checkpointId){ if (!$this->checkpointExists($checkpointId) || $checkpointId === ''){ diff --git a/src/Utils/FilesystemHelper.php b/src/Utils/FilesystemHelper.php index 679157e1..3960f89b 100644 --- a/src/Utils/FilesystemHelper.php +++ b/src/Utils/FilesystemHelper.php @@ -32,6 +32,20 @@ public function filemtime($path){ return filemtime($path); } + /** + * Wrapper for scandir function. + * Filters current and parent directories + * @param string $path + * @return array + */ + public function scandirFiltered($path){ + $content = $this->scandir($path); + if (is_array($content)){ + return array_diff($content, ['.', '..']); + } + return []; + } + /** * Wrapper for scandir function * @param string $path From b0589e0bebab15520957496644974f24babd81cb Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 3 May 2016 20:12:33 +0300 Subject: [PATCH 2/3] Upgrade shipped apps --- src/Command/CheckSystemCommand.php | 8 +++++ src/Command/UpgradeShippedAppsCommand.php | 41 +++++++---------------- src/Utils/Checkpoint.php | 2 +- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/Command/CheckSystemCommand.php b/src/Command/CheckSystemCommand.php index 45a6d25a..1cf89d6e 100644 --- a/src/Command/CheckSystemCommand.php +++ b/src/Command/CheckSystemCommand.php @@ -39,6 +39,14 @@ protected function configure(){ protected function execute(InputInterface $input, OutputInterface $output){ $locator = $this->container['utils.locator']; $fsHelper = $this->container['utils.filesystemhelper']; + /** @var \Owncloud\Updater\Utils\Registry $registry */ + $registry = $this->container['utils.registry']; + /** @var \Owncloud\Updater\Utils\AppManager $occRunner */ + $appManager = $this->container['utils.appmanager']; + $registry->set( + 'shippedApps', + $appManager->getShippedApps() + ); $occRunner = $this->container['utils.occrunner']; $collection = new Collection(); diff --git a/src/Command/UpgradeShippedAppsCommand.php b/src/Command/UpgradeShippedAppsCommand.php index 29ca02aa..56057a32 100644 --- a/src/Command/UpgradeShippedAppsCommand.php +++ b/src/Command/UpgradeShippedAppsCommand.php @@ -52,39 +52,22 @@ protected function execute(InputInterface $input, OutputInterface $output){ if ($feed){ $locator = $this->container['utils.locator']; - $appManager = $this->container['utils.appmanager']; $fsHelper = $this->container['utils.filesystemhelper']; $fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion(); $newAppsDir = $fullExtractionPath . '/owncloud/apps'; - $tmpAppsDir = $locator->getExtractionBaseDir() - . '/' - . $registry->get('installedVersion') - . '/apps' - ; - $fsHelper->removeIfExists($tmpAppsDir); - $fsHelper->mkDir($tmpAppsDir); - $shippedApps =$appManager->getShippedApps(); - foreach ($shippedApps as $appId){ - $oldPath = $appManager->getAppPath($appId); - $output->writeln('Upgrading the application ' . $appId); - $newPath = $newAppsDir . '/' . $appId; - - if (file_exists($oldPath)){ - $fsHelper->copyr($oldPath, $tmpAppsDir . '/' . $appId, false); - $fsHelper->rmdirr($oldPath); - } - if (file_exists($newPath)){ - $fsHelper->copyr($newPath, $oldPath, false); - $fsHelper->rmdirr($newPath); - } - try { - $plain = $this->occRunner->run('upgrade'); - $output->writeln($plain); - } catch (ProcessFailedException $e){ - if ($e->getProcess()->getExitCode() !== 3){ - throw ($e); - } + $newAppsList = $fsHelper->scandirFiltered($newAppsDir); + foreach ($newAppsList as $appId){ + $output->writeln('Copying the application ' . $appId); + $fsHelper->copyr($newAppsDir . '/' . $appId, $locator->getOwnCloudRootPath() . '/apps/' . $appId, false); + } + + try { + $plain = $this->occRunner->run('upgrade'); + $output->writeln($plain); + } catch (ProcessFailedException $e){ + if ($e->getProcess()->getExitCode() !== 3){ + throw ($e); } } } diff --git a/src/Utils/Checkpoint.php b/src/Utils/Checkpoint.php index 21f8a5b2..2da2dd5c 100644 --- a/src/Utils/Checkpoint.php +++ b/src/Utils/Checkpoint.php @@ -153,7 +153,7 @@ public function checkpointExists($checkpointId){ /** * Get the most recent checkpoint Id - * @return bool + * @return string|bool */ public function getLastCheckpointId(){ $allCheckpointIds = $this->getAllCheckpointIds(); From f48bfd19e443f3d2796af5d233ef664f7a8064d6 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 3 May 2016 20:35:35 +0300 Subject: [PATCH 3/3] Reenable notShipped apps --- src/Command/CheckSystemCommand.php | 4 ++-- src/Command/EnableNotShippedAppsCommand.php | 22 ++++++++++++++++++++- src/Utils/AppManager.php | 6 ++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Command/CheckSystemCommand.php b/src/Command/CheckSystemCommand.php index 1cf89d6e..0eb3afc7 100644 --- a/src/Command/CheckSystemCommand.php +++ b/src/Command/CheckSystemCommand.php @@ -44,8 +44,8 @@ protected function execute(InputInterface $input, OutputInterface $output){ /** @var \Owncloud\Updater\Utils\AppManager $occRunner */ $appManager = $this->container['utils.appmanager']; $registry->set( - 'shippedApps', - $appManager->getShippedApps() + 'notShippedApps', + $appManager->getNotShippedApps() ); $occRunner = $this->container['utils.occrunner']; diff --git a/src/Command/EnableNotShippedAppsCommand.php b/src/Command/EnableNotShippedAppsCommand.php index 4e05adc3..fca61b0c 100644 --- a/src/Command/EnableNotShippedAppsCommand.php +++ b/src/Command/EnableNotShippedAppsCommand.php @@ -36,11 +36,31 @@ protected function configure(){ } protected function execute(InputInterface $input, OutputInterface $output){ + /** @var \Owncloud\Updater\Utils\Locator $locator */ + $locator = $this->container['utils.locator']; + /** @var \Owncloud\Updater\Utils\Checkpoint $checkpoint */ + $checkpoint = $this->container['utils.checkpoint']; + /** @var \Owncloud\Updater\Utils\FilesystemHelper $fsHelper */ + $fsHelper = $this->container['utils.filesystemhelper']; + $registry = $this->container['utils.registry']; + + $notShippedApps = $registry->get('notShippedApps'); + $notShippedApps = is_array($notShippedApps) ? $notShippedApps : []; + + $lastCheckpointId = $checkpoint->getLastCheckpointId(); + $lastCheckpointPath = $checkpoint->getCheckpointPath($lastCheckpointId); + if ($lastCheckpointId){ + $oldSourcesDir = $locator->getOwnCloudRootPath(); + foreach ($notShippedApps as $notShippedApp) { + $fsHelper->copyr($lastCheckpointPath . '/apps/' . $notShippedApp, $oldSourcesDir . '/apps/' . $notShippedApp, false); + } + } + + /** @var \Owncloud\Updater\Utils\AppManager $appManager */ $appManager = $registry->get('appManager'); if (!is_null($appManager)){ $appManager->reenableNotShippedApps($output); } } - } diff --git a/src/Utils/AppManager.php b/src/Utils/AppManager.php index 421f0b04..5168f5e9 100644 --- a/src/Utils/AppManager.php +++ b/src/Utils/AppManager.php @@ -100,6 +100,12 @@ public function getAllApps(){ return $allApps; } + public function getNotShippedApps(){ + $shippedApps = $this->occRunner->runJson('app:list --shipped false'); + $allApps = array_merge(array_keys($shippedApps['enabled']), array_keys($shippedApps['disabled'])); + return $allApps; + } + public function getShippedApps(){ $shippedApps = $this->occRunner->runJson('app:list --shipped true'); $allApps = array_merge(array_keys($shippedApps['enabled']), array_keys($shippedApps['disabled']));