protected function execute(InputInterface $input, OutputInterface $output) { $this->doctrine = $this->getContainer()->get('doctrine'); // get all cities $qb = $this->doctrine->getManager()->createQueryBuilder(); $qb->select('ct')->from('HelperBundle:City', 'ct')->where('ct.geoCityId IS NOT NULL')->orderBy('ct.id', 'ASC'); $cities = $qb->getQuery()->getResult(); $connection = $this->doctrine->getConnection(); foreach ($cities as $city) { $output->write('Updating data of old city #' . $city->getId()); $sql = "SELECT cg_gct.* FROM `chromedia_global`.`geo_cities` cg_gct WHERE cg_gct.`id` = ?"; $statement = $connection->prepare($sql); $statement->bindValue(1, $city->getGeoCityId()); $statement->execute(); $globalCityData = $statement->fetch(); if ($globalCityData) { $updateSql = "UPDATE `cities` SET `id` = :geoCityId, `name` = :geoCityName, `slug` = :geoCitySlug WHERE `old_id` = :oldId"; $updateStatement = $connection->prepare($updateSql); $updateStatement->bindValue('geoCityId', $globalCityData['id']); $updateStatement->bindValue('geoCityName', $globalCityData['name']); $updateStatement->bindValue('geoCitySlug', $globalCityData['slug']); $updateStatement->bindValue('oldId', $city->getOldId()); $updateStatement->execute(); $output->writeln(' OK'); } else { $output->writeln(' Not found'); } } }
/** * @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrine */ public function __construct($doctrine) { $dbConfig = $doctrine->getConnection()->getParams(); if (isset($dbConfig['dsn'])) { $data = EhrlichAndreas_Util_Dsn::parseDsn($dbConfig['dsn']); foreach ($data as $key => $value) { $dbConfig[$key] = $value; } $data = EhrlichAndreas_Util_Dsn::parseUri($dbConfig['dsn']); if (isset($data[0])) { $dbConfig['adapter'] = ucfirst($data[0]); } if (isset($dbConfig['adapter']) && $dbConfig['driver']) { $dbConfig['adapter'] = $dbConfig['driver'] . '_' . $dbConfig['adapter']; } } if (!isset($dbConfig['adapter']) && isset($dbConfig['driver'])) { $dbConfig['adapter'] = $dbConfig['driver']; unset($dbConfig['driver']); } if (!isset($dbConfig['driver_options']) && isset($dbConfig['driverOptions'])) { $dbConfig['driver_options'] = $dbConfig['driverOptions']; unset($dbConfig['driverOptions']); } if (!isset($dbConfig['username']) && isset($dbConfig['user'])) { $dbConfig['username'] = $dbConfig['user']; unset($dbConfig['user']); } $this->adapter = EhrlichAndreas_Db_Db::factory($dbConfig); $this->adapter->setConnection($doctrine->getConnection()->getWrappedConnection()); }
private function reset() { if ($this->doctrine) { /** @var Connection $c */ $c = $this->doctrine->getConnection(); $c->close(); $this->doctrine->resetManager(); } }
/** * @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrine * @param \Symfony\Bridge\Monolog\Logger $logger */ public function __construct(Doctrine $doctrine, Logger $logger) { $this->entityManager = $doctrine->getManager(); $dLogger = new \Doctrine\DBAL\Logging\DebugStack(); $doctrine->getConnection()->getConfiguration()->setSQLLogger($dLogger); $logger->info(json_encode($dLogger->queries)); }
/** * Merge $fromTreatment to $toTreatment * * @param Treatment $fromTreatment * @param Treatment $toTreatment */ public function mergeTreatmentToAnotherTreatment(Treatment $fromTreatment, Treatment $toTreatment) { /*** * Steps for merge * 1. Move all institution_treatments of $fromTreatment to $toTreatment. Considerations: * a. Consider existing institution_treatments.institution_id and institution_treatments.toTreatment combination * 2. Delete $fromTreatment */ $connection = $this->doctrine->getConnection(); $em = $this->doctrine->getManager(); // step 1 $sql = "UPDATE IGNORE `institution_treatments` inst_tr \n SET inst_tr.`treatment_id` = :toTreatmentId\n WHERE inst_tr.`treatment_id` = :fromTreatmentId"; $statement = $connection->prepare($sql); $statement->bindValue('fromTreatmentId', $fromTreatment->getId()); $statement->bindValue('toTreatmentId', $toTreatment->getId()); $statement->execute(); // remove the remaining institutions $fromTreatment with existing $toTreatment that were left out from the above operation $sql = "DELETE FROM `institution_treatments` WHERE `treatment_id` = :fromTreatmentId"; $statement = $connection->prepare($sql); $statement->bindValue('fromTreatmentId', $fromTreatment->getId()); $statement->execute(); // step 2 // remove $fromTreatment $em->remove($fromTreatment); $em->flush(); }
public function testGetUnknownConnection() { $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $registry = new Registry($container, array(), array(), 'default', 'default'); $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Connection named "default" does not exist.'); $registry->getConnection('default'); }
private function doInstitution(Institution $institution, $em) { //$this->output->write("Institution #{$institution->getId()}"); $oldState = \trim($institution->getStateBak()); if ($oldState == '') { //$this->output->writeln('[No old state]'); return; } $country = $institution->getCountry(); // find a state with the same name for this country in chromedia_global $connection = $this->doctrine->getConnection(); $sql = "SELECT gs.* FROM `chromedia_global`.`geo_states` gs WHERE `name` LIKE :state AND `geo_country_id` = :geoCountryId"; $statement = $connection->prepare($sql); $statement->bindValue('state', $oldState); $statement->bindValue('geoCountryId', $country->getId()); $statement->execute(); if (!($rowCount = $statement->rowCount())) { //$this->output->writeln('[No matching state]'); $this->nonMatchingInstitutions[] = $institution; return; } else { if ($rowCount == 1) { $globalStateData = $statement->fetch(); $hcaState = $this->getHcaState($globalStateData, $country); $institution->setState($hcaState); $em->persist($institution); //$this->output->writeln("[Set to {$hcaState->getName()} ]"); } else { if (strtolower($oldState) == 'singapore') { // manual for singapore while ($globalStateData = $statement->fetch()) { if ($globalStateData['id'] == 2732) { $hcaState = $this->getHcaState($globalStateData, $country); $institution->setState($hcaState); $em->persist($institution); //$this->output->writeln("[Set to {$hcaState->getName()} ]"); break; } } } else { $this->nonUniqueStates[] = array('country_id' => $country->getId(), 'state' => $oldState); //$this->output->writeln("[Non unique state {$oldState}]"); $this->nonMatchingInstitutions[] = $institution; } } } }
protected function execute(InputInterface $input, OutputInterface $output) { $this->doctrine = $this->getContainer()->get('doctrine'); $this->om = $this->doctrine->getManager(); $this->connection = $this->doctrine->getConnection(); $this->output = $output; $this->termRepository = $this->doctrine->getRepository('TermBundle:Term'); // reset internal flag to 0 for terms linked to a treatment $this->resetInternalFlagOfTermsWithTreatmentTypeDocuments(); // get all treatments $qb = $this->doctrine->getManager()->createQueryBuilder(); $qb->select('t1')->from('TreatmentBundle:Treatment', 't1')->orderBy('t1.name', 'ASC'); $treatments = $qb->getQuery()->getResult(); foreach ($treatments as $treatment) { $this->cleanupTerms($treatment); } $this->om->flush(); }
private function updateEmail($accountId, $accountEmail, $contactEmail) { $updateSql = "UPDATE `chromedia_global`.`accounts` SET `email` = :contactEmail WHERE `id` = :accountId AND `email` = :accountEmail"; $statement = $this->doctrine->getConnection()->prepare($updateSql); $statement->bindValue('accountId', $accountId); $statement->bindvalue('accountEmail', $accountEmail); $statement->bindValue('contactEmail', $contactEmail); $statement->execute(); }
/** * @param Registry $doctrine * @param Selector $selector */ public function __construct(Registry $doctrine, Selector $selector) { $this->repository = $doctrine->getRepository('AnimeDbCatalogBundle:Item'); $this->selector = $selector; // register custom lower() $conn = $doctrine->getConnection()->getWrappedConnection(); if (method_exists($conn, 'sqliteCreateFunction')) { $conn->sqliteCreateFunction('lower', function ($str) { return mb_strtolower($str, 'UTF8'); }, 1); } }
/** * @param Registry $registry * @param \Knp\Component\Pager\Paginator $paginator * @param $connection * @param $manager * @param $itemsPerPage * @internal param $items */ public function __construct(Registry $registry, Paginator $paginator, $connection, $manager, $itemsPerPage) { $this->registry = $registry; $this->paginator = $paginator; $this->itemsPerPage = $itemsPerPage; // this prevents a 'NULL not support' exception if (!$connection || empty($connection)) { $connection = null; } $this->connection = $registry->getConnection($connection); if (!$manager || empty($manager)) { $manager = null; } $this->manager = $registry->getManager($manager); }
/** * @param string $connectionName * @param string $mysqlHost * @param string $mysqlUsername * @param string $mysqlPassword * @param string $mysqlDbname * @param array $onlyTables */ public function run(string $connectionName = 'default', string $mysqlHost = 'localhost', string $mysqlUsername = null, string $mysqlPassword = null, string $mysqlDbname = null, array $onlyTables = []) { $this->connection = $this->doctrine->getConnection($connectionName); if ($mysqlHost) { $this->initMysqlSettings($mysqlHost, $mysqlUsername, $mysqlPassword, $mysqlDbname); } $tables = $this->showTables(); foreach ($tables as $tableName) { $this->fs->remove([self::DUMP_IN_FILE_NAME, self::DUMP_OUT_FILE_NAME]); if (!empty($onlyTables) && !in_array($tableName, $onlyTables)) { continue; } $this->dumpTableIntoFile($tableName); $this->convertTextInFile(self::DUMP_IN_FILE_NAME); $this->restoreFromFile(self::DUMP_OUT_FILE_NAME); } }
/** * Execute the command. Get all the deposits needing to be harvested. Each * deposit will be passed to the commands processDeposit() function. * * @param InputInterface $input * @param OutputInterface $output */ protected final function execute(InputInterface $input, OutputInterface $output) { $force = $input->getOption('force'); $this->em->getConnection()->getConfiguration()->setSQLLogger(null); $q = $this->em->createQuery('SELECT d FROM AppBundle\\Entity\\Deposit d where d.plnState = :state'); $q->setParameter('state', 'agreement'); $iterator = $q->iterate(); $i = 0; foreach ($iterator as $row) { $deposit = $row[0]; $this->processDeposit($deposit, $force); $i++; if ($i % 50 === 0) { $this->em->clear(); gc_collect_cycles(); } } }
public function setDoctrine(Registry $doctrine) { $this->doctrine = $doctrine; $this->connection = $doctrine->getConnection('hca_blog'); }
/** * @param Table $table */ private function enableUserTriggers(Table $table) { $tableFullName = $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName(); $sql = "ALTER TABLE " . $tableFullName . " ENABLE TRIGGER USER"; $this->doctrine->getConnection($this->parameters->getManagerTo())->executeQuery($sql); }
/** * Sets up Key Mapping, if enabled * * Creates the necessary tables, if they arent there, and updates the service * * @param array $configs * @param Registry $doctrine * * @throws \Exception */ public function setupKeyMap(array $configs, Registry $doctrine) { if ($configs['enabled']) { // Make sure the connection isn't empty if ($configs['connection'] === '') { throw new \Exception("Please specify a `connection` for the keyMap setting under memcached. "); } // Grab the connection from doctrine /** @var \Doctrine\DBAL\Connection $connection */ $connection = $doctrine->getConnection($configs['connection']); // Fetch the memcached service, set key mapping to enabled, and set the connection $this->setKeyMapEnabled(true)->setKeyMapConnection($connection); } }
/** * @return string */ protected function generateUuid() { $conn = $this->doctrine->getConnection(); $sql = 'SELECT ' . $conn->getDatabasePlatform()->getGuidExpression(); return $conn->query($sql)->fetchColumn(0); }
public function tearDown() { $this->doctrine->getConnection()->rollback(); }