本文整理汇总了PHP中Claroline\CoreBundle\Persistence\ObjectManager::startFlushSuite方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::startFlushSuite方法的具体用法?PHP ObjectManager::startFlushSuite怎么用?PHP ObjectManager::startFlushSuite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::startFlushSuite方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateDefaultPerms
public function updateDefaultPerms()
{
$tools = array(array('home', false, true), array('parameters', true, true), array('resource_manager', false, true), array('agenda', false, true), array('logs', false, true), array('analytics', false, true), array('users', false, true), array('badges', false, true));
$this->log('updating tools...');
foreach ($tools as $tool) {
$entity = $this->om->getRepository('ClarolineCoreBundle:Tool\\Tool')->findOneByName($tool[0]);
if ($entity) {
$entity->setIsLockedForAdmin($tool[1]);
$entity->setIsAnonymousExcluded($tool[2]);
$this->om->persist($entity);
}
}
$this->log('updating resource types...');
$resourceTypes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findAll();
foreach ($resourceTypes as $resourceType) {
$resourceType->setDefaultMask(1);
$this->om->persist($resourceType);
}
$this->om->flush();
$this->log('updating manager roles...');
$this->log('this may take a while...');
$managerRoles = $this->om->getRepository('ClarolineCoreBundle:Role')->searchByName('ROLE_WS_MANAGER');
foreach ($managerRoles as $role) {
$this->conn->query("DELETE FROM claro_ordered_tool_role\n WHERE role_id = {$role->getId()}");
}
$this->log('updating resource rights...');
$this->log('removing administrator rights...');
$roleAdmin = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_ADMIN');
$adminRights = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceRights')->findBy(array('role' => $roleAdmin));
foreach ($adminRights as $adminRight) {
$this->om->remove($adminRight);
}
$this->om->flush();
$this->log('adding user rights... ');
$this->log('it may take a while...');
$resourceNodes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findAll();
$roleUser = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_USER');
$this->om->startFlushSuite();
$i = 0;
foreach ($resourceNodes as $resourceNode) {
$rightsManager = $this->container->get('claroline.manager.rights_manager');
$rightsManager->create(0, $roleUser, $resourceNode, false);
$i++;
if ($i % 200 === 0) {
$this->om->endFlushSuite();
$this->om->startFlushSuite();
}
}
$this->om->endFlushSuite();
}
示例2: importDirectoriesFromCsv
public function importDirectoriesFromCsv($file)
{
$data = file_get_contents($file);
$data = $this->container->get('claroline.utilities.misc')->formatCsvOutput($data);
$lines = str_getcsv($data, PHP_EOL);
$this->om->startFlushSuite();
$i = 0;
$resourceType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('directory');
foreach ($lines as $line) {
$values = str_getcsv($line, ';');
$code = $values[0];
$workspace = $this->om->getRepository('ClarolineCoreBundle:Workspace\\Workspace')->findOneByCode($code);
$name = $values[1];
$directory = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneBy(['workspace' => $workspace, 'name' => $name, 'resourceType' => $resourceType]);
if (!$directory) {
$directory = new Directory();
$directory->setName($name);
$this->log("Create directory {$name} for workspace {$code}");
$this->create($directory, $resourceType, $workspace->getCreator(), $workspace, $this->getWorkspaceRoot($workspace));
++$i;
} else {
$this->log("Directory {$name} already exists for workspace {$code}");
}
if ($i % 100 === 0) {
$this->om->forceFlush();
$this->om->clear();
$resourceType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('directory');
$this->om->merge($resourceType);
}
}
$this->om->endFlushSuite();
}
示例3: checkIntegrity
public function checkIntegrity()
{
$this->log('Checking roles integrity for resources... This may take a while.');
$workspaceManager = $this->container->get('claroline.manager.workspace_manager');
$workspaces = $this->om->getRepository('Claroline\\CoreBundle\\Entity\\Workspace\\Workspace')->findAll();
$this->om->startFlushSuite();
$i = 0;
foreach ($workspaces as $workspace) {
$this->log('Checking ' . $workspace->getCode() . '...');
$roles = $workspace->getRoles();
$root = $this->container->get('claroline.manager.resource_manager')->getWorkspaceRoot($workspace);
$collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
if ($root && $collaboratorRole) {
$collaboratorFound = false;
foreach ($root->getRights() as $right) {
if ($right->getRole()->getName() == $this->roleManager->getCollaboratorRole($workspace)->getName()) {
$collaboratorFound = true;
}
}
if (!$collaboratorFound) {
$this->log('Adding missing right on root for ' . $workspace->getCode() . '.', LogLevel::DEBUG);
$collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
$this->editPerms(5, $collaboratorRole, $root, true, array(), true);
$i++;
if ($i % 3 === 0) {
$this->log('flushing...');
$this->om->forceFlush();
$this->om->clear();
}
}
}
}
$this->om->endFlushSuite();
}
示例4: importWorkspaces
/**
* 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];
$errors = array();
if (isset($workspace[6]) && trim($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) {
$this->om->forceFlush();
$this->om->clear();
}
$this->om->endFlushSuite();
}
}
示例5: deleteAssociatedShortcuts
private function deleteAssociatedShortcuts(ResourceNode $resourceNode)
{
$this->om->startFlushSuite();
$shortcuts = $this->shortcutRepo->findByTarget($resourceNode);
foreach ($shortcuts as $shortcut) {
$this->om->remove($shortcut->getResourceNode());
}
$this->om->endFlushSuite();
}
示例6: fieldFacet
public function fieldFacet(PanelFacet $panelFacet, $name, $type, array $choices = [], $isRequired = false)
{
$this->om->startFlushSuite();
$field = $this->container->get('claroline.manager.facet_manager')->addField($panelFacet, $name, $isRequired, $type);
foreach ($choices as $choice) {
$this->container->get('claroline.manager.facet_manager')->addFacetFieldChoice($choice, $field);
}
$this->om->endFlushSuite();
return $field;
}
示例7: load
/**
* Loads the four base roles commonly used within the platform :
* - anonymous user (fixture ref : role/anonymous)
* - registered user (fixture ref : role/user)
* - workspace creator (fixture ref : role/ws_creator)
* - administrator (fixture ref : role/admin).
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$manager->startFlushSuite();
$roleManager = $this->container->get('claroline.manager.role_manager');
$roleManager->createBaseRole(PlatformRoles::USER, 'user');
$roleManager->createBaseRole(PlatformRoles::WS_CREATOR, 'ws_creator');
$roleManager->createBaseRole(PlatformRoles::ADMIN, 'admin');
$roleManager->createBaseRole(PlatformRoles::ANONYMOUS, 'anonymous');
$roleManager->createBaseRole('ROLE_HOME_MANAGER', 'home_manager');
$manager->endFlushSuite();
}
示例8: import
public function import(array $data)
{
$this->om->startFlushSuite();
//this is the root of the unzipped archive
$rootPath = $this->getRootPath();
$exoPath = $data['data']['exercise']['path'];
$newExercise = $this->createExo($data['data']['exercise'], $this->qtiRepository->getQtiUser());
if (file_exists($rootPath . '/' . $exoPath)) {
$this->createQuestion($data['data']['steps'], $newExercise, $rootPath . '/' . $exoPath);
}
$this->om->endFlushSuite();
$this->om->forceFlush();
return $newExercise;
}
示例9: createOrderedToolByToolForAllUsers
public function createOrderedToolByToolForAllUsers(LoggerInterface $logger, Tool $tool, $type = 0, $isVisible = true)
{
$toolName = $tool->getName();
$usersQuery = $this->userRepo->findAllEnabledUsers(false);
$users = $usersQuery->iterate();
$this->om->startFlushSuite();
$index = 0;
$countUser = $this->userRepo->countAllEnabledUsers();
$logger->info(sprintf("%d users to check tools on.", $countUser));
foreach ($users as $row) {
$user = $row[0];
/** @var \Claroline\CoreBundle\Entity\Tool\OrderedTool[] $orderedTools */
$orderedTools = $this->orderedToolRepo->findOrderedToolsByToolAndUser($tool, $user, $type);
if (count($orderedTools) === 0) {
$orderedTool = new OrderedTool();
$orderedTool->setName($toolName);
$orderedTool->setTool($tool);
$orderedTool->setUser($user);
$orderedTool->setVisibleInDesktop($isVisible);
$orderedTool->setOrder(1);
$orderedTool->setType($type);
$this->om->persist($orderedTool);
$index++;
if ($index % 100 === 0) {
$this->om->forceFlush();
$this->om->clear($orderedTool);
$logger->info(sprintf(" %d users checked.", 100));
}
} else {
$orderedTool = $orderedTools[0];
if ($orderedTool->isVisibleInDesktop() !== $isVisible) {
$orderedTool->setVisibleInDesktop($isVisible);
$this->om->persist($orderedTool);
$index++;
if ($index % 100 === 0) {
$this->om->forceFlush();
$this->om->clear($orderedTool);
$logger->info(sprintf(" %d users checked.", 100));
}
}
}
}
if ($index % 100 !== 0) {
$logger->info(sprintf(" %d users checked.", 100 - $index));
}
$this->om->endFlushSuite();
}
示例10: replace
/**
* Replace a node icon.
*
* @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource
* @param \Claroline\CoreBundle\Entity\Resource\ResourceIcon $icon
*
* @return \Claroline\CoreBundle\Entity\Resource\ResourceNode
*/
public function replace(ResourceNode $resource, ResourceIcon $icon)
{
$this->om->startFlushSuite();
$oldIcon = $resource->getIcon();
if (!$oldIcon->isShortcut()) {
$oldShortcutIcon = $oldIcon->getShortcutIcon();
$shortcutIcon = $icon->getShortcutIcon();
if (!is_null($oldShortcutIcon) && !is_null($shortcutIcon)) {
$nodes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findBy(array('icon' => $oldShortcutIcon));
foreach ($nodes as $node) {
$node->setIcon($shortcutIcon);
$this->om->persist($node);
}
}
}
$this->delete($oldIcon);
$resource->setIcon($icon);
$this->om->persist($resource);
$this->om->endFlushSuite();
return $resource;
}
示例11: importWorkspaces
/**
* Import a workspace list from a csv data.
*
* @param array $workspaces
*/
public function importWorkspaces(array $workspaces, $logger = null, $update = false)
{
$i = 0;
$workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
foreach ($workspaces as $workspace) {
++$i;
$this->om->startFlushSuite();
$endDate = null;
$model = null;
$name = $workspace[0];
$code = $workspace[1];
$isVisible = $workspace[2];
$selfRegistration = $workspace[3];
$registrationValidation = $workspace[4];
$selfUnregistration = $workspace[5];
if (isset($workspace[6]) && trim($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 (isset($workspace[8])) {
$endDate = new \DateTime();
$endDate->setTimestamp($workspace[8]);
}
if ($update) {
$workspace = $this->getOneByCode($code);
if (!$workspace) {
//if the workspace doesn't exists, just keep going...
continue;
}
if ($logger) {
$logger('Updating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
}
} else {
$workspace = new Workspace();
}
$workspace->setName($name);
$workspace->setCode($code);
$workspace->setDisplayable($isVisible);
$workspace->setSelfRegistration($selfRegistration);
$workspace->setSelfUnregistration($selfUnregistration);
$workspace->setRegistrationValidation($registrationValidation);
$workspace->setCreator($user);
if ($endDate) {
$workspace->setEndDate($endDate);
}
if (!$update) {
if ($logger) {
$logger('Creating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
}
if ($model) {
$guid = $this->ut->generateGuid();
$this->createWorkspace($workspace);
$workspace->setGuid($guid);
$date = new \Datetime(date('d-m-Y H:i'));
$workspace->setCreationDate($date->getTimestamp());
$workspaceModelManager->addDataFromModel($model, $workspace, $user);
} else {
$template = new File($this->container->getParameter('claroline.param.default_template'));
$this->container->get('claroline.manager.transfer_manager')->createWorkspace($workspace, $template, true);
}
} else {
if ($model) {
$workspaceModelManager->updateDataFromModel($model, $workspace);
}
}
$this->om->persist($workspace);
$logger('UOW: ' . $this->om->getUnitOfWork()->size());
if ($i % 100 === 0) {
$this->om->forceFlush();
$user = $this->om->getRepository('ClarolineCoreBundle:User')->find($user->getId());
$this->om->merge($user);
$this->om->refresh($user);
}
}
$logger('Final flush...');
$this->om->endFlushSuite();
}
示例12: testNestedFlushSuites
public function testNestedFlushSuites()
{
$oom = $this->mock('Doctrine\\Common\\Persistence\\ObjectManager');
$oom->shouldReceive('flush')->once();
$om = new ObjectManager($oom);
$om->startFlushSuite();
$om->flush();
$om->flush();
$om->startFlushSuite();
$om->flush();
$om->flush();
$om->endFlushSuite();
$om->flush();
$om->endFlushSuite();
}