You are here

function drush_replication_active in Replication 8

Same name and namespace in other branches
  1. 8.2 replication.drush.inc \drush_replication_active()

Implements drush_hook_COMMAND().

Prints information about the specific active replication between target and source databases.

File

./replication.drush.inc, line 245
Drush integration for the replication module.

Code

function drush_replication_active($source = NULL, $target = NULL) {
  try {
    $client = replication_client_factory();
    $results = $client
      ->getActiveTasks();
    foreach ($results as $key => $result) {
      $results[$key]['started_on'] = date('D, j M Y, H:i:s e', $result['started_on']);
      if ($source && $target && is_array($results)) {
        $source_diff = array_diff(replication_get_url_parts($result['source']), replication_get_url_parts($source));
        $target_diff = array_diff(replication_get_url_parts($result['target']), replication_get_url_parts($target));
        if (empty($source_diff) && empty($target_diff)) {

          // Return information about one active replication.
          return [
            $results[$key],
          ];
        }
        else {
          drush_print('No active replication.');
          return;
        }
      }
    }
    if (!empty($results)) {

      // Return information about all active replications.
      return $results;
    }
    else {
      drush_print('No active replications.');
    }
  } catch (\Exception $e) {
    drush_set_error($e
      ->getMessage());
  }
}