static function configure() { if (empty($_COOKIE['selenium'])) { return; } $cookie = $_COOKIE['selenium']; App::import('Model', 'ConnectionManager', false); ClassRegistry::flush(); Configure::write('Cache.disable', true); $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); $_prefix = null; if ($testDbAvailable) { // Try for test DB restore_error_handler(); @($db =& ConnectionManager::getDataSource('test')); set_error_handler('simpleTestErrorHandler'); $testDbAvailable = $db->isConnected(); } // Try for default DB if (!$testDbAvailable) { $db =& ConnectionManager::getDataSource('default'); } $_prefix = $db->config['prefix']; $db->config['prefix'] = $cookie . '_'; ConnectionManager::create('test_suite', $db->config); $db->config['prefix'] = $_prefix; // Get db connection $db =& ConnectionManager::getDataSource('test_suite'); $db->cacheSources = false; ClassRegistry::config(array('ds' => 'test_suite')); }
public function createDatabaseFile($data) { App::uses('File', 'Utility'); App::uses('ConnectionManager', 'Model'); $config = $this->defaultConfig; foreach ($data['Install'] as $key => $value) { if (isset($data['Install'][$key])) { $config[$key] = $value; } } $result = copy(APP . 'Config' . DS . 'database.php.install', APP . 'Config' . DS . 'database.php'); if (!$result) { return __d('croogo', 'Could not copy database.php file.'); } $file = new File(APP . 'Config' . DS . 'database.php', true); $content = $file->read(); foreach ($config as $configKey => $configValue) { $content = str_replace('{default_' . $configKey . '}', $configValue, $content); } if (!$file->write($content)) { return __d('croogo', 'Could not write database.php file.'); } try { ConnectionManager::create('default', $config); $db = ConnectionManager::getDataSource('default'); } catch (MissingConnectionException $e) { return __d('croogo', 'Could not connect to database: ') . $e->getMessage(); } if (!$db->isConnected()) { return __d('croogo', 'Could not connect to database.'); } return true; }
public function setUp() { parent::setUp(); $config = array('datasource' => 'Copula.RemoteTokenSource', 'login' => 'login', 'password' => 'password', 'authMethod' => 'OAuth', 'scheme' => 'https', 'authorize' => 'auth', 'access' => 'token', 'host' => 'accounts.example.com/oauth2', 'scope' => 'https://www.exampleapis.com/auth/', 'callback' => 'https://www.mysite.com/oauth2callback'); $this->Source = ConnectionManager::create('testapi', $config); $this->Source->Http = $this->getMock('HttpSocketOauth', array('request')); $this->Model = new Model(); }
/** * Adds the datasource to the connection manager if it's not already there, * which it won't be if you've not added it to your app/config/database.php * file. * * @param $id * @param $table * @param $ds * @return void */ public function __construct($id = false, $table = null, $ds = null) { $sources = ConnectionManager::sourceList(); if (!in_array('braintree', $sources)) { ConnectionManager::create('braintree', array('datasource' => 'Braintree.BraintreeSource')); } parent::__construct($id, $table, $ds); }
function __construct() { App::import(array('type' => 'File', 'name' => 'YahooBoss.YAHOO_BOSS_CONFIG', 'file' => 'config' . DS . 'yahoo_boss.php')); App::import(array('type' => 'File', 'name' => 'YahooBoss.YahooBossSource', 'file' => 'models' . DS . 'datasources' . DS . 'yahoo_boss_source.php')); $config =& new YAHOO_BOSS_CONFIG(); ConnectionManager::create('yahooBoss', $config->yahooBoss); parent::__construct(); }
function __construct() { App::import(array('type' => 'File', 'name' => 'GoogleAnalytics.GOOGLE_ANALYTICS_CONFIG', 'file' => 'config' . DS . 'google_analytics.php')); App::import(array('type' => 'File', 'name' => 'GoogleAnalytics.GoogleAnalyticsSource', 'file' => 'models' . DS . 'datasources' . DS . 'google_analytics_source.php')); $config =& new GOOGLE_ANALYTICS_CONFIG(); ConnectionManager::create('googleAnalytics', $config->googleAnalytics); parent::__construct(); }
public function setUp() { parent::setUp(); Configure::write('Copula.testapi.path', $this->paths); Configure::write('Copula.testapi.Api', $this->config); $this->Apis = ConnectionManager::create('testapi', $this->dbconf); $this->model = ClassRegistry::init('CopulaTestModel'); }
/** * Imports the datasources from the plugin and adds to the connection manager */ function __construct() { App::import(array('type' => 'File', 'name' => 'Gdata.GDATA_CONFIG', 'file' => 'config' . DS . 'gdata_config.php')); App::import(array('type' => 'File', 'name' => 'Gdata.GdataSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata_source.php')); App::import(array('type' => 'File', 'name' => 'Gdata.GdataAnalyticsSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata' . DS . 'gdata_analytics.php')); $config =& new GDATA_CONFIG(); ConnectionManager::create('analytics', $config->analytics); parent::__construct(); }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); }
function __construct() { // Datasource config App::import(array('type' => 'File', 'name' => 'Twitter.TWITTER_CONFIG', 'file' => 'config' . DS . 'twitter.php')); // Datasource App::import(array('type' => 'File', 'name' => 'Twitter.TwitterSource', 'file' => 'models' . DS . 'datasources' . DS . 'twitter_source.php')); $config =& new TWITTER_CONFIG(); ConnectionManager::create('twitter', $config->twitter); }
/** * Imports the datasources from the plugin and adds to the connection manager */ public function __construct() { App::import(array('type' => 'File', 'name' => 'Gdata.GDATA_CONFIG', 'file' => 'config' . DS . 'gdata_config.php')); App::import(array('type' => 'File', 'name' => 'Gdata.GdataSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata_source.php')); App::import(array('type' => 'File', 'name' => 'Gdata.GdataPicasa', 'file' => 'models' . DS . 'datasources' . DS . 'gdata' . DS . 'gdata_picasa.php')); $config =& new GDATA_CONFIG(); ConnectionManager::create('picasa', $config->picasa); parent::__construct(); }
public function __construct($id = false, $table = null, $ds = null) { $oDatabase = new DATABASE_CONFIG(); $config = $oDatabase->default; $config["schema"] = "cms"; $ds = ConnectionManager::create("cms", $config); $this->useDbConfig = "cms"; parent::__construct($id, $table, $ds); }
function beforeFilter() { App::Import('ConnectionManager'); App::Import('DataSource'); App::import(array('type' => 'File', 'name' => 'Twitter.TWITTER_CONFIG', 'file' => 'config' . DS . 'core.php')); App::import(array('type' => 'File', 'name' => 'Twitter.TwitterSource', 'file' => 'models' . DS . 'datasources' . DS . 'twitter_source.php')); $TwitterConfig =& new TWITTER_CONFIG(); ConnectionManager::create('twitter', $TwitterConfig->login); $this->Twitter = ConnectionManager::getDataSource('twitter'); }
function __construct() { App::import(array('type' => 'File', 'name' => 'Twitter.TWITTER_CONFIG', 'file' => 'config' . DS . 'core.php')); App::import(array('type' => 'File', 'name' => 'Twitter.TwitterSource', 'file' => 'models' . DS . 'datasources' . DS . 'twitter_source.php')); $TwitterConfig =& new TWITTER_CONFIG(); ConnectionManager::create('twitter', $TwitterConfig->login); $this->Api = ConnectionManager::getDataSource('twitter'); #debug($config); parent::__construct(); }
/** * Start Test * * @return void */ public function startTest() { $config = new DATABASE_CONFIG(); if (isset($config->couchdb_test)) { $this->config = $config->couchdb_test; } ConnectionManager::create('couchdb_test', $this->config); $this->Post = ClassRegistry::init('Post'); $this->removeAllDocuments(); }
public function setUp() { parent::setUp(); ConnectionManager::create('testapi', array('login' => 'login', 'password' => 'password', 'authMethod' => 'OAuthV2', 'datasource' => 'Copula.ApisSource')); $this->request = new CakeRequest(); $this->controller = $this->getMock('FakeController'); $this->components = $this->getMock('ComponentCollection'); $this->components->expects($this->any())->method('getController')->will($this->returnValue($this->controller)); $this->auth = new OauthAuthorize($this->components); }
public function database() { if ($this->request->is('post')) { /** * init config */ foreach ($this->data['Db'] as $key => $value) { if (isset($this->data['Db'][$key])) { $config[$key] = $value; } } /** * additional db settings */ $config['datasource'] = 'Database/Mysql'; $config['prefix'] = ''; //debug($config); //return; /** * check submitted db config */ App::uses('ConnectionManager', 'Model'); try { $db = ConnectionManager::create('default', $config); } catch (Exception $e) { $db = false; } if ($db && $db->isConnected()) { /** * setup database config file */ $src = APP . 'Config' . DS . 'database.php.install'; $target = APP . 'Config' . DS . 'database.php'; copy($src, $target); $file = new File($target, true); $content = $file->read(); $content = str_replace('{default_host}', $config['host'], $content); $content = str_replace('{default_login}', $config['login'], $content); $content = str_replace('{default_password}', $config['password'], $content); $content = str_replace('{default_database}', $config['database'], $content); $content = str_replace('{default_prefix}', $config['prefix'], $content); if ($file->write($content)) { /** * execute sql */ $statements = file_get_contents(APP . 'Config' . DS . 'sql' . DS . 'app.sql'); $db->query($statements); $this->redirect('/installer/thanks'); } else { $this->Session->setFlash(__('Could not write database.php file.'), 'flash_bad'); } } else { $this->Session->setFlash(__('Could not connect to database.'), 'flash_bad'); } } }
/** * Connects to specified database * * @param array $config Server config to use {datasource:?, database:?} * @return array db->config on success, false on failure * @access public */ function dbConnect($config = array()) { ClassRegistry::init('ConnectionManager'); $nds = $config['datasource'] . '_' . $config['host']; $db =& ConnectionManager::getDataSource($config['datasource']); #$db->setConfig(array('name' => $nds, 'database' => $config['database'], 'persistent' => false)); $db->setConfig(array('name' => $nds, 'host' => $config['host'], 'database' => $config['database'], 'login' => $config['login'], 'password' => $config['password'], 'persistent' => false)); if (($ds = ConnectionManager::create($nds, $db->config)) && $db->connect()) { return $db->config; } return false; }
/** * Connects to specified database * * @param String name of different database to connect with. * @param String name of existing datasource * @return boolean true on success, false on failure * @access public */ public function setDatabase($database, $datasource = 'default') { $nds = $datasource . '_' . $database; $db =& ConnectionManager::getDataSource($datasource); $db->setConfig(array('name' => $nds, 'database' => $database, 'persistent' => false)); if ($ds = ConnectionManager::create($nds, $db->config)) { $this->useDbConfig = $nds; $this->cacheQueries = false; return true; } return false; }
/** * Sets up the environment for each test method * * @return void * @access public */ public function startTest() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } ConnectionManager::create('mongo_test', $this->_config); $this->Mongo = new MongodbSource($this->_config); $this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'mongo_test')); $this->_setupData(); }
public function setUp() { App::build(array('Model' => CakePlugin::path('MongoCake') . 'Test' . DS . 'Fixture' . DS), APP::RESET); ConnectionManager::create('testMongo', array('datasource' => 'MongoCake.CakeMongoSource', 'database' => 'test')); $this->request = new CakeRequest('users/index'); $this->request->params['pass'] = $this->request->params['named'] = array(); $this->Controller = new Controller($this->request, new CakeResponse()); $this->Paginator = new DocumentPaginatorComponent($this->getMock('ComponentCollection'), array()); $this->Controller->Paginator = $this->Paginator; $this->Paginator->Controller = $this->Controller; $this->Controller->uses = array('User'); }
/** * Sets up the environment for each test method * * @return void */ function startTest() { $config = array('datasource' => 'Divan', 'database' => false, 'persistent' => false, 'host' => 'localhost', 'port' => '5984', 'login' => 'root', 'password' => ''); $this->Divan = new DivanSource($config); ConnectionManager::create('Divan', $config); $this->Post = ClassRegistry::init('MockPost'); $this->Post->table = 'posts'; $this->Post->setDataSource('Divan'); // Quick fixtures $this->Socket = new HttpSocket("http://{$config['host']}:{$config['port']}/"); $this->Socket->put('/posts', array()); $this->Socket->post('/posts', json_encode(array('testkey' => 'testvalue'))); }
public function setUp() { $connections = ConnectionManager::enumConnectionObjects(); if (!empty($connections['test']['classname']) && $connections['test']['classname'] === 'mongodbSource') { $config = new DATABASE_CONFIG(); $this->_config = $config->test; } if (!isset($connections['test_mongo'])) { ConnectionManager::create('test_mongo', $this->_config); $this->Mongo = new MongodbSource($this->_config); } $this->Post = ClassRegistry::init(array('class' => 'SqlCompatiblePost', 'alias' => 'Post', 'ds' => 'test_mongo'), true); }
public function beforeQuery($query) { $api = $query['api']; if (isset(ConnectionManager::$config->{$api}) && !isset(ConnectionManager::$config->{$api . 'Token'})) { $static = Configure::read("Copula.{$api}.Auth"); $datasourceConfig = ConnectionManager::getDataSource($api)->config; $config = array_merge($datasourceConfig, $static); $config['datasource'] = 'Copula.RemoteTokenSource'; ConnectionManager::create($api . 'Token', $config); } $this->switchDbConfig($api . 'Token'); unset($query['api']); return $query; }
/** * Dynamically creates a B3 DataSource object at runtime based on server selection. * Sets DataSource as 'default' if $this->b3Database is set to false. * * @param bool $id * @param null $table * @param null $ds */ public function __construct($id = false, $table = null, $ds = null) { if ($this->b3Database) { $serverId = Configure::read('server_id'); $host = Configure::read('servers.' . $serverId . '.dbhost'); $login = Configure::read('servers.' . $serverId . '.dbuser'); $password = Configure::read('servers.' . $serverId . '.dbpass'); $database = Configure::read('servers.' . $serverId . '.dbname'); $config = array('datasource' => 'Database/Mysql', 'persistent' => false, 'host' => $host, 'login' => $login, 'password' => $password, 'database' => $database, 'prefix' => ''); ConnectionManager::create('b3', $config); $this->useDbConfig = 'b3'; } else { $this->setDataSource('default'); } parent::__construct($id, $table, $ds); }
protected function _initDb() { $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects())); if ($testDbAvailable) { // Try for test DB restore_error_handler(); $db = ConnectionManager::getDataSource('test'); $testDbAvailable = $db->isConnected(); } // Try for default DB if (!$testDbAvailable) { $db = ConnectionManager::getDataSource('default'); $db->config['prefix'] = 'test_suite_'; } ConnectionManager::create('test_suite', $db->config); ClassRegistry::config(array('ds' => 'test_suite')); }
/** * Execution method always used for tasks * * @return void */ public function execute() { if (isset($this->params['plugin'])) { $plugin = $this->params['plugin']; $pluginPath = $plugin . '.'; App::uses($plugin . 'AppModel', $pluginPath . 'Model'); $pluginmodel = $plugin . 'AppModel'; $plugin_model = new $pluginmodel(); $db = ConnectionManager::getDataSource('default'); $db->cacheSources = false; $config = $db->config; $config['prefix'] = $plugin_model->tablePrefix; ConnectionManager::create('tmpDataSource', $config); $this->connection = 'tmpDataSource'; } parent::execute(); }
function setUp() { parent::setUp(); $Request = new CakeRequest(); $Response = new CakeResponse(); $collection = new ComponentCollection(); $this->controller = new TestController($Request, $Response); $this->controller->Apis = array('testapi'); $this->controller->constructClasses(); $this->Oauth = new OauthComponent($collection); Configure::write('Copula.testapi.Auth', array('authMethod' => 'OAuthV2', 'scheme' => 'https', 'host' => 'www.example.com/api', 'authorize' => 'auth', 'access' => 'token', 'request' => 'request', 'host' => 'accounts.example.com/oauth2', 'scope' => 'https://www.example.com/auth/', 'callback' => 'https://localhost.local/oauth2callback')); ConnectionManager::create('testapi', array('datasource' => 'Copula.ApisSource', 'login' => 'login', 'password' => 'password')); $this->Oauth->initialize($this->controller); $this->Oauth->startup($this->controller); $this->Oauth->TokenSource->beforeQuery(array('api' => 'testapi')); $ds = ConnectionManager::getDataSource('testapiToken'); $ds->Http = $this->getMock('HttpSocketOauth', array('request')); }
/** * Updates config from: app/config/authnet_config.php * Sets up $this->logModel * @param mixed $id * @param string $table * @param mixed $ds */ public function __construct($id = false, $table = null, $ds = null) { // Default minimum config $config = set::merge(array('login' => null, 'key' => null), $this->config); // Try an import the plugins/authnet/config/authnet_config.php file and merge // any default and datasource specific config with the defaults above if (App::import(array('type' => 'File', 'name' => 'AUTHNET.AUTHNET_CONFIG', 'file' => APP . 'config' . DS . 'authnet_config.php'))) { $AUTHNET_CONFIG = new AUTHNET_CONFIG(); if (isset($AUTHNET_CONFIG->config)) { $config = set::merge($config, $AUTHNET_CONFIG->config); } } elseif (App::import(array('type' => 'File', 'name' => 'AUTHNET.AUTHNET_CONFIG', 'file' => 'config' . DS . 'authnet_config.php'))) { if (isset($AUTHNET_CONFIG->config)) { $config = set::merge($config, $AUTHNET_CONFIG->config); } } // Add any config from Configure class that you might have added at any // point before the model is instantiated. if (($configureConfig = Configure::read('AUTHNET.config')) != false) { $config = set::merge($config, $configureConfig); } // double-check we have required keys if (empty($config['login']) || empty($config['login'])) { trigger_error(__d('authnet', "Invalid AUTHNET Configuration, missing 'login' field.", true), E_USER_WARNING); die; } elseif (empty($config['key']) || empty($config['key'])) { trigger_error(__d('authnet', "Invalid AUTHNET Configuration, missing 'key' field.", true), E_USER_WARNING); die; } $this->config = $config; // initialize extras: transaction log model if (!empty($this->config['logModel'])) { if (App::import('model', $this->config['logModel'])) { $this->logModel = ClassRegistry::init(array_pop(explode('.', $this->config['logModel']))); if (isset($this->config['logModel.useTable']) && $this->config['logModel.useTable'] !== null) { $this->logModel->useTable = $this->config['logModel.useTable']; } } } ConnectionManager::create($this->useDbConfig, $config); $db =& ConnectionManager::getDataSource($this->useDbConfig); parent::__construct($id, $table, $ds); }
/** * Sets up a connection using passed settings * * ### Config * - `config` The name of an existing Cache configuration to use. Default is 'default' * - `clearOnSave` Whether or not to delete the cache on saves * - `clearOnDelete` Whether or not to delete the cache on deletes * - `auto` Automatically cache or look for `'cache'` in the find conditions * where the key is `true` or a duration * * @param Model $Model The calling model * @param array $config Configuration settings * @see Cache::config() */ public function setup(Model $Model, $config = array()) { $_defaults = array('config' => 'default', 'clearOnDelete' => true, 'clearOnSave' => true, 'auto' => false, 'gzip' => false); $settings = array_merge($_defaults, $config); $Model->_useDbConfig = $Model->useDbConfig; $ds = ConnectionManager::getDataSource($Model->useDbConfig); if (!in_array('cacher', ConnectionManager::sourceList())) { $settings += array('original' => $Model->useDbConfig, 'datasource' => 'Cacher.CacheSource'); $settings = array_merge($ds->config, $settings); ConnectionManager::create('cacher', $settings); } else { $ds = ConnectionManager::getDataSource('cacher'); $ds->config = array_merge($ds->config, $settings); } if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = $settings; } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings); }