Beispiel #1
0
 public function action_get_index_collection()
 {
     $db = service('db.config');
     $phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'), 'parser' => 'php'];
     $phinx_app = new Phinx\Console\PhinxApplication();
     $phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config);
     $migration_results = call_user_func([$phinx_wrapper, 'getMigrate'], 'ushahidi', null);
     $error = $phinx_wrapper->getExitCode() > 0;
     $this->_response_payload = ['results' => explode("\n", $migration_results, -1)];
 }
Beispiel #2
0
 public function action_get_index_collection($command = 'status')
 {
     $user = service('session.user');
     if ('admin' != $user->role) {
         throw new HTTP_Exception_403('Must be an admin to access this service');
     }
     $commands = ['status' => 'getStatus', 'rollback' => 'getRollback'];
     // add return status if invalid command is selected
     if (!array_key_exists($command, $commands)) {
         $command = 'status';
     }
     $db = service('db.config');
     $phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'), 'parser' => 'php'];
     $phinx_app = new Phinx\Console\PhinxApplication();
     $phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config);
     $migration_results = call_user_func([$phinx_wrapper, $commands[$command]], 'ushahidi', null);
     $error = $phinx_wrapper->getExitCode() > 0;
     $this->_response_payload = ['results' => explode("\n", $migration_results, -1)];
 }
Beispiel #3
0
$app = (require __DIR__ . '/phinx.php');
$wrap = new Phinx\Wrapper\TextWrapper($app);
// Mapping of route names to commands.
$routes = ['status' => 'getStatus', 'migrate' => 'getMigrate', 'rollback' => 'getRollback'];
// Extract the requested command from the URL, default to "status".
$command = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if (!$command) {
    $command = 'status';
}
// Verify that the command exists, or list available commands.
if (!isset($routes[$command])) {
    $commands = implode(', ', array_keys($routes));
    header('Content-Type: text/plain', true, 404);
    die("Command not found! Valid commands are: {$commands}.");
}
// Get the environment and target version parameters.
$env = isset($_GET['e']) ? $_GET['e'] : null;
$target = isset($_GET['t']) ? $_GET['t'] : null;
// Check if debugging is enabled.
$debug = !empty($_GET['debug']) && filter_var($_GET['debug'], FILTER_VALIDATE_BOOLEAN);
// Execute the command and determine if it was successful.
$output = call_user_func([$wrap, $routes[$command]], $env, $target);
$error = $wrap->getExitCode() > 0;
// Finally, display the output of the command.
header('Content-Type: text/plain', true, $error ? 500 : 200);
if ($debug) {
    // Show what command was executed based on request parameters.
    $args = implode(', ', [var_export($env, true), var_export($target, true)]);
    echo "DEBUG: {$command}({$args})" . PHP_EOL . PHP_EOL;
}
echo $output;