public function testRunNewMigrationUpdateCompletedTable() { $this->simulateLogin('*****@*****.**', true); $controller = new UpgradeDatabaseController(true); $this->newMigrationFiles('some_stuff'); $this->newMigrationFiles('some_stuff', $old = true); // older already ran? $db_version = UpgradeDatabaseController::getCurrentDBVersion($cached = false); $list = $controller->getMigrationList($db_version); $this->assertEqual(count($list), 1); $this->assertTrue($list[0]['new_migration']); $this->assertPattern("/^2011-09-21_some_stuff_v\\d+\\.\\d+\\.sql\$/", $list[0]['filename']); // create completion table $com_sql_file = THINKUP_WEBAPP_PATH . 'install/sql/completed_migrations.sql'; //echo $com_sql_file; $com_sql = file_get_contents($com_sql_file); $com_sql = str_replace('tu_', $this->table_prefix, $com_sql); $this->pdo->query($com_sql); $this->pdo->query("alter table " . $this->table_prefix . "completed_migrations DROP column sql_ran"); $_GET['migration_index'] = 1; $results = $controller->go(); $obj = json_decode($results); $this->assertTrue($obj->processed); $sql = file_get_contents($this->test_migrations[0]); $sql = preg_replace('/\\-\\-.*/', '', $sql); $sql = str_replace('tu_', $this->table_prefix, $sql); $this->assertEqual($obj->sql, $sql); $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations"); $data2 = $stmt->fetchAll(PDO::FETCH_ASSOC); $this->assertEqual(count($data2), 3); $this->assertPattern('/CREATE TABLE `.*test1`/', $data2[0]['sql_ran']); }
/** * Determine if ThinkUp needs to show the upgrading page. * @param bool Is the current user an admin * @param str The calling classname * @return bool Whether or not we need to show the upgrade page */ public static function isUpgrading($is_admin, $class_name) { $config = Config::getInstance(); $status = false; $db_version = UpgradeDatabaseController::getCurrentDBVersion($config->getValue('cache_pages')); if (version_compare($db_version, $config->getValue('THINKUP_VERSION'), '<')) { if ($class_name != 'UpgradeDatabaseController') { $status = true; } else { if (!$is_admin && !isset($_GET['upgrade_token'])) { $status = true; } } if ($status == true) { self::generateUpgradeToken(); } } return $status; }
// don't run via the web... if (isset($_SERVER['SERVER_NAME'])) { die("This script should only be run via the command line."); } // help? array_shift($argv); if (isset($argv[0]) && preg_match('/^(\\-h|\\-\\-help)$/i', $argv[0])) { usage(); } $no_version = false; if (isset($argv[0]) && preg_match('/^(\\-\\-with\\-new\\-sql)$/i', $argv[0])) { $no_version = true; } try { // do we need a migration? $db_version = UpgradeDatabaseController::getCurrentDBVersion($cached = false); $config = Config::getInstance(); $thinkup_db_version = $config->getValue('THINKUP_VERSION'); $filename = false; if ($db_version == $thinkup_db_version && !$no_version) { error_log("\nYour ThinkUp database structure is up to date.\n"); exit; } else { if (!$no_version) { print "\nThinkup needs to be upgraded to version {$thinkup_db_version}, proceed? => [y|n] "; $handle = fopen("php://stdin", "r"); $line = fgets($handle); if (trim($line) != 'y') { exit; } }