本文整理汇总了PHP中Claroline\CoreBundle\Persistence\ObjectManager::detach方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::detach方法的具体用法?PHP ObjectManager::detach怎么用?PHP ObjectManager::detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Claroline\CoreBundle\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::detach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPublicUrlOnUsers
protected function setPublicUrlOnUsers()
{
$this->log('Updating public url for users...');
/** @var \Claroline\CoreBundle\Repository\UserRepository $userRepository */
$userRepository = $this->objectManager->getRepository('ClarolineCoreBundle:User');
$this->log('User to update - ' . date('Y/m/d H:i:s'));
$this->log('It may take a while to process, go grab a coffee.');
/** @var \Claroline\CoreBundle\Manager\UserManager $userManager */
$userManager = $this->container->get('claroline.manager.user_manager');
$nbUsers = 0;
/** @var \Claroline\CoreBundle\Entity\User $user */
$user = $userRepository->findOneByPublicUrl(null);
while (null !== $user) {
$publicUrl = $userManager->generatePublicUrl($user);
$user->setPublicUrl($publicUrl);
$this->objectManager->persist($user);
$this->objectManager->flush();
$nbUsers++;
if (100 === $nbUsers) {
$this->log(' ' . $nbUsers . ' updated users - ' . date('Y/m/d H:i:s'));
$nbUsers = 0;
}
$personalWorkspace = $user->getPersonalWorkspace();
if (null !== $personalWorkspace) {
$this->objectManager->detach($personalWorkspace);
}
$this->objectManager->detach($user);
$user = $userRepository->findOneByPublicUrl(null);
}
$this->log('Public url for users updated.');
}
示例2: reorder
/**
* @param ResourceNode $node
* @param bool $detach
*/
public function reorder(ResourceNode $node, $detach = false)
{
/** @var \Claroline\CoreBundle\Repository\ResourceNodeRepository $resourceNodeRepository */
$resourceNodeRepository = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode');
$children = $resourceNodeRepository->getChildren($node, true, 'index');
$index = 1;
foreach ($children as $child) {
$child->setIndex($index);
$index++;
$this->om->persist($child);
}
$this->om->flush();
if ($detach) {
foreach ($children as $child) {
$this->om->detach($child);
}
}
}