コード例 #1
0
ファイル: common.php プロジェクト: Gentoshi/Greyhole
 static function parse($config_string, $dir_selection_groups)
 {
     $ds = array();
     if ($config_string == 'random' || $config_string == 'most_available_space') {
         global $storage_pool_directories;
         $ds[] = new DirectorySelection(count($storage_pool_directories), $config_string, $storage_pool_directories, FALSE);
         return $ds;
     }
     if (!preg_match('/forced ?\\((.+)\\) ?(random|most_available_space)/i', $config_string, $regs)) {
         gh_log(CRITICAL, "Can't understand the dir_selection_algorithm value: {$config_string}");
     }
     $selection_algorithm = $regs[2];
     $groups = array_map('trim', explode(',', $regs[1]));
     foreach ($groups as $group) {
         $group = explode(' ', preg_replace('/^([0-9]+)x/', '\\1 ', $group));
         $num_dirs = trim($group[0]);
         $group_name = trim($group[1]);
         if ($num_dirs == 'all' || $num_dirs > count($dir_selection_groups[$group_name])) {
             $num_dirs = count($dir_selection_groups[$group_name]);
         }
         $ds[] = new DirectorySelection($num_dirs, $selection_algorithm, $dir_selection_groups[$group_name], TRUE);
     }
     return $ds;
 }
コード例 #2
0
ファイル: sql.php プロジェクト: R3vXX/Greyhole
function db_migrate() {
	global $db_options, $db_use_mysql, $db_use_sqlite;
	// Migration #1 (complete = frozen|thawed)
	if (@$db_use_mysql) {
		$query = "DESCRIBE tasks";
		$result = db_query($query) or die("Can't describe tasks with query: $query - Error: " . db_error());
		while ($row = db_fetch_object($result)) {
			if ($row->Field == 'complete') {
				if ($row->Type == "enum('yes','no')") {
					// migrate
					db_query("ALTER TABLE tasks CHANGE complete complete ENUM('yes','no','frozen','thawed') NOT NULL");
					db_query("ALTER TABLE tasks_completed CHANGE complete complete ENUM('yes','no','frozen','thawed') NOT NULL");
				}
				break;
			}
		}
	} else if (@$db_use_sqlite) {
		$query = "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'tasks'";
		$result = db_query($query) or die("Can't describe tasks with query: $query - Error: " . db_error());
		while ($row = db_fetch_object($result)) {
			if (strpos($row->sql, 'complete BOOL NOT NULL') !== FALSE) {
				// migrate; not supported! @see http://sqlite.org/omitted.html
				gh_log(CRITICAL, "Your SQLite database is not up to date. Column tasks.complete needs to be a TINYTEXT. Please fix, then retry.");
			}
		}
	}
	// Migration #2 (complete = idle)
	if (@$db_use_mysql) {
		$query = "DESCRIBE tasks";
		$result = db_query($query) or die("Can't describe tasks with query: $query - Error: " . db_error());
		while ($row = db_fetch_object($result)) {
			if ($row->Field == 'complete') {
				if ($row->Type == "enum('yes','no','frozen','thawed')") {
					// migrate
					db_query("ALTER TABLE tasks CHANGE complete complete ENUM('yes','no','frozen','thawed','idle') NOT NULL");
					db_query("ALTER TABLE tasks_completed CHANGE complete complete ENUM('yes','no','frozen','thawed','idle') NOT NULL");
				}
				break;
			}
		}
	}
	// Migration #3 (larger settings.value: tinytext > text)
	if (@$db_use_mysql) {
		$query = "DESCRIBE settings";
		$result = db_query($query) or die("Can't describe settings with query: $query - Error: " . db_error());
		while ($row = db_fetch_object($result)) {
			if ($row->Field == 'value') {
				if ($row->Type == "tinytext") {
					// migrate
					db_query("ALTER TABLE settings CHANGE value value TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL");
				}
				break;
			}
		}
	}
	// Migration #4 (new index for find_next_task function, used by simplify_task, and also for execute_next_task function; also remove deprecated indexes)
	if (@$db_use_mysql) {
		$query = "SHOW INDEX FROM tasks WHERE Key_name = 'find_next_task'";
		$result = db_query($query) or die("Can't show index with query: $query - Error: " . db_error());
		if (db_fetch_object($result) === FALSE) {
			// migrate
			db_query("ALTER TABLE tasks ADD INDEX find_next_task (complete, share(64), id)");
		}

		$query = "SHOW INDEX FROM tasks WHERE Key_name = 'incomplete_open'";
		$result = db_query($query) or die("Can't show index with query: $query - Error: " . db_error());
		if (db_fetch_object($result)) {
			// migrate
			db_query("ALTER TABLE tasks DROP INDEX incomplete_open");
		}

		$query = "SHOW INDEX FROM tasks WHERE Key_name = 'subsequent_writes'";
		$result = db_query($query) or die("Can't show index with query: $query - Error: " . db_error());
		if (db_fetch_object($result)) {
			// migrate
			db_query("ALTER TABLE tasks DROP INDEX subsequent_writes");
		}

		$query = "SHOW INDEX FROM tasks WHERE Key_name = 'unneeded_unlinks'";
		$result = db_query($query) or die("Can't show index with query: $query - Error: " . db_error());
		if (db_fetch_object($result)) {
			// migrate
			db_query("ALTER TABLE tasks DROP INDEX unneeded_unlinks");
		}
	}
}