/** * @see Console\Command\Command */ protected function execute(Input\InputInterface $input, Output\OutputInterface $output) { $schemaFile = $input->getArgument('schema-file'); $configFile = $input->getArgument('config-file'); $dataSource = $input->getOption('datasource'); $ignoreConstraints = $input->getOption('ignore-constraints'); // initialize propel \Propel::init($configFile); // get xml representation of schema file $schemaXml = simplexml_load_file($schemaFile); // intitialize doctrine DBAL with data from propel $config = \PropelCli\Configuration::getDataSourceConfiguration($dataSource, \Propel::getConfiguration()); $conn = DBAL\DriverManager::getConnection($config->toArray(), new DBAL\Configuration()); $sm = $conn->getSchemaManager(); // create a schema of the existing db $fromSchema = $sm->createSchema(); // initialize a schema for the updated db $toSchema = new \Doctrine\DBAL\Schema\Schema(); // generate the schema object $generator = new \PropelCli\Schema\Generator($schemaXml); $generator->generate($toSchema); // generate the sql to migrate from fromSchema to toSchema $sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform()); if ($input->getOption('dump-sql')) { foreach ($sql as $stmt) { if ($ignoreConstraints && preg_match('/CONSTRAINT/', $stmt)) { continue; } $output->write($stmt . ';' . PHP_EOL); } } }
/** * Get a list of all Propel-model classes. * * @param bool $packages Group by package name. * @return array */ public static function getModels($packages = true) { $classes = array(); $configArray = Propel::getConfiguration(); foreach ($configArray['classmap'] as $className => $file) { if (preg_match('@^(.*)/map/(\\w+)TableMap\\.php$@', $file, $match)) { $package = $match[1]; $clazz = $match[2]; if ($packages) { if (!isset($classes[$package])) { $classes[$package] = array(); } $classes[$package][] = $clazz; } else { $classes[] = $clazz; } } } if ($packages) { ksort($classes, SORT_STRING); foreach ($classes as $package => &$cl) { sort($cl, SORT_STRING); } unset($cl); } return $classes; }
public static function enablePropelLogging() { $logger = Logging::getLogger(); Propel::setLogger($logger); $con = Propel::getConnection(); $con->useDebug(true); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); $config->setParameter('debugpdo.logging.details.method.enabled', true); $config->setParameter('debugpdo.logging.details.time.enabled', true); $config->setParameter('debugpdo.logging.details.mem.enabled', true); }
/** * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ public function getConnection() { if (self::$testCon === null) { self::$propelCon = Propel::getConnection(); $propelConfig = Propel::getConfiguration(PropelConfiguration::TYPE_ARRAY); $this->assertTrue(isset($propelConfig['datasources'][PROJECT_NAME]['connection'])); $dbConfig = $propelConfig['datasources'][PROJECT_NAME]['connection']; $this->assertTrue(isset($dbConfig['dsn'], $dbConfig['database'], $dbConfig['user'], $dbConfig['password'])); self::$testCon = $this->createDefaultDBConnection(new PDO($dbConfig['dsn'], $dbConfig['user'], $dbConfig['password']), $dbConfig['database']); } return self::$testCon; }
/** * Class constructor. * * @see initialize() */ public function __construct($url = 'http://voota.es') { $this->serverUrl = $url; $dbConf = Propel::getConfiguration(); $dsn = $dbConf['datasources']['propel']['connection']['dsn']; if (preg_match("/dbname=(.*);host=(.*)\$/", $dsn, $matches)) { $db = $matches[1]; $host = $matches[2]; } $databaseArray = array('server' => $host, 'username' => $dbConf['datasources']['propel']['connection']['user'], 'password' => $dbConf['datasources']['propel']['connection']['password'], 'database' => $db); OAuthStore::instance('MySQL', OAuthStore::instance('MySQL', $databaseArray)); }
public static function storeInstance() { $dbConf = Propel::getConfiguration(); $dsn = $dbConf['datasources']['propel']['connection']['dsn']; if (preg_match("/dbname=(.*);host=(.*)\$/", $dsn, $matches)) { $db = $matches[1]; $host = $matches[2]; } $store = OAuthStore::instance('MySQL', array('server' => $host, 'username' => $dbConf['datasources']['propel']['connection']['user'], 'password' => $dbConf['datasources']['propel']['connection']['password'], 'database' => $db)); if (!$store) { sfContext::getInstance()->getLogger()->err("Cannot connect to database."); throw new OAuthException("Cannot connect to database."); } return $store; }
/** * @static * @param string $connectionName * @return PropelPDO */ public static function instanciate($connectionName) { $propelConfiguration = Propel::getConfiguration(); if (isset($propelConfiguration['datasources'][$connectionName]['connection'])) { $parameters = $propelConfiguration['datasources'][$connectionName]['connection']; } else { if (isset($propelConfiguration['datasources'][Propel::getDefaultDB()])) { $propelConfiguration['datasources'][$connectionName] = $propelConfiguration['datasources'][Propel::getDefaultDB()]; Propel::setConfiguration(new PropelConfiguration($propelConfiguration)); $parameters = $propelConfiguration['datasources'][$connectionName]['connection']; } else { throw new Exception(sprintf("Unable to find connection parameters for connection '%s'", $connectionName)); } } return Propel::initConnection($parameters, $connectionName); }
protected function setUp() { if (Propel::isInit()) { $this->oldPropelConfiguration = Propel::getConfiguration(); } $xmlDom = new DOMDocument(); $xmlDom->load(dirname(__FILE__) . '/../../fixtures/reverse/mysql/runtime-conf.xml'); $xml = simplexml_load_string($xmlDom->saveXML()); $phpconf = PlatformDatabaseBuildTimeBaseTask::simpleXmlToArray($xml); Propel::setConfiguration($phpconf); Propel::initialize(); $this->con = Propel::getConnection('reverse-bookstore'); $this->parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore')); $this->parser->setGeneratorConfig(new QuickGeneratorConfig(new MysqlPlatform())); parent::setUp(); }
/** * Databases and tables list helper * * @return array */ public function processDatabaseList() { $aConfiguration = Propel::getConfiguration(); // Extract default connection $sDefault = ''; if (isset($aConfiguration['datasources']['default'])) { $sDefault = $aConfiguration['datasources']['default']; unset($aConfiguration['datasources']['default']); } $aDatabases = array(); // Generating response foreach ($aConfiguration['datasources'] as $db_connection => $db_connecttion_info) { $sDsn = $db_connecttion_info['connection']['dsn']; $aDsnInfo = afsDatabaseQuery::parseDSN($sDsn); $aTables = afsDatabaseQuery::getTables($db_connection); // Generate list of databases and tables $aDatabases[] = array('name' => $aDsnInfo['dbname'], 'tables_num' => count($aTables), 'connection' => $db_connection, 'tables' => array_values((array) $aTables)); } return $aDatabases; }
/** * Load Propel config * * @param AgaviDatabaseManager The database manager of this instance. * @param array An assoc array of initialization params. * * @author David Zülke <*****@*****.**> * @since 0.10.0 */ public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array()) { parent::initialize($databaseManager, $parameters); $configPath = AgaviToolkit::expandDirectives($this->getParameter('config')); $datasource = $this->getParameter('datasource', null); $use_as_default = $this->getParameter('use_as_default', false); $config = (require $configPath); if ($datasource === null || $datasource == 'default') { if (isset($config['propel']['datasources']['default'])) { $datasource = $config['propel']['datasources']['default']; } elseif (isset($config['datasources']['default'])) { $datasource = $config['datasources']['default']; } else { throw new AgaviDatabaseException('No datasource given for Propel connection, and no default datasource specified in runtime configuration file.'); } } if (!class_exists('Propel')) { include 'propel/Propel.php'; } if (!Propel::isInit()) { Propel::init($configPath); } $is13 = version_compare(Propel::VERSION, '1.4', '<'); // grab the configuration values and inject possibly defined overrides for this data source if ($is13) { // old-style config array; PropelConfiguration was added after 1.3.0, http://trac.agavi.org/ticket/1195 $config = Propel::getConfiguration(); $config['datasources'][$datasource]['adapter'] = $this->getParameter('overrides[adapter]', $config['datasources'][$datasource]['adapter']); $config['datasources'][$datasource]['connection'] = array_merge($config['datasources'][$datasource]['connection'], $this->getParameter('overrides[connection]', array())); // also the autoload classes $config['datasources'][$datasource]['classes'] = array_merge($config['datasources'][$datasource]['classes'], $this->getParameter('overrides[classes]', array())); // and init queries if (!isset($config['datasources'][$datasource]['connection']['settings']['queries']['query'])) { $config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array(); } // array cast because "query" might be a string if just one init query was given, http://trac.agavi.org/ticket/1194 $config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array_merge((array) $config['datasources'][$datasource]['connection']['settings']['queries']['query'], (array) $this->getParameter('init_queries')); // set the new config Propel::setConfiguration($config); } else { $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); $overrides = (array) $this->getParameter('overrides'); // set override values foreach ($overrides as $key => $value) { $config->setParameter($key, $value); } // handle init queries in a cross-adapter fashion (they all support the "init_queries" param) $queries = (array) $config->getParameter('datasources.' . $datasource . '.connection.settings.queries.query', array()); // yes... it's one array, [connection][settings][queries][query], with all the init queries from the config, so we append to that $queries = array_merge($queries, (array) $this->getParameter('init_queries')); $config->setParameter('datasources.' . $datasource . '.connection.settings.queries.query', $queries); } if (true === $this->getParameter('enable_instance_pooling')) { Propel::enableInstancePooling(); } elseif (false === $this->getParameter('enable_instance_pooling')) { Propel::disableInstancePooling(); } }
/** * Returns the slow query threshold. * * @return integer|null */ protected function getSlowQueryThreshold() { return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter('debugpdo.logging.details.slow.threshold'); }
{ $result = $this->db->query("SELECT session_data FROM session WHERE session_id = '{$sess_id}'"); if ($result->rowCount() === 0) { $this->db->exec("INSERT INTO session (session_id, date_created, last_updated, session_data) VALUES ('{$sess_id}', NOW(), NOW(), '')"); return ''; } $res = $result->fetch(PDO::FETCH_ASSOC); $this->db->exec("UPDATE session SET last_updated = NOW() WHERE session_id = '{$sess_id}'"); return $res['session_data']; } function write($sess_id, $data) { $this->db->exec("UPDATE session SET session_data = '{$data}', last_updated = NOW() WHERE session_id = '{$sess_id}'"); return true; } function destroy($sess_id) { $this->db->exec("DELETE FROM session WHERE session_id = '{$sess_id}'"); return true; } function gc($sess_maxlifetime) { $this->db->exec("DELETE FROM session WHERE session_data = \"slim.flash|a:0:{}\" AND last_updated < '" . date('c', time() - 86400 * 30) . "'"); return true; } } $conf = Propel::getConfiguration(PropelConfiguration::TYPE_ARRAY); $dbconf = $conf['datasources']['datawrapper']['connection']; $pdo = new PDO($dbconf['dsn'], $dbconf['user'], $dbconf['password']); $handler = new DatabaseSessionHandler($pdo); session_set_save_handler(array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'));
/** * Get the runtime configuration * * @return PropelConfiguration */ public function getConfiguration() { if (null === $this->configuration) { $this->configuration = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); } return $this->configuration; }
private function _initPropel($propelConfig) { if (!file_exists($propelConfig)) { throw new ZFscaffold_ZfTool_Exception("Propel config {$propelConfig} not exist"); } //require_once $this->cwd. . '/../library/propel/Propel.php'; Propel::init($propelConfig); $propelConf = Propel::getConfiguration(); if ($propelConf['classmap']) { foreach ($propelConf['classmap'] as $class => $file) { if (substr($class, -4) === 'Peer') { class_exists($class); } } } $this->tables = Propel::getDatabaseMap()->getTables(); /** @var $table TableMap */ foreach ($this->tables as $table) { $table->buildRelations(); Dfi_Propel_Helper::bulidRelationsOnFK($table); Dfi_Propel_Helper::findAutoLabel($table); } }
/** * Returns the name of the database which is used by Propel * * @return string the name of the database which is used by Propel */ private function getDatabaseName() { $config = Propel::getConfiguration(); $dsnString = $config['datasources'][Propel::getDefaultDB()]['connection']['dsn']; $dbNameStart = stripos($dsnString, 'dbname=') + strlen('dbname='); return substr($dsnString, $dbNameStart, strpos($dsnString, ';', $dbNameStart) - $dbNameStart); }
private function getDbConfig() { $aResult = array(); $aDbConfig = Propel::getConfiguration(); $aDbConfig = $aDbConfig['datasources'][Propel::getDefaultDB()]['connection']; $aResult['user'] = isset($aDbConfig['user']) ? $aDbConfig['user'] : $aDbConfig['username']; $aResult['password'] = $aDbConfig['password']; $aResult['host'] = @$aDbConfig['hostspec']; $aResult['database'] = @$aDbConfig['database']; if (isset($aDbConfig['dsn'])) { $sDsn = $aDbConfig['dsn']; $sDsn = substr($sDsn, strpos($sDsn, ':') + 1); $aDsn = explode(';', $sDsn); $aDsnAssoc = array(); foreach ($aDsn as $sDsnEntry) { $aDsnEntry = explode('=', $sDsnEntry); $aDsnAssoc[$aDsnEntry[0]] = $aDsnEntry[1]; } $aResult['host'] = $aDsnAssoc['host']; $aResult['database'] = $aDsnAssoc['dbname']; } return $aResult; }
/** * Check if the propel build files was built with the running Propel-version. * * @return bool */ public static function isPropelBuildInvalid() { $pc = Propel::getConfiguration(); return $pc['generator_version'] != Propel::VERSION; }
public function testDebugLog() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); // save data to return to normal state after test $logger = $con->getLogger(); $testLog = new myLogger(); $con->setLogger($testLog); $logEverything = array('PropelPDO::exec', 'PropelPDO::query', 'PropelPDO::beginTransaction', 'PropelPDO::commit', 'PropelPDO::rollBack', 'DebugPDOStatement::execute'); Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->setParameter("debugpdo.logging.methods", $logEverything, false); $con->useDebug(true); // test transaction log $con->beginTransaction(); $this->assertEquals('log: Begin transaction', $testLog->latestMessage, 'PropelPDO logs begin transation in debug mode'); $con->commit(); $this->assertEquals('log: Commit transaction', $testLog->latestMessage, 'PropelPDO logs commit transation in debug mode'); $con->beginTransaction(); $con->rollBack(); $this->assertEquals('log: Rollback transaction', $testLog->latestMessage, 'PropelPDO logs rollback transation in debug mode'); $con->beginTransaction(); $testLog->latestMessage = ''; $con->beginTransaction(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested begin transation in debug mode'); $con->commit(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested commit transation in debug mode'); $con->beginTransaction(); $con->rollBack(); $this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested rollback transation in debug mode'); $con->rollback(); // test query log $con->beginTransaction(); $c = new Criteria(); $c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE); $books = BookPeer::doSelect($c, $con); $latestExecutedQuery = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.title LIKE 'Harry%s'"; $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs queries and populates bound parameters in debug mode'); BookPeer::doDeleteAll($con); $latestExecutedQuery = "DELETE FROM `book`"; $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs deletion queries in debug mode'); $latestExecutedQuery = 'DELETE FROM book WHERE 1=1'; $con->exec($latestExecutedQuery); $this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs exec queries in debug mode'); $con->commit(); // return to normal state after test $con->setLogger($logger); $config->setParameter("debugpdo.logging.methods", array('PropelPDO::exec', 'PropelPDO::query', 'DebugPDOStatement::execute')); }
/** * Sets database configuration parameter * * @param string $key * @param mixed $value */ public function setConnectionParameter($key, $value) { if ('host' == $key) { $key = 'hostspec'; } Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->setParameter('datasources.' . $this->getParameter('datasource') . '.connection.' . $key, $value); $this->setParameter($key, $value); }
/** * Opens a new PDO connection for passed-in db name. * * @param array $conparams Connection paramters. * @param string $name Datasource name. * @param string $defaultClass The PDO subclass to instantiate if there is no explicit classname * specified in the connection params (default is Propel::CLASS_PROPEL_PDO) * * @return PDO A database connection of the given class (PDO, PropelPDO, SlavePDO or user-defined) * * @throws PropelException - if lower-level exception caught when trying to connect. */ public static function initConnection($conparams, $name, $defaultClass = Propel::CLASS_PROPEL_PDO) { $dsn = $conparams['dsn']; if ($dsn === null) { throw new PropelException('No dsn specified in your connection parameters for datasource [' . $name . ']'); } if (isset($conparams['classname']) && !empty($conparams['classname'])) { $classname = $conparams['classname']; if (!class_exists($classname)) { throw new PropelException('Unable to load specified PDO subclass: ' . $classname); } } else { $classname = $defaultClass; } $user = isset($conparams['user']) ? $conparams['user'] : null; $password = isset($conparams['password']) ? $conparams['password'] : null; // load any driver options from the config file // driver options are those PDO settings that have to be passed during the connection construction $driver_options = array(); if (isset($conparams['options']) && is_array($conparams['options'])) { try { self::processDriverOptions($conparams['options'], $driver_options); } catch (PropelException $e) { throw new PropelException('Error processing driver options for datasource [' . $name . ']', $e); } } try { $con = new $classname($dsn, $user, $password, $driver_options); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter('debugpdo.logging.enabled', false)) { $con->useLogging(true); } } catch (PDOException $e) { throw new PropelException("Unable to open PDO connection", $e); } // load any connection options from the config file // connection attributes are those PDO flags that have to be set on the initialized connection if (isset($conparams['attributes']) && is_array($conparams['attributes'])) { $attributes = array(); try { self::processDriverOptions($conparams['attributes'], $attributes); } catch (PropelException $e) { throw new PropelException('Error processing connection attributes for datasource [' . $name . ']', $e); } foreach ($attributes as $key => $value) { $con->setAttribute($key, $value); } } // initialize the connection using the settings provided in the config file. this could be a "SET NAMES <charset>" query for MySQL, for instance $adapter = self::getDB($name); $adapter->initConnection($con, isset($conparams['settings']) && is_array($conparams['settings']) ? $conparams['settings'] : array()); return $con; }
/** * Initializes Propel. */ private static function initPropel() { if (!file_exists(self::$config->curry->propel->conf)) { self::log("Propel configuration missing, skipping propel initialization."); return; } // Use Composer autoloader instead of the built-in propel autoloader Propel::configure(self::$config->curry->propel->conf); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); $classmap = array(); $projectClassPath = self::$config->curry->propel->projectClassPath; foreach ($config['classmap'] as $className => $file) { $classmap[$className] = $projectClassPath . DIRECTORY_SEPARATOR . $file; } $level = error_reporting(error_reporting() & ~E_USER_WARNING); Propel::initialize(); PropelAutoloader::getInstance()->unregister(); self::getAutoloader()->addClassMap($classmap); error_reporting($level); // Initialize debugging/logging if (self::$config->curry->propel->debug) { Propel::getConnection()->useDebug(true); if (self::$logger && self::$config->curry->propel->logging) { Propel::setLogger(self::$logger); } } }
private static function enableSlaveConf($dbName) { $configuration = Propel::getConfiguration(); if (!isset($configuration['datasources'][$dbName]['slaves']['connection'])) { $configuration['datasources'][$dbName]['slaves']['connection'] = self::$_slaveConfig[$dbName]; Propel::setConfiguration($configuration); Propel::initialize(); } Propel::setForceMasterConnection(false); }
private function search($data) { $q = $this->getRequestParameter("q", ''); if (!$q) { throw new BadRequestException('A search string must be provided.'); } $page = $this->getRequestParameter("page", '1'); $limit = $this->getRequestParameter("limit", self::PAGE_SIZE); $culture = $this->getRequestParameter("culture", 'es'); $type = $this->getRequestParameter("type", false); $cl = new SphinxClient(); $dbConf = Propel::getConfiguration(); $dsn = $dbConf['datasources']['propel']['connection']['dsn']; $sphinxServer = sfConfig::get('sf_sphinx_server'); $cl->SetServer($sphinxServer, 3312); $this->limit = 1000; $cl->SetLimits(0, $this->limit, $this->limit); $cl->SetArrayResult(true); $entities = array(); $cl->SetArrayResult(true); if ($type && $type != 'party' && $type != 'politician' && $type != 'proposal') { throw new BadRequestException('Invalid type.'); } if (!$type || $type == 'party') { $this->res = $cl->Query(SfVoUtil::stripAccents($q), "partido_{$culture}"); if ($this->res !== false) { if (isset($this->res["matches"]) && is_array($this->res["matches"])) { $c = new Criteria(); $list = array(); foreach ($this->res["matches"] as $idx => $match) { $list[] = $match['id']; } $c->add(PartidoPeer::ID, $list, Criteria::IN); //$c->addDescendingOrderByColumn(PartidoPeer::SUMU); $pager = new sfPropelPager('Partido', $limit); $pager->setCriteria($c); $pager->setPage($this->getRequestParameter('page', $page)); $pager->init(); foreach ($pager->getResults() as $partido) { $entities[] = new Entity($partido); } } } } if (!$type || $type == 'politician') { $this->res = $cl->Query(SfVoUtil::stripAccents($q), "politico_{$culture}"); if ($this->res !== false) { if (isset($this->res["matches"]) && is_array($this->res["matches"])) { $c = new Criteria(); $list = array(); foreach ($this->res["matches"] as $idx => $match) { $list[] = $match['id']; } $c = new Criteria(); $c->add(PoliticoPeer::ID, $list, Criteria::IN); //$c->addDescendingOrderByColumn(PoliticoPeer::SUMU); $pager = new sfPropelPager('Politico', $limit); $pager->setCriteria($c); $pager->setPage($this->getRequestParameter('page', $page)); $pager->init(); foreach ($pager->getResults() as $politico) { $entities[] = new Entity($politico); } } } } if (!$type || $type == 'proposal') { $this->res = $cl->Query(SfVoUtil::stripAccents($q), "propuesta_{$culture}"); if ($this->res !== false) { if (isset($this->res["matches"]) && is_array($this->res["matches"])) { $c = new Criteria(); $list = array(); foreach ($this->res["matches"] as $idx => $match) { $list[] = $match['id']; } $c = new Criteria(); $c->add(PropuestaPeer::ID, $list, Criteria::IN); //$c->addDescendingOrderByColumn(PropuestaPeer::SUMU); $pager = new sfPropelPager('Propuesta', $limit); $pager->setCriteria($c); $pager->setPage($this->getRequestParameter('page', $page)); $pager->init(); foreach ($pager->getResults() as $propuesta) { $entities[] = new Entity($propuesta); } } } } return $entities; }
private function resetSphinxClient() { $cl = new SphinxClient(); $dbConf = Propel::getConfiguration(); $dsn = $dbConf['datasources']['propel']['connection']['dsn']; $sphinxServer = sfConfig::get('sf_sphinx_server'); $cl->SetServer($sphinxServer, 3312); $cl->SetConnectTimeout(1); $this->limit = 15; $cl->SetArrayResult(true); return $cl; }
function get_DirDB($workspace) { $dbFile = PATH_DB . $workspace . PATH_SEP . 'db.php'; if (!file_exists($dbFile)) { throw new Exception("the db file does not exist, {$dbFile}"); } require_once $dbFile; require_once "propel/Propel.php"; G::LoadSystem('templatePower'); Propel::init(PATH_CORE . "config/databases.php"); $configuration = Propel::getConfiguration(); $connectionDSN = $configuration['datasources']['workflow']['connection']; // printf("using DSN Connection %s \n", pakeColor::colorize( $connectionDSN, 'INFO')); $con = Propel::getConnection('workflow'); $sql = "show variables like 'datadir'"; $stmt = $con->createStatement(); $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); $rs->next(); $row = $rs->getRow(); if (!is_array($row)) { throw new Exception("unable to execute query in database"); } $dataDir = $row['Value']; if ($dataDir[count($dataDir) - 1] == '/') { $dataDir = substr($dataDir, count($dataDir) - 1); } $info_db = array(); $info_db['conx'] = $configuration['datasources']['workflow']['connection']; $info_db['adap'] = $configuration['datasources']['workflow']['adapter']; $info_db['datadir'] = $dataDir; $info_db['DB_ADAPTER'] = DB_ADAPTER; $info_db['DB_HOST'] = DB_HOST; $info_db['DB_NAME'] = DB_NAME; $info_db['DB_USER'] = DB_USER; $info_db['DB_PASS'] = DB_PASS; $info_db['DB_RBAC_HOST'] = DB_RBAC_HOST; $info_db['DB_RBAC_NAME'] = DB_RBAC_NAME; $info_db['DB_RBAC_USER'] = DB_RBAC_USER; $info_db['DB_RBAC_PASS'] = DB_RBAC_PASS; $info_db['DB_REPORT_HOST'] = DB_REPORT_HOST; $info_db['DB_REPORT_NAME'] = DB_REPORT_NAME; $info_db['DB_REPORT_USER'] = DB_REPORT_USER; $info_db['DB_REPORT_PASS'] = DB_REPORT_PASS; return $info_db; }
/** * Returns a named configuration item from the Propel runtime configuration, from under the * 'debugpdo.logging' prefix. If such a configuration setting hasn't been set, the given default * value will be returned. * * @param string $key Key for which to return the value. * @param mixed $defaultValue Default value to apply if config item hasn't been set. * @return mixed */ protected function getLoggingConfig($key, $defaultValue) { return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter("debugpdo.logging.{$key}", $defaultValue); }
/** * Initializes Propel. */ protected function initPropel() { if (!file_exists($this['propel.conf'])) { $this->logger->notice("Propel configuration missing, skipping propel initialization."); return; } // Use Composer autoloader instead of the built-in propel autoloader \Propel::configure($this['propel.conf']); $config = \Propel::getConfiguration(\PropelConfiguration::TYPE_OBJECT); $classmap = array(); $projectClassPath = $this['propel.projectClassPath']; foreach ($config['classmap'] as $className => $file) { $classmap[$className] = $projectClassPath . DIRECTORY_SEPARATOR . $file; } $level = error_reporting(error_reporting() & ~E_USER_WARNING); \Propel::initialize(); \PropelAutoloader::getInstance()->unregister(); $this->autoloader->addClassMap($classmap); error_reporting($level); // Initialize debugging/logging if ($this['propel.debug']) { \Propel::getConnection()->useDebug(true); if ($this['propel.logging']) { \Propel::setLogger($this->logger); } } }
/** * Returns the current PropelConfiguration. * * @return PropelConfiguration */ protected function getPropelConfiguration() { return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); }
public static function generateBuildXml() { $aConfiguration = array('propel' => Propel::getConfiguration()); $oDoc = new DOMDocument(); $oRoot = $oDoc->createElement('config'); $oDoc->appendChild($oRoot); self::writeConfiguration($oDoc, $aConfiguration, $oRoot); $sConfigOutputPath = MAIN_DIR . '/' . DIRNAME_GENERATED . '/buildtime-conf.xml'; file_put_contents($sConfigOutputPath, $oDoc->saveXML()); }