本文整理汇总了PHP中OA_DB::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP OA_DB::singleton方法的具体用法?PHP OA_DB::singleton怎么用?PHP OA_DB::singleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OA_DB
的用法示例。
在下文中一共展示了OA_DB::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UserMigration
function UserMigration()
{
// We will need the admin and per-agency languages to assign the correct "Default" languages to advertiser and websites
if (!$this->init(OA_DB::singleton())) {
$this->_logError('Failed to initialise UserMigration class');
return false;
}
$this->_log('Initialised UserMigration class, construction begun');
$table = $this->_getQuotedTableName('preference');
// Get admin language
$query = "\n SELECT\n agencyid AS id,\n language AS language\n FROM\n {$table}\n WHERE\n agencyid = 0\n ";
$adminLang = $this->oDBH->getAssoc($query);
if (PEAR::isError($adminLang)) {
$this->_logError("Error while retrieving admin language: " . $adminLang->getUserInfo());
return false;
}
// Get agency languages
$table = $this->_getQuotedTableName('agency');
$query = "\n SELECT\n agencyid AS id,\n language AS language\n FROM\n {$table}";
$agencyLang = $this->oDBH->getAssoc($query);
if (PEAR::isError($agencyLang)) {
$this->_logError("Error while retrieving agency languages: " . $agencyLang->getUserInfo());
return false;
}
// Set the admin's language for id 0, then set each agencies language as specified, using admins if unset
$this->aLanguageByAgency[0] = !empty($adminLang[0]) ? $adminLang[0] : 'english';
foreach ($agencyLang as $id => $language) {
if (!empty($language)) {
$this->aLanguageByAgency[$id] = $language;
} else {
$this->aLanguageByAgency[$id] = $this->aLanguageByAgency[0];
}
}
$this->_log('UserMigration class, construction complete');
}
示例2: testSaveAllocatedImpressions
/**
* A method to test the saveAllocatedImpressions method.
*/
function testSaveAllocatedImpressions()
{
$oDbh =& OA_DB::singleton();
$oDal = new OA_Dal_Maintenance_Priority();
// Create the required temporary table for the tests
$oTable =& OA_DB_Table_Priority::singleton();
$oTable->createTable('tmp_ad_zone_impression');
// Prepare the test data
$aData = array(array('ad_id' => 56, 'zone_id' => 11, 'required_impressions' => 9997, 'requested_impressions' => 9000), array('ad_id' => 56, 'zone_id' => 12, 'required_impressions' => 24, 'requested_impressions' => 24));
$result = $oDal->saveAllocatedImpressions($aData);
$query = "SELECT * FROM " . $oDbh->quoteIdentifier('tmp_ad_zone_impression', true) . " ORDER BY ad_id, zone_id";
$rc = $oDbh->query($query);
$result = $rc->fetchAll();
$this->assertTrue(is_array($result));
$this->assertTrue(count($result) == 2);
$tmp = $result[0];
$this->assertTrue(array_key_exists('ad_id', $tmp));
$this->assertEqual($tmp['ad_id'], 56);
$this->assertTrue(array_key_exists('zone_id', $tmp));
$this->assertEqual($tmp['zone_id'], 11);
$this->assertTrue(array_key_exists('required_impressions', $tmp));
$this->assertEqual($tmp['required_impressions'], 9997);
$this->assertTrue(array_key_exists('requested_impressions', $tmp));
$this->assertEqual($tmp['requested_impressions'], 9000);
$tmp = $result[1];
$this->assertTrue(array_key_exists('ad_id', $tmp));
$this->assertEqual($tmp['ad_id'], 56);
$this->assertTrue(array_key_exists('zone_id', $tmp));
$this->assertEqual($tmp['zone_id'], 12);
$this->assertTrue(array_key_exists('required_impressions', $tmp));
$this->assertEqual($tmp['required_impressions'], 24);
$this->assertTrue(array_key_exists('requested_impressions', $tmp));
$this->assertEqual($tmp['requested_impressions'], 24);
TestEnv::dropTempTables();
}
示例3: testAllMaintenanceStatisticsTables
/**
* Tests creating/dropping all of the MPE temporary tables.
*
* Requirements:
* Test 1: Test that all MPE temporary tables can be created and dropped.
*/
function testAllMaintenanceStatisticsTables()
{
$tmpTables = array('tmp_ad_impression', 'tmp_ad_click', 'tmp_tracker_impression_ad_impression_connection', 'tmp_tracker_impression_ad_click_connection', 'tmp_ad_connection');
// Test 1
$conf =& $GLOBALS['_MAX']['CONF'];
$conf['table']['prefix'] = '';
$oDbh =& OA_DB::singleton();
foreach ($tmpTables as $tableName) {
$query = "SELECT * FROM {$tableName}";
OA::disableErrorHandling();
$result = $oDbh->query($query);
OA::enableErrorHandling();
$this->assertEqual(strtolower(get_class($result)), 'mdb2_error');
}
$oTable =& OA_DB_Table_Statistics::singleton();
foreach ($tmpTables as $tableName) {
$oTable->createTable($tableName);
}
$aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
foreach ($tmpTables as $tableName) {
// Test that the table has been created
$query = "SELECT * FROM {$tableName}";
$result = $oDbh->query($query);
$this->assertTrue($result);
// Test that the table can be dropped
// Use a different query to overcome MDB2 query buffering
$query = "SELECT foo FROM {$tableName}";
OA::disableErrorHandling();
$result = $oDbh->query($query);
OA::enableErrorHandling();
$this->assertEqual(strtolower(get_class($result)), 'mdb2_error');
}
// Restore the testing environment
TestEnv::restoreEnv();
}
示例4: while
/**
* A factory method which returns the currently supported best advisory lock
* instance.
*
* @return OA_DB_AdvisoryLock Reference to an OA_DB_AdvisoryLock object.
*/
function &factory($sType = null)
{
if (is_null($sType)) {
$oDbh =& OA_DB::singleton();
if (PEAR::isError($oDbh)) {
OA::debug('Error connecting to database to obtain locking object. Native error follows:', PEAR_LOG_ERR);
OA::debug($oDbh, PEAR_LOG_ERR);
OA::debug('Will re-try connection...', PEAR_LOG_ERR);
$retryCount = 0;
while (PEAR::isError($oDbh) && $retryCount < 6) {
$retryCount++;
sleep(10);
OA::debug('Re-try connection attempt #' . $retryCount, PEAR_LOG_ERR);
$oDbh =& OA_DB::singleton();
}
if (PEAR::isError($oDbh)) {
OA::debug('Failed in re-try attempts to connect to database. Aborting.', PEAR_LOG_CRIT);
exit;
}
}
$aDsn = MDB2::parseDSN($oDbh->getDSN());
$sType = $aDsn['phptype'];
}
include_once MAX_PATH . '/lib/OA/DB/AdvisoryLock/' . $sType . '.php';
$sClass = "OA_DB_AdvisoryLock_" . $sType;
$oLock = new $sClass();
if (!$oLock->_isLockingSupported()) {
// Fallback to file based locking if the current class won't work
$oLock =& OA_DB_AdvisoryLock::factory('file');
}
return $oLock;
}
示例5: setUp
function setUp()
{
$this->oDbh = OA_DB::singleton(OA_DB::getDsn());
$this->oTable = new OA_DB_Table();
$this->oTable->init(MAX_PATH . '/lib/OA/Upgrade/tests/data/migration_test_1.xml');
$this->aDefinition = $this->oTable->aDefinition;
}
示例6: Test_OA_DB_XmlCache
/**
* The constructor method.
*/
function Test_OA_DB_XmlCache()
{
$this->UnitTestCase();
$this->oDbh = OA_DB::singleton();
$this->oCache = new OA_DB_XmlCache();
$this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false));
}
示例7: __construct
/**
* Constructor
*
* @param array $conf array, if null reads the global variable
* @param array $pref array, if null reads the global variable
*/
function __construct($conf = null, $pref = null)
{
$this->aConf = is_null($conf) ? $GLOBALS['_MAX']['CONF'] : $conf;
$this->aPref = is_null($pref) ? $GLOBALS['_MAX']['PREF'] : $pref;
$this->_conf = $this->aConf['oacSync'];
$this->oDbh =& OA_DB::singleton();
}
示例8: __construct
/**
* The constructor method.
*/
function __construct()
{
parent::__construct();
$this->oDbh = OA_DB::singleton();
$this->oCache = new OA_DB_XmlCache();
$this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false));
}
示例9: removeDashboardColumns
function removeDashboardColumns()
{
$this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()));
$prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
$table = 'preference';
$aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received');
OA_DB::setCaseSensitive();
$aDef = $this->oSchema->getDefinitionFromDatabase(array($prefix . $table));
OA_DB::disableCaseSensitive();
if (is_array($aDef) && count($aDef) > 0) {
$aTask['remove'] = array();
if (isset($aDef['tables'][$prefix . $table])) {
foreach ($aColumns as $column) {
if (isset($aDef['tables'][$prefix . $table]['fields'][$column])) {
$aTask['remove'][$column] = array();
$this->oUpgrade->oLogger->logOnly("preference.{$column} found");
}
}
}
if (count($aTask['remove'] > 0)) {
$result = $this->oSchema->db->manager->alterTable($prefix . $table, $aTask, false);
}
}
$this->oUpgrade->oLogger->logOnly('preference table schema upgrade for dashboard unnecessary');
return true;
}
示例10: testSqlForInsert
function testSqlForInsert()
{
$sql = OA_DB_Sql::sqlForInsert('zones', array('zonetype' => 1, 'name' => "120x72"));
$oDbh = OA_DB::singleton();
$table = $oDbh->quoteIdentifier($this->getPrefix() . 'zones', true);
$this->assertEqual("INSERT INTO {$table} (zonetype,name) VALUES (1,'120x72')", $sql);
}
示例11: alterDatabaseActionTable
function alterDatabaseActionTable()
{
$this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()));
$prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
OA_DB::setCaseSensitive();
$aPrev = $this->oSchema->getDefinitionFromDatabase(array($prefix . 'database_action'));
OA_DB::disableCaseSensitive();
$aCurr = $this->_getLatestDatabaseActionSchema($prefix);
$aChanges = $this->oSchema->compareDefinitions($aCurr, $aPrev);
if (is_array($aChanges) && count($aChanges) > 0) {
if (isset($aChanges['tables']['change'][$prefix . 'database_action'])) {
if (isset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey'])) {
unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey']);
unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['change']);
}
if (isset($aChanges['tables']['change'][$prefix . 'database_action']['add']['database_action_id'])) {
$result = $this->oSchema->alterDatabase($aCurr, $aPrev, $aChanges);
if (PEAR::isError($result)) {
$this->oUpgrade->oLogger->logError($result->getUserInfo());
return false;
}
$this->oUpgrade->oLogger->log('database_action table schema successfully upgraded');
return true;
}
}
}
$this->oUpgrade->oLogger->log('database_action table schema upgrade unnecessary');
return true;
}
示例12: __construct
function __construct()
{
// Get a connection to the datbase
$this->oDbh =& OA_DB::singleton();
// Locate all plugins (packages) that have been installed
$oPluginManager = new OX_PluginManager();
$this->aPackages = $oPluginManager->getPackagesList();
}
示例13: _getValidCampaigns
/**
* A method that uses the getAllCampaigns() method to obtain all campaigns
* that meet the requirements of this class. That is:
*
* - The campaign is active, and has a priority of at least 1; and
* - The campaign has daily inventory requirements.
*
* @access private
* @return array An array of {@link OX_Maintenance_Priority_Campaign} objects.
*/
function _getValidCampaigns()
{
$conf = $GLOBALS['_MAX']['CONF'];
$oDbh = OA_DB::singleton();
$table = $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['campaigns'], true);
$aWheres = array(array("{$table}.priority >= 1", 'AND'), array("{$table}.status = " . OA_ENTITY_STATUS_RUNNING, 'AND'), array("({$table}.target_impression > 0 OR {$table}.target_click > 0 OR {$table}.target_conversion > 0)", 'AND'), array("({$table}.expire_time IS NULL OR ({$table}.views = -1 AND {$table}.clicks = -1 AND {$table}.conversions = -1))", 'AND'));
return $this->_getAllCampaigns($aWheres);
}
示例14: init
function init($aParams)
{
$this->className = get_class($this);
$this->oDBUpgrade = $aParams[0];
$this->_log('****************************************');
$this->oDbh = OA_DB::singleton(OA_DB::getDsn());
return true;
}
示例15: _getAuditObject
function _getAuditObject($classToTest)
{
$oAuditor = new $classToTest();
$oDbh = OA_DB::singleton(OA_DB::getDsn());
$oAuditor->prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
$oAuditor->oDbh = $oDbh;
return $oAuditor;
}