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;
 }
 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;
 }
 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;
 }
 function init($aParams)
 {
     $this->className = get_class($this);
     $this->oDBUpgrade = $aParams[0];
     $this->_log('****************************************');
     $this->oDbh = OA_DB::singleton(OA_DB::getDsn());
     return true;
 }
 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;
 }
 function test_putComponentGroupVersion()
 {
     $oVerCtrl = new OA_Version_Controller();
     $oVerCtrl->init(OA_DB::singleton(OA_DB::getDsn()));
     $this->assertEqual($oVerCtrl->putComponentGroupVersion('plugin_test', 1001), 1001, 'error inserting plugin version');
     $this->assertEqual($oVerCtrl->putComponentGroupVersion('plugin_test', 1002), 1002, 'error updating plugin version');
     $this->assertNotEqual($oVerCtrl->getComponentGroupVersion('plugin_test'), 1001, 'wrong plugin version retrieved');
     $this->_deleteTestRecord('plugin_test');
 }
示例#7
0
 function _setupDataObjectOptionsOLD()
 {
     static $needsSetup;
     if (isset($needsSetup)) {
         return;
     }
     $needsSetup = false;
     // Set DB_DataObject options
     $MAX_ENT_DIR = MAX_PATH . '/lib/max/Dal/DataObjects';
     $options =& PEAR::getStaticProperty('DB_DataObject', 'options');
     $options = array('database' => OA_DB::getDsn(), 'schema_location' => $MAX_ENT_DIR, 'class_location' => $MAX_ENT_DIR, 'require_prefix' => $MAX_ENT_DIR . '/', 'class_prefix' => 'DataObjects_', 'debug' => 0, 'production' => 0);
 }
示例#8
0
 /**
  * A method to disconnect a database connection resource.
  *
  * @static
  * @param string $dsn Optional database DSN details - disconnects from the
  *                    database defined by the configuration file otherwise.
  *                    See {@link OA_DB::getDsn()} for format.
  * @return void
  */
 static function disconnect($dsn)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Get the DSN, if not set
     $dsn = is_null($dsn) ? OA_DB::getDsn() : $dsn;
     // Create an MD5 checksum of the DSN
     $dsnMd5 = md5($dsn);
     // Does this database connection already exist?
     $aConnections = array_keys($GLOBALS['_OA']['CONNECTIONS']);
     if (count($aConnections) > 0 && in_array($dsnMd5, $aConnections)) {
         $GLOBALS['_OA']['CONNECTIONS'][$dsnMd5]->disconnect();
         unset($GLOBALS['_OA']['CONNECTIONS'][$dsnMd5]);
     }
 }
示例#9
0
 /**
  * create the empty database
  *
  * @return boolean
  */
 function _createDatabase($aDsn = '')
 {
     if ($aDsn) {
         $this->aDsn = $aDsn;
     }
     $GLOBALS['_MAX']['CONF']['database'] = $this->aDsn['database'];
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = $this->aDsn['table']['prefix'];
     $GLOBALS['_MAX']['CONF']['table']['type'] = $this->aDsn['table']['type'];
     // Try connecting to the database
     $this->oDbh =& OA_DB::singleton(OA_DB::getDsn($this->aDsn));
     if (PEAR::isError($this->oDbh)) {
         $GLOBALS['_OA']['CONNECTIONS'] = array();
         $GLOBALS['_MDB2_databases'] = array();
         if (PEAR::isError($result)) {
             $this->oLogger->logError($result->getMessage());
             $this->oLogger->logErrorUnlessEmpty($result->getUserInfo());
             return false;
         }
         //attempt to create DB
         $result = OA_DB::createDatabase($this->aDsn['database']['name']);
         if (PEAR::isError($result)) {
             $this->oLogger->logError($result->getMessage());
             $this->oLogger->logErrorUnlessEmpty($result->getUserInfo());
             return false;
         }
         $this->oDbh = OA_DB::changeDatabase($this->aDsn['database']['name']);
         if (PEAR::isError($this->oDbh)) {
             $this->oLogger->logError($this->oDbh->getMessage());
             $this->oLogger->logErrorUnlessEmpty($this->getUserInfo());
             $this->oDbh = null;
             return false;
         }
         $this->oLogger->log('Database created ' . $this->aDsn['database']['name']);
         $this->can_drop_database = true;
     }
     $result = OA_DB::createFunctions();
     if (PEAR::isError($result)) {
         $this->oLogger->logError($result->getMessage());
         return false;
     }
     return true;
 }
示例#10
0
 /**
  * php5 class constructor
  *
  * @param string The XML schema file we are working on
  */
 function __construct($file_schema = 'tables_core.xml', $file_changes = '', $path_schema)
 {
     $this->oLogger = new OA_UpgradeLogger();
     $this->oLogger->setLogFile('schema.log');
     if (empty($path_schema)) {
         $path_schema = '/etc/';
     }
     if (!empty($path_schema) && substr($path_schema, 0, 1) != '/') {
         $path_schema = '/' . $path_schema;
     }
     if (!empty($path_schema) && substr($path_schema, strlen($path_schema) - 4, 4) != 'etc/') {
         $path_schema = $path_schema . 'etc/';
     }
     $this->path_schema_final = MAX_PATH . $path_schema;
     $this->path_schema_trans = MAX_PATH . '/var/';
     $this->path_changes_final = MAX_PATH . $path_schema . 'changes/';
     $this->path_changes_trans = MAX_PATH . '/var/';
     if ($path_schema == '/etc/') {
         $this->path_dbo = MAX_PATH . '/lib/max/Dal/DataObjects/';
     } else {
         $this->path_dbo = $this->path_schema_final . 'DataObjects/';
     }
     //$this->path_links_final = MAX_PATH.'/lib/max/Dal/DataObjects/';
     $this->path_links_final = $this->path_dbo;
     $this->path_links_trans = MAX_PATH . '/var/';
     $file_changes = $file_changes ? $file_changes : 'changes_' . $file_schema;
     $file_links = 'db_schema.links.ini';
     $this->schema_final = $this->path_schema_final . $file_schema;
     $this->schema_trans = $this->path_schema_trans . $file_schema;
     $this->oLogger->log($this->schema_final);
     $this->use_links = $file_schema == 'tables_core.xml';
     if ($this->use_links) {
         $this->links_final = $this->path_links_final . $file_links;
         $this->links_trans = $this->path_links_trans . $file_links;
     }
     $this->changes_final = $this->path_changes_final . $file_changes;
     $this->changes_trans = $this->path_changes_trans . $file_changes;
     $this->oLogger->log($this->changes_final);
     if ($this->use_links) {
         $this->aFile_perms = array($this->path_schema_trans, $this->path_changes_final, $this->path_changes_trans, $this->path_links_trans, $this->links_final, $this->schema_final, MAX_SCHEMA_LOG, MAX_PATH . '/www/devel/');
     } else {
         $this->aFile_perms = array($this->path_schema_trans, $this->path_changes_final, $this->path_changes_trans, $this->schema_final, MAX_SCHEMA_LOG, MAX_PATH . '/www/devel/');
     }
     $this->aDump_options = array('output_mode' => 'file', 'output' => $this->schema_trans, 'end_of_line' => "\n", 'xsl_file' => "xsl/mdb2_schema.xsl", 'custom_tags' => array('version' => '', 'status' => 'transitional'));
     $this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()), $this->aDump_options);
     $this->dd_file = 'etc/dd.generic.xml';
     $this->aDD_definition = $this->oSchema->parseDictionaryDefinitionFile($this->dd_file);
     ksort($this->aDD_definition);
     //$this->aXMLRPCServer = array('path'=>'/upms/xmlrpc.php', 'host'=>'localhost','port'=>'80');
 }
示例#11
0
 /**
  * A method to generate a lock id.
  *
  * @access protected
  *
  * @param string The lock name.
  * @return string The lock id.
  */
 function _getId($sName)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     $sId = sha1($this->oDbh->getDsn() . '/' . $aConf['table']['prefix']);
     return "OA_{$sName}.{$sId}";
 }
示例#12
0
function save_scenario($basename, $conf)
{
    $dsn = OA_DB::getDsn($conf);
    $dbh =& OA_DB::singleton($dsn);
    $conf['simdb']['version'] = get_max_version($dbh, $conf);
    $versname = $conf['simdb']['version'] . '_' . $basename;
    $sql = get_sql_truncate() . strip_prefix(get_sql_insert($dbh, $conf), $conf['table']['prefix']);
    $maintenance_startdate = date('Y-m-d h:i:s', strtotime("+1 hour", strtotime($conf['startdate'])));
    $sql .= "INSERT INTO `log_maintenance_statistics` (`log_maintenance_statistics_id`, `start_run`, `end_run`, `duration`, `adserver_run_type`, `search_run_type`, `tracker_run_type`, `updated_to`) VALUES (1, '{$maintenance_startdate}', '{$maintenance_startdate}', 0, 2, NULL, NULL, '{$maintenance_startdate}');";
    $sql .= $conf['scenario']['resetpriority'] ? "UPDATE `ad_zone_assoc` SET priority=0;\n" : '';
    sim_write_file('/' . FOLDER_DATA, $versname . '.sql', $sql);
    // create request set
    $conf['scenario']['day'] = date('Y-m-d', strtotime($conf['scenario']['startdate']));
    $conf['scenario']['hour'] = date('G', strtotime($conf['scenario']['startdate']));
    $php = file_get_contents(TPL_PATH . '/scenario_config.php.txt');
    foreach ($conf['request'] as $k => $v) {
        $php = str_replace("conf[request][{$k}]", '"' . $v . '"', $php);
    }
    foreach ($conf['scenario'] as $k => $v) {
        $php = str_replace("conf[scenario][{$k}]", '"' . $v . '"', $php);
    }
    foreach ($conf['simdb'] as $k => $v) {
        $php = str_replace("conf[simdb][{$k}]", '"' . $v . '"', $php);
    }
    foreach ($conf['database'] as $k => $v) {
        $php = str_replace("conf[database][{$k}]", '"' . $v . '"', $php);
    }
    sim_write_file('/' . FOLDER_DATA, $versname . '.php', $php);
    // create child class
    $php = file_get_contents(TPL_PATH . '/scenario_class.php.txt');
    $php = str_replace("<#versname>", $versname, $php);
    $php = str_replace("<#basename>", $basename, $php);
    sim_write_file('/' . FOLDER_SAVE, $basename . '.php', $php);
}
 /**
  * Disconnects from the database server
  *
  * @return boolean
  * @static
  */
 function disconnect()
 {
     $ret = true;
     // reset DataObject cache
     $dsn = OA_DB::getDsn();
     $dsn_md5 = md5($dsn);
     global $_DB_DATAOBJECT;
     if (isset($_DB_DATAOBJECT['CONNECTIONS'][$dsn_md5])) {
         $dbh =& $_DB_DATAOBJECT['CONNECTIONS'][$dsn_md5];
         if (!PEAR::isError($dbh)) {
             $ret = $dbh->disconnect();
         }
         unset($_DB_DATAOBJECT['CONNECTIONS'][$dsn_md5]);
     }
     return $ret;
 }
示例#14
0
 /**
  * instantiate the mdb2_schema object
  */
 function initMDB2Schema()
 {
     $result = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()));
     if (!$this->_isPearError($result, 'failed to instantiate MDB2_Schema')) {
         $this->oSchema = $result;
         $this->portability = $this->oSchema->db->getOption('portability');
         $this->_setupSQLStatements();
         $this->oTable = new OA_DB_Table();
     }
 }