コード例 #1
0
ファイル: 007_CASHSystem.php プロジェクト: nodots/DIY
 function test_setSystemSetting()
 {
     // also tests findAndReplaceInFile()
     $control = CASHSystem::getSystemSettings('timezone');
     CASHSystem::setSystemSetting('timezone', 'Not really a timezone');
     $return = CASHSystem::getSystemSettings('timezone');
     $this->assertNotEqual($control, $return);
     $this->assertEqual('Not really a timezone', $return);
 }
コード例 #2
0
ファイル: settings.php プロジェクト: blacktire/DIY
<?php

$misc_message = false;
if (isset($_POST['domisc'])) {
    CASHSystem::setSystemSetting('timezone', $_POST['timezone']);
    CASHSystem::setSystemSetting('systememail', $_POST['systememail']);
    $cash_admin->page_data['page_message'] = 'Success. All changed.';
}
$migrate_message = false;
if (isset($_POST['domigrate'])) {
    $new_settings = array('hostname' => $_POST['hostname'], 'username' => $_POST['adminuser'], 'password' => $_POST['adminpassword'], 'database' => $_POST['databasename']);
    $migrate_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'migratedb', 'todriver' => $_POST['driver'], 'tosettings' => $new_settings));
    if ($migrate_request->response['payload']) {
        $cash_admin->page_data['page_message'] = 'Success. So that happened.';
    } else {
        $cash_admin->page_data['error_message'] = 'Error. There was a problem migrating your data.';
    }
}
$platform_settings = CASHSystem::getSystemSettings();
$cash_admin->page_data['system_email'] = $platform_settings['systememail'];
$cash_admin->page_data['timezone_options'] = AdminHelper::drawTimeZones($platform_settings['timezone']);
$db_types = array('mysql' => 'MySQL', 'sqlite' => 'SQLite');
$db_type = 'unknown';
if (array_key_exists($platform_settings['driver'], $db_types)) {
    $cash_admin->page_data['db_type'] = $db_types[$platform_settings['driver']];
}
if ($cash_admin->page_data['db_type'] == 'MySQL') {
    $cash_admin->page_data['migrate_from_mysql'] = true;
} elseif ($cash_admin->page_data['db_type'] == 'SQLite') {
    $cash_admin->page_data['migrate_from_sqlite'] = true;
}
コード例 #3
0
ファイル: CASHDBA.php プロジェクト: blacktire/DIY
 public function migrateDB($todriver = 'mysql', $tosettings = false)
 {
     /* for mysql we're expecting a $tosettings array that looks like:
     		   hostname => hostname[:port]
     		   username => username
     		   password => password
     		   database => databasename
     		*/
     if ($todriver != 'mysql' || !is_array($tosettings)) {
         return false;
     } else {
         $newdb_hostname = false;
         $newdb_port = false;
         if (strpos($tosettings['hostname'], ':') === false) {
             $newdb_hostname = $tosettings['hostname'];
             $newdb_port = 3306;
         } else {
             if (substr($tosettings['hostname'], 0, 2) == ':/') {
                 $newdb_hostname = $tosettings['hostname'];
             } else {
                 $host_and_port = explode(':', $tosettings['hostname']);
                 $newdb_hostname = $host_and_port[0];
                 $newdb_port = $host_and_port[1];
             }
         }
         if ($newdb_hostname) {
             try {
                 if (substr($this->hostname, 0, 2) == ':/') {
                     $newdb = new PDO("{$todriver}:unix_socket={$newdb_hostname};dbname={$tosettings['database']}", $tosettings['username'], $tosettings['password']);
                 } else {
                     $newdb = new PDO("{$todriver}:host={$newdb_hostname};port={$newdb_port};dbname={$tosettings['database']}", $tosettings['username'], $tosettings['password']);
                 }
                 $newdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             } catch (PDOException $e) {
                 return false;
             }
             // run the baseline sql file — will blow away any old bullshit but leave non-standard tables
             if ($newdb->query(file_get_contents(CASH_PLATFORM_ROOT . '/settings/sql/cashmusic_db.sql'))) {
                 // begin a transaction for the newdb
                 $newdb->beginTransaction();
                 // get all the current tables
                 $current_tables = $this->getRealTableNames();
                 foreach ($current_tables as $tablename) {
                     // looping through and starting the CRAAAAZZZZEEEEEE
                     // first get all data in the current table
                     $tabledata = $this->doQuery('SELECT * FROM ' . $tablename);
                     // now jam that junk into an insert on the new db
                     if (is_array($tabledata)) {
                         // we found data, so loop through each one with an insert
                         foreach ($tabledata as $data) {
                             $query = "INSERT INTO {$tablename} (";
                             $separator = '';
                             $query_columns = '';
                             $query_values = '';
                             foreach ($data as $fieldname => $value) {
                                 $query_columns .= $separator . $fieldname;
                                 $query_values .= $separator . ':' . $fieldname;
                                 $separator = ',';
                             }
                             $query .= "{$query_columns}) VALUES ({$query_values})";
                             try {
                                 $q = $newdb->prepare($query);
                                 $q->execute($data);
                             } catch (PDOException $e) {
                                 // something went wrong. roll back and quit
                                 $newdb->rollBack();
                                 return false;
                             }
                         }
                     }
                 }
                 // f****n a right.
                 $result = $newdb->commit();
                 if ($result) {
                     CASHSystem::setSystemSetting('driver', $todriver);
                     CASHSystem::setSystemSetting('hostname', $tosettings['hostname']);
                     CASHSystem::setSystemSetting('username', $tosettings['username']);
                     CASHSystem::setSystemSetting('password', $tosettings['password']);
                     CASHSystem::setSystemSetting('database', $tosettings['database']);
                     return $result;
                 } else {
                     return $result;
                 }
             }
         } else {
             return false;
         }
     }
 }