protected function truncateTable($class, $connection = null) { //@TODO Comprendre comment marche exactement getManager et récupérer le manager avec la class $tableName = $this->getTableName($class, $connection); $connection = $this->managerRegistry->getConnection($connection); $connection->exec('DELETE FROM ' . $tableName); }
protected function execute(InputInterface $input, OutputInterface $output) { $dbname = $input->getArgument('dbname'); $designdoc = $input->getArgument('designdoc'); $view = $input->getArgument('view'); /** @var \Doctrine\CouchDB\CouchDBClient $client */ $client = $this->registry->getConnection($dbname); $query = $client->createViewQuery($designdoc, $view); $ret = $query->execute(); $output->writeln('Updated'); }
protected function execute(InputInterface $input, OutputInterface $output) { // Bangpound\Bundle\TwitterStreamingBundle\CouchDocument\AtomEntry $em = $this->registry->getManager(); /** @var \Doctrine\CouchDB\CouchDBClient $default_client */ $default_client = $this->registry->getConnection(); $tag = $input->getArgument('tag'); $outputFile = $input->getOption('output'); $start = \DateTime::createFromFormat('Y-m-d', $input->getOption('start')); $end = \DateTime::createFromFormat('Y-m-d', $input->getOption('end')); $limit = 1000; // Executing the query without grouping allows the view to be refreshed. /** @var $query */ $query = $default_client->createViewQuery('maint', 'tag'); if ($input->getOption('stale') !== 'ok') { $output->writeln('Updating view.'); $query->execute(); } // All other executions will allow stale results. $query->setGroup(false); $query->setIncludeDocs(true); $query->setStale('ok'); $query->setReduce(false); $query->setStartKey([$tag, (int) $start->format('Y'), (int) $start->format('m'), (int) $start->format('d')]); $query->setEndKey([$tag, (int) $end->format('Y'), (int) $end->format('m'), (int) $end->format('d')]); $query->setLimit($limit + 1); file_put_contents($outputFile, '['); do { $result = $query->execute(); $next_start_key = null; if (count($result) > 0) { if (count($result) == $limit + 1) { $next_start_key = $result[$limit]['key']; $query->setStartKey($result[$limit]['key']); $query->setStartKeyDocId($result[$limit]['id']); $output->writeln('resume with ' . implode('-', $result[$limit]['key']) . ' ' . $result[$limit]['id']); } $rows = array(); foreach ($result as $i => $row) { if ($i < $limit) { $rows[] = json_encode($row['doc']); } } $data = implode(',', $rows); if ($next_start_key) { $data .= ','; } file_put_contents($outputFile, $data, FILE_APPEND | LOCK_EX); } } while ($next_start_key); file_put_contents($outputFile, ']', FILE_APPEND | LOCK_EX); }
/** * Handle article PUT */ public function putDocumentAction(Request $request, $id) { $path = '/' . $id; $data = $request->request->all(); $session = $this->registry->getConnection($this->name); $node = $session->getNode($path); if (empty($node)) { throw new ResourceNotFoundException($path . ' not found'); } $this->fromJsonLD($node, $data); $session->save(); // return the updated version $view = View::create($this->toJsonLd($node))->setFormat('json'); return $this->viewHandler->handle($view, $request); }
/** * @return AbstractPlatform */ protected function getPlatform() { if (!$this->platform) { $this->platform = $this->managerRegistry->getConnection()->getDatabasePlatform(); } return $this->platform; }
/** * Construct AclFilter * * @DI\InjectParams({ * "doctrine" = @DI\Inject("doctrine"), * "securityContext" = @DI\Inject("security.context"), * "aclWalker" = @DI\Inject("%vib.security.acl_walker%"), * "roleHierarchy" = @DI\Inject("%security.role_hierarchy.roles%") * }) * * @param Doctrine\Common\Persistence\ManagerRegistry $doctrine * @param Symfony\Component\Security\Core\SecurityContextInterface $securityContext * @param string $aclWalker * @param array $roleHierarchy */ public function __construct(ManagerRegistry $doctrine, SecurityContextInterface $securityContext, $aclWalker, $roleHierarchy) { $this->em = $doctrine->getManager(); $this->securityContext = $securityContext; $this->aclConnection = $doctrine->getConnection('default'); $this->aclWalker = $aclWalker; $this->roleHierarchy = $roleHierarchy; }
protected function setUp() { $this->registry = new SimpleManagerRegistry(function ($id) { switch ($id) { case 'default_connection': return $this->createConnection(); case 'default_manager': return $this->createEntityManager($this->registry->getConnection()); default: throw new \RuntimeException(sprintf('Unknown service id "%s".', $id)); } }); $this->serializer = SerializerBuilder::create()->setMetadataDriverFactory(new CallbackDriverFactory(function (array $metadataDirs, Reader $annotationReader) { $defaultFactory = new DefaultDriverFactory(); return new DoctrineTypeDriver($defaultFactory->createDriver($metadataDirs, $annotationReader), $this->registry); }))->build(); $this->prepareDatabase(); }
/** * {@inheritdoc} */ public function truncateTable($className) { $metadata = $this->getClassMetadata($className); if ($metadata instanceof ClassMetadata) { $connection = $this->registry->getConnection(); $connection->beginTransaction(); try { $sql = 'DELETE FROM :table'; $stmt = $connection->prepare($sql); $stmt->bindValue('table', $metadata->getTableName()); $stmt->execute(); $connection->commit(); return true; } catch (\Exception $e) { $connection->rollback(); } } return false; }
protected function execute(InputInterface $input, OutputInterface $output) { // Bangpound\Bundle\TwitterStreamingBundle\CouchDocument\AtomEntry $em = $this->registry->getManager(); /** @var \Doctrine\CouchDB\CouchDBClient $default_client */ $default_client = $this->registry->getConnection(); $date = \DateTime::createFromFormat('Y-m-d', $input->getArgument('date')); $limit = 1000; // Executing the query without grouping allows the view to be refreshed. /** @var $query */ $query = $default_client->createViewQuery('maint', 'date'); $output->writeln('Updating view.'); $query->execute(); // All other executions will allow stale results. $query->setGroup(false); $query->setIncludeDocs(false); $query->setStale('ok'); $query->setReduce(false); $query->setStartKey(array()); $query->setEndKey(array((int) $date->format('Y'), (int) $date->format('m'), (int) $date->format('d'), array())); $query->setLimit($limit + 1); do { $result = $query->execute(); $next_start_key = null; if (count($result) > 0) { if (count($result) == $limit + 1) { $next_start_key = $result[$limit]['key']; $query->setStartKey($result[$limit]['key']); $query->setStartKeyDocId($result[$limit]['id']); $output->writeln('resume with ' . implode('-', $result[$limit]['key']) . ' ' . $result[$limit]['id']); } $bulk = $default_client->createBulkUpdater(); foreach ($result as $i => $row) { if ($i < $limit) { $bulk->deleteDocument($row['id'], $row['value']); } } $result = $bulk->execute(); } } while ($next_start_key); }
/** * Construct AclFilter * * @DI\InjectParams({ * "doctrine" = @DI\Inject("doctrine"), * "tokenStorage" = @DI\Inject("security.token_storage"), * "aclWalker" = @DI\Inject("%bluemesa_acl.walker%"), * "roleHierarchy" = @DI\Inject("%security.role_hierarchy.roles%") * }) * * @param ManagerRegistry $doctrine * @param TokenStorageInterface $tokenStorage * @param string $aclWalker * @param array $roleHierarchy * @throws Exception */ public function __construct(ManagerRegistry $doctrine, TokenStorageInterface $tokenStorage, $aclWalker, $roleHierarchy) { $em = $doctrine->getManager(); if (!$em instanceof EntityManager) { throw new Exception(); } $this->em = $em; $this->tokenStorage = $tokenStorage; $this->aclConnection = $doctrine->getConnection('default'); $this->aclWalker = $aclWalker; $this->roleHierarchy = $roleHierarchy; }
/** * @param $name * @return object */ public function getConnection($name) { return $this->managerRegistry->getConnection($name); }
/** * Determines whether the given value is reserved SQL word or not * * @param string $value * @return bool */ protected function isReservedWord($value) { return $this->doctrine->getConnection()->getDatabasePlatform()->getReservedKeywordsList()->isKeyword($value); }
/** * @param string|null $name * * @return Configuration */ public function getForConnection($name = null) { $connection = $this->registry->getConnection($name); return $this->factory->make($connection); }