From 55bf806ab6a12456d479c3fc6cf7597fa7bcee70 Mon Sep 17 00:00:00 2001
From: Marco Antonio Villegas Vega <marvil07@gmail.com>
Date: Fri, 13 Mar 2009 03:09:31 -0500
Subject: [PATCH] start port to 6.x with coder suggestions

versioncontrol api changes are pending
---
 versioncontrol_git.admin.inc |    6 +-
 versioncontrol_git.info      |    3 +-
 versioncontrol_git.install   |  339 +++++++++++++++++++++++++++---------------
 versioncontrol_git.log.inc   |    2 +-
 versioncontrol_git.module    |   26 ++--
 5 files changed, 235 insertions(+), 141 deletions(-)

diff --git a/versioncontrol_git.admin.inc b/versioncontrol_git.admin.inc
index 43bdfa4..6675064 100644
--- a/versioncontrol_git.admin.inc
+++ b/versioncontrol_git.admin.inc
@@ -12,16 +12,16 @@
  * Implementation of hook_form_alter(): Add elements to various
  * administrative forms that the Version Control API provides.
  */
-function versioncontrol_git_form_alter($form_id, &$form) {
+function versioncontrol_git_form_alter(&$form, $form_state, $form_id) {
   if ($form['#id'] == 'versioncontrol-repository-form' && $form['#vcs'] == 'git') {
-    versioncontrol_git_repository_admin_form_alter($form_id, $form);
+    versioncontrol_git_repository_admin_form_alter($form, $form_state, $form_id);
   }
 }
 
 /**
  * Add Git specific elements to the add/edit repository form.
  */
-function versioncontrol_git_repository_admin_form_alter($form_id, &$form) {
+function versioncontrol_git_repository_admin_form_alter(&$form, $form_state, $form_id) {
   $repository = $form['#repository'];
 
   $form['versioncontrol_git'] = array(
diff --git a/versioncontrol_git.info b/versioncontrol_git.info
index be5c5e7..2eaabdd 100644
--- a/versioncontrol_git.info
+++ b/versioncontrol_git.info
@@ -1,5 +1,6 @@
 ; $Id: versioncontrol_git.info,v 1.1 2008/01/26 21:31:44 boombatower Exp $
 name = "Git backend"
 description = "Git backend for Version Control API - Provides Git commit information and account management as a pluggable backend."
-dependencies = versioncontrol
+dependencies[] = versioncontrol
 package = Version Control
+core=6.x
diff --git a/versioncontrol_git.install b/versioncontrol_git.install
index bafdc02..a633cfb 100644
--- a/versioncontrol_git.install
+++ b/versioncontrol_git.install
@@ -9,131 +9,233 @@
  */
 
 /**
- * Implementation of hook_install().
+ * Implementation of hook_schema().
  */
-function versioncontrol_git_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      db_query("CREATE TABLE {versioncontrol_git_accounts} (
-        uid int unsigned NOT NULL default 0,
-        repo_id int unsigned NOT NULL default 0,
-        password varchar(64) NOT NULL default '',
-        PRIMARY KEY (uid, repo_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-
-      db_query("CREATE TABLE {versioncontrol_git_repositories} (
-        repo_id int unsigned NOT NULL default 0,
-        update_method tinyint unsigned NOT NULL default 0,
-        updated int unsigned NOT NULL default 0,
-        PRIMARY KEY (repo_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-
-      db_query("CREATE TABLE {versioncontrol_git_commit_branches} (
-        vc_op_id int NOT NULL,
-        branch_id int NOT NULL,
-        PRIMARY KEY (vc_op_id, branch_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-
-      db_query("CREATE TABLE {versioncontrol_git_item_revisions} (
-        item_revision_id int unsigned NOT NULL default 0,
-        vc_op_id int unsigned NOT NULL default 0,
-        action tinyint unsigned NOT NULL default 0,
-        type tinyint NOT NULL default 0,
-        path varchar(255) NOT NULL default '',
-        lines_added smallint unsigned NOT NULL default 0,
-        lines_removed smallint unsigned NOT NULL default 0,
-        PRIMARY KEY (item_revision_id),
-        UNIQUE KEY (vc_op_id, path)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-
-      db_query("CREATE TABLE {versioncontrol_git_item_tags} (
-        vc_op_id int unsigned NOT NULL default 0,
-        item_revision_id int unsigned NOT NULL default 0,
-        PRIMARY KEY (vc_op_id, item_revision_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-
-      db_query("CREATE TABLE {versioncontrol_git_tag_operations} (
-        vc_op_id int NOT NULL default 0,
-        revision varchar(255) NOT NULL default '',
-        PRIMARY KEY (vc_op_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
+function versioncontrol_git_schema() {
+  $schema['versioncontrol_git_accounts'] = array(
+    'description' => t('Git accounts.'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('Drupal User identifier.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'repo_id' => array(
+        'description' => t('Repository identifier.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'password' => array(
+        'description' => t('Password.'),
+        'type' => 'varchar',
+        'length' => 64,
+        'not null' => TRUE,
+        'default' => '',
+        ),
+      ),
+    'primary key' => array('uid', 'repo_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_latest_commits} (
-        lastest_commits_id int NOT NULL,
-        branch_id int NOT NULL,
-        revision varchar(255) NOT NULL,
-        repo_id int(11) NOT NULL,
-        PRIMARY KEY (lastest_commits_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
+  $schema['versioncontrol_git_repositories'] = array(
+    'description' => t('Git repositories.'),
+    'fields' => array(
+      'repo_id' => array(
+        'description' => t('Repository identifier.'),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      'update_method' => array(
+        'description' => t('Update method.'),
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'updated' => array(
+        'description' => t('Last update.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      ),
+    'primary key' => array('repo_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_item_source_revisions} (
-        item_revision_id int NOT NULL,
-        source_item_revision_id int NOT NULL,
-        PRIMARY KEY (item_revision_id, source_item_revision_id)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-      break;
+  $schema['versioncontrol_git_commit_branches'] = array(
+    'description' => t('Git commit branches.'), //FIXME not sure here about concept
+    'fields' => array(
+      'vc_op_id' => array(
+        'description' => '', //FIXME what's that?
+        'type' => 'int', // TODO serial or int?
+        'not null' => TRUE,
+        ),
+      'branch_id' => array(
+        'description' => t('Branch identifier.'),
+        'type' => 'int', // TODO serial or int?
+        'not null' => TRUE,
+        ),
+      ),
+    'primary key' => array('vc_op_id', 'branch_id'),
+  );
 
-    case 'pgsql':
-      db_query("CREATE TABLE {versioncontrol_git_accounts} (
-        uid int NOT NULL default 0,
-        repo_id int NOT NULL default 0,
-        password varchar(64) NOT NULL default '',
-        PRIMARY KEY (uid, repo_id)
-      )");
+  $schema['versioncontrol_git_item_revisions'] = array(
+    'description' => t('Item revisions.'),
+    'fields' => array(
+      'item_revision_id' => array(
+        'description' => t('Item revision identifier.'),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      'vc_op_id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'action' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'type' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'path' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        ),
+      'lines_added' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'lines_removed' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      ),
+    'primary key' => array('item_revision_id'),
+    'unique keys' => array('versioncontrol_git_item_revisions_vc_op_id_path' => array('vc_op_id', 'path'))
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_repositories} (
-        repo_id int NOT NULL default 0,
-        update_method smallint NOT NULL default 0,
-        updated int NOT NULL default 0,
-        PRIMARY KEY (repo_id)
-      )");
+  $schema['versioncontrol_git_item_tags'] = array(
+    'description' => t('Git tags.'), //FIXME not sure here about concept
+    'fields' => array(
+      'vc_op_id' => array(
+        'description' => '', //FIXME what's that?
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'item_revision_id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      ),
+    'primary key' => array('vc_op_id', 'item_revision_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_commit_branches} (
-        vc_op_id int NOT NULL,
-        branch_id int NOT NULL,
-        PRIMARY KEY (vc_op_id, branch_id)
-      )");
+  $schema['versioncontrol_git_tag_operations'] = array(
+    'description' => t('Git tags.'), //FIXME not sure here about concept
+    'fields' => array(
+      'vc_op_id' => array(
+        'description' => '', //FIXME what's that?
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      'revision' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        ),
+      ),
+    'primary key' => array('vc_op_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_item_revisions} (
-        item_revision_id int NOT NULL default 0,
-        vc_op_id int NOT NULL default 0,
-        action smallint NOT NULL default 0,
-        type smallint NOT NULL default 0,
-        path varchar(255) NOT NULL default '',
-        lines_added smallint NOT NULL default 0,
-        lines_removed smallint NOT NULL default 0,
-        PRIMARY KEY (item_revision_id),
-        UNIQUE (vc_op_id, path)
-      )");
+  $schema['versioncontrol_git_latest_commits'] = array(
+    'description' => t('Git latest commits.'),
+    'fields' => array(
+      'lastest_commits_id' => array(
+        'description' => t('Item revision identifier.'),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      'branch_id' => array(
+        'description' => t('Branch identifier.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        ),
+      'revision' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        ),
+      'repo_id' => array(
+        'description' => t('Repository identifier.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        ),
+      ),
+    'primary key' => array('lastest_commits_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_item_tags} (
-        vc_op_id int NOT NULL default 0,
-        item_revision_id int NOT NULL default 0,
-        PRIMARY KEY (vc_op_id, item_revision_id)
-      )");
+  $schema['versioncontrol_git_item_source_revisions'] = array(
+    'description' => t('Git tags.'), //FIXME not sure here about concept
+    'fields' => array(
+      'item_revision_id' => array(
+        'description' => '', //FIXME what's that?
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      'source_item_revision_id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      ),
+    'primary key' => array('item_revision_id', 'source_item_revision_id'),
+  );
 
-      db_query("CREATE TABLE {versioncontrol_git_tag_operations} (
-        vc_op_id int NOT NULL default 0,
-        revision varchar(255) NOT NULL default '',
-        PRIMARY KEY (vc_op_id)
-      )");
+  return $schema;
 
-      db_query("CREATE TABLE {versioncontrol_git_latest_commits} (
-        lastest_commits_id int NOT NULL,
-        branch_id int NOT NULL,
-        revision varchar(255) NOT NULL,
-        repo_id int(11) NOT NULL,
-        PRIMARY KEY (lastest_commits_id)
-      )");
+}
 
-      db_query("CREATE TABLE {versioncontrol_git_item_source_revisions} (
-        item_revision_id int NOT NULL,
-        source_item_revision_id int NOT NULL,
-        PRIMARY KEY (item_revision_id, source_item_revision_id)
-      )");
-      break;
-  }
+/**
+ * Implementation of hook_install().
+ */
+function versioncontrol_git_install() {
+  drupal_install_schema('versioncontrol_git');
 }
 
 /**
@@ -152,14 +254,7 @@ function versioncontrol_git_uninstall() {
     }
   }
 
-  db_query('DROP TABLE {versioncontrol_git_accounts}');
-  db_query('DROP TABLE {versioncontrol_git_repositories}');
-  db_query('DROP TABLE {versioncontrol_git_commit_branches}');
-  db_query('DROP TABLE {versioncontrol_git_item_revisions}');
-  db_query('DROP TABLE {versioncontrol_git_item_tags}');
-  db_query('DROP TABLE {versioncontrol_git_tag_operations}');
-  db_query('DROP TABLE {versioncontrol_git_latest_commits}');
-  db_query('DROP TABLE {versioncontrol_git_item_source_revisions}');
+  drupal_uninstall_schema('versioncontrol_git');
 
   variable_del('versioncontrol_git_log_use_file');
 }
diff --git a/versioncontrol_git.log.inc b/versioncontrol_git.log.inc
index 20321ea..0993d42 100644
--- a/versioncontrol_git.log.inc
+++ b/versioncontrol_git.log.inc
@@ -60,7 +60,7 @@ function _versioncontrol_git_log_update_repository(&$repository) {
     if ($branch_id !== NULL) {
       db_query('DELETE FROM {versioncontrol_git_latest_commits} WHERE branch_id = %d', $branch_id);
 
-      $lastest_commits_id = db_next_id('{versioncontrol_git_latest_commits}_lastest_commits_id');
+      $lastest_commits_id = db_last_insert_id('{versioncontrol_git_latest_commits}_lastest_commits_id');
       db_query("INSERT INTO {versioncontrol_git_latest_commits} (lastest_commits_id, repo_id, branch_id, revision) VALUES (%d, %d, %d, '%s')",
         $lastest_commits_id, $repository['repo_id'], $branch_id, $latest_commits[$branch]);
     }
diff --git a/versioncontrol_git.module b/versioncontrol_git.module
index 353f7da..73482ad 100644
--- a/versioncontrol_git.module
+++ b/versioncontrol_git.module
@@ -18,7 +18,7 @@ include_once(drupal_get_path('module', 'versioncontrol_git') .'/versioncontrol_g
 /**
  * Implementation of hook_help().
  */
-function versioncontrol_git_help($section = "admin/help#versioncontrol_git") {
+function versioncontrol_git_help($section, $arg) {
   $output = '';
   if ($section == 'admin/help/versioncontrol_git' || $section == 'admin/help#versioncontrol_git') {
     $output = '<p>The Git Backend can be used to retrieve and view commit information. The commit
@@ -94,20 +94,18 @@ function versioncontrol_git_versioncontrol_backends() {
 /**
  * Implementation of hook_menu().
  */
-function versioncontrol_git_menu($may_cache) {
+function versioncontrol_git_menu() {
   global $user;
   $items = array();
-  $admin_access = user_access('administer version control systems');
-
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/project/versioncontrol-repositories/update/git',
-      'title' => t('Fetch log'),
-      'callback' => 'versioncontrol_git_update_repository_callback',
-      'access' => $admin_access,
-      'type' => MENU_CALLBACK,
-    );
-  }
+
+  $items['admin/project/versioncontrol-repositories/update/git'] = array(
+    'title' => 'Fetch log',
+    'page callback' => 'versioncontrol_git_update_repository_callback',
+    'access callback' => 'user_access',
+    'access arguments' => array('administer version control systems'),
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
@@ -606,7 +604,7 @@ function versioncontrol_git_commit($op, $commit, $commit_actions) {
           $revision = $action['git_specific']['revision'];
         }
 
-        $item_revision_id = db_next_id('{versioncontrol_git_item_revisions}_item_revision_id');
+        $item_revision_id = db_last_insert_id('{versioncontrol_git_item_revisions}_item_revision_id');
         db_query(
           "INSERT INTO {versioncontrol_git_item_revisions}
            (item_revision_id, vc_op_id, type, path,
-- 
1.5.6.5

