本文整理匯總了PHP中Doctrine\Common\Persistence\ObjectManager::clear方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectManager::clear方法的具體用法?PHP ObjectManager::clear怎麽用?PHP ObjectManager::clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::clear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
/**
* @param Message $message
*/
public function process(Message $message)
{
// Only process messages where ShareMonkey is mentioned
if ($this->shareMonkeyIsMentioned($message->getText()) === false) {
return;
}
$text = $message->getText();
$urls = $text->getUrls();
$tags = $text->getTags();
if (count($urls) === 0) {
$this->logger->debug('No urls found in message');
return;
}
$user = $this->userRepository->findOneBySlackId($message->getUserId());
if (!$user instanceof User) {
$this->logger->error(sprintf('User "%s" not found', $message->getUserId()->getValue()));
return;
}
foreach ($urls as $url) {
$this->logger->debug(sprintf('processing url %s', $url));
$info = Embed::create($url);
$link = Link::fromSlack($message->getId(), $user, $message->getCreatedAt(), $info->getTitle() ?: $message->getText(), $url, $tags);
$this->objectManager->persist($link);
$this->objectManager->flush();
$this->objectManager->clear();
$this->logger->debug(sprintf('Saved link %s', $link->getUrl()));
}
}
示例2: load
public function load(ObjectManager $manager)
{
$data = (include __DIR__ . '/../fixtures/user/users.php');
$encoder = $this->container->get('security.password_encoder');
$userManager = $this->container->get('medievistes.user_manager');
$connection = $manager->getConnection();
if ($connection->getDatabasePlatform()->getName() === 'mysql') {
$connection->exec("ALTER TABLE {$manager->getClassMetadata(User::class)->getTableName()} AUTO_INCREMENT = 1;");
}
foreach ($data as $userData) {
$class = $userManager->getUserClass($userData['type']);
$user = (new $class())->setId((int) $userData['id'])->setUsername($userData['username'])->setEmail($userData['email'])->setPlainPassword($userData['plain_password'])->setSalt(md5(uniqid(null, true)))->enable((bool) $userData['is_active'])->setCreatedAt(new \DateTime($userData['created_at']))->setUpdatedAt(new \DateTime($userData['updated_at']));
if (!empty($userData['activation_link_id'])) {
$user->setActivationLink($this->getReference("activation-link-{$userData['activation_link_id']}"));
}
foreach ($userData['roles'] as $role) {
$user->addRole($role);
}
foreach ($userData['troops'] as $troop) {
$association = (new Association())->setUser($user)->setTroop($this->getReference("troop-{$troop['troop_id']}"))->setRole($this->getReference("troop-role-{$troop['role_id']}"));
$user->addTroopAssociation($association);
$manager->persist($association);
}
$password = $encoder->encodePassword($user, $userData['plain_password']);
$user->setPassword($password);
$manager->persist($user);
$manager->flush();
$this->addReference("user-{$user->getId()}", $user);
}
$manager->clear($class);
$manager->clear(Association::class);
}
示例3: set
public function set($configKey, $value)
{
$configItem = $this->get($configKey);
if (!$configItem) {
$configItem = ConfigItemFactory::createConfigItem($configKey, $value, $this->applicationId);
}
$this->_em->persist($configItem);
$this->_em->flush();
$this->_em->clear();
return $configItem;
}
示例4: saveRatioList
/**
* @param array $ratioList
*/
public function saveRatioList($ratioList)
{
$doctrineStorageRatios = $this->objectManager->getRepository('Tbbc\\MoneyBundle\\Entity\\DoctrineStorageRatio')->findAll();
foreach ($doctrineStorageRatios as $doctrineStorageRatio) {
$this->objectManager->remove($doctrineStorageRatio);
}
$this->objectManager->flush();
foreach ($ratioList as $currencyCode => $ratio) {
$this->objectManager->persist(new DoctrineStorageRatio($currencyCode, $ratio));
}
$this->objectManager->flush();
$this->objectManager->clear();
$this->ratioList = $ratioList;
}
示例5: execute
public function execute()
{
/** @var Ticket $ticket */
$ticket = $this->context->getFact()->getTarget();
$branchId = $this->context->getParameters()->has('branch') ? $this->context->getParameters()->get('branch') : null;
if (is_null($branchId)) {
throw new \RuntimeException("Invalid rule configuration");
}
$branch = $this->em->getRepository('DiamanteDeskBundle:Branch')->get($branchId);
$ticket->move($branch);
$this->em->persist($ticket);
$this->em->flush();
$this->em->clear($ticket);
}
示例6: load
/**
* Load fixtures.
*
* @param \Doctrine\Common\Persistence\ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$manager->clear();
$discriminator = $this->container->get('pugx_user.manager.user_discriminator');
$discriminator->setClass('Truckee\\MatchBundle\\Entity\\Staff');
$userManager = $this->container->get('pugx_user_manager');
$staff = $userManager->createUser();
$staff->setUsername('jmelanzane');
$staff->setEmail('jmelanzane@bogus.info');
$staff->setPlainPassword('123Abcd');
$staff->setEnabled(true);
$staff->setFirstName('Joe');
$staff->setLastName('Melanzane');
$staff->addRole('ROLE_STAFF');
$org = new Organization();
$org->setOrgName('Glenshire Marmite Fund');
$org->setAddress('PO Box 999');
$org->setCity('Truckee');
$org->setState('CA');
$org->setZip('96160');
$org->setWebsite('www.melanzanemarmots.org');
$org->setEmail('jmelanzane@bogus.info');
$org->setTemp(true);
$foc1 = $manager->getRepository('TruckeeMatchBundle:Focus')->findOneByFocus('Seniors');
$org->addFocus($foc1);
$manager->persist($org);
$staff->setOrganization($org);
$manager->flush();
$userManager->updateUser($staff, true);
}
示例7: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
foreach ($this->attributes as $item) {
// Create attribute label
$label = new AttributeLabel();
$label->setValue($item['label']);
// Create attribute
$attribute = new Attribute();
$attribute->setCode($item['code']);
$attribute->setType($item['type']);
$attribute->setSharingType(SharingType::GENERAL);
$attribute->setLocalized($item['localized']);
$attribute->setSystem($item['system']);
$attribute->setRequired($item['required']);
$attribute->setUnique($item['unique']);
$attribute->addLabel($label);
if (isset($item['options'])) {
foreach ($item['options'] as $optionItem) {
$masterOption = new AttributeOption();
$masterOption->setValue($optionItem['value']);
$masterOption->setOrder($optionItem['order']);
$attribute->addOption($masterOption);
}
}
$manager->persist($attribute);
}
if (!empty($this->attributes)) {
$manager->flush();
$manager->clear();
}
}
示例8: load
/**
* Load fixtures.
*
* @param \Doctrine\Common\Persistence\ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$manager->clear();
$discriminator = $this->container->get('pugx_user.manager.user_discriminator');
$discriminator->setClass('Truckee\\MatchBundle\\Entity\\Staff');
$userManager = $this->container->get('pugx_user_manager');
$staff = $userManager->createUser();
$staff->setUsername('bborko');
$staff->setEmail('bborko@bogus.info');
$staff->setPlainPassword('123Abcd');
$staff->setEnabled(true);
$staff->setFirstName('Benny');
$staff->setLastName('Borko');
$staff->addRole('ROLE_STAFF');
$org = new Organization();
$org->setOrgName('Turkeys R Us');
$org->setAddress('PO Box 234');
$org->setCity('Truckee');
$org->setState('CA');
$org->setZip('96160');
$org->setWebsite('www.turkeys.org');
$org->setEmail('turkeys@bogus.info');
$org->setTemp(false);
$org->setAddDate(new \DateTime());
$foc1 = $manager->getRepository('TruckeeMatchBundle:Focus')->findOneByFocus('Animal Welfare');
$org->addFocus($foc1);
$manager->persist($org);
$staff->setOrganization($org);
$manager->flush();
$userManager->updateUser($staff, true);
}
示例9: load
/**
* @param array $options
*/
public final function load(array $options)
{
$options = $this->optionsResolver->resolve($options);
$i = 0;
foreach ($options['custom'] as $resourceOptions) {
$resource = $this->exampleFactory->create($resourceOptions);
$this->objectManager->persist($resource);
++$i;
if (0 === $i % 10) {
$this->objectManager->flush();
$this->objectManager->clear();
}
}
$this->objectManager->flush();
$this->objectManager->clear();
}
示例10: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$manager->clear();
$focus = new Focus();
$focus->setFocus('All');
$focus->setEnabled(true);
$manager->persist($focus);
$skill = new Skill();
$skill->setSkill('All');
$skill->setEnabled(true);
$manager->persist($skill);
$manager->flush();
$discriminator = $this->container->get('pugx_user.manager.user_discriminator');
$discriminator->setClass('Truckee\\MatchBundle\\Entity\\Admin');
$userManager = $this->container->get('pugx_user_manager');
$admin = $userManager->createUser();
$userName = $this->container->getParameter('admin_username');
$email = $this->container->getParameter('admin_email');
$password = $this->container->getParameter('admin_password');
$firstName = $this->container->getParameter('admin_first_name');
$lastName = $this->container->getParameter('admin_last_name');
$admin->setUsername($userName);
$admin->setEmail($email);
$admin->setPlainPassword($password);
$admin->setEnabled(true);
$admin->setFirstName($firstName);
$admin->setLastName($lastName);
$admin->addRole('ROLE_SUPER_ADMIN');
$userManager->updateUser($admin, true);
}
示例11: load
/**
* @param DocumentManager $manager
*/
public function load(ObjectManager $manager)
{
$this->root = $manager->find(null, '/test');
$doc = new TestDocument();
$doc->id = '/test/doc';
$doc->bool = true;
$doc->date = new \DateTime('2014-01-14');
$doc->integer = 42;
$doc->long = 24;
$doc->number = 3.14;
$doc->text = 'text content';
$manager->persist($doc);
$doc = new TestDocument();
$doc->id = '/test/doc2';
$doc->bool = true;
$doc->date = new \DateTime('2014-01-14');
$doc->integer = 42;
$doc->long = 24;
$doc->number = 3.14;
$doc->text = 'text content';
$manager->persist($doc);
$ref = new ReferrerDocument();
$ref->id = '/test/ref';
$ref->addDocument($doc);
$manager->persist($ref);
$manager->flush();
$node = $manager->getPhpcrSession()->getNode('/test/doc');
$node->addNode('child');
$node->addNode('second');
$manager->getPhpcrSession()->save();
$manager->clear();
}
示例12: saveEntities
/**
* @param ObjectManager $manager
* @param array $entities
*/
protected function saveEntities(ObjectManager $manager, array $entities)
{
foreach ($entities as $activity) {
$manager->persist($activity);
}
$manager->flush();
$manager->clear();
}
示例13: decrementTotalFlushSize
/**
* @param ObjectManager $manager
*/
public function decrementTotalFlushSize(ObjectManager $manager)
{
--$this->totalFlushSize;
if ($this->totalFlushSize % $this->maxFlushSize === 0 || $this->totalFlushSize === 0) {
$manager->flush();
$manager->clear();
}
}
示例14: populateCountries
/**
* Populate geo schema given a set of country codes and flush all countries.
*
* This method assumes that country and all the structure is defined with
* persist=cascade, so persisting and flushing just the country, all
* structure will be persisted and flushed
*
* @param OutputInterface $output The output interface
* @param array $countryCodes Set of country codes
* @param boolean $sourcePackageMustbeReloaded Source package must be reloaded
*
* @return $this self Object
*/
public function populateCountries(OutputInterface $output, $countryCodes, $sourcePackageMustbeReloaded)
{
foreach ($countryCodes as $countryCode) {
$country = $this->populateCountry($output, $countryCode, $sourcePackageMustbeReloaded);
if (!is_null($country)) {
$started = new DateTime();
$output->writeln('<header>[Geo]</header> <body>Starting flushing manager</body>');
$this->countryObjectManager->persist($country);
$this->countryObjectManager->flush($country);
$this->countryObjectManager->clear($country);
$finished = new DateTime();
$elapsed = $finished->diff($started);
$output->writeln('<header>[Geo]</header> <body>Manager flushed in ' . $elapsed->format('%s') . ' seconds</body>');
}
}
return $this;
}
示例15: load
public function load(ObjectManager $manager)
{
$data = (include __DIR__ . '/../fixtures/agility/feedbacks.php');
foreach ($data as $feedbackData) {
$feedback = (new Feedback())->setName($feedbackData['name'])->setSlug($feedbackData['slug'])->setDescription($feedbackData['description'])->setAuthor($this->getReference("user-{$feedbackData['author_id']}"))->setProject($this->getReference("agility-project-{$feedbackData['project_id']}"))->setStatus($feedbackData['status'])->setCreatedAt(new \DateTime($feedbackData['created_at']))->setUpdatedAt(new \DateTime($feedbackData['updated_at']));
$manager->persist($feedback);
}
$manager->flush();
$manager->clear(Feedback::class);
}