コード例 #1
0
 /**
  * Connects to the host/database.
  *
  * @param string $conn_string Squiz Matrix system root.
  *
  * @return boolean true on success, false on failure
  */
 public function connect($conn_string)
 {
     $SYSTEM_ROOT = $conn_string;
     if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
         echo "You need to supply the path to the System Root as the first argument\n";
         exit(1);
     }
     require_once $SYSTEM_ROOT . '/fudge/dev/dev.inc';
     require_once $SYSTEM_ROOT . '/core/include/general.inc';
     require_once $SYSTEM_ROOT . '/core/lib/DAL/DAL.inc';
     require_once $SYSTEM_ROOT . '/core/lib/MatrixDAL/MatrixDAL.inc';
     require_once $SYSTEM_ROOT . '/data/private/conf/db.inc';
     $this->_dsn = $db_conf['db2'];
     $this->_db_type = $db_conf['db2']['type'];
     // Attempt to connect
     MatrixDAL::dbConnect($this->_dsn, $this->_db_type);
     MatrixDAL::changeDb($this->_db_type);
     // Matrix will throw a FATAL error if it can't connect, so if we got here
     // we're all good
     return true;
 }
コード例 #2
0
    $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
    // Switch the db back if required.
    if ($restoreConnection) {
        $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
    }
}
if ($db_type == 'pgsql') {
    // fairly broad brush used here, we know that slon uses '<schema_name>_(logtrigger|denyaccess)_[0-9]', so we'll use that to sniff for slon and it's schema name. denyaccess indicates slave.
    $slon_schema_query = 'SELECT REGEXP_REPLACE(trigger_name, \'(_logtrigger|_denyaccess)(_[0-9]+)?\', \'\') FROM information_schema.triggers WHERE (trigger_name LIKE \'%_logtrigger%\' OR trigger_name LIKE \'%_denyaccess%\') limit 1';
    // {SLON_SCHEMA} is replaced after the schema name is worked out.
    $slon_schema_lag_query = 'SELECT cast(extract(epoch from st_lag_time) as int8) FROM {SLON_SCHEMA}.sl_status WHERE st_origin = (SELECT last_value FROM {SLON_SCHEMA}.sl_local_node_id)';
    $output .= 'slon:';
    $lag = 0;
    // Slon test
    $db_conf['dbslon'] = $db_conf['db2'];
    MatrixDAL::dbConnect($db_conf['dbslon'], 'dbslon');
    $db = MatrixDAL::getDb('dbslon');
    $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
    $start_time = time();
    $query = MatrixDAL::preparePdoQuery($slon_schema_query);
    try {
        $slon_schema = MatrixDAL::executePdoOne($query);
    } catch (Exception $e) {
        $slon_schema = '';
        $return_code = '500';
    }
    if (!empty($slon_schema)) {
        $output .= $slon_schema . ':';
        $query = MatrixDAL::preparePdoQuery(str_replace('{SLON_SCHEMA}', $slon_schema, $slon_schema_lag_query));
        try {
            $lag = MatrixDAL::executePdoOne($query);
コード例 #3
0
 * the whole array up.
 * If we just used the db type, we couldn't read from and write to the same type.
 * This is actually quite handy - reading from oracle encoding 8859p1, then
 * writing to utf8.
 */
$dest_db = serialize($destination_dsn);
$source_db = serialize($source_dsn);
$db_error = false;
try {
    $source_db_connection = MatrixDAL::dbConnect($source_dsn, $source_db);
} catch (Exception $e) {
    echo "Unable to connect to the source db: " . $e->getMessage() . "\n";
    $db_error = true;
}
try {
    $dest_db_connection = MatrixDAL::dbConnect($destination_dsn, $dest_db);
} catch (Exception $e) {
    echo "Unable to connect to the destination db: " . $e->getMessage() . "\n";
    $db_error = true;
}
/**
 * If we got an error connecting to either system, just stop.
 * The error(s) have already been displayed.
 */
if ($db_error) {
    exit;
}
MatrixDAL::changeDb($dest_db);
$dest_exists = checkDestinationDb();
if (!$dest_exists) {
    echo "Before running the conversion script, you need to run step_02.php from the installer to create the destination tables.\n";
コード例 #4
0
$SYSTEM_ROOT = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
if (empty($SYSTEM_ROOT)) {
    echo "ERROR: You need to supply the path to the System Root as the first argument\n";
    exit;
}
if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT . '/core/include/init.inc')) {
    echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
    exit;
}
require_once $SYSTEM_ROOT . '/data/private/conf/db.inc';
require_once $SYSTEM_ROOT . '/core/include/init.inc';
require_once $SYSTEM_ROOT . '/core/lib/DAL/DAL.inc';
require_once $SYSTEM_ROOT . '/core/lib/MatrixDAL/MatrixDAL.inc';
$db_error = false;
try {
    $db_connection = MatrixDAL::dbConnect($db_conf['db']);
} catch (Exception $e) {
    echo "Unable to connect to the db: " . $e->getMessage() . "\n";
    $db_error = true;
}
if ($db_error) {
    exit;
}
MatrixDAL::changeDb('db');
/**
 * A couple of indexes for postgres do some automatic casting
 * - sq_ast_attr_val_concat
 * - sq_rb_ast_attr_val_concat
 *
 * Postgres does this automatically.
 *