/** * Delete the repository. */ public function removeDirectory() { $fs = new FileSystem(); $fs->rmdir($this->userRootDir, true); }
public function installBundle($bundle, $zipFile, $date = null) { $logFile = $this->getLogFile(); if ($date) { $logFile = $logFile . '-' . $date; } $logFile .= '.log'; @unlink($logFile); $fileLogger = new \Monolog\Logger('package.update'); $fileLogger->pushHandler(new \Monolog\Handler\StreamHandler($logFile)); $fileLogger->addInfo('Downloading archive...'); $version = $this->getBundleLastInstallableVersion($bundle, $this->getCoreBundleVersion()); $fs = new FileSystem(); //extract and unzip in the correct directory $extractPath = sys_get_temp_dir() . '/' . uniqid(); $zip = new \ZipArchive(); $zip->open($zipFile); $fileLogger->addInfo("Extraction..."); $zip->extractTo($extractPath); //rename the $extractPath root (it currently has -version at the end) $iterator = new \DirectoryIterator($extractPath); foreach ($iterator as $el) { //there should be only one directory so... if ($el->isDir() && !$el->isDot()) { $parts = explode('-', $el->getBaseName()); $fs->rename($el->getPathName(), $extractPath . '/' . $parts[0]); } } //move the source where they should be $composer = $extractPath . "/{$bundle}/composer.json"; $json = file_get_contents($composer); $data = json_decode($json); $targetDir = 'target-dir'; $parts = explode('/', $data->{$targetDir}); $newPath = $this->vendorDir . '/' . $data->name . '/' . $data->{$targetDir}; $vendor = $parts[0]; $baseParts = explode('Bundle', $parts[1]); $baseName = $baseParts[0]; $fileLogger->addInfo("Removing old sources..."); $fs->rmdir($newPath, true); $fileLogger->addInfo("Copying sources from temporary directory..."); $fs->copyDir($extractPath . "/{$bundle}", $newPath); //then we update the autoloader $parts = explode('/', $data->name); $vname = $parts[0]; $bname = $parts[1]; $bundleType = $data->type; $updatedTarget = str_replace('/', '\\', $data->{$targetDir}); $fqcn = $updatedTarget . '\\' . str_replace('\\', '', $updatedTarget); $fileLogger->addInfo("Updating vendor/composer/autoload_namespace.php..."); $this->updateAutoload($vendor, $baseName, $vname, $bname); $fileLogger->addInfo("Updating app/config/bundle.ini..."); $this->updateIniFile($vendor, $baseName); $fileLogger->addInfo("Generating app/config/operations.xml..."); $this->generateUniqueOperationFile($bundle, $version, $bundleType, $fqcn, $logFile); //We need a different process to execute the update as the new sources were //not loaded by php yet. //It's much easier than trying to load/refresh everything. //TODO: use Sf2 proces library to avoid mistakes //sanitize this $executor = $this->kernelRootDir . '/../vendor/claroline/core-bundle/Claroline/CoreBundle/Library/Installation/scripts/operation_executor.php'; $phpErrors = $this->kernelRootDir . "/logs/php_errors_{$date}.log"; exec("php {$executor} {$date} > {$phpErrors}"); }
private function unzip($archivePath, ResourceNode $root, $published = true) { $extractPath = $this->container->get('claroline.config.platform_config_handler')->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $this->container->get('claroline.utilities.misc')->generateGuid(); $archive = new ZipArchive(); if ($archive->open($archivePath) === true) { $archive->extractTo($extractPath); $archive->close(); $this->om->startFlushSuite(); $perms = $this->container->get('claroline.manager.rights_manager')->getCustomRoleRights($root); $resources = $this->uploadDir($extractPath, $root, $perms, true, $published); $this->om->endFlushSuite(); $fs = new FileSystem(); $fs->rmdir($extractPath, true); return $resources; } throw new \Exception("The archive {$archivePath} can't be opened"); }