Ejemplo n.º 1
0
 /**
  * @EXT\Route(
  *     "/",
  *     name="claro_admin_plugins",
  *     options = {"expose"=true}
  * )
  *
  * @EXT\Template()
  *
  * Display the plugin list
  *
  * @return Response
  */
 public function listAction()
 {
     $fs = new FileSystem();
     $rootPath = $this->container->getParameter('claroline.param.root_directory') . '/';
     $danger = array('simple' => array(realpath($rootPath . 'vendor/composer/autoload_namespaces.php') => is_writable(realpath($rootPath . 'vendor/composer/autoload_namespaces.php')), realpath($rootPath . 'app/config/bundles.ini') => is_writable(realpath($rootPath . 'app/config/bundles.ini')), realpath($rootPath . 'vendor') => is_writable(realpath($rootPath . 'vendor')), realpath($rootPath . 'app/logs') => is_writable(realpath($rootPath . 'app/logs')), realpath($rootPath . 'web/bundles') => is_writable(realpath($rootPath . 'web/bundles'))), 'recursive' => array(realpath($rootPath . 'web/js') => $fs->isWritable(realpath($rootPath . 'web/js'), true), realpath($rootPath . 'app/cache') => $fs->isWritable(realpath($rootPath . 'app/cache'), true), realpath($rootPath . 'web/themes') => $fs->isWritable(realpath($rootPath . 'web/themes'), true), realpath($rootPath . 'web/css') => $fs->isWritable(realpath($rootPath . 'web/css'), true), realpath($rootPath . 'web/vendor') => $fs->isWritable(realpath($rootPath . 'web/vendor'), true)));
     $refresh = array('simple' => array(realpath($rootPath . 'web/bundles') => is_writable(realpath($rootPath . 'web/bundles'))), 'recursive' => array(realpath($rootPath . 'web/js') => $fs->isWritable(realpath($rootPath . 'web/js'), true), realpath($rootPath . 'web/themes') => $fs->isWritable(realpath($rootPath . 'web/themes'), true), realpath($rootPath . 'web/css') => $fs->isWritable(realpath($rootPath . 'web/css'), true), realpath($rootPath . 'web/vendor') => $fs->isWritable(realpath($rootPath . 'web/vendor'), true)));
     $coreBundle = $this->bundleManager->getBundle('CoreBundle');
     $coreVersion = $coreBundle->getVersion();
     $api = $this->configHandler->getParameter('repository_api');
     $url = $api . "/version/{$coreVersion}/tags/last";
     if ($this->configHandler->getParameter('use_repository_test')) {
         $url .= '/test';
     }
     //ask the server wich are the last available packages now.
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $data = curl_exec($ch);
     curl_close($ch);
     $fetched = json_decode($data);
     $installed = $this->bundleManager->getInstalled();
     $plugins = $this->bundleManager->getConfigurablePlugins();
     foreach ($installed as $install) {
         foreach ($plugins as $plugin) {
             if ($plugin->getBundleName() === $install->getName()) {
                 $install->setIsConfigurable(true);
             }
         }
     }
     $uninstalled = $this->bundleManager->getUninstalledFromServer($fetched);
     return array('fetched' => $fetched, 'installed' => $installed, 'uninstalled' => $uninstalled, 'danger' => $danger, 'refresh' => $refresh, 'useTestRepo' => $this->configHandler->getParameter('use_repository_test'));
 }
Ejemplo n.º 2
0
 private function removeOldTemplateDir()
 {
     $claroRoot = $this->container->getParameter('claroline.param.root_directory');
     $claroRoot .= '/templates';
     $this->log('Removing old template directory ' . $claroRoot);
     $fs = new FileSystem();
     $fs->remove($claroRoot, true);
 }
Ejemplo n.º 3
0
 public function renderMissingPermissions($basePath)
 {
     $fs = new FileSystem();
     $fullPath = realpath($this->vendorPath . '/' . $basePath);
     $basePath = realpath($this->vendorPath . '/' . substr($basePath, 0, strrpos($basePath, '/')));
     $fullPathElement = $basePathElement = '';
     $notWritable = $this->translator->trans('is_not_writable', array(), 'platform');
     $notWritableRecursive = $this->translator->trans('is_not_writable_recursive', array(), 'platform');
     if ($fullPath && !$fs->isWritable($fullPath, true)) {
         $fullPathElement = "<li class='alert alert-danger'>" . $fullPath . ' ' . $notWritableRecursive . "</li>";
     }
     if (!is_writable($basePath) && $basePath) {
         $basePathElement = "<li class='alert alert-danger'>" . $basePath . ' ' . $notWritable . "</li>";
     }
     $rendering = sprintf('<ul>%s%s</ul>', $fullPathElement, $basePathElement);
     return $rendering;
 }
Ejemplo n.º 4
0
 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}");
 }
Ejemplo n.º 5
0
 public function deleteWebsite(Website $website)
 {
     $websiteUploadFolder = $this->webDir . DIRECTORY_SEPARATOR . $website->getOptions()->getUploadDir();
     $fs = new FileSystem();
     $fs->remove($websiteUploadFolder);
     $this->om->remove($website);
     $this->om->flush();
 }
Ejemplo n.º 6
0
 /**
  * Delete the repository
  *
  * @access public
  *
  */
 public function removeDirectory()
 {
     if (is_dir($this->userRootDir)) {
         exec('rm -rf ' . $this->userRootDir . '*');
         $fs = new FileSystem();
         $iterator = new \DirectoryIterator($this->userRootDir);
         foreach ($iterator as $el) {
             if ($el->isDir()) {
                 $fs->rmDir($el->getRealPath(), true);
             }
             if ($el->isFile()) {
                 $fs->rm($el->getRealPath());
             }
         }
     }
 }
Ejemplo n.º 7
0
 public function deleteWebsiteTestsFolder(Website $website, $webDir)
 {
     $websiteUploadFolder = $webDir . DIRECTORY_SEPARATOR . $website->getOptions()->getUploadDir();
     $fs = new FileSystem();
     $fs->remove($websiteUploadFolder);
 }
Ejemplo n.º 8
0
 /**
  * Delete the repository.
  */
 public function removeDirectory()
 {
     $fs = new FileSystem();
     $fs->rmdir($this->userRootDir, true);
 }
Ejemplo n.º 9
0
 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");
 }