本文整理匯總了PHP中Doctrine\ORM\EntityManager::flush方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::flush方法的具體用法?PHP EntityManager::flush怎麽用?PHP EntityManager::flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
/**
* @param Todo $entity
*/
public function run(EntityInterface $entity)
{
assert($entity instanceof Todo);
$entity->setStatus(new TodoStatus());
$this->repository->add($entity);
$this->entityManager->flush();
}
示例2: down
public function down(Schema $schema)
{
$lookingFor = new Profile\LookingFor();
$lookingFor->setName('Intimate');
$this->em->persist($lookingFor);
$this->em->flush();
}
示例3: onCoreController
/**
* Update the user "lastActivity" on each request
*
* @param FilterControllerEvent $event
*/
public function onCoreController(FilterControllerEvent $event)
{
// Here we are checking that the current request is a "MASTER_REQUEST",
// and ignore any
// subrequest in the process (for example when
// doing a render() in a twig template)
if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
return;
}
// We are checking a token authentification is available before using
// the User
if ($this->securityContext->getToken()) {
$user = $this->securityContext->getToken()->getUser();
// We are using a delay during wich the user will be considered as
// still active, in order to
// avoid too much UPDATE in the
// database
// $delay = new \DateTime ();
// $delay->setTimestamp (strtotime ('2 minutes ago'));
// We are checking the Admin class in order to be certain we can
// call "getLastActivity".
// && $user->getLastActivity() < $delay) {
if ($user instanceof User) {
$user->isActiveNow();
$this->em->persist($user);
$this->em->flush();
}
}
}
示例4: onKernelTerminate
/**
* Flush on kernel terminate.
*/
public function onKernelTerminate()
{
if ($this->em->isOpen()) {
$this->em->flush();
// That was not so hard... And you need a bundle to do that! Poor guy...
}
}
示例5: save
/**
* @param ProviderLocation $providerLocation
* @param bool $withFlush
*/
public function save(ProviderLocation $providerLocation, $withFlush = true)
{
$this->entityManager->persist($providerLocation);
if ($withFlush) {
$this->entityManager->flush();
}
}
示例6: schedule
public function schedule()
{
$licenseRepo = $this->em->getRepository('AppBundle:License');
$drillSchemaEventsRepo = $this->em->getRepository('AppBundle:DrillSchemaEvent');
$licensesWithoutSchema = $licenseRepo->findWithoutRegisteredSchema();
foreach ($licensesWithoutSchema as $license) {
$drillSchemaEvents = $drillSchemaEventsRepo->findByAddonKey($license->getAddonKey());
if (empty($drillSchemaEvents)) {
continue;
}
$drillRegisteredSchema = new DrillRegisteredSchema();
$drillRegisteredSchema->setLicenseId($license->getLicenseId());
$drillRegisteredSchema->setAddonKey($license->getAddonKey());
$this->em->persist($drillRegisteredSchema);
foreach ($drillSchemaEvents as $drillSchemaEvent) {
$sendDate = $this->calculateSendDate($drillSchemaEvent, $license);
$today = new \DateTime();
// prevent creating events from past
if ($sendDate < $today->modify('-2 days')) {
continue;
}
$drillRegisteredEvent = new DrillRegisteredEvent();
$drillRegisteredEvent->setDrillRegisteredSchema($drillRegisteredSchema);
$drillRegisteredEvent->setDrillSchemaEvent($drillSchemaEvent);
// Calculate
$drillRegisteredEvent->setSendDate($sendDate);
$drillRegisteredEvent->setStatus('new');
$this->em->persist($drillRegisteredEvent);
}
}
$this->em->flush();
}
示例7: onKernelTerminate
public function onKernelTerminate(PostResponseEvent $event)
{
/** @var Request $request */
$request = $event->getRequest();
if (!$this->isEnable || !$this->isLoggableRequest($request)) {
return;
}
try {
/** @var Response $response */
$response = $event->getResponse();
$route = $request->get('_route');
$content = $this->cleanSensitiveContent($route, $request->getContent());
$token = $this->tokenStorage->getToken();
$user = !is_null($token) ? $token->getUser() : null;
$logRequest = new LogRequest();
$logRequest->setRoute($route)->setPath($request->getPathInfo())->setMethod($request->getMethod())->setQuery(urldecode($request->getQueryString()))->setContent($content)->setStatus($response->getStatusCode())->setIp($request->getClientIp())->setUser(!is_string($user) ? $user : null);
if ($this->logResponse($response)) {
$logRequest->setResponse($response->getContent());
}
$this->em->persist($logRequest);
$this->em->flush();
} catch (\Exception $e) {
$this->logger->error(sprintf("LogRequest couldn't be persist : %s", $e->getMessage()));
}
}
示例8: get
public function get($name)
{
$uppername = strtoupper($name);
/*
//create unique key for kind and uppercased name
$key = md5('kind.' . $uppername);
//cache has value return this one
$cached = Cache::get($key);
if ($cached) {
return $cached;
}*/
//find or create in store
$kind = $this->em->getRepository($this->class)->findOneBy(['name' => $uppername]);
if (!$kind) {
$kind = new Kind(new Name($uppername));
$this->em->persist($kind);
$this->em->flush();
}
/*
//cache it for next request
Cache::forever($key, $kind);
return Cache::get($key);
*/
return $kind;
}
示例9: onResponse
/**
* Process onReslonse event, updates user history information
*
* @param FilterResponseEvent $event
* @return bool|void
*/
public function onResponse(FilterResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
// Do not do anything
return;
}
$request = $event->getRequest();
$response = $event->getResponse();
// do not process requests other than in html format
// with 200 OK status using GET method and not _internal and _wdt
if (!$this->matchRequest($response, $request)) {
return false;
}
$postArray = ['url' => $request->getRequestUri(), 'user' => $this->user];
/** @var $historyItem NavigationHistoryItem */
$historyItem = $this->em->getRepository('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem')->findOneBy($postArray);
if (!$historyItem) {
/** @var $historyItem \Oro\Bundle\NavigationBundle\Entity\NavigationItemInterface */
$historyItem = $this->navItemFactory->createItem(NavigationHistoryItem::NAVIGATION_HISTORY_ITEM_TYPE, $postArray);
}
$historyItem->setTitle($this->titleService->getSerialized());
// force update
$historyItem->doUpdate();
$this->em->persist($historyItem);
$this->em->flush($historyItem);
return true;
}
示例10: testRemovePage
public function testRemovePage()
{
$page = new Page();
$page->setTitle('Test')->setContent('<p>test</p>')->setCurrentSlugUrl('/remove');
$this->entityManager->persist($page);
$childPage1 = new Page();
$childPage1->setTitle('Test child Page 1')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child1');
$this->entityManager->persist($childPage1);
$childPage2 = new Page();
$childPage2->setTitle('Test child Page 2')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child2');
$this->entityManager->persist($childPage2);
$page->addChildPage($childPage1);
$page->addChildPage($childPage2);
$this->entityManager->flush($page);
$pageSlugId = $page->getCurrentSlug()->getId();
$childPage1SlugId = $childPage1->getCurrentSlug()->getId();
$childPage2SlugId = $childPage2->getCurrentSlug()->getId();
$this->entityManager->remove($page);
$this->entityManager->flush();
// make sure data updated correctly
$this->entityManager->clear();
$this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $pageSlugId));
$this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage1SlugId));
$this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage2SlugId));
}
示例11: finishBatch
/**
* Finish processed batch
*/
protected function finishBatch()
{
$this->entityManager->flush();
if ($this->entityManager->getConnection()->getTransactionNestingLevel() == 1) {
$this->entityManager->clear();
}
}
示例12: duplicate
/**
* Duplicate Jam entities
*
* For details see
* {@link http://stackoverflow.com/questions/9071094/how-to-re-save-the-entity-as-another-row-in-doctrine-2}
*
* @param Jam $entity
* @param integer $count
*/
public function duplicate(Jam $entity, $count = 0)
{
for ($i = 0; $i < $count; $i++) {
$this->em->persist($this->cloneService->cloneObject($entity));
}
$this->em->flush();
}
示例13: formSucceeded
/**
* Callback method, that is called once form is successfully submitted, without validation errors.
*
* @param Form $form
* @param Nette\Utils\ArrayHash $values
*/
public function formSucceeded(Form $form, $values)
{
if (!($user = $this->userRepository->findOneBy(['email' => $values->email]))) {
$form['email']->addError("User with given email doesn't exist");
return;
}
// this is not a very secure way of getting new password
// but it's the same way the symfony app is doing it...
$newPassword = $user->generateRandomPassword();
$this->em->flush();
try {
$message = new Nette\Mail\Message();
$message->setSubject('Notejam password');
$message->setFrom('noreply@notejamapp.com');
$message->addTo($user->getEmail());
// !!! Never send passwords through email !!!
// This is only for demonstration purposes of Notejam.
// Ideally, you can create a unique link where user can change his password
// himself for limited amount of time, and then send the link.
$message->setBody("Your new password is {$newPassword}");
$this->mailer->send($message);
} catch (Nette\Mail\SendException $e) {
Debugger::log($e, 'email');
$form->addError('Could not send email with new password');
}
$this->onSuccess($this);
}
示例14: publish
/**
* Publishes a gif and posts a link on social networks
* @param Gif $gif
* @return bool
*/
public function publish(Gif $gif)
{
if (!$gif) {
return false;
}
if (!$gif->getGifStatus() == GifState::ACCEPTED) {
return false;
}
$gif->setPublishDate(new DateTime());
$gif->setGifStatus(GifState::PUBLISHED);
$gif->generateUrlReadyPermalink();
// Check if permalink is unique
/** @var GifRepository $gifsRepo */
$gifsRepo = $this->em->getRepository('LjdsBundle:Gif');
$permalink = $gif->getPermalink();
$i = 1;
while (!empty($gifsRepo->findBy(['permalink' => $gif->getPermalink(), 'gifStatus' => GifState::PUBLISHED]))) {
// Generate a new permalink
$gif->setPermalink($permalink . $i);
$i++;
}
$this->em->flush();
if ($this->facebookAutopost) {
$this->facebookService->postGif($gif);
}
if ($this->twitterAutopost) {
$this->twitterService->postGif($gif);
}
return true;
}
示例15: makeDrawForNextRound
/**
* @param Tournament $tournament
* @return void
*/
public function makeDrawForNextRound(Tournament $tournament)
{
$nextRound = $tournament->getCurrentRound() + 1;
$this->makeDraw($tournament, $nextRound);
$tournament->setCurrentRound($nextRound);
$this->manager->flush($tournament);
}