/** * Returns Doctrine databases from the supplied database manager. * * @param sfDatabaseManager $databaseManager * @param array|null $names An array of names or NULL for all databases * * @return array An associative array of {@link sfDoctrineDatabase} objects and their names * * @throws InvalidArgumentException If a requested database is not a Doctrine database */ protected function getDoctrineDatabases(sfDatabaseManager $databaseManager, array $names = null) { $databases = array(); if (null === $names) { foreach ($databaseManager->getNames() as $name) { $database = $databaseManager->getDatabase($name); if ($database instanceof sfDoctrineDatabase) { $databases[$name] = $database; } } } else { foreach ($names as $name) { $database = $databaseManager->getDatabase($name); if (!$database instanceof sfDoctrineDatabase) { throw new InvalidArgumentException(sprintf('The database "%s" is not a Doctrine database.', $name)); } $databases[$name] = $database; } } return $databases; }
public static function getDatabaseParams($configuration, $dbname = false) { $dbManager = new sfDatabaseManager($configuration); $names = $dbManager->getNames(); $db = $dbManager->getDatabase($dbname ? $dbname : $names[0]); if (!$db) { throw new sfException("No database connection called {$db} is defined"); } $username = $db->getParameter('username'); //root $dsn = $db->getParameter('dsn'); //mysql:dbname=mydbtest;host=localhost because it's test config $password = $db->getParameter('password'); //password if (!preg_match('/^mysql:(.*)\\s*$/', $dsn, $matches)) { throw new sfException("I don't understand the DSN {$dsn}, sorry"); } $pairs = explode(';', $matches[1]); $data = array(); foreach ($pairs as $pair) { list($key, $val) = explode('=', $pair); $data[$key] = $val; } $data['username'] = $username; $data['password'] = $password; return $data; }
public static function createPDOInstance() { $configuration = sfContext::getInstance()->getConfiguration(); $config = ProjectConfiguration::getApplicationConfiguration($configuration->getApplication(), $configuration->getEnvironment(), $configuration->isDebug()); $dbManager = new sfDatabaseManager($config); $names = $dbManager->getNames(); $db = $dbManager->getDatabase($names[0]); return new PDO($db->getParameter('dsn'), $db->getParameter('username'), $db->getParameter('password')); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); foreach ($databaseManager->getNames() as $connection) { if (!is_null($options['connection']) && $options['connection'] != $connection) { continue; } $this->reverseDatabase($databaseManager, $connection, $options); } }
/** * Returns the Mondongo. * * @return Mondongo The Mondongo. */ protected function getMondongo() { if (null === $this->mondongo) { $this->mondongo = new Mondongo(); $databaseManager = new sfDatabaseManager($this->configuration); foreach ($databaseManager->getNames() as $name) { $database = $databaseManager->getDatabase($name); if ($database instanceof sfMondongoDatabase) { $this->mondongo->setConnection($name, $database->getMondongoConnection()); } } Container::setDefault($this->mondongo); } return $this->mondongo; }
public function __construct($testMode = false, $debugMode = false, $configuration = null, $user = null, $browserTimeout = 30) { $this->appConfiguration = $configuration; //initialize database manager with configuration $doctrineManager = Doctrine_Manager::getInstance(); $databaseManager = new sfDatabaseManager($configuration); $databaseManager->initialize($configuration); //set db array foreach ($databaseManager->getNames() as $name) { $this->conn[$name] = $doctrineManager->openConnection($databaseManager->getDatabase($name)->getParameter('dsn'), $name); } //set db $doctrineManager->setCurrentConnection('main'); $this->db = $doctrineManager->getCurrentConnection(); //logging (DISABLED UNTIL NOTICES CAN BE REMOVED) /* require_once 'Log.php'; $this->logDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR.'scraper'.DIRECTORY_SEPARATOR; $this->logFile = get_class($this); $this->logger = &Log::singleton('file', $this->logDir . $this->logFile, 'SCRAPER'); */ //browser $this->defaultHeaders = array('User-Agent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)'); $this->browser = new sfWebBrowser($this->defaultHeaders, 'sfCurlAdapter', array('Timeout' => $browserTimeout)); $this->cookieBrowser = new sfWebBrowser($this->defaultHeaders, 'sfCurlAdapter', array('cookies' => true, 'Timeout' => $browserTimeout)); //modes $this->testMode = $testMode; $this->debugMode = $debugMode; //meta if ($this->testMode) { $this->testMode = false; $this->testMeta = $this->getAllMeta(); $this->testMode = true; } //login as scraper user if (!$user) { $context = sfContext::createInstance($configuration); $user = $context->getUser(); $user->setAttribute('user_id', sfGuardUserTable::SCRAPER_USER_ID, 'sfGuardSecurityUser'); } if (!$user->isAuthenticated()) { $user->setAuthenticated(true); $user->clearCredentials(); } $this->user = $user->getGuardUser(); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $compiledFile = sfConfig::get('sf_cache_dir') . '/doctrine.compiled.php'; if (file_exists($compiledFile)) { $this->logSection('error', $compiledFile . ' already exists', null, 'ERROR'); $this->logBlock('Run symfony:cache-clear first', 'INFO'); return; } $drivers = array(); foreach ($databaseManager->getNames() as $name) { $drivers[] = strtolower($databaseManager->getDatabase($name)->getDoctrineConnection()->getDriverName()); } $drivers = array_unique($drivers); $this->logSection('compile', 'Included drivers: ' . implode(', ', $drivers)); Doctrine_Core::compile($compiledFile, $drivers); $this->logSection('file+', $compiledFile); }
public static function getDatabaseParams() { echo "appConfig\n"; $appConfig = self::$configuration ? self::$configuration : sfContext::getInstance()->getConfiguration(); echo "appManager\n"; $dbManager = new sfDatabaseManager($appConfig); echo "after appManager\n"; $names = $dbManager->getNames(); $db = $dbManager->getDatabase($names[0]); $username = $db->getParameter('username'); //root $dsn = $db->getParameter('dsn'); //mysql:dbname=mydbtest;host=localhost because it's test config $password = $db->getParameter('password'); //password if (!preg_match('/^mysql:(.*)\\s*$/', $dsn, $matches)) { throw new sfException("I don't understand the DSN {$dsn}, sorry"); } $pairs = explode(';', $matches[1]); $data = array(); foreach ($pairs as $pair) { list($key, $val) = explode('=', $pair); $data[$key] = $val; } $data['username'] = $username; $data['password'] = $password; return $data; }
sfCoreAutoload::register(); require_once dirname(__FILE__) . '/cleanup.php'; $projectPath = dirname(__FILE__) . '/../fixtures/project'; require_once $projectPath . '/config/ProjectConfiguration.class.php'; if (!isset($app)) { $configuration = new ProjectConfiguration($projectPath); } else { $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true); $context = sfContext::createInstance($configuration); } if (isset($app)) { $configuration->initializeDoctrine(isset($fixtures) && $fixtures ? true : false); $databaseManager = $context->getDatabaseManager(); } else { if (isset($database) && $database) { $databaseManager = new sfDatabaseManager($configuration); $configuration->initializeDoctrine(isset($fixtures) && $fixtures ? true : false); } } if (isset($databaseManager)) { $names = $databaseManager->getNames(); $em = $databaseManager->getDatabase(end($names))->getEntityManager(); } require_once $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php'; function autoload_again($class) { $autoload = sfSimpleAutoload::getInstance(); $autoload->reload(); return $autoload->autoload($class); } spl_autoload_register('autoload_again');
public function executeStepThree(sfWebRequest $request) { $error = 0; $configuration = sfProjectConfiguration::getActive(); $db = new sfDatabaseManager($configuration); foreach ($db->getNames() as $connection) { try { @$db->getDatabase($connection)->getConnection(); } catch (Exception $e) { $error = 1; } } if ($error == 1) { $this->getUser()->setFlash('error', $e->getMessage()); $this->redirect('firstBoot/stepOne'); } $moderator = new Moderator(); $login = new Login(); $login->setIsModerator(true); $moderator->setLogin($login); $this->form = new ModeratorForm($moderator, array('new' => true)); }