/** * @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())); } }
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); }
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; }
/** * @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; }
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); }
/** * 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('*****@*****.**'); $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('*****@*****.**'); $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); }
/** * {@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(); } }
/** * 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('*****@*****.**'); $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('*****@*****.**'); $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); }
/** * @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(); }
/** * {@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); }
/** * @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(); }
/** * @param ObjectManager $manager * @param array $entities */ protected function saveEntities(ObjectManager $manager, array $entities) { foreach ($entities as $activity) { $manager->persist($activity); } $manager->flush(); $manager->clear(); }
/** * @param ObjectManager $manager */ public function decrementTotalFlushSize(ObjectManager $manager) { --$this->totalFlushSize; if ($this->totalFlushSize % $this->maxFlushSize === 0 || $this->totalFlushSize === 0) { $manager->flush(); $manager->clear(); } }
/** * 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; }
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); }
/** * {@inheritdoc} */ public function load($file) { $this->eventDispatcher->dispatch(static::EVENT_STARTED, new FixtureLoaderEvent($file)); $this->reader->setFilePath($file); if ($this->multiple) { $items = $this->reader->read(); foreach ($this->processor->process($items) as $object) { $this->persistObjects($object); } } else { while ($item = $this->reader->read()) { $this->persistObjects($this->processor->process($item)); } } $this->objectManager->flush(); $this->objectManager->clear(); $this->doctrineCache->clear(); $this->eventDispatcher->dispatch(static::EVENT_COMPLETED, new FixtureLoaderEvent($file)); }
/** * Load fixtures * * @param \Doctrine\Common\Persistence\ObjectManager $manager */ public function load(ObjectManager $manager) { $manager->clear(); gc_collect_cycles(); // Could be useful if you have a lot of fixtures $this->eventId = 0; $manager->persist(new PostList(1, 'Title One')); $manager->persist(new PostList(2, 'Title Two')); $manager->flush(); }
public function load(ObjectManager $manager) { $data = (include __DIR__ . '/../fixtures/agility/projects.php'); foreach ($data as $projectData) { $project = (new Project())->setId($projectData['id'])->setName($projectData['name'])->setSlug($projectData['slug'])->setDescription($projectData['description'])->setBetaTestStatus('open')->setNbBetaTesters(5)->setProductOwner($this->getReference("user-{$projectData['product_owner_id']}"))->setCreatedAt(new \DateTime($projectData['created_at'])); $manager->persist($project); $this->addReference("agility-project-{$project->getId()}", $project); } $manager->flush(); $manager->clear(Project::class); }
public function load(ObjectManager $manager) { $data = (include __DIR__ . '/../fixtures/troop/centuries.php'); foreach ($data as $centuryData) { $century = (new Century())->setCentury($centuryData); $manager->persist($century); $this->addReference("century-{$centuryData}", $century); } $manager->flush(); $manager->clear(Century::class); }
public function load(ObjectManager $manager) { $data = (include __DIR__ . '/../fixtures/troop/membership_requests.php'); foreach ($data as $membershipRequestData) { $membershipRequest = (new MembershipRequest())->setUser($this->getReference("user-{$membershipRequestData['user_id']}"))->setTroop($this->getReference("troop-{$membershipRequestData['troop_id']}"))->setDetails($membershipRequestData['details']); $manager->persist($membershipRequest); $this->addReference("membership-request-{$membershipRequestData['id']}", $membershipRequest); } $manager->flush(); $manager->clear(MembershipRequest::class); }
public function load(ObjectManager $manager) { $data = (include 'fixtures/addresses.php'); foreach ($data as $addressData) { $address = (new Address())->setId($addressData['id'])->setStreetName($addressData['street_name'])->setCity($addressData['city'])->setCountry($addressData['country'])->setZipCode($addressData['zip_code']); $manager->persist($address); $this->addReference("address-{$address->getId()}", $address); } $manager->flush(); $manager->clear(Address::class); }
public function load(ObjectManager $manager) { $data = (include __DIR__ . '/../fixtures/troop/roles.php'); foreach ($data as $roleData) { $role = (new Role())->setId($roleData['id'])->setTroop($this->getReference("troop-{$roleData['troop_id']}"))->setLabel($roleData['label'])->setSlug($roleData['slug'])->setPosition($roleData['position']); $manager->persist($role); $this->addReference("troop-role-{$roleData['id']}", $role); } $manager->flush(); $manager->clear(Role::class); }
protected function persistObject($object, ObjectManager $manager) { $manager->persist($object); if ($this->maxFlushSize !== null) { $this->decrementTotalFlushSize(); if ($this->totalFlushSize % $this->maxFlushSize === 0 || $this->totalFlushSize === 0) { $manager->flush(); $manager->clear(); } } }
public function load(ObjectManager $manager) { $data = (include 'fixtures/activation_links.php'); foreach ($data as $activationLinkData) { $activationLink = (new ActivationLink())->setId($activationLinkData['id'])->setHash($activationLinkData['hash'])->setCreatedAt(new \DateTime($activationLinkData['created_at'])); $manager->persist($activationLink); $this->addReference("activation-link-{$activationLink->getId()}", $activationLink); } $manager->flush(); $manager->clear(ActivationLink::class); }
/** * Load fixtures * * @param \Doctrine\Common\Persistence\ObjectManager $manager */ public function load(ObjectManager $manager) { $manager->clear(); gc_collect_cycles(); // Could be useful if you have a lot of fixtures $this->eventId = 0; $this->generateEvents($manager, 'Entity', new Id(1), 3); $this->generateEvents($manager, 'Other', new Id(1), 4); $this->generateEvents($manager, 'Entity', new Id(2), 6); $manager->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $em) { for ($i = 1; $i < 5; $i++) { $menu = new Menu(); $menu->setName("Parent_{$i}"); $menu->setDescription("Parent_{$i} description"); $menu->setParent(0); $menu->setRoute("parent/{$i}"); $menu->setIsActive(1); $menu->setRoles(0); $menu->setSort($i * 777); $em->persist($menu); } $em->flush(); $em->clear(); for ($i = 5; $i < 41; $i++) { $menu = new Menu(); if ($i <= 40) { $p = 4; } if ($i <= 30) { $p = 3; } if ($i <= 20) { $p = 2; } if ($i <= 10) { $p = 1; } $menu->setName("Child_{$i} of {$p}"); $menu->setDescription("Child_{$i} of {$p} description"); $menu->setParent($p); $menu->setRoute("child/{$i}"); $menu->setIsActive(1); $menu->setRoles(0); $menu->setSort($i * 777); $em->persist($menu); } $em->flush(); $em->clear(); }
public function load(ObjectManager $om) { $om->clear(); //Februus $start = \DateTime::createFromFormat("d-m-Y H:i:s", "06-02-2016 16:00:00"); $finish = \DateTime::createFromFormat("d-m-Y H:i:s", "06-02-2016 19:00:00"); $event = new Event(); $event->setTitle("AnkaraPHP Februus")->setDescription("February event")->setLocation("Kivilcim TTGV")->setStart($start)->setFinish($finish); $this->addReference('event-februus', $event); $om->persist($event); $om->flush(); }
/** * @param Reaction $reaction */ public function process(Reaction $reaction) { // Only process reaction on saved links $link = $this->linkRepository->findOneBySlackMessageId($reaction->getMessageId()); if (!$link instanceof Link) { return; } $user = $this->userRepository->findOneBySlackId($reaction->getUserId()); if (!$user instanceof User) { $this->logger->error(sprintf('User "%s" not found', $reaction->getUserId())); return; } if ($reaction->isLike()) { $link->likedBy($user); } if ($reaction->isDislike()) { $link->dislikedBy($user); } $this->objectManager->flush(); $this->objectManager->clear(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { foreach ($this->productUnits as $item) { $productUnit = new ProductUnit(); $productUnit->setCode($item['code'])->setDefaultPrecision($item['defaultPrecision']); $manager->persist($productUnit); } if (!empty($this->productUnits)) { $manager->flush(); $manager->clear(); } }
/** * Insert new users * * @param Collection $users */ private function insertUsers(Collection $users) { set_time_limit(60); $this->manager->getConnection()->getConfiguration()->setSQLLogger(null); // Get existan user from DB $existantUsers = $this->repository->findBy(['email' => $this->extractEmails($users)->toArray()]); // Create an array of emails $existantEmails = array_map(function ($user) { return $user->getEmail(); }, $existantUsers); unset($existantUsers); // Get not existant users ready to import $nonExistantUsers = $users->filter(function ($user) use($existantEmails) { return !in_array($user->getEmail(), $existantEmails); }); unset($existantEmails); foreach ($nonExistantUsers as $user) { $user->addRole('ROLE_USER'); $this->manager->persist($user); $this->manager->flush(); $this->manager->clear(); $this->manager->detach($user); gc_enable(); gc_collect_cycles(); } }