protected function execute(InputInterface $input, OutputInterface $output)
 {
     $locator = $this->container['utils.locator'];
     $fsHelper = $this->container['utils.filesystemhelper'];
     $registry = $this->container['utils.registry'];
     $fetcher = $this->container['utils.fetcher'];
     $installedVersion = implode('.', $locator->getInstalledVersion());
     $registry->set('installedVersion', $installedVersion);
     $feed = $registry->get('feed');
     if ($feed) {
         $path = $fetcher->getBaseDownloadPath($feed);
         $fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion();
         if (file_exists($fullExtractionPath)) {
             $fsHelper->removeIfExists($fullExtractionPath);
         }
         try {
             $fsHelper->mkdir($fullExtractionPath, true);
         } catch (\Exception $e) {
             $output->writeln('Unable create directory ' . $fullExtractionPath);
             throw $e;
         }
         $output->writeln('Extracting source into ' . $fullExtractionPath);
         if (preg_match('|\\.tar\\.bz2$|', $path)) {
             $extractor = new BzipExtractor($path, $fullExtractionPath);
         } else {
             $extractor = new ZipExtractor($path, $fullExtractionPath);
         }
         try {
             $extractor->extract();
         } catch (\Exception $e) {
             $output->writeln('Extraction has been failed');
             $fsHelper->removeIfExists($locator->getExtractionBaseDir());
             throw $e;
         }
         $tmpDir = $locator->getExtractionBaseDir() . '/' . $installedVersion;
         $fsHelper->removeIfExists($tmpDir);
         $fsHelper->mkdir($tmpDir);
         $fsHelper->mkdir($tmpDir . '/config');
         $oldSourcesDir = $locator->getOwncloudRootPath();
         $newSourcesDir = $fullExtractionPath . '/owncloud';
         foreach ($locator->getRootDirContent() as $dir) {
             $this->getApplication()->getLogger()->debug('Moving ' . $dir);
             $fsHelper->tripleMove($oldSourcesDir, $newSourcesDir, $tmpDir, $dir);
         }
         try {
             $plain = $this->occRunner->run('upgrade');
             $output->writeln($plain);
         } catch (ProcessFailedException $e) {
             if ($e->getProcess()->getExitCode() != 3) {
                 throw $e;
             }
         }
     }
 }
 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);
     $feed = $registry->get('feed');
     if ($feed) {
         $path = $fetcher->getBaseDownloadPath($feed);
         $fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion();
         if (file_exists($fullExtractionPath)) {
             $fsHelper->removeIfExists($fullExtractionPath);
         }
         try {
             $fsHelper->mkdir($fullExtractionPath, true);
         } catch (\Exception $e) {
             $output->writeln('Unable create directory ' . $fullExtractionPath);
             throw $e;
         }
         $output->writeln('Extracting source into ' . $fullExtractionPath);
         $extractor = new ZipExtractor($path, $fullExtractionPath, $output);
         try {
             $extractor->extract();
         } catch (\Exception $e) {
             $output->writeln('Extraction has been failed');
             $fsHelper->removeIfExists($locator->getExtractionBaseDir());
             throw $e;
         }
         $tmpDir = $locator->getExtractionBaseDir() . '/' . $installedVersion;
         $fsHelper->removeIfExists($tmpDir);
         $fsHelper->mkdir($tmpDir);
         $oldSourcesDir = $locator->getOwncloudRootPath();
         $newSourcesDir = $fullExtractionPath . '/owncloud';
         foreach ($locator->getRootDirContent() as $dir) {
             $this->getApplication()->getLogger()->debug('Replacing ' . $dir);
             $fsHelper->tripleMove($oldSourcesDir, $newSourcesDir, $tmpDir, $dir);
         }
         $fsHelper->copyr($tmpDir . '/config/config.php', $oldSourcesDir . '/config/config.php');
         //Remove old apps
         $appDirectories = $fsHelper->scandirFiltered($oldSourcesDir . '/apps');
         foreach ($appDirectories as $appDirectory) {
             $fsHelper->rmdirr($oldSourcesDir . '/apps/' . $appDirectory);
         }
         //Put new shipped apps
         $newAppsDir = $fullExtractionPath . '/owncloud/apps';
         $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) {
             $lastCheckpointId = $checkpoint->getLastCheckpointId();
             if ($lastCheckpointId) {
                 $lastCheckpointPath = $checkpoint->getCheckpointPath($lastCheckpointId);
                 $fsHelper->copyr($lastCheckpointPath . '/apps', $oldSourcesDir . '/apps', false);
             }
             if ($e->getProcess()->getExitCode() != 3) {
                 throw $e;
             }
         }
     }
 }