Index: pifr.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue_file_review/pifr.install,v
retrieving revision 1.31
diff -u -r1.31 pifr.install
--- pifr.install	7 Aug 2009 05:14:43 -0000	1.31
+++ pifr.install	29 Oct 2009 04:53:47 -0000
@@ -1,5 +1,6 @@
 <?php
 // $Id: pifr.install,v 1.31 2009/08/07 05:14:43 boombatower Exp $
+
 /**
  * @file
  * Automatically review patches attached to issues.
@@ -15,21 +16,9 @@
   variable_del('pifr_debug');
 }
 
-/*
- * Assumptions made for PIFR 1.x to 2.x upgrade.
- *   1) pifr_file has been renamed to pifr_file_old.
- *   2) pifr_result has been renamed to pifr_result_old.
- *   3) pifr_server has been enabled.
- *   4) pifr_log has been renamed to pifr_log_old.
- *
- * The table renames can be achomplished by executing the following SQL.
- *   RENAME TABLE pifr_file TO pifr_file_old;
- *   RENAME TABLE pifr_result TO pifr_result_old;
- *   RENAME TABLE pifr_log TO pifr_log_old;
- *
- * Afterwards enable pifr_server to ensure that the new schema is installed
- * properly and does not conflict with the old schema.
- */
+function pifr_update_message($message, $success = TRUE) {
+  return array('success' => $success, 'query' => $message);
+}
 
 /**
  * Remove old variables.
@@ -59,112 +48,272 @@
     'pifr_last_test_count',
   );
 
+  // Cycle through variables and remove them.
   foreach ($vars as $var) {
     variable_del($var);
+    $ret[] = pifr_update_message('Deleted [' . $var . '] variable.');
   }
 
   return $ret;
 }
 
 /**
- * Remove the pifr_server table and rename old tables.
+ * Rename old tables with suffix '_old'.
  */
 function pifr_update_6201() {
   $ret = array();
 
-  // Remove old server table since all clients will be re-added anyway.
-  db_drop_table($ret, 'pifr_server');
+  // Rename old tables so new schema can be installed and data migrated.
+  foreach (array('file', 'result', 'log', 'server') as $table) {
+    db_rename_table($ret, "pifr_$table", "pifr_{$table}_old");
+  }
 
-  // Rename old tables so new schema can be installed and data converted.
-  db_rename_table($ret, 'pifr_file', 'pifr_file_old');
-  db_rename_table($ret, 'pifr_result', 'pifr_result_old');
-  db_rename_table($ret, 'pifr_log', 'pifr_log_old');
+  return $ret;
+}
+
+/**
+ * Enable equivilent 2.x modules.
+ */
+function pifr_update_6202() {
+  $ret = array();
 
-  // Install pifr_server schema.
+  // Install equivilent 2.x modules and dependencies.
   include_once './includes/install.inc';
-  drupal_install_schema('pifr_server');
+  $modules = array(
+    'chart',
+    'views',
+    'tabs',
+    'pifr_server',
+    'pifr_assertion',
+    'pifr_simpletest'
+  );
+  foreach ($modules as $module) {
+    drupal_install_modules(array($module));
+    $ret[] = pifr_update_message('Installed [' . $module . '].');
+  }
+
+  // Clear out statics.
+  module_list(TRUE, FALSE);
+  module_implements('', FALSE, TRUE);
+  drupal_get_schema(NULL, TRUE);
+
+  return $ret;
+}
+
+/**
+ * Setup default MySQL 5.0 ISAM environment.
+ */
+function pifr_update_6203() {
+  $ret = array();
+
+  $environment = array(
+    'title' => 'MySQL 5.0 ISAM',
+    'description' => 'MySQL 5.0 ISAM environment for running Drupal SimpleTest tests.',
+    'require_pass' => TRUE,
+    'client' => array(),
+    'project' => array(),
+    'branch' => array(),
+    'type' => array(),
+    'plugin' => 'pifr_simpletest',
+    'plugin_argument' => array('database' => 'mysql-5.0-isam'),
+  );
+  $environment = pifr_server_environment_save($environment);
+
+  $ret[] = pifr_update_message('Added [' . $environment['title'] . '] environment.', !empty($environment['environment_id']));
+
+  return $ret;
+}
+
+
+/**
+ * Migrate pifr_server table.
+ */
+function pifr_update_6204() {
+  $ret = array();
+
+  $result = db_query('SELECT * FROM {pifr_server_old} ORDER BY server_id');
+  while ($server_old = db_fetch_array($result)) {
+    $client = array(
+      'client_key' => $server_old['server_key'],
+      'type' => pifr_update_6204_type($server_old['type']),
+      'environment' => $server_old['type'] == 1 ? array() : array(1), // Assume MySQL will be environment ID 1.
+      'uid' => 1, // Not migration path, this will need to be manually fixed.
+      'url' => $server_old['url'],
+      'status' => $server_old['type'] == 4 ? PIFR_SERVER_CLIENT_STATUS_DISABLED : PIFR_SERVER_CLIENT_STATUS_TESTING,
+    );
+
+    if ($client['type'] == 0) {
+      // Test master which does not exist in 2.x.
+      continue;
+    }
+
+    // Save converted client data.
+    $client = pifr_server_client_save($client);
+
+    $ret[] = pifr_update_message('Updated server [' . $server_old['server_id'] . '] to client [' .
+      $client['client_id'] . '].', (bool) $client['client_id']);
+  }
 
   return $ret;
 }
 
 /**
- * Migrate pifr_file and pifr_result to new data structure.
+ * Convert 1.x client status code to 2.x status code.
  *
- * Assumes:
- *   1) pifr_file has been renamed to pifr_file_old.
- *   2) pifr_result has been renamed to pifr_result_old.
- *   3) pifr_server has been enabled.
+ * @param integer $status 1.x client status code.
+ * @return integer 2.x client status code.
  */
-function pifr_update_6202(&$sandbox = NULL) {
+function pifr_update_6204_type($type) {
+  $map = array(
+    1 => 1, // PIFR_SERVER_PROJECT => PIFR_SERVER_CLIENT_TYPE_PROJECT.
+    2 => 0, // PIFR_SERVER_TEST_MASTER => Does not exist in 2.x.
+    3 => 2, // PIFR_SERVER_SLAVE => PIFR_SERVER_CLIENT_TYPE_TEST.
+    4 => 2, // PIFR_SERVER_DISABLED => PIFR_SERVER_CLIENT_TYPE_TEST.
+  );
+  return $map[$type];
+}
+
+/**
+ * Setup Drupal core project and 7.x HEAD branch.
+ */
+function pifr_update_6205() {
+  $ret = array();
+
+  // Determine drupal.org project client ID.
+  $client_id = db_result(db_query("SELECT client_id FROM {pifr_client} WHERE url = '%s'", 'http://drupal.org/'));
+  $ret[] = pifr_update_message('Found drupal.org client with ID [' . $client_id . '].', (bool) $client_id);
+
+  $project = array(
+    'client_id' => $client_id,
+    'client_identifier' => 3060,
+    'name' => 'Drupal',
+    'repository_type' => 'cvs',
+    'repository_url' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal/drupal/',
+    'link' => 'http://drupal.org/node/3060',
+  );
+  $project = pifr_server_project_save($project, FALSE);
+  $ret[] = pifr_update_message('Created Drupal core project.' , (bool) $project['project_id']);
+
+  $branch = array(
+    'project_id' => $project['project_id'],
+    'client_identifier' => 156281,
+    'vcs_identifier' => 'HEAD',
+    'dependency' => '',
+    'plugin_argument' => array('core' => 6),
+    'link' => 'http://drupal.org/node/156281',
+  );
+  $branch = pifr_server_branch_save($branch, FALSE);
+  $ret[] = pifr_update_message('Created Drupal core 7.x branch.', (bool) $branch['branch_id']);
+
+  return $ret;
+}
+
+/**
+ * Migrate pifr_file and pifr_result tables.
+ */
+function pifr_update_6206(&$sandbox = NULL) {
   $ret = array();
 
   if (!isset($sandbox['progress'])) {
     $sandbox['progress'] = 0;
     $sandbox['current_file_id'] = 0;
     $sandbox['max'] = db_result(db_query('SELECT COUNT(file_id) FROM {pifr_file_old}'));
+//    $sandbox['max'] = 650;
+
+    // Generate initial file map output file.
+    $sandbox['map_file'] = file_directory_path() . '/pifr.file.map';
+    file_put_contents($sandbox['map_file'], '');
+    file_put_contents('output.html', '');
   }
 
   $result = db_query_range('SELECT *
                             FROM {pifr_file_old}
                             WHERE file_id > %d
-                            ORDER BY file_id ASC', $sandbox['current_file_id'], 0, 75);
+                            ORDER BY file_id ASC', $sandbox['current_file_id'], 0, 300);
+  $file_map = array();
   while ($file_old = db_fetch_array($result)) {
     // Insert file record and create test record.
-    $file = pifr_server_file_save(array(
-      'branch_id' => 1,
-      'issue_nid' => $file_old['nid'],
-      'issue_cid' => $file_old['cid'],
+    $file = array(
+      'branch_id' => 1, // Assume Drupal 7.x core branch will be branch ID 1.
+      'client_identifier' => $file_old['server_file_id'],
       'file_url' => 'http://drupal.org/files/issues/' . $file_old['filename'],
       'file_name' => $file_old['filename'],
-    ), FALSE);
+      'link' => 'http://drupal.org/node/' . $file_old['nid'] . ($file_old['cid'] ? '#comment-' . $file_old['cid'] : ''),
+    );
+    $file = pifr_server_file_save($file, FALSE);
+
+    // Keep track of new file test ID and server file ID.
+    $file_map[] = $file['test_id'] . ',' . $file_old['server_file_id'];
 
     // Update test record with current state.
     $test = pifr_server_test_get($file['test_id']);
-    pifr_server_test_save(array(
-      'status' => pifr_update_6202_status($file_old['status']),
-      'client_id' => 0, // Client will be re-created.
+    $test = array(
+      'status' => pifr_update_6206_status($file_old['status']),
       'last_recieved' => $file_old['received'],
       'last_requested' => $file_old['sent'],
       'last_tested' => $file_old['last_tested'],
       'test_count' => $file_old['test_count'],
-    ) + $test);
-
-    // Insert test result and details.
-    $test_result = array(
-      'test_id' => $test['test_id'],
-      'type' => 1, // PIFR_SERVER_CLIENT_ENVIRONMENT_MYSQL_5_0_ISAM
-      'code' => $code = pifr_update_6202_code($file_old),
-      'details' => serialize(pifr_update_6202_details($code, $file_old['message'])),
-      'pass' => $file_old['pass'],
-      'fail' => $file_old['fail'],
-      'exception' => $file_old['exception'],
-      'result_details' => array(),
-    );
+    ) + $test;
+    $test = pifr_server_test_save($test);
 
-    if ($test_result['code'] >= PIFR_SERVER_TEST_RESULT_FAIL) {
-      // Some data is corrupted, ignore test results unless proper code.
-      $file_result_details = db_query('SELECT *
-                                       FROM {pifr_result_old}
-                                       WHERE file_id = %d', $file_old['file_id']);
-      while ($file_result_detail = db_fetch_array($file_result_details)) {
-        $result_detail = array(
-          'test_name' => $file_result_detail['test_class'],
-          'pass' => $file_result_detail['pass'],
-          'fail' => $file_result_detail['fail'],
-          'exception' => $file_result_detail['exception'],
-          'assertions' => array(), // Assertion data is not collected in 1.x.
-        );
-        $test_result['result_details'][] = $result_detail;
+    // Only store a result record if test has a result.
+    if ($test['status'] == PIFR_SERVER_TEST_STATUS_RESULT) {
+      // Insert test result and details.
+      $test_result = array(
+        'test_id' => $test['test_id'],
+        'environment_id' => 1, // Assume MySQL ISAM will be environment ID 1.
+        'code' => $code = pifr_update_6206_code($file_old),
+        'details' => serialize(pifr_update_6206_details($code, $file_old)),
+        'data' => array(),
+      );
+
+      if ($test_result['code'] >= PIFR_SERVER_TEST_RESULT_FAIL) {
+        // Some data is corrupted, ignore test results unless proper code.
+        $file_result_details = db_query('SELECT *
+                                         FROM {pifr_result_old}
+                                         WHERE file_id = %d', $file_old['file_id']);
+        while ($file_result_detail = db_fetch_array($file_result_details)) {
+          $test_result['data'][$file_result_detail['test_class']] = array(
+            'test_name' => $file_result_detail['test_class'],
+            'pass' => $file_result_detail['pass'],
+            'fail' => $file_result_detail['fail'],
+            'exception' => $file_result_detail['exception'],
+            'assertions' => array(), // Assertion data is not collected in 1.x.
+          );
+        }
       }
-    }
 
-    pifr_server_result_save($test_result);
+      pifr_server_result_save($test_result);
+    }
 
     $sandbox['progress']++;
     $sandbox['current_file_id'] = $file_old['file_id'];
   }
 
+  // Store map of new file test ID to old server file ID.
+  if ($file_map) {
+    file_put_contents($sandbox['map_file'], implode("\n", $file_map) . "\n", FILE_APPEND);
+  }
+
+  file_put_contents('output.html', $sandbox['progress'] . ' / ' . $sandbox['max'] . ' (' . $sandbox['current_file_id'] . ")<br />\n", FILE_APPEND);
+
   $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+//  $ret['#finished'] = 1;
+
+  // Upon completion of the migration check the number of rows in the new
+  // tables to ensure that all the data was migrated successfully.
+  if ($ret['#finished'] == 1) {
+    $test_count = db_result(db_query('SELECT COUNT(test_id) FROM {pifr_test} WHERE type = %d', PIFR_SERVER_TEST_TYPE_FILE));
+    $result_count = db_result(db_query('SELECT COUNT(result_id) FROM {pifr_result}'));
+
+    $success = ($test_count == $result_count && $test_count == $sandbox['max']);
+    $ret[] = pifr_update_message('Migrated [' . number_format($sandbox['max']) . '] tests and results.', $success);
+
+    // Ensure that generated map file has the proper number of lines.
+    $line_count = count(file($sandbox['map_file']));
+    $success = ($line_count == $test_count);
+    $ret[] = pifr_update_message('Generated map file [' . $sandbox['map_file'] . '].', $success);
+  }
 
   return $ret;
 }
@@ -175,13 +324,13 @@
  * @param integer $status 1.x test status code.
  * @return integer 2.x test status code.
  */
-function pifr_update_6202_status($status) {
+function pifr_update_6206_status($status) {
   $map = array(
     1 => 2, // PIFR_FILE_QUEUED => PIFR_SERVER_TEST_STATUS_QUEUED.
-    2 => 4, // PIFR_FILE_SENT => PIFR_SERVER_TEST_STATUS_SENT.
-    3 => 5, // PIFR_FILE_ERROR => PIFR_SERVER_TEST_STATUS_RESULT.
-    4 => 5, // PIFR_FILE_TEST_FAIL => PIFR_SERVER_TEST_STATUS_RESULT.
-    5 => 5, // PIFR_FILE_TEST_PASS => PIFR_SERVER_TEST_STATUS_RESULT.
+    2 => 2, // PIFR_FILE_SENT => PIFR_SERVER_TEST_STATUS_QUEUED.
+    3 => 4, // PIFR_FILE_ERROR => PIFR_SERVER_TEST_STATUS_RESULT.
+    4 => 4, // PIFR_FILE_TEST_FAIL => PIFR_SERVER_TEST_STATUS_RESULT.
+    5 => 4, // PIFR_FILE_TEST_PASS => PIFR_SERVER_TEST_STATUS_RESULT.
   );
   return $map[$status];
 }
@@ -192,7 +341,7 @@
  * @param array $file 1.x file information.
  * @return integer 2.x test result code.
  */
-function pifr_update_6202_code(array $file) {
+function pifr_update_6206_code(array $file) {
   switch ($file['message']) {
     case 'Failed to fetch file.':
       return PIFR_SERVER_TEST_RESULT_FETCH;
@@ -220,88 +369,95 @@
  * Convert 1.x message to 2.x details array.
  *
  * @param integer $code 2.x test result code.
- * @param string $message 1.x message.
+ * @param array $file 1.x file information.
  * @return array 2.x details.
  */
-function pifr_update_6202_details($code, $message) {
+function pifr_update_6206_details($code, array $file) {
   switch ($code) {
     case 2: // PIFR_SERVER_TEST_RESULT_FETCH.
-      return array('@reason' => 'failed to retrieve file from project client');
+      return array('@reason' => 'failed to retrieve [' . $file['filename'] . '] from project client');
     case 3: // PIFR_SERVER_TEST_RESULT_CVS.
-     return array('@reason' => 'failed to checkout Drupal core');
+     return array('@reason' => 'failed to checkout from [:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal/drupal]');
     case 9: // PIFR_SERVER_TEST_RESULT_TEST.
-      return array('@reason' => 'failed to run tests');
+      return array('@reason' => 'failed during invocation of run-tests.sh');
     case 6: // PIFR_SERVER_TEST_RESULT_SYNTAX.
-      if (preg_match('/Invalid PHP syntax in (.*?)\.$/', $message, $match)) {
+      if (preg_match('/Invalid PHP syntax in (.*?)\.$/', $file['message'], $match)) {
         return array('@filename' => $match[1]);
       }
       return array('@filename' => 'unknown');
+    case 9: // PIFR_SERVER_TEST_RESULT_FAIL.
+    case 10: // PIFR_SERVER_TEST_RESULT_PASS.
+      return array(
+        '@pass' => $file['pass'],
+        '@fail' => $file['fail'],
+        '@exception' => $file['exception'],
+      );
   }
   return array();
 }
 
-/**
- * Add drupal.org client, and Drupal HEAD project and branch information.
- *
- * Assumes pifr_server enabled.
- */
-function pifr_update_6203() {
-  $ret = array();
-
-  pifr_server_client_save(array(
-    'client_key' => md5(uniqid()),
-    'type' => 1, // PIFR_SERVER_CLIENT_TYPE_PROJECT
-    'environment_id' => 1, // Arbitrary.
-    'url' => 'http://drupal.org/',
-    'status' => 4, // PIFR_SERVER_CLIENT_STATUS_ENABLED
-  ));
-
-  pifr_server_project_save(array(
-    'project_nid' => 3060,
-    'client_id' => 1,
-    'name' => 'Drupal',
-    'type' => 1, // PIFR_SERVER_PROJECT_TYPE_CORE
-    'repository_type' => 'cvs',
-    'repository_url' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal/drupal/',
-  ));
-
-  pifr_server_branch_save(array(
-    'branch_nid' => 156281,
-    'project_id' => 1,
-    'core_branch_id' => 0,
-    'identifier' => 'HEAD',
-  ));
-
-  return $ret;
-}
 
 /**
- * Migrate log data.
+ * Migrate pifr_log table.
  *
  * Assumes pifr_log has been renamed to pifr_log_old.
  */
-function pifr_update_6204(&$sandbox = NULL) {
+function pifr_update_6207(&$sandbox = NULL) {
   $ret = array();
 
   if (!isset($sandbox['progress'])) {
     $sandbox['progress'] = 0;
     $sandbox['current_log_id'] = 0;
     $sandbox['max'] = db_result(db_query('SELECT COUNT(log_id) FROM {pifr_log_old}'));
+
+    file_put_contents('output.html', "<br />\n--LOG--<br />\n", FILE_APPEND);
   }
 
-  $result = db_query_range('SELECT *
-                            FROM {pifr_log_old}
-                            WHERE log_id > %d
-                            ORDER BY log_id ASC', $sandbox['current_log_id'], 0, 10000);
-  while ($log = db_fetch_array($result)) {
-    db_query("INSERT INTO {pifr_log} (test_id, timestamp, message)
-              VALUES (%d, %d, '%s')", $log['file_id'], $log['timestamp'], pifr_update_6204_message($log['message']));
+  // Query is quite intensive, go through in large batches.
+  set_time_limit(0);
+
+  $result = db_query_range('SELECT l.*, f.test_id
+                            FROM {pifr_log_old} l
+                            JOIN {pifr_file_old} o
+                              ON l.file_id = o.file_id
+                            JOIN {pifr_file} f
+                              ON o.server_file_id = f.client_identifier
+                            WHERE l.log_id > %d
+                            ORDER BY l.log_id ASC', $sandbox['current_log_id'], 0, 10000);
+  while ($log_old = db_fetch_array($result)) {
+    list($client_id, $code) = pifr_update_6207_details($log_old['message']);
+
+    // If log details are determined then migrate record.
+    if ($client_id !== FALSE) {
+      $log = array(
+        'test_id' => $log_old['test_id'],
+        'client_id' => $client_id,
+        'code' => $code,
+        'timestamp' => $log_old['timestamp'],
+      );
+      drupal_write_record('pifr_log', $log);
+    }
+    else {
+      $ret['#abort'] = pifr_update_message('Failed to migrate log record [' . $log_old['log_id'] . '].', FALSE);
+    }
 
     $sandbox['progress']++;
-    $sandbox['current_log_id'] = $log['log_id'];
+    $sandbox['current_log_id'] = $log_old['log_id'];
   }
 
   $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+//  $ret['#finished'] = 1;
+
+  file_put_contents('output.html', $sandbox['progress'] . ' / ' . $sandbox['max'] . ' (' . $sandbox['current_log_id'] . ")<br />\n", FILE_APPEND);
+
+  // Upon completion of the migration check the number of rows in the new
+  // tables to ensure that all the data was migrated successfully.
+  if ($ret['#finished'] == 1) {
+    $log_count = db_result(db_query('SELECT COUNT(log_id) FROM {pifr_log}'));
+
+    $success = ($log_count == $sandbox['max']);
+    $ret[] = pifr_update_message('Migrated [' . number_format($sandbox['max']) . '] log entries.', $success);
+  }
 
   return $ret;
 }
@@ -312,34 +468,42 @@
  * @param string $message 1.x log message.
  * @return string 2.x log message.
  */
-function pifr_update_6204_message($message) {
+function pifr_update_6207_details($message) {
+  static $client_id;
+
+  if (!isset($client_id)) {
+    // Determine drupal.org project client ID.
+    $client_id = db_result(db_query("SELECT client_id FROM {pifr_client} WHERE url = '%s'", 'http://drupal.org/'));
+    $ret[] = pifr_update_message('Found drupal.org client with ID [' . $client_id . '].', (bool) $client_id);
+  }
+
   switch ($message) {
     case 'Results sent to project server.':
-      return 'Result retrieved by project client.';
+      return array($client_id, PIFR_SERVER_LOG_CLIENT_RETRIEVE);
     case 'Test request received from the project server.':
-      return 'Test request received.';
+      return array($client_id, PIFR_SERVER_LOG_CLIENT_REQUEST);
     case 'Re-test request received from the project server.':
-      return 'Re-test request received.';
+      return array($client_id, PIFR_SERVER_LOG_CLIENT_REQUEST);
   }
 
   if (preg_match('/Test relayed to slave #(\d+)/', $message, $match)) {
-    return t('Requested by test client #@client_id.', array('@client_id' => $match[1]));
+    return array($match[1], PIFR_SERVER_LOG_TEST_REQUEST);
   }
-  else if (preg_match('/Result received from slave #(\d+) \(.*?\)/', $message, $match)) {
-    return t('Result received from test client #@client_id.', array('@client_id' => $match[1]));
+  else if (preg_match('/Result received from slave #(\d+) \(/', $message, $match)) {
+    return array($match[1], PIFR_SERVER_LOG_CLIENT_RESULT);
   }
-  return 'unknown';
+  return array(FALSE, FALSE);
 }
 
 /**
  * Remove old tables.
  */
-function pifr_update_6205() {
+function pifr_update_6208() {
   $ret = array();
 
-  db_drop_table($ret, 'pifr_file_old');
-  db_drop_table($ret, 'pifr_result_old');
-  db_drop_table($ret, 'pifr_log_old');
+  foreach (array('file', 'result', 'log', 'server') as $table) {
+    db_drop_table($ret, "pifr_{$table}_old");
+  }
 
   return $ret;
 }
Index: server/pifr_server.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue_file_review/server/pifr_server.install,v
retrieving revision 1.40
diff -u -r1.40 pifr_server.install
--- server/pifr_server.install	28 Oct 2009 04:12:12 -0000	1.40
+++ server/pifr_server.install	29 Oct 2009 04:53:48 -0000
@@ -64,6 +64,13 @@
         'default' => '',
         'serialize' => TRUE,
       ),
+      'link' => array(
+        'description' => t('Link to relevant information determined by project client.'),
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => '',
+      ),
     ),
     'indexes' => array(
       'test_id' => array('test_id'),
@@ -286,10 +293,9 @@
       ),
       'client_identifier' => array(
         'description' => t('Client identifier used to reference the file.'),
-        'type' => 'varchar',
+        'type' => 'int',
+        'unsigned' => TRUE,
         'not null' => TRUE,
-        'length' => 255,
-        'default' => '',
       ),
       'file_url' => array(
         'description' => t('Absolute URL to file.'),
@@ -305,6 +311,13 @@
         'length' => 255,
         'default' => '',
       ),
+      'link' => array(
+        'description' => t('Link to relevant information determined by project client.'),
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => '',
+      ),
     ),
     'indexes' => array(
       'test_id' => array('test_id'),
@@ -324,7 +337,7 @@
       'test_id' => array(
         'description' => t('Reference to test event occured to.'),
         'type' => 'int',
-        'not null' => FALSE,
+        'not null' => TRUE,
       ),
       'client_id' => array(
         'description' => t('Reference to client (if any) that was involved in the event.'),
@@ -342,7 +355,7 @@
         'description' => t('Timestamp when the event occured.'),
         'type' => 'int',
         'unsigned' => FALSE,
-        'not null' => FALSE,
+        'not null' => TRUE,
       ),
     ),
     'indexes' => array(
@@ -394,6 +407,13 @@
         'length' => 255,
         'default' => '',
       ),
+      'link' => array(
+        'description' => t('Link to relevant information determined by project client.'),
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'default' => '',
+      ),
     ),
     'indexes' => array(
       'client_identifier' => array('client_identifier'),
@@ -511,10 +531,8 @@
  * Implementation of hook_install().
  */
 function pifr_server_install() {
-  // Schema may have been installed during pifr update.
-  if (!db_table_exists('pifr_client')) {
-    drupal_install_schema('pifr_server');
-  }
+  // Install schema.
+  drupal_install_schema('pifr_server');
 
   // Set chart global background to transparent.
   variable_set('chart_global_bg', 'FFFFFF00');
@@ -535,31 +553,3 @@
   variable_del('pifr_server_client_project_interval');
   variable_del('pifr_server_client_test_interval');
 }
-
-/**
- * Add title field to pifr_test and insert the appriopriate value.
- */
-function pifr_server_update_6200() {
-  $ret = array();
-
-  // Add title field to pifr_test.
-  $spec = array(
-    'description' => t('Title representing the test.'),
-    'type' => 'varchar',
-    'not null' => TRUE,
-    'length' => 256,
-    'default' => '',
-  );
-  db_add_field($ret, 'pifr_test', 'title', $spec);
-
-  // Update all existing test records.
-  $tests = db_query('SELECT test_id
-                     FROM {pifr_test}');
-  while ($test_id = db_result($tests)) {
-    $test = pifr_server_test_get($test_id);
-    $test['title'] = pifr_server_test_title($test['type'], $test);
-    pifr_server_test_save($test);
-  }
-
-  return $ret;
-}
