/** * @medium */ public function testImportExport() { $sourceStorage = new LocalFileStorage(new \SplFileInfo(__DIR__ . '/../../../metadata/testfiles/100.csv'), new CsvFormat()); $targetStorage = new DoctrineStorage(self::$em, 'TestEntities\\Address'); $this->assertEquals(new StorageInfo(['name' => 'SELECT o FROM TestEntities\\Address o', 'count' => 0, 'type' => 'DQL Query']), $targetStorage->info()); $importer = Importer::build($targetStorage); $importConfiguration = new ImportConfiguration(); $importRun = $importConfiguration->toRun(); $import = Import::build($importer, $sourceStorage, $importRun); $eventDispatcher = new EventDispatcher(); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $importRunner->run($import); $entities = self::$em->getRepository('TestEntities\\Address')->findAll(); //import worked $this->assertEquals(100, count($entities)); $exportFile = '/tmp/doctrine_test.csv'; @unlink($exportFile); $sourceStorage = new DoctrineStorage(self::$em, null, self::$em->createQuery("SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'")); $this->assertEquals(new StorageInfo(['name' => "SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'", 'count' => 10, 'type' => 'DQL Query']), $sourceStorage->info()); $targetStorage = new LocalFileStorage(new \SplFileInfo($exportFile), new CsvFormat()); $importer = Importer::build($targetStorage); $importConfiguration = new ImportConfiguration(); $importRun = $importConfiguration->toRun(); $import = Import::build($importer, $sourceStorage, $importRun); $eventDispatcher = new EventDispatcher(); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $importRunner->run($import); $this->assertFileExists($exportFile); $this->assertEquals(11, count(file($exportFile))); //+header $this->assertEquals(10, $import->getRun()->toArray()['statistics']['processed']); }
/** * {@inheritdoc} */ public function startJobs(ProjectInterface $project) { $query = 'UPDATE Worldia\\Bundle\\TextmasterBundle\\Entity\\Job j ' . 'SET j.status = :status ' . 'WHERE j.projectId = :projectId '; $q = $this->entityManager->createQuery($query)->setParameter('status', JobInterface::STATUS_STARTED)->setParameter('projectId', $project->getId()); $q->execute(); $this->entityManager->clear(); }
private function fillData() { self::$data = []; $q = $this->entityManager->createQuery("select partial c.{id,name,value} from ItBlaster\\SingleConfigBundle\\Entity\\Config c"); $res = $q->execute(null, Query::HYDRATE_ARRAY); foreach ($res as $k => $v) { self::$data[$v['name']] = $v['value']; } }
public function it_performs_a_fulltext_query(EntityManagerInterface $entityManager, AbstractQuery $query, $result = []) { $entityManager->createQuery(Argument::any())->shouldBeCalled()->willReturn($query); $query->setParameter(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($query); $query->getResult()->shouldBeCalled()->willReturn($result); $this->query('black', $entityManager)->shouldBeArray(); }
/** * @param $fileName * @return bool */ protected function uniqueNameExists($fileName, EntityManagerInterface $em) { $dql = "SELECT COUNT(image) FROM EDVFileBundle:EdImage AS image WHERE image.hashString = :name"; $query = $em->createQuery($dql)->setParameters(array('name' => $fileName)); $result = $query->getSingleScalarResult(); return $result > 0; }
/** * @param Supplier $supplier * @param EntityManagerInterface $entityManager * @return null */ public function import(Supplier $supplier, EntityManagerInterface $entityManager) { $params = array('input/webpage/url' => $this->url, '_user' => $this->importIoConfig['user_id'], '_apikey' => $this->importIoConfig['api_key']); $result = $this->DataSource->query($this->importIoConfig['connectorGuid'], $params); if ($result = json_decode($result)) { // delete all supplier products $entityManager->createQuery('DELETE ProductBundle:Product p WHERE p.supplier = :supplier')->setParameter('supplier', $supplier)->execute(); $this->createProducts($entityManager, $supplier, $result); } }
public function existsAnyShipmentOption() { $query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentPersonalPoint'); $query->setMaxResults(1); if (count($query->getResult()) > 0) { return true; } $query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentCollectionPoint'); $query->setMaxResults(1); if (count($query->getResult()) > 0) { return true; } $query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentTransportCompany'); $query->setMaxResults(1); if (count($query->getResult()) > 0) { return true; } return false; }
protected function clearDb() { // We can't rely on FK delete cascade as long as we're using sqlite for // tests. Doctrine doesn't enable FK support for it. $this->em->createQuery('delete from common\\entities\\Outpost')->execute(); $this->em->createQuery('delete from common\\entities\\CelestialBody')->execute(); $this->em->createQuery('delete from common\\entities\\System')->execute(); $this->em->createQuery('delete from common\\entities\\Galaxy')->execute(); $this->em->createQuery('delete from common\\entities\\CelestialBodyTypeSpecs')->execute(); $this->em->createQuery('delete from common\\entities\\Universe')->execute(); $this->em->createQuery('delete from common\\entities\\User')->execute(); $this->em->flush(); }
/** * Constructs a Query instance from the current specifications of the builder. * * <code> * $qb = $em->createQueryBuilder() * ->select('u') * ->from('User', 'u'); * $q = $qb->getQuery(); * $results = $q->execute(); * </code> * * @return Query */ public function getQuery() { $parameters = clone $this->parameters; $query = $this->_em->createQuery($this->getDQL())->setParameters($parameters)->setFirstResult($this->_firstResult)->setMaxResults($this->_maxResults); if ($this->lifetime) { $query->setLifetime($this->lifetime); } if ($this->cacheMode) { $query->setCacheMode($this->cacheMode); } if ($this->cacheable) { $query->setCacheable($this->cacheable); } if ($this->cacheRegion) { $query->setCacheRegion($this->cacheRegion); } return $query; }
/** * @return Order[]|\Traversable */ public function getAll($limit, $offset) { $query = $this->entityManager->createQuery(sprintf('SELECT o FROM %s o', Order::class)); $query->setFirstResult($offset)->setMaxResults($limit); return new Paginator($query); }
public function __invoke() { $query = $this->em->createQuery('SELECT b.title, COUNT(a) as authorsCount FROM AppBundle:Book b LEFT JOIN AppBundle:Author a WITH b MEMBER OF a.books'); return $query->getResult(); }
/** * {@inheritdoc} */ public function createQuery($dql = '') { return $this->wrapped->createQuery($dql); }
private function queryEntity(EntityManagerInterface $em, $label) { $times = 100; $size = 500; $startPersist = microtime(true); echo PHP_EOL . $label; for ($i = 0; $i < $size; $i++) { $em->persist(new Country("Country {$i}")); } $em->flush(); $em->clear(); printf("\n[%s] persist %s countries", number_format(microtime(true) - $startPersist, 6), $size); $dql = 'SELECT c FROM Doctrine\\Tests\\Models\\Cache\\Country c WHERE c.name LIKE :name'; $startFind = microtime(true); for ($i = 0; $i < $times; $i++) { $em->createQuery($dql)->setParameter('name', "%Country%")->setCacheable(true)->getResult(); } printf("\n[%s] select %s countries (%s times)", number_format(microtime(true) - $startFind, 6), $size, $times); printf("\n%s\n", str_repeat('-', 50)); }
/** * @return Integer */ public function count() { return $this->entityManager->createQuery("SELECT COUNT('e') FROM " . $this->getEntity() . " e")->getSingleScalarResult(); }
/** * Gets total results count. * * @param array $query * * @return int */ private function getResultsCount($query) { $queryObject = $this->entityManager->createQuery(str_replace('SELECT ' . $this->select, 'SELECT COUNT(p.id) cnt', $query['query'])); $queryObject->setParameters($query['parameters']); return $queryObject->getSingleScalarResult(); }