Example #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $workspaceManager = $this->container->get('claroline.manager.workspace_manager');
     $count = $manager->getRepository('ClarolineCoreBundle:Workspace\\Workspace')->count();
     $totalWorkspaces = $count + 1;
     $admin = $this->findJohnDoe($manager);
     $personalWsTemplateFile = $this->container->getParameter('claroline.param.templates_directory') . "default.zip";
     $config = new Configuration($personalWsTemplateFile);
     $start = time();
     for ($j = 0, $i = 0; $i < $this->numberWorkspaces; $i++, $totalWorkspaces++) {
         $mandatoryFieldValue = "ws_batch" . $totalWorkspaces;
         $config->setWorkspaceName($mandatoryFieldValue);
         $config->setWorkspaceCode($mandatoryFieldValue);
         $workspaceManager->create($config, $admin);
         if ($i % self::BATCH_SIZE === 0) {
             $j++;
             $manager->flush();
             $manager->clear();
             $admin = $this->findJohnDoe($manager);
             $totalInserts = $i + 1;
             $this->log("batch [{$j}] | workspaces [{$totalInserts}] | UOW  [{$manager->getUnitOfWork()->size()}]");
         }
     }
     $manager->flush();
     $manager->clear();
     $end = time();
     $duration = $this->container->get('claroline.utilities.misc')->timeElapsed($end - $start);
     $this->log("Time elapsed for the workspace creation: " . $duration);
     return $duration;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $workspaceManager = $this->container->get('claroline.manager.workspace_manager');
     $personalWsTemplateFile = $this->container->getParameter('claroline.param.templates_directory') . "default.zip";
     foreach ($this->workspaces as $name => $username) {
         $config = new Configuration($personalWsTemplateFile);
         $config->setWorkspaceName($name);
         $config->setWorkspaceCode(substr($name, 0, 1) . self::$codeDiscrCount);
         $config->setDisplayable(true);
         $workspace = $workspaceManager->create($config, $this->getReference('user/' . $username));
         $this->setReference("workspace/{$name}", $workspace);
         $wsRoot = $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findWorkspaceRoot($workspace);
         $this->setReference('directory/' . $name, $wsRoot);
         ++self::$codeDiscrCount;
     }
 }
Example #3
0
 /**
  * Import a workspace list from a csv data.
  *
  * @param array $workspaces
  */
 public function importWorkspaces(array $workspaces, $logger = null)
 {
     $this->om->clear();
     $ds = DIRECTORY_SEPARATOR;
     $i = 0;
     $j = 0;
     $workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
     foreach ($workspaces as $workspace) {
         $this->om->startFlushSuite();
         $model = null;
         $name = $workspace[0];
         $code = $workspace[1];
         $isVisible = $workspace[2];
         $selfRegistration = $workspace[3];
         $registrationValidation = $workspace[4];
         $selfUnregistration = $workspace[5];
         if (isset($workspace[6])) {
             $user = $this->om->getRepository('ClarolineCoreBundle:User')->findOneByUsername($workspace[6]);
         } else {
             $user = $this->container->get('security.context')->getToken()->getUser();
         }
         if (isset($workspace[7])) {
             $model = $this->om->getRepository('ClarolineCoreBundle:Model\\WorkspaceModel')->findOneByName($workspace[7]);
         }
         if ($model) {
             $guid = $this->ut->generateGuid();
             $workspace = new Workspace();
             $this->createWorkspace($workspace);
             $workspace->setName($name);
             $workspace->setCode($code);
             $workspace->setDisplayable($isVisible);
             $workspace->setSelfRegistration($selfRegistration);
             $workspace->setSelfUnregistration($selfUnregistration);
             $workspace->setRegistrationValidation($registrationValidation);
             $workspace->setGuid($guid);
             $date = new \Datetime(date('d-m-Y H:i'));
             $workspace->setCreationDate($date->getTimestamp());
             $workspace->setCreator($user);
             $workspaceModelManager->addDataFromModel($model, $workspace, $user, $errors);
         } else {
             //this should be changed later
             $configuration = new Configuration($this->templateDir . $ds . 'default.zip');
             $configuration->setWorkspaceName($name);
             $configuration->setWorkspaceCode($code);
             $configuration->setDisplayable($isVisible);
             $configuration->setSelfRegistration($selfRegistration);
             $configuration->setSelfUnregistration($registrationValidation);
             $this->container->get('claroline.manager.transfert_manager')->createWorkspace($configuration, $user);
         }
         $i++;
         $j++;
         if ($i % self::MAX_WORKSPACE_BATCH_SIZE === 0) {
             if ($logger) {
                 $logger(" [UOW size: " . $this->om->getUnitOfWork()->size() . "]");
             }
             $i = 0;
             $this->om->forceFlush();
             if ($logger) {
                 $logger(" Workspace {$j} ({$name}) being created");
             }
             $this->om->clear();
         }
         $this->om->endFlushSuite();
     }
 }