/[drupal]/contributions/modules/project_issue_file_test/pift.install
ViewVC logotype

Contents of /contributions/modules/project_issue_file_test/pift.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.19 - (show annotations) (download) (as text)
Fri Oct 30 20:07:23 2009 UTC (3 weeks, 4 days ago) by boombatower
Branch: MAIN
Branch point for: DRUPAL-7--1
Changes since 1.18: +9 -2 lines
File MIME type: text/x-php
Update the location of the file map used during update.
1 <?php
2 // $Id: pift.install,v 1.18 2009/08/19 04:32:00 boombatower Exp $
3
4 /**
5 * @file
6 * Provide schema and installation functions.
7 *
8 * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
9 */
10
11 /**
12 * Implementation of hook_schema().
13 */
14 function pift_schema() {
15 $schema['pift_test'] = array(
16 'description' => t('Stores test results.'),
17 'fields' => array(
18 'test_id' => array(
19 'description' => t('Unique test ID.'),
20 'type' => 'int',
21 'unsigned' => TRUE,
22 'not null' => TRUE,
23 ),
24 'type' => array(
25 'description' => t('Type of test, PIFT_TYPE_*.'),
26 'type' => 'int',
27 'unsigned' => TRUE,
28 'not null' => TRUE,
29 ),
30 'id' => array(
31 'description' => t('Related test detail record ID, either rid, or fid.'),
32 'type' => 'int',
33 'unsigned' => TRUE,
34 'not null' => TRUE,
35 ),
36 'status' => array(
37 'description' => t('Status of the test, PIFT_STATUS_*.'),
38 'type' => 'int',
39 'unsigned' => TRUE,
40 'not null' => TRUE,
41 ),
42 'message' => array(
43 'description' => t('Summary message of test result.'),
44 'type' => 'text',
45 'size' => 'big',
46 'not null' => TRUE,
47 ),
48 'last_tested' => array(
49 'description' => t('Timestamp when test results were last recieved.'),
50 'type' => 'int',
51 'not null' => TRUE,
52 'default' => 0,
53 ),
54 ),
55 'primary key' => array('test_id', 'type', 'id'),
56 'indexes' => array(
57 'status' => array('status'),
58 'last_tested' => array('last_tested'),
59 ),
60 );
61 $schema['pift_project'] = array(
62 'description' => t('Store project testing preference.'),
63 'fields' => array(
64 'pid' => array(
65 'description' => t('Reference to project NID.'),
66 'type' => 'serial',
67 'unsigned' => TRUE,
68 'not null' => TRUE,
69 ),
70 ),
71 'primary key' => array('pid'),
72 );
73
74 return $schema;
75 }
76
77 /**
78 * Implementation of hook_install().
79 */
80 function pift_install() {
81 // Create tables.
82 drupal_install_schema('pift');
83
84 // Ensure that pift runs after comment_upload.
85 db_query("UPDATE {system}
86 SET weight = 3
87 WHERE name = '%s'", 'pift');
88
89 // Check for pift_data and as such an update.
90 if (db_table_exists('pift_data')) {
91 // Set schema version just before first update to ensure that updates are
92 // triggered even though the module has been renamed.
93 register_shutdown_function('pift_install_force_update');
94 }
95 }
96
97 /**
98 * Force update by reverting schema.
99 *
100 * The schema must be reverted after hook_install() has finished.
101 */
102 function pift_install_force_update() {
103 db_query("UPDATE {system}
104 SET schema_version = 6199
105 WHERE name = '%s'", 'pift');
106 }
107
108 /**
109 * Implementation of hook_uninstall().
110 */
111 function pift_uninstall() {
112 // Remove tables.
113 drupal_uninstall_schema('pift');
114
115 $vars = array(
116 'pift_frequency',
117 'pift_last',
118 'pift_key',
119 'pift_server',
120 'pift_description',
121 'pift_followup_fail',
122 'pift_followup_retest',
123 'pift_regex',
124 'pift_status',
125 'pift_core',
126 'pift_pid',
127 'pift_retest',
128 'pift_delete',
129 'pift_last_cid',
130 );
131
132 foreach ($vars as $var) {
133 variable_del($var);
134 }
135 }
136
137 /**
138 * Remove old variables an setup drupal.org defaults.
139 */
140 function pift_update_6200() {
141 $ret = array();
142
143 // List of old variables.
144 $vars = array(
145 'pift_server_sites',
146 'pift_server_send_frequency',
147 'pift_server_last_sent',
148 'pift_next_test_server',
149 'pift_server_file_description',
150 'pift_send_limit',
151 'pift_batch_size',
152 'pift_file_regex',
153 'pift_resend_time',
154 'pift_retest_time',
155 'pift_test_status',
156 'pift_projects',
157 'pift_server_release_tag_regex',
158 'pift_server_debug_file_testing_link',
159 'pift_server_auto_followup_sid',
160 );
161
162 // Remove old variables.
163 foreach ($vars as $var) {
164 variable_del($var);
165 }
166
167 // List of default drupal.org values.
168 $vars = array(
169 'pift_frequency' => 0, // Per cron run.
170 'pift_server' => 'http://testing.drupal.org/',
171 'pift_description' => 'Only files ending in <em>.patch</em> or <em>.diff</em> will be sent for testing. '.
172 'For patches that apply specifically to Drupal 5 or Drupal 6, you can prefix the extension ' .
173 'with <em>-D5</em> or <em>-D6</em> to prevent them from being queued for testing. For example, ' .
174 '<em>foo.patch</em> and <em>bar.diff</em> would both be queued for testing, whereas ' .
175 '<em>foo-D5.patch</em> and <em>bar-D6.diff</em> would not be queued for testing.',
176 'pift_followup_fail' => 13, // Status: 'Needs work'.
177 'pift_followup_retest' => 8, // Status: 'Needs review'.
178 'pift_regex' => '/(?<![.\-_][Dd][56])(\.diff|\.patch)$/',
179 'pift_status' => array(8, 14), // Statuses: 'Needs review', 'reviewed & tested by the community'.
180 'pift_core' => array(7 => 7),
181 'pift_pid' => 3060, // Drupal core project NID.
182 'pift_retest' => 86400, // 1 day.
183 );
184
185 // Store each default variable value.
186 foreach ($vars as $key => $value) {
187 variable_set($key, $value);
188 }
189
190 // Enable testing for the drupal project.
191 db_query('INSERT INTO {pift_project} (pid)
192 VALUES (%d)', 3060);
193
194 return $ret;
195 }
196
197 /**
198 * Update test records.
199 */
200 function pift_update_6201(&$sandbox = NULL) {
201 $ret = array();
202
203 if (!isset($sandbox['progress'])) {
204 $sandbox['progress'] = 0;
205 $sandbox['current_ftid'] = 0;
206 $sandbox['max'] = db_result(db_query('SELECT COUNT(ftid) FROM {pift_data}'));
207 }
208
209 // Map of old status to equivilent new ones.
210 $statuses = array(
211 0 => 1, // PIFT_UNTESTED => PIFT_STATUS_QUEUE
212 1 => 4, // PIFT_PASSED => PIFT_STATUS_PASS
213 2 => 3, // PIFT_FAILED => PIFT_STATUS_FAIL
214 3 => 1, // PIFT_RETEST => PIFT_STATUS_QUEUE
215 4 => 1, // PIFT_NOT_READABLE => PIFT_STATUS_QUEUE
216 );
217
218 // Read in map of ftid => test_id provided from pifr server 1.x, in a comma
219 // delimited file of the format: file_id(test_id),ftid.
220 if ($lines = file(drupal_get_path('module', 'pift') . '/pifr.file.map')) {
221 $map = array();
222 foreach ($lines as $line) {
223 $parts = explode(',', $line);
224 $map[trim($parts[1])] = trim($parts[0]);
225 }
226
227 // Update old data and insert into test table.
228 $result = db_query_range('SELECT *
229 FROM {pift_data}
230 WHERE ftid > %d
231 ORDER BY ftid ASC', $sandbox['current_ftid'], 0, 5000);
232 while ($test = db_fetch_object($result)) {
233 // Only covert data that testing.drupal.org has a record of.
234 if (isset($map[$test->ftid])) {
235 // Remove link from display data.
236 $message = preg_replace('/\s+(<a|a) href.*?$/', '', $test->display_data);
237
238 db_query("INSERT INTO {pift_test} (test_id, type, id, status, message, last_tested)
239 VALUES (%d, %d, %d, %d, '%s', %d)",
240 $map[$test->ftid], PIFT_TYPE_FILE, $test->fid, $statuses[$test->status], $message, $test->timestamp);
241 }
242 $sandbox['progress']++;
243 $sandbox['current_ftid'] = $test->ftid;
244 }
245
246 $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
247 }
248
249 return $ret;
250 }
251
252 /**
253 * Remove old data.
254 */
255 function pift_update_6202() {
256 $ret = array();
257
258 $ret[] = update_sql('DROP TABLE {pift_data}');
259
260 return $ret;
261 }

  ViewVC Help
Powered by ViewVC 1.1.2