<?php
// $Id: versioncontrol_svn.install,v 1.14 2009/01/10 16:11:09 jpetso Exp $
/**
 * @file
 * Subversion backend for Version Control API - Provides Subversion commit
 * information and account management as a pluggable backend.
 *
 * Copyright 2006 by Karthik ("Zen", http://drupal.org/user/21209)
 * Copyright 2006, 2007 by Gavin Mogan ("halkeye", http://drupal.org/user/56779)
 * Copyright 2006, 2007 by Derek Wright ("dww", http://drupal.org/user/46549)
 * Copyright 2007, 2008, 2009 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
 */

/**
 * Implementation of hook_schema().
 */
function versioncontrol_svn_schema() {
  $schema['versioncontrol_svn_repositories'] = array(
    'description' => 'This table extends {versioncontrol_repositories} with additional properties specific to SVN repositories.',
    'fields' => array(
      'repo_id' => array(
        'description' => 'The repository identifier referring to {versioncontrol_repositories}.repo_id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'update_method' => array(
        'description' =>
          'Specifies whether the repository is updated via log parsing on cron runs (VERSIONCONTROL_SVN_UPDATE_CRON) or via hook scripts (VERSIONCONTROL_SVN_UPDATE_XSVN). Updating the repository and fetching new revisions into the database are the same thing, by the way.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'updated' => array(
        'description' =>
          'Date/time when the repository was last updated, as Unix timestamp. Unlike the CVS backend, the SVN backend uses this property only for displaying purposes, so it is not required for log parsing. 0 if the repository has never been updated at all.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_revision' => array(
        'description' => 'The last revision that was recorded for the repository. 0 if the repository has never been updated at all (and no revisions have yet been recorded).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'auth_username' => array(
        'description' => 'Empty if the repository is accessed anonymously, or the login username if credentials are being supplied.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'auth_password' => array(
        'description' => 'Empty if the repository is accessed anonymously, or the login password if credentials are being supplied.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'path_trunk' => array(
        'description' => 'The path of the trunk directory (often "/trunk"), for branch emulation purposes.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'path_branches' => array(
        'description' =>
          'The path of the branches directory (e.g. "/branches/%project/%branch"), for branch emulation purposes. "%project" is a placeholder for the project\'s short name and "%branch" holds the name of the branch itself.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'path_tags' => array(
        'description' =>
          'The path of the tags directory (e.g. "/tags/%project/%branch/%tag"), for tag emulation purposes. "%project" is a placeholder for the project\'s short name, "%branch" optionally denotes a branch specific directory part (but may be left out), and "%tag" holds the name of the tag itself.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array('repo_id'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function versioncontrol_svn_install() {
  // Create tables.
  drupal_install_schema('versioncontrol_svn');
}

/**
 * Implementation of hook_uninstall().
 */
function versioncontrol_svn_uninstall() {
  // Make sure we can access the required functions even from the .install file.
  include_once(drupal_get_path('module', 'versioncontrol') .'/versioncontrol.module');
  include_once(drupal_get_path('module', 'versioncontrol_svn') .'/versioncontrol_svn.module');

  if (db_table_exists('versioncontrol_repositories')) {
    $result = db_query("SELECT repo_id FROM {versioncontrol_repositories}
                        WHERE vcs = 'svn'");
    while ($repository = db_fetch_array($result)) {
      versioncontrol_delete_repository($repository);
    }
  }

  // Remove tables.
  drupal_uninstall_schema('versioncontrol_svn');
}


// Update functions. To be named versioncontrol_svn_update_xyzz(), where x is
// the major version of Drupal core, y is the major version of the CVS backend
// for this version of Drupal core, and zz is a consecutive number.

// versioncontrol_svn_update_3() was the last update on Drupal 5.x (-2.x).

/**
 * Update 6100: Blah blah blah.
 */
/* function versioncontrol_svn_update_6100() {
  $ret = array();
  $ret[] = update_sql('UPDATE {versioncontrol_svn_blah} SET value = othervalue');
  return $ret;
}*/
