本文整理匯總了PHP中Doctrine\ORM\EntityManager::detach方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::detach方法的具體用法?PHP EntityManager::detach怎麽用?PHP EntityManager::detach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::detach方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertFromLoanApp
public function convertFromLoanApp(LoanApplication $application)
{
$this->em->detach($application);
$vantage = $this->formatVantage($application);
$applicationXml = $this->container->get('templating')->render('SudouxMortgageBundle:LoanApplicationAdmin/formats:vantageFull.xml.twig', array('application' => $vantage), 'text/xml');
return $applicationXml;
}
示例2: onMessage
/**
* @param ConnectionInterface $from
* @param string $data
*/
public function onMessage(ConnectionInterface $from, $data)
{
$data = json_decode($data);
if (JSON_ERROR_NONE !== json_last_error() || !is_array($data) || count($data) < 0) {
return;
}
$message = $this->onReceiveData($from->user, $data);
if (null !== $message) {
$this->em->detach($message);
}
}
示例3: onBroadcast
/**
* @param ChannelBroadcastEvent $event
*/
public function onBroadcast(ChannelBroadcastEvent $event)
{
if (!$event->checkContext('email')) {
return;
}
// Get list of published broadcasts or broadcast if there is only a single ID
$id = $event->getId();
$emails = $this->model->getRepository()->getPublishedBroadcasts($id);
$output = $event->getOutput();
/** @var Email $email */
while (($email = $emails->next()) !== false) {
list($sentCount, $failedCount, $ignore) = $this->model->sendEmailToLists($email[0], null, 100, true, $output);
$event->setResults($this->translator->trans('mautic.email.email') . ': ' . $email[0]->getName(), $sentCount, $failedCount);
$this->em->detach($email[0]);
}
}
示例4: resetCacheEntity
/**
* Resets the last stored entity.
*
* @codeCoverageIgnore
*/
private function resetCacheEntity()
{
if (null !== $this->_entity) {
$this->_em->detach($this->_entity);
$this->_entity = null;
}
}
示例5: handleCannibalisticEntity
/**
* @param Entity $entity
*
* @return $this
*/
protected function handleCannibalisticEntity(Entity $entity)
{
if ($this->metadata->isCannibal()) {
$this->manager->flush($entity);
$this->manager->detach($entity);
}
return $this;
}
示例6: toEntity
/**
* @param string $entityName
* @param array $values
* @throws \RuntimeException
* @return object Detached Doctrine2 entity instance
*/
public function toEntity($entityName, $values)
{
$false = serialize(false);
if (!empty($values[self::SERIALIZED_KEY])) {
foreach ($values[self::SERIALIZED_KEY] as $field) {
$result = unserialize($values[$field]);
if ($values[$field] !== $false && $result === false) {
throw new RuntimeException('Could not unserialize value: ' . $values[$field]);
}
$values[$field] = $result;
}
}
$unit = $this->em->getUnitOfWork();
$entity = $unit->createEntity($entityName, $values);
$this->em->detach($entity);
return $entity;
}
示例7: clearRound
/**
* @param Tournament $tournament
* @param int $round
* @return void
*/
private function clearRound(Tournament $tournament, int $round)
{
$this->getTournamentHandler()->clearRound($tournament, $round);
foreach ($this->possibleTournamentGames as $possibleTournamentGame) {
$this->manager->detach($possibleTournamentGame);
$this->manager->detach($possibleTournamentGame->getGame());
}
$this->possibleTournamentGames = [];
}
示例8: write
/**
* Do persist into EntityManager
*
* @param array $items
*/
private function write(array $items)
{
foreach ($items as $item) {
$this->em->persist($item);
}
$this->em->flush();
foreach ($items as $item) {
$this->em->detach($item);
}
}
示例9: filterProductValues
/**
* Filter on product values
*
* @param AbstractProduct $product
*
* @return AbstractProduct
*/
public function filterProductValues(AbstractProduct $product)
{
$this->entityManager->detach($product);
$productValues = $product->getValues();
$identifierType = $product->getIdentifier()->getAttribute()->getAttributeType();
foreach ($productValues as $productValue) {
if ($identifierType != $productValue->getAttribute()->getAttributeType() && (null == $productValue->getUpdated() || null != $productValue->getUpdated() && $product->getUpdated()->getTimestamp() - $productValue->getUpdated()->getTimestamp() > 60)) {
$product->removeValue($productValue);
}
}
return $product;
}
示例10: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$mapper = $input->getOption('mapper');
$this->validateMapper($mapper);
$this->entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
$iterableResult = $this->getIterableResult();
/**
* @var \Closure $closure
*/
$closure = (require $mapper);
foreach ($iterableResult as $collection) {
foreach ($collection as $perspective) {
$perspective = $closure($perspective);
$this->entityManager->persist($perspective);
$this->entityManager->flush($perspective);
$this->entityManager->detach($perspective);
}
}
$successMessage = $this->getContainer()->get('translator')->trans('perspective_mapping_success');
$output->writeln($successMessage);
}
示例11: testUserRepository
public function testUserRepository()
{
$user = $this->em->getRepository('AppBundle:User')->loadUserByUsername('belac');
$this->assertEquals('belac', $user->getUsername());
// }
// public function testRefreshUser()
// {
$user = $this->em->getRepository('AppBundle:User')->loadUserByUsername('belac');
$this->em->detach($user);
$user->setUsername('notBelac');
$serializedUser = serialize($user);
$unSerializedUser = unserialize($serializedUser);
$user = $this->em->getRepository('AppBundle:User')->refreshUser($unSerializedUser);
$this->assertEquals('belac', $user->getUsername());
// }
//public function testSearchUsers()
//{
$criteria = array('email' => 'belackriv@gmail.com');
$users = $this->em->getRepository('AppBundle:User')->searchUsers($criteria);
$this->assertCount(1, $users);
$this->assertEquals('belackriv@gmail.com', $users[0]->getEmail());
}
示例12: exportData
/**
* クエリビルダにもとづいてデータ行を出力する.
* このメソッドを使う場合は, 事前にsetExportQueryBuilder($qb)で出力対象のクエリビルダをわたしておく必要がある.
*
* @param \Closure $closure
*/
public function exportData(\Closure $closure)
{
if (is_null($this->qb) || is_null($this->em)) {
throw new \LogicException('query builder not set.');
}
$this->fopen();
$query = $this->qb->getQuery();
foreach ($query->getResult() as $iteratableResult) {
$closure($iteratableResult, $this);
$this->em->detach($iteratableResult);
$query->free();
flush();
}
$this->fclose();
}
示例13: createTicket
/**
* Creates Ticket and Message Reference fot it
*
* @param $messageId
* @param $branchId
* @param $subject
* @param $description
* @param $reporter
* @param $assigneeId
* @param array $attachments
* @return \Diamante\DeskBundle\Model\Ticket\Ticket
* @throws \RuntimeException if unable to load required branch, reporter, assignee
*/
public function createTicket($messageId, $branchId, $subject, $description, $reporter, $assigneeId, array $attachments = null)
{
if (empty($subject)) {
$subject = self::EMPTY_SUBJECT_PLACEHOLDER;
}
$this->ticketBuilder->setSubject($subject)->setDescription($description)->setBranchId($branchId)->setReporter($reporter)->setAssigneeId($assigneeId)->setSource(Source::EMAIL);
$ticket = $this->ticketBuilder->build();
if ($attachments) {
$this->createAttachments($attachments, $ticket);
}
$this->ticketRepository->store($ticket);
$this->createMessageReference($messageId, $ticket);
$this->em->detach($ticket);
$this->dispatchEvents($ticket);
return $ticket;
}
示例14: createTicket
/**
* Create Ticket
* @param CreateTicketCommand $command
* @return \Diamante\DeskBundle\Model\Ticket\Ticket
* @throws \RuntimeException if unable to load required branch, reporter, assignee
*/
public function createTicket(CreateTicketCommand $command)
{
$this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Ticket');
\Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
$this->ticketBuilder->setSubject($command->subject)->setDescription($command->description)->setBranchId($command->branch)->setReporter($command->reporter)->setAssigneeId($command->assignee)->setPriority($command->priority)->setSource($command->source)->setStatus($command->status)->setTags($command->tags);
$ticket = $this->ticketBuilder->build();
if (is_array($command->attachmentsInput) && false === empty($command->attachmentsInput)) {
foreach ($command->attachmentsInput as $each) {
$this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $ticket);
}
}
$this->ticketRepository->store($ticket);
if ($this->securityFacade->getOrganization()) {
$this->tagManager->saveTagging($ticket);
}
$this->em->detach($ticket);
$this->dispatchEvents($ticket);
return $ticket;
}
示例15: findWithFilters
/**
* Find the latest revisions of all connections that match the given filters and return them as Dto's
*
* @param array $filter
* @param string|null $sortBy
* @param string $sortOrder
* @return ConnectionDtoCollection
*/
public function findWithFilters(array $filter = array(), $sortBy = null, $sortOrder = 'DESC')
{
/** @var $sortFieldDefaultValue string */
$sortFieldName = $this->config->getString('entity.prettyname', NULL);
$revisions = $this->connectionRepository->findLatestRevisionsWithFilters($filter, $sortBy, $sortOrder, $sortFieldName);
$metadataDefinitionHelper = $this->metadataDefinitionHelper;
$dtos = array();
$i = 0;
/** @var Revision $revision */
while ($revision = array_shift($revisions)) {
$dtos[] = $revision->toDto($metadataDefinitionHelper);
// Done this this revision, Entity Manager and PHP in general please forget it now.
$this->entityManager->detach($revision);
unset($revision);
// Every 100 entities clear the entity memory to reduce memory usage for 1100 entities from 270Mb to 100Mb.
if ($i++ % 100 === 0) {
$this->clearEntities();
}
}
$this->clearEntities();
return new ConnectionDtoCollection($dtos);
}