/** * Delete all Subscriptions of an Exercise. * * @param Exercise $exercise * @param bool $flush * * @return SubscriptionManager */ public function deleteSubscriptions(Exercise $exercise, $flush = false) { $subscriptions = $this->om->getRepository('UJMExoBundle:Subscription')->findByExercise($exercise); foreach ($subscriptions as $subscription) { $this->om->remove($subscription); } if ($flush) { $this->om->flush(); } return $this; }
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(); }
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(); }
/** * Delete a translation of content. * * @param string $locale * @param $id */ public function deleteTranslation($locale, $id) { if ($locale === 'en') { $content = $this->content->findOneBy(array('id' => $id)); } else { $content = $this->translations->findOneBy(array('foreignKey' => $id, 'locale' => $locale)); } if ($content instanceof ContentTranslation || $content instanceof Content) { $this->manager->remove($content); $this->manager->flush(); } }
/** * @param \Claroline\CoreBundle\Entity\Resource\ResourceIcon $icon */ public function delete(ResourceIcon $icon, Workspace $workspace = null) { if ($icon->getMimeType() === 'custom') { //search if this icon is used elsewhere (ie copy) $res = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findBy(array('icon' => $icon)); if (count($res) <= 1 && $icon->isShortcut() === false) { $shortcut = $icon->getShortcutIcon(); $this->om->remove($shortcut); $this->om->remove($icon); $this->om->flush(); $this->removeImageFromThumbDir($icon, $workspace); $this->removeImageFromThumbDir($icon->getShortcutIcon(), $workspace); } } }
/** * Deletes all the papers associated with an exercise. * * @todo optimize request number using repository method(s) * * @param Exercise $exercise * * @throws \Exception if the exercise has been published at least once */ public function deletePapers(Exercise $exercise) { if ($exercise->wasPublishedOnce()) { throw new \Exception("Cannot delete exercise {$exercise->getId()} papers as it has been published at least once"); } $paperRepo = $this->om->getRepository('UJMExoBundle:Paper'); $linkHintPaperRepo = $this->om->getRepository('UJMExoBundle:LinkHintPaper'); $responseRepo = $this->om->getRepository('UJMExoBundle:Response'); $papers = $paperRepo->findByExercise($exercise); foreach ($papers as $paper) { $links = $linkHintPaperRepo->findByPaper($paper); foreach ($links as $link) { $this->om->remove($link); } $responses = $responseRepo->findByPaper($paper); foreach ($responses as $response) { $this->om->remove($response); } $this->om->remove($paper); } $this->om->flush(); }
public function deleteDuplicatedOldOrderedTools() { $usersOts = $this->orderedToolRepo->findDuplicatedOldOrderedToolsByUsers(); $wsOts = $this->orderedToolRepo->findDuplicatedOldOrderedToolsByWorkspaces(); $exitingUsers = array(); foreach ($usersOts as $ot) { $toolId = $ot->getTool()->getId(); $userId = $ot->getUser()->getId(); if (isset($exitingUsers[$toolId])) { if (isset($exitingUsers[$toolId][$userId])) { $this->om->remove($ot); } else { $exitingUsers[$toolId][$userId] = true; } } else { $exitingUsers[$toolId] = array(); $exitingUsers[$toolId][$userId] = true; } } $this->om->flush(); $exitingWorkspaces = array(); foreach ($wsOts as $ot) { $toolId = $ot->getTool()->getId(); $workspaceId = $ot->getWorkspace()->getId(); if (isset($exitingWorkspaces[$toolId])) { if (isset($exitingWorkspaces[$toolId][$workspaceId])) { $this->om->remove($ot); } else { $exitingWorkspaces[$toolId][$workspaceId] = true; } } else { $exitingWorkspaces[$toolId] = array(); $exitingWorkspaces[$toolId][$workspaceId] = true; } } $this->om->flush(); }
/** * Removes a favourite workspace. * * @param \Claroline\CoreBundle\Entity\Workspace\WorkspaceFavourite $favourite */ public function removeFavourite(WorkspaceFavourite $favourite) { $this->om->remove($favourite); $this->om->flush(); }
public function deletePage(WebsitePage $page) { $this->objectManager->remove($page); $this->objectManager->flush(); }