本文整理汇总了PHP中Doctrine\ORM\EntityManager::refresh方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::refresh方法的具体用法?PHP EntityManager::refresh怎么用?PHP EntityManager::refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refreshEntity
/**
* Refreshes an entity with real translations
* @param $entity
* @param $language
*
* @author Yohann Marillet
*/
public function refreshEntity($entity, $language)
{
$translatableProperties = $this->getTranslatableProperties($entity);
$setLocaleMethod = $translatableProperties['setLocaleMethod'];
$entity->{$setLocaleMethod}($language);
$this->em->refresh($entity);
if ($this->defaultLocale != $language) {
if (false !== $translatableProperties['usePersonalTranslations']) {
/** @var HasTranslations $entity */
$allTranslations = $entity->getTranslations();
$translations = [];
/** @var AbstractPersonalTranslation $translationEntity */
foreach ($allTranslations as $translationEntity) {
if (!isset($translations[$translationEntity->getLocale()])) {
$translations[$translationEntity->getLocale()] = [];
}
$translations[$translationEntity->getLocale()][$translationEntity->getField()] = $translationEntity->getContent();
}
} else {
$translations = $this->getRepository()->findTranslations($entity);
}
if (!isset($translations[$language])) {
$translations[$language] = $translatableProperties['fields'];
}
foreach ($translations[$language] as $field => $value) {
$setter = Strings::toSetter($field);
$entity->{$setter}($value);
}
}
}
示例2: insert
public function insert(array $data)
{
$entity = new $this->entity($data);
$this->em->persist($entity);
$this->em->flush();
$this->em->refresh($entity);
return $entity;
}
示例3: testPut
public function testPut()
{
$data = ['isExpanded' => 1, 'layoutPosition' => [2, 20]];
$this->client->request('PUT', $this->getUrl('oro_api_put_dashboard_widget', ['dashboardId' => $this->widget->getDashboard()->getId(), 'widgetId' => $this->widget->getId()]), $data);
$result = $this->client->getResponse();
$this->assertEmptyResponseStatusCodeEquals($result, 204);
$this->em->refresh($this->widget);
$model = $this->dashboardManager->findWidgetModel($this->widget->getId());
$this->assertEquals($data['isExpanded'], $model->isExpanded());
$this->assertEquals($data['layoutPosition'], $this->widget->getLayoutPosition());
$this->assertEquals($data['layoutPosition'], $model->getLayoutPosition());
}
示例4: userIsUnsubscribed
/**
* @Given /^пользователь "([^"]*)" должен быть отписан от рассылки$/
*/
public function userIsUnsubscribed($username)
{
$user = $this->em->getRepository('ApplicationUserBundle:User')->findOneBy(['username' => $username]);
$this->em->refresh($user);
Assert::assertNotNull($user);
Assert::assertFalse($user->isSubscribe());
}
示例5: mergeFolders
/**
* @param EmailFolderModel[]|ArrayCollection $syncedFolderModels
* @param ImapEmailFolder[]|ArrayCollection $existingImapFolders
*
* @return EmailFolderModel[]
*/
protected function mergeFolders($syncedFolderModels, &$existingImapFolders)
{
foreach ($syncedFolderModels as $syncedFolderModel) {
$f = $existingImapFolders->filter(function (ImapEmailFolder $imapEmailFolder) use($syncedFolderModel) {
return $imapEmailFolder->getUidValidity() === $syncedFolderModel->getUidValidity();
});
if ($f->isEmpty()) {
// there is a new folder on server, create it
$imapEmailFolder = $this->createImapEmailFolder($syncedFolderModel);
// persist ImapEmailFolder and (by cascade) EmailFolder
$this->em->persist($imapEmailFolder);
} else {
/** @var ImapEmailFolder $existingImapFolder */
$existingImapFolder = $f->first();
$emailFolder = $existingImapFolder->getFolder();
$this->em->refresh($emailFolder);
$emailFolder->setName($syncedFolderModel->getEmailFolder()->getName());
$emailFolder->setFullName($syncedFolderModel->getEmailFolder()->getFullName());
$emailFolder->setType($syncedFolderModel->getEmailFolder()->getType());
$emailFolder->setSynchronizedAt($syncedFolderModel->getEmailFolder()->getSynchronizedAt());
$syncedFolderModel->setEmailFolder($emailFolder);
$existingImapFolders->removeElement($existingImapFolder);
}
if ($syncedFolderModel->hasSubFolderModels()) {
$syncedFolderModel->setSubFolderModels($this->mergeFolders($syncedFolderModel->getSubFolderModels(), $existingImapFolders));
}
}
return $syncedFolderModels;
}
示例6: testDeactivateAndActivateActions
public function testDeactivateAndActivateActions()
{
// set and assert active workflow
$this->getWorkflowManager()->activateWorkflow(LoadWorkflowDefinitions::WITH_START_STEP);
$this->assertActiveWorkflow($this->entityClass, LoadWorkflowDefinitions::WITH_START_STEP);
// create and assert test entity
$testEntity = $this->createNewEntity();
$this->assertEntityWorkflowItem($testEntity, LoadWorkflowDefinitions::WITH_START_STEP);
// deactivate workflow for entity
$this->client->request('GET', $this->getUrl('oro_workflow_api_rest_workflow_deactivate', array('entityClass' => $this->entityClass)));
$result = $this->getJsonResponseContent($this->client->getResponse(), 200);
$this->assertActivationResult($result);
$this->assertActiveWorkflow($this->entityClass, null);
// assert that entity still has relation to workflow
$this->entityManager->refresh($testEntity);
$this->assertEntityWorkflowItem($testEntity, LoadWorkflowDefinitions::WITH_START_STEP);
// activate other workflow through API
$this->client->request('GET', $this->getUrl('oro_workflow_api_rest_workflow_activate', array('workflowDefinition' => LoadWorkflowDefinitions::NO_START_STEP)));
$result = $this->getJsonResponseContent($this->client->getResponse(), 200);
$this->assertActivationResult($result);
$this->assertActiveWorkflow($this->entityClass, LoadWorkflowDefinitions::NO_START_STEP);
// assert that entity workflow item was reset
$this->entityManager->refresh($testEntity);
$this->assertEntityWorkflowItem($testEntity, null);
}
示例7: applicationSignAction
public function applicationSignAction(Request $request)
{
/** @var ClientAccount $account */
$account = $this->em->getRepository('WealthbotClientBundle:ClientAccount')->find($request->get('account_id'));
if (!$account) {
throw $this->createNotFoundException();
}
$signature = $this->signatureManager->findActiveDocumentSignatureBySourceIdAndType($account->getId(), DocumentSignature::TYPE_OPEN_OR_TRANSFER_ACCOUNT);
if (!$signature) {
throw $this->createNotFoundException();
}
if (null === $signature->getDocusignEnvelopeId()) {
$this->electronicSignature->sendEnvelopeForApplication($account);
$this->em->refresh($signature);
}
$envelopeId = $signature->getDocusignEnvelopeId();
$primaryApplicant = $account->getPrimaryApplicant();
if ($primaryApplicant instanceof AccountOwnerInterface) {
$recipient = new AccountOwnerRecipientAdapter($primaryApplicant);
$returnUrl = $this->generateUrl('wealthbot_docusign_application_sign_callback', array('envelope_id' => $envelopeId, 'application_id' => $account->getId()), true);
$embeddedUrl = $this->api->getEmbeddedSigningUrl($envelopeId, $recipient, $returnUrl);
if ($embeddedUrl) {
return $this->render('WealthbotSignatureBundle:Default:application_sign_iframe.html.twig', array('url' => $embeddedUrl));
}
}
return $this->render('WealthbotSignatureBundle:Default:application_sign_error.html.twig', array('message' => 'An error has occurred. Please try again later.'));
}
示例8: addNewUser
protected function addNewUser($username, $email, $password, $active = true, $banned = false, $persist = true, $andFlush = true)
{
$user = new User();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled($active);
$user->setLocked($banned);
if ($persist) {
$this->em->persist($user);
if ($andFlush) {
$this->em->flush();
$this->em->refresh($user);
}
}
return $user;
}
示例9: set
/**
* Set parameter value, if parameter does not exist, create one.
*
* @param type $entity
* @param type $name
* @param type $value
* @param type $type parameter data type (string, integer, boolean, text)
*/
public function set($entity, $name, $value, $category = E\Parameter::CATEGORY_GENERAL)
{
$param = $this->findParameter($entity, $name);
if (!$param instanceof \Application\MainBundle\Entity\Parameter) {
list($entityType, $entityId) = $this->getEntityData($entity);
$param = new E\Parameter();
$param->setEntityType($entityType)->setEntityId($entityId)->setName($name)->setCategory($category);
}
if ($param->isDeleted()) {
$param->restore();
$this->em->flush();
$this->em->refresh($param);
}
$param->setValue($value);
$this->em->persist($param);
$this->em->flush();
return $param;
}
示例10: testActivateDeactivate
public function testActivateDeactivate()
{
$definition = $this->createNewEnabledProcessDefinition();
$definitionName = $definition->getName();
$this->assertTrue($definition->isEnabled());
// deactivate process
$this->client->request('GET', $this->getUrl('oro_workflow_api_rest_process_deactivate', array('processDefinition' => $definitionName)));
$this->assertResult($this->getJsonResponseContent($this->client->getResponse(), 200));
// assert that process definition item was deactivated
$this->entityManager->refresh($definition);
$this->assertFalse($definition->isEnabled());
// activate process
$this->client->request('GET', $this->getUrl('oro_workflow_api_rest_process_activate', array('processDefinition' => $definitionName)));
$this->assertResult($this->getJsonResponseContent($this->client->getResponse(), 200));
// assert that process definition item was activated
$this->entityManager->refresh($definition);
$this->assertTrue($definition->isEnabled());
}
示例11: onOpen
/**
* @param ConnectionInterface $conn
*/
public function onOpen(ConnectionInterface $conn)
{
$userData = $conn->Session->get('user');
if (count($userData) == 2 && is_int($userData[0])) {
list($userId, $userRole) = $userData;
$user = User::find($userId);
if (null === $user) {
$conn->close();
return;
}
$this->em->refresh($user);
$conn->user = $user;
$this->send(Protocol::userJoin($user));
$this->clients[$user->id] = $conn;
$users = array();
foreach ($this->clients as $conn) {
$users[] = $conn->user->export();
}
$this->sendToUser($user->id, Protocol::data(Protocol::SYNCHRONIZE, $users));
} else {
$conn->close();
}
}
示例12: retrieveConfigurationFromSecret
private function retrieveConfigurationFromSecret(ConnectionInterface $from, array $msg, $type, $comKey)
{
$secret = $msg['secret'];
$user = $this->em->getRepository('AppBundle:User')->findOneBy(['secret' => $secret]);
if (!$user) {
$this->answerError($from, $type, $comKey, 'Invalid secret');
return;
}
$this->em->refresh($user);
$config = ['socket_url' => $this->socketUrl, 'web_url' => $this->webUrl, 'secret' => $user->getSecret(), 'web_hooks' => []];
foreach ($user->getWebHooks() as $webHook) {
$config['web_hooks'][] = ['endpoint' => $webHook->getEndpoint()];
}
$this->answer($from, $type, $comKey, $config);
$this->logger->info("Configuration retrieved for user", ['user' => $user->getUsername(), 'conn' => $from->resourceId, 'ck' => $comKey]);
}
示例13: addNewSubscription
protected function addNewSubscription($forum, $topic, $user, $isRead = false, $persist = true, $andFlush = true)
{
$subscription = $this->getSubscriptionModel()->createSubscription();
$subscription->setTopic($topic);
$subscription->setOwnedBy($user);
$subscription->setForum($forum);
$subscription->setRead($isRead);
$subscription->setSubscribed(true);
if ($persist) {
$this->em->persist($subscription);
if ($andFlush) {
$this->em->flush();
$this->em->refresh($subscription);
}
}
return $subscription;
}
示例14: refresh
/**
* Refresh entity.
*
* @param BaseEntityAbstract $entity
*
* @return $this
*/
public function refresh(BaseEntityAbstract $entity)
{
$this->entityManager->refresh($entity);
$metaData = $this->entityManager->getClassMetaData($this->entityName);
$mappings = $metaData->getAssociationMappings();
foreach ($mappings as $mapping) {
$fieldName = $mapping['fieldName'];
$assoc = $entity->{$fieldName};
if ($assoc instanceof \Traversable) {
foreach ($assoc as $ent) {
if ($ent instanceof BaseEntityAbstract) {
$this->entityManager->refresh($ent);
}
}
} elseif ($assoc instanceof BaseEntityAbstract) {
$this->entityManager->refresh($assoc);
}
}
return $this;
}
示例15: testPositions
/**
* @param array $widgets
* @param array $expectedPositions
*
* @dataProvider widgetsProvider
*/
public function testPositions($widgets, $expectedPositions)
{
foreach ($widgets as $widget) {
$this->em->persist($widget);
}
$this->em->flush();
$dashboard = null;
$data = ['layoutPositions' => []];
foreach ($widgets as $widget) {
/* @var Widget $widget */
$data['layoutPositions'][$widget->getId()] = array_map(function ($item) {
return $item * 10;
}, $widget->getLayoutPosition());
$dashboard = $widget->getDashboard();
}
$this->client->request('PUT', $this->getUrl('oro_api_put_dashboard_widget_positions', ['dashboardId' => $dashboard->getId()]), $data);
$result = $this->client->getResponse();
$this->assertEmptyResponseStatusCodeEquals($result, 204);
foreach ($widgets as $key => $widget) {
$this->em->refresh($widget);
$this->assertEquals($expectedPositions[$key], $widget->getLayoutPosition());
}
}