From 471a5cdd4df25297a544c49a703a5146bbff0801 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Mon, 29 Nov 2010 03:01:34 -0500
Subject: [PATCH] Remove export-import accounts feature.

If we decide to re-insert this, probably we should use some more popular
import/export method (aka no reinvent the wheel).

- Remove export accounts feature.
- Remove import accounts feature.
---
 includes/VersioncontrolRepository.php       |   18 ---
 includes/interfaces.inc                     |   38 -----
 versioncontrol.admin.inc                    |  208 ---------------------------
 versioncontrol.module                       |   33 -----
 versioncontrol_fakevcs/includes/classes.inc |   64 +--------
 5 files changed, 1 insertions(+), 360 deletions(-)

diff --git includes/VersioncontrolRepository.php includes/VersioncontrolRepository.php
index 83c9b33..8173f38 100644
--- includes/VersioncontrolRepository.php
+++ includes/VersioncontrolRepository.php
@@ -354,24 +354,6 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface
   protected function backendDelete($options) {}
 
   /**
-   * Export a repository's authenticated accounts to the version control system's
-   * password file format.
-   *
-   * FIXME this is TOTALLY broken, it calls itself.
-   * @param $repository
-   *   The repository array of the repository whose accounts should be exported.
-   *
-   * @return
-   *   The plaintext result data which could be written into the password file
-   *   as is.
-   *
-   */
-  public function exportAccounts() {
-    $accounts = $this->loadAccounts();
-    return $repository->exportAccounts($accounts);
-  }
-
-  /**
    * Convinience method to call backend analogue.
    *
    * @param $revision
diff --git includes/interfaces.inc includes/interfaces.inc
index b7f2dad..c34dfea 100644
--- includes/interfaces.inc
+++ includes/interfaces.inc
@@ -181,44 +181,6 @@ interface VersioncontrolRepositoryGetItem {
 
 }
 
-interface VersioncontrolRepositoryImportExport {
-
-  /**
-   * Import accounts into a repository, given text data from the accounts
-   * file.
-   * No accounts are deleted, new accounts are inserted, and existing
-   * accounts are updated with imported ones.
-   *
-   * This function is optional for backend modules to implement. If it's not
-   * implemented, the user will simply not be offered import functionality.
-   *
-   * @param $data
-   *   The contents of the "account data" text area where the user has to
-   *   enter/copy the contents of the version control system's accounts file.
-   */
-  public function importAccounts($data);
-
-  /**
-   * Export accounts of a repository to text data that is suitable for
-   * copying to the version control system's accounts file.
-   *
-   * This function is optional for backend modules to implement. If it's
-   * not implemented, the user will simply not be offered export
-   * functionality.
-   *
-   * @param $accounts
-   *   The list (array) of accounts that should be exported, given in the
-   *   same format as the return value of
-   *   VersioncontrolAccountCache::getInstance()->getAccounts().  All
-   *   accounts in this list are from the above repository.
-   *
-   * @return
-   *   The exported textual representation of the account list.
-   */
-  public function exportAccounts($accounts);
-
-}
-
 interface VersioncontrolUserMapperInterface {
   /**
    * Map the author of the passed VersioncontrolOperation object to a Drupal
diff --git versioncontrol.admin.inc versioncontrol.admin.inc
index 4c81ecd..83da054 100644
--- versioncontrol.admin.inc
+++ versioncontrol.admin.inc
@@ -334,214 +334,6 @@ function versioncontrol_versioncontrol_filter_accounts(&$accounts) {
   }
 }
 
-
-/**
- * Form callback for "admin/project/versioncontrol-accounts/import":
- * A repository select box and a text area for VCS specific account data
- * that will be imported into the selected repository.
- */
-function versioncontrol_admin_account_import_form(&$form_state) {
-  $form = array();
-  $selected_backends = array();
-
-  foreach (versioncontrol_get_backends() as $vcs => $backend) {
-    $build_data = array(
-      'repo_id' => 0,
-      'vcs' => $backend->name,
-    );
-    $repo = $backend->buildEntity('repo', $build_data);
-    if ($repo instanceof VersioncontrolRepositoryImportExport) {
-      $selected_backends[] = $vcs;
-    }
-  }
-  $repositories = versioncontrol_repository_load_multiple(array('vcs' => $selected_backends));
-
-  if (empty($repositories)) {
-    $form['no_repositories'] = array(
-      '#type' => 'markup',
-      '#value' => t('There are no repositories for which the accounts can be imported.'),
-      '#prefix' => '<p>',
-      '#suffix' => '</p>',
-    );
-    return $form;
-  }
-
-  $repository_names = array();
-  foreach ($repositories as $repo_id => $repository) {
-    if (!isset($first_repo_id)) {
-      $first_repo_id = $repo_id;
-    }
-    $repository_names[$repo_id] = check_plain($repository['name']);
-  }
-
-  $form['repo_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Import accounts into'),
-    '#options' => $repository_names,
-    '#default_value' => $first_repo_id,
-  );
-  $form['data'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Account data'),
-    '#description' => t('The contents of the config file that contains the accounts that shall be imported. Existing accounts will be updated, new accounts will be created, and all others will be left untouched.'),
-    '#cols' => 70,
-    '#rows' => 24,
-    '#required' => TRUE,
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Import accounts'),
-    '#weight' => 100,
-  );
-  return $form;
-}
-
-/**
- * Validation form callback for VCS account data.
- *
- * Only actually validates that the repo backend is correctly configured.
- */
-function versioncontrol_admin_account_import_form_validate($form, &$form_state) {
-  if (is_null(versioncontrol_repository_load($form_state['values']['repo_id']))) {
-    form_error($form['data'], t('The selected repository could not be found.'));
-  }
-}
-
-/**
- * Submit handler for the "select repository to import" form from above:
- * Call the repo::importAccounts() with the given data.
- */
-function versioncontrol_admin_account_import_form_submit($form, &$form_state) {
-  $repository = versioncontrol_repository_load($form_state['values']['repo_id']);
-  $repository->importAccounts($form_state['values']['data']);
-}
-
-
-/**
- * Callback for 'admin/project/versioncontrol-accounts/export/%versioncontrol_repository':
- * Export a repository's authenticated accounts to the version control system's
- * password file format.
- */
-function versioncontrol_admin_account_export_page($repository) {
-  if (!$repository instanceof VersioncontrolRepositoryImportExport) {
-    drupal_not_found();
-    return;
-  }
-
-  // The repository has already been selected, export the accounts.
-  $data = $repository->exportAccounts();
-
-  if (arg(5) == 'plaintext') {
-    drupal_set_header('Content-Type: text/plain; charset=utf-8');
-    print $data;
-  }
-  else {
-    return drupal_get_form(
-      'versioncontrol_admin_account_export_display_form', $repository, $data
-    );
-  }
-}
-
-/**
- * Form callback for "admin/project/versioncontrol-accounts/export":
- * Select the repository from which to extract data, and show the exported
- * data on submitting the form.
- */
-function versioncontrol_admin_account_export_form(&$form_state) {
-  $form = array();
-  $selected_backends = array();
-
-  foreach (versioncontrol_get_backends() as $vcs => $backend) {
-    $build_data = array(
-      'repo_id' => 0,
-      'vcs' => $backend->name,
-    );
-    $repo = $backend->buildEntity('repo', $build_data);
-    if ($repo instanceof VersioncontrolRepositoryImportExport) {
-      $selected_backends[] = $vcs;
-    }
-  }
-  $repositories = versioncontrol_repository_load_multiple(array(), array('vcs' => $selected_backends));
-
-  if (empty($repositories)) {
-    $form['no_repositories'] = array(
-      '#type' => 'markup',
-      '#value' => t('There are no repositories for which the accounts can be exported.'),
-      '#prefix' => '<p>',
-      '#suffix' => '</p>',
-    );
-    return $form;
-  }
-
-  $repository_names = array();
-  foreach ($repositories as $repo_id => $repository) {
-    if (!isset($first_repo_id)) {
-      $first_repo_id = $repo_id;
-    }
-    $repository_names[$repo_id] = check_plain($repository['name']);
-  }
-
-  $form['repository'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Select repository'),
-    '#weight' => 10,
-  );
-  $form['repository']['repo_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Export accounts from'),
-    '#options' => $repository_names,
-    '#default_value' => $first_repo_id,
-  );
-  $form['repository']['buttons'] = array();
-  $form['repository']['buttons']['export_to_form'] = array(
-    '#type' => 'submit',
-    '#value' => t('Export to page'),
-  );
-  $form['repository']['buttons']['export_to_plaintext'] = array(
-    '#type' => 'submit',
-    '#value' => t('Export to plaintext'),
-  );
-  return $form;
-}
-
-/**
- * Submit handler for the "select repository to export" form from above:
- * Redirect to the export form for the specific repository.
- */
-function versioncontrol_admin_account_export_form_submit($form, &$form_state) {
-  $form_state['redirect'] = 'admin/project/versioncontrol-accounts/export/'. $form_state['values']['repo_id'];
-
-  if ($form_state['values']['op'] == t('Export to plaintext')) {
-    $form_state['redirect'] .= '/plaintext';
-  }
-}
-
-/**
- * Form callback for 'admin/project/versioncontrol-accounts/export/%versioncontrol_repository':
- * Show the exported account data in a form as text area.
- *
- * @param $repository
- *   The repository for which accounts have been exported.
- * @param $data
- *   The exported account data - the text that is supposed to be copied
- *   to the version control system's accounts file.
- */
-function versioncontrol_admin_account_export_display_form(&$form_state, $repository, $data) {
-  $form = array();
-  $form['#repo_id'] = $repository['repo_id'];
-
-  $form['data'] = array(
-    '#type' => 'textarea',
-    '#title' => t('@vcs account data', array('@vcs' => $repository->getBackend()->name)),
-    '#description' => t('The exported account data. You can copy this to the config file that contains the @vcs accounts.', array('@vcs' => $backend['name'])),
-    '#default_value' => $data,
-    '#cols' => 70,
-    '#rows' => 30,
-  );
-  return $form;
-}
-
-
 /**
  * Form callback for "admin/project/versioncontrol-repositories":
  * A simple list of repositories, sorted by version control system.
diff --git versioncontrol.module versioncontrol.module
index d9cb7fa..1d98b73 100644
--- versioncontrol.module
+++ versioncontrol.module
@@ -265,39 +265,6 @@ function versioncontrol_menu() {
     'weight' => 0,
   );
 
-  // former !$may_cache
-  /// TODO: Backend specific stuff was done in !$may_cache, as it once
-  ///       screwed up after activating a new backend in admin/build/modules.
-  ///       Make sure this works now.
-  // TODO (sdb): this should all be reworked using a version of the loader that
-  // takes additional arguments for implementation checking.
-  foreach (versioncontrol_get_backends() as $vcs => $backend) {
-    // we need to check and interface, so create an empty repo here
-    if (is_subclass_of($backend->classesEntities['repo'], 'VersioncontrolRepositoryImportExport')) {
-      $items['admin/project/versioncontrol-accounts/import'] = array(
-        'title' => 'Import',
-        'description' => 'Import an existing set of VCS user accounts.',
-        'page arguments' => array('versioncontrol_admin_account_import_form'),
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 2,
-      ) + $admin;
-      $items['admin/project/versioncontrol-accounts/export'] = array(
-        'title' => 'Export',
-        'description' => 'Export VCS user accounts of a specific repository.',
-        'page arguments' => array('versioncontrol_admin_account_export_form'),
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 3,
-      ) + $admin;
-      $items['admin/project/versioncontrol-accounts/export/%versioncontrol_repository'] = array(
-        'title' => 'Export',
-        'page callback' => 'versioncontrol_admin_account_export_page',
-        'page arguments' => array(4),
-        'type' => MENU_CALLBACK,
-      ) + $admin;
-    }
-  }
-  // end former !$may_cache
-
   // Account registration and editing pages for the regular user.
   $items['versioncontrol/register'] = array(
     'title' => 'Get commit access',
diff --git versioncontrol_fakevcs/includes/classes.inc versioncontrol_fakevcs/includes/classes.inc
index 1e32fed..85e1eb7 100644
--- versioncontrol_fakevcs/includes/classes.inc
+++ versioncontrol_fakevcs/includes/classes.inc
@@ -36,7 +36,7 @@ class VersioncontrolFakeBackend extends VersioncontrolBackend {
 
 }
 
-class VersioncontrolFakeRepository extends VersioncontrolRepository implements VersioncontrolRepositoryImportExport, VersioncontrolRepositoryGetItem {
+class VersioncontrolFakeRepository extends VersioncontrolRepository implements VersioncontrolRepositoryGetItem {
 
   public function formatRevisionIdentifier($revision, $format = 'full') {
     switch ($format) {
@@ -68,68 +68,6 @@ class VersioncontrolFakeRepository extends VersioncontrolRepository implements V
     return array('item' => $item, 'selected_label' => NULL);
   }
 
-  public function importAccounts($data) {
-    $accounts = $this->parseAccountData($data);
-
-    foreach ($accounts as $account) {
-      $additional_data = array(
-        'fakevcs_specific' => array('password' => $password),
-      );
-      $username = $account->author;
-      $uid = $this->getAccountUidForUsername($username, TRUE);
-
-      if (isset($uid)) {
-        $account->uid = $uid;
-        $account->update($additional_data);
-        $names[] = t('updated !username', array('!username' => $username));
-      }
-      else {
-        $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $username));
-        if ($uid) {
-          $account->uid = $uid;
-          $account->insert($additional_data);
-          $names[] = t('added !username', array('!username' => $username));
-        }
-        else {
-          $names[] = t('didn\'t add !username (no matching Drupal username exists)',
-            array('!username' => $username));
-        }
-      }
-    }
-  }
-
-  public function exportAccounts($accounts) {
-    if (empty($accounts)) {
-      return '# '. t('no user accounts available to export');
-    }
-    $accounts_flat = array();
-    $uid_constraints = array();
-    $params = array($this->repo_id);
-
-    foreach ($accounts as $uid => $accounts_per_repository) {
-      foreach ($accountss_per_repository as $repo_id => $account) {
-        $accounts_flat[$uid] = array('uid' => $uid, 'author' => $account->author);
-        $uid_constraints[] = 'uid = %d';
-        $params[] = $uid;
-      }
-    }
-
-    $result = db_query('SELECT uid, password FROM {versioncontrol_fakevcs_accounts}
-      WHERE repo_id = %d
-      AND ('. implode(' OR ', $uid_constraints) .')',
-      $params);
-    while ($account = db_fetch_object($result)) {
-      $accounts_flat[$account->uid]['password'] = $account->password;
-    }
-
-    $data = '';
-    foreach ($accounts_flat as $uid => $account) {
-      $data .= '# '. url('user/'. $uid, array('absolute' => TRUE)) ."\n";
-      $data .= $account['author'] .':'. $account['password'] ."\n";
-    }
-    return $data;
-  }
-
 }
 
 class VersioncontrolFakeAccount extends VersioncontrolAccount {
-- 
1.7.2.3

