Commit 81c495e8 authored by Marco Villegas's avatar Marco Villegas
Browse files

Issue #1291904: First round of updates to the example fakevcs backend module.

parent e676e225
Loading
Loading
Loading
Loading
+50 −2
Changes for versioncontrol_fakevcs/includes/classes.inc: 50 added lines, 2 removed lines.
Original line number Diff line number Diff line
<?php
// FIXME use new CRUD

/**
 * @file
 *   An example of the classes a backend would need.
 *   Please notice this is just a subsetimplementation
 */
class VersioncontrolFakeBackend extends VersioncontrolBackend {

  public $classes = array(
@@ -60,6 +63,8 @@ class VersioncontrolFakeRepository extends VersioncontrolRepository {

class VersioncontrolFakeOperation extends VersioncontrolOperation {

  public $parent_commit = '';

  /**
   * Implementation of abstract method.
   */
@@ -73,6 +78,49 @@ class VersioncontrolFakeOperation extends VersioncontrolOperation {
    // label for each item has to be determined.
  }

  // Asumming for fakevcs is better retrieving information if we have the
  // parent commit revision, we interact to have CRUD around that in out own
  // table.

  protected function backendInsert($options) {
    db_insert('versioncontrol_fakevcs_operations')
      ->fields(array(
        'vc_op_id' => $this->vc_op_id,
        'parent_commit' => $this->parent_commit,
      ))
      ->execute();
  }

  protected function backendUpdate($options) {
    db_update('versioncontrol_fakevcs_operations')
      ->fields(array(
        'vc_op_id' => $this->vc_op_id,
        'parent_commit' => $this->parent_commit,
      ))
      ->condition('vc_op_id', $this->vc_op_id)
      ->execute();
  }

  protected function backendDelete($options) {
    db_delete('versioncontrol_fakevcs_operations')
      ->condition('vc_op_id', $this->vc_op_id)
      ->execute();
  }
}

class VersioncontrolGitOperationController extends VersioncontrolOperationController {
  /**
   * Extend the base query with the fakevcs backend's additional data in
   * {versioncontrol_fakevcs_operations}.
   *
   * @return SelectQuery
   */
  protected function buildQueryBase($ids, $conditions) {
    $query = parent::buildQueryBase($ids, $conditions);
    $alias = $this->addTable($query, 'versioncontrol_fakevcs_operations', 'vcfo', 'base.vc_op_id = vcfo.vc_op_id');
    $query->fields($alias, drupal_schema_fields_sql('versioncontrol_fakevcs_operations'));
    return $query;
  }
}

class VersioncontrolFakeItem extends VersioncontrolItem {
−144

File deleted.

+1 −83
Changes for versioncontrol_fakevcs/versioncontrol_fakevcs.module: 1 added line, 83 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * @file
 * FakeVCS backend for Version Control API -
 *   FakeVCS backend for Version Control API
 *   An example module illustrating how to write a VCS backend.
 *
 * Copyright 2007, 2008 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
 */

// Update methods.
define('VERSIONCONTROL_FAKEVCS_UPDATE_CRON',   0);
define('VERSIONCONTROL_FAKEVCS_UPDATE_SCRIPT', 1);

// The admin pages.
include_once(drupal_get_path('module', 'versioncontrol_fakevcs') .'/versioncontrol_fakevcs.admin.inc');

/**
 * Implementation of hook_versioncontrol_backends().
 */
@@ -24,78 +17,3 @@ function versioncontrol_fakevcs_versioncontrol_backends() {
    'fakevcs' => new VersioncontrolFakeBackend(),
  );
}

/**
 * Implementation of [versioncontrol_backend]_operation():
 * Act on database changes when commit, tag or branch operations are inserted
 * or deleted. Note that this hook is not necessarily called at the time
 * when the operation actually happens - operations can also be inserted
 * by a cron script when the actual commit/branch/tag has been accomplished
 * for quite a while already.
 *
 * @param $op
 *   'insert' when the operation has just been recorded and inserted into the
 *   database, or 'delete' if it will be deleted right after this hook
 *   has been called.
 *
 * @param $operation
 *   A VersioncontrolOperation object containing basic information about
 *   the commit, branch or tag operation.
 *
 * @param $operation_items
 *   A structured array containing all items that were affected by the above
 *   operation. Array keys are the current/new paths, even if the item doesn't
 *   exist anymore (as is the case with delete actions in commits).
 *   The associated array elements are VersioncontrolItem objects.
 */
function versioncontrol_fakevcs_operation($op, $operation, $operation_items) {
  // Mmkay, with Version Control API not being able to extend operations
  // anymore like in 5.x-1.x, I'm running out of good examples for this hook.
  // But let's say we want to store the original branch for a commit, so that
  // we can improve commit visualizations (should Version Control API
  // respectively Commit Log support that sometime in the future).
  if ($operation['type'] != VERSIONCONTROL_OPERATION_COMMIT) {
    return; // Not interested in branch and tag operations.
  }

  switch ($op) {
    case 'insert':
      foreach ($operation['labels'] as $label) {
        db_query(
          "INSERT INTO {versioncontrol_fakevcs_original_commit_branches}
          (vc_op_id, label_id) VALUES (%d, %d)",
          $operation['vc_op_id'], $label['label_id']
        );
      }
      break;

    case 'delete':
      db_query('DELETE FROM {versioncontrol_fakevcs_original_commit_branches}
                WHERE vc_op_id = %d', $operation['vc_op_id']);
      break;
  }
}

/**
 * Implementation of [versioncontrol_backend]_repository():
 * Manage (insert, update or delete) additional FakeVCS repository data
 * in the database.
 *
 * Mind that you can also use the $repository['data'] array to store repository
 * settings, see the API docs for hook_versioncontrol_repository_submit()
 * in hook_versioncontrol.php for more information on that matter.
 *
 * @param $op
 *   Either 'insert' when the repository has just been created, or 'update'
 *   when repository name, root, URL backend or module specific data change,
 *   or 'delete' if it will be deleted after this function has been called.
 *
 * @param $repository
 *   The repository object.
 */
function versioncontrol_fakevcs_repository($op, $repository) {
  if ($op == 'delete') {
    db_query('DELETE FROM {versioncontrol_fakevcs_repository_ponies}
              WHERE repo_id = %d', $repository['repo_id']);
  }
}