Skip to content

Commit

Permalink
Merge pull request #347 from owncloud/fix-332
Browse files Browse the repository at this point in the history
Do not create __apps dir.
  • Loading branch information
Vincent Petry committed May 12, 2016
2 parents a8030ad + f48bfd1 commit 38df298
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 37 deletions.
8 changes: 8 additions & 0 deletions src/Command/CheckSystemCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'notShippedApps',
$appManager->getNotShippedApps()
);
$occRunner = $this->container['utils.occrunner'];

$collection = new Collection();
Expand Down
22 changes: 21 additions & 1 deletion src/Command/EnableNotShippedAppsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
20 changes: 14 additions & 6 deletions src/Command/ExecuteCoreUpgradeScriptsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
41 changes: 12 additions & 29 deletions src/Command/UpgradeShippedAppsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Utils/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down
11 changes: 10 additions & 1 deletion src/Utils/Checkpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ public function checkpointExists($checkpointId){
return in_array($checkpointId, $this->getAllCheckpointIds());
}

/**
* Get the most recent checkpoint Id
* @return string|bool
*/
public function getLastCheckpointId(){
$allCheckpointIds = $this->getAllCheckpointIds();
return count($allCheckpointIds) > 0 ? end($allCheckpointIds) : false;
}

/**
* Return array of all checkpoint ids
* @return array
Expand Down Expand Up @@ -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 === ''){
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/FilesystemHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38df298

Please sign in to comment.