Commit e42bf6f6 authored by Frédéric G. Marand's avatar Frédéric G. Marand
Browse files

Added UI to close remote cursors from the server ad admin/content/migrate_remote/(rcid).

parent 55afae32
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ function migrate_remote_page_client($client) {
      );

      // Client cursors information
      $cursors = db_query('SELECT rt.entity_type entity_name, rt.bundle, rt.rcid, rt.created, rt.offset, rt.ids '
      $cursors = db_query('SELECT rt.token, rt.entity_type entity_name, rt.bundle, rt.rcid, rt.created, rt.offset, rt.ids '
        . 'FROM {res_token} rt'
        . '  INNER JOIN {res_client} rc ON rt.rcid = rc.rcid '
        . 'WHERE rc.base = :base', array(':base' => $client['base']))->fetchAll();
@@ -92,6 +92,7 @@ function migrate_remote_page_client($client) {
          t('Entity/bundle'),
          t('Progress'),
          t('Created'),
          t('Operations'),
        );
        $rows = array();
        foreach ($cursors as $cursor) {
@@ -102,7 +103,9 @@ function migrate_remote_page_client($client) {
            ? t('Unknown')
            : t('@offset / @count', array('@offset' => $cursor->offset, '@count' => count($ids)));
          $row[] = format_date($cursor->created, 'custom', 'Y-m-d H:i:s');
          $row[] = l(t('Close'), 'admin/content/migrate_remote/close/' . $client['rcid'] . '/' . $cursor->token);
          $rows[] = $row;

        }
        $ret['cursors'] = array(
          '#theme' => 'table',
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ function migrate_remote_client_load($rcid) {
  static $clients = array(); // called 4 times on a page, so use a static

  if (!isset($clients[$rcid])) {
    $client = db_query('SELECT rc.base, rc.endpoint, rc.status FROM {res_client} rc WHERE rc.rcid = :rcid', array(
    $client = db_query('SELECT rc.rcid, rc.base, rc.endpoint, rc.status FROM {res_client} rc WHERE rc.rcid = :rcid', array(
      ':rcid' => $rcid))->fetchAssoc();
    $clients[$rcid] = $client;
    // dsm($client, 'SQL');
+24 −0
Original line number Diff line number Diff line
@@ -25,3 +25,27 @@ function res_settings_form($form, $form_state) {

  return system_settings_form($form);
}

function migrate_remote_cursor_close_confirm_form($form, $form_state, $client, $token) {
  $path = 'admin/content/migrate_remote/' . $client['rcid'];
  $form['path']  = array('#type' => 'value', '#value' => $path);
  $form['token'] = array('#type' => 'value', '#value' => $token);
  $form['base']  = array('#type' => 'value', '#value' => $client['base']);

  $ret = confirm_form($form,
    t('Do you confirm closing cursor %cursor for client %base', array(
      '%cursor' => $token,
      '%base' => $client['base'])),
    $path
  );
  return $ret;
}

function migrate_remote_cursor_close_confirm_form_submit($form, &$form_state) {
  $form_state['redirect'] = $form_state['values']['path'];
  drupal_set_message(t('Cursor for %base deleted', array('%base' => $form_state['values']['base'])));

  db_delete('res_token')
    ->condition('token', $form_state['values']['token'])
    ->execute();
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ files[] = res_migration.inc
files[] = res_source.inc
files[] = views/res_views_plugin_query.inc
files[] = views/res_views_handler_field_token_idlist.inc
files[] = views/res_views_handler_field_token_close.inc

; Not currently used
;files[] = res_map.inc
+20 −0
Original line number Diff line number Diff line
@@ -317,6 +317,15 @@ function res_menu() {
    'access arguments' => array('migration information'), // from Migrate UI
  );

  $items['admin/content/migrate_remote/close/%migrate_remote_client/%res_token'] = array(
    'title' => 'Cursor close',
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array('migrate_remote_cursor_close_confirm_form', 4, 5),
    'file' => 'res.admin.inc',
    'access arguments' => array('migration information'), // from Migrate UI
  );

  return $items;
}

@@ -464,3 +473,14 @@ function res_res_post_load_alter($ret) {
    }
  }
}

/**
 * Load a RES token if it exists.
 *
 * @param string $token
 */
function res_token_load($token) {
  $value = db_query("SELECT 'found' FROM {res_token} rt WHERE rt.token = :token",
    array(':token' => (string) $token))->fetchField();
  return $value === 'found' ? $token : FALSE;
}
Loading