public function moveThumbnailsDir() { $this->log('Moving thumbnail directory'); $fs = new FileSystem(); $oldIconDir = $this->container->getParameter('claroline.param.web_dir') . '/thumbnails'; try { $fs->rename($oldIconDir, $this->container->getParameter('claroline.param.thumbnails_directory')); } catch (\Exception $e) { $this->log('Operation already done...'); } $om = $this->container->get('doctrine.orm.entity_manager'); $iconRepository = $om->getRepository('Claroline\\CoreBundle\\Entity\\Resource\\ResourceIcon'); $icons = $iconRepository->findCustomIcons(); $i = 1; foreach ($icons as $icon) { if (strpos($icon->getRelativeUrl(), 'uploads/') === false) { $icon->setRelativeUrl('uploads/' . $icon->getRelativeUrl()); $om->persist($icon); ++$i; } if ($i % 50 === 0) { $this->log('Flushing 50 icons...'); $om->flush(); } } $this->log('Final icon flush !'); $om->flush(); }
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}"); }