Added place holders for a the steps and added conversion info for categories, projects, and bugs
Jeremy D

Jeremy D commited on 2011-09-28 13:48:37
Showing 1 changed files, with 113 additions and 3 deletions.

... ...
@@ -150,11 +150,11 @@ class mbt_to_tbg
150 150
 	*
151 151
 	* Gets the current substep
152 152
 	*
153
-	* @param init $step The current step we should be on, if this changes substep is ignored and reset
153
+	* @param string $step The current function we are on.
154 154
 	*/
155 155
 	function getSubStep($step)
156 156
 	{
157
-		if (!isset($_GET['step']) || !isset($_GET['substep']) || $step != $_GET['step'])
157
+		if (!isset($_GET['step']) || !isset($_GET['substep']) || str_replace('doStep', '', $step) != $_GET['step'])
158 158
 			return 0;
159 159
 		else
160 160
 			return (int) $_GET['substep'];
... ...
@@ -217,7 +217,7 @@ class mbt_to_tbg
217 217
 	*/
218 218
 	function doStep1()
219 219
 	{
220
-		$substep = $this->getSubStep(1);
220
+		$substep = $this->getSubStep(__FUNCTION__);
221 221
 
222 222
 		$query = '
223 223
 			SELECT
... ...
@@ -240,6 +240,116 @@ class mbt_to_tbg
240 240
 		$this->updateSubStep($substep + 500);
241 241
 		$this->checkTimeout(__FUNCTION__);
242 242
 	}
243
+
244
+	/**
245
+	* Convert Projects.
246
+	*
247
+	*/
248
+	function doStep2()
249
+	{
250
+		$substep = $this->getSubStep(__FUNCTION__);
251
+
252
+		$query = '
253
+			SELECT
254
+				id, name, description,
255
+				(CASE WHEN enabled = 0 THEN 1 ELSE 0) AS locked
256
+				FROM ' . $this->mbt_db_prefix . 'project_table
257
+			LIMIT ' . $substep . ' 500');
258
+
259
+		foreach ($this->db->query($sql) as $row)
260
+			$this->db->query('
261
+				INSERT INTO ' . $this->tbg_db_prefix . 'projects (id, name, locked, description)
262
+				VALUES (' . $row['id'] . ', "' . $row['name'] . '", ' . $row['locked'] . ', "' . $row['description'] . '")');
263
+
264
+		$this->updateSubStep($substep + 500);
265
+		$this->checkTimeout(__FUNCTION__);
266
+	}
267
+
268
+	/**
269
+	* Convert Categories.
270
+	*
271
+	*/
272
+	function doStep3()
273
+	{
274
+		$substep = $this->getSubStep(__FUNCTION__);
275
+
276
+		$query = '
277
+			SELECT
278
+				name
279
+				FROM ' . $this->mbt_db_prefix . 'category_table
280
+			LIMIT ' . $substep . ' 500');
281
+
282
+		foreach ($this->db->query($sql) as $row)
283
+			$this->db->query('
284
+				INSERT INTO ' . $this->tbg_db_prefix . 'listtypes (name, itemtype, scope)
285
+				VALUES (' . $row['name'] . ', "category", 1)');
286
+
287
+		$this->updateSubStep($substep + 500);
288
+		$this->checkTimeout(__FUNCTION__);
289
+	}
290
+
291
+	/**
292
+	* Convert Versions.
293
+	*
294
+	*/
295
+	function doStep4()
296
+	{
297
+		$substep = $this->getSubStep(__FUNCTION__);
298
+
299
+	}
300
+
301
+
302
+	/**
303
+	* Normally we want to fix them, but in this case we want to convert bugs.
304
+	*
305
+	*/
306
+	function doStep5()
307
+	{
308
+		$substep = $this->getSubStep(__FUNCTION__);
309
+
310
+		$query = '
311
+			SELECT
312
+				bt.id, bt.project_id, bt.summary AS title, bt.handler_id AS assigned_to, bt.duplicate_id AS duplicate_of,
313
+				bt.date_submitted AS posted, bt.last_updated, bt.status AS state, bt.cagegory_id AS category,
314
+				bt.priority,
315
+				bt.severity /* NEEDS FIXED */,
316
+				(CASE
317
+					WHEN bt.reproducability = 10 THEN 12
318
+					WHEN bt.reproducability > 30 AND bt.reproducability < 70 THEN 11
319
+					WHEN bt.reproducability > 70 AND bt.reproducability < 90 THEN 9
320
+					ELSE 0) AS reproducability,
321
+					IFNULL(btt.steps_to_reproduce, "") AS reproduction_steps
322
+					IFNULL(btt.description, "") AS description,
323
+					version
324
+				FROM ' . $this->mbt_db_prefix . 'bug_table AS bt
325
+					LEFT JOIN ' . $this->mbt_db_prefix . 'bug_text_table AS btt ON (btt.id = bt.bug_text_id)
326
+			LIMIT ' . $substep . ' 500');
327
+
328
+		foreach ($this->db->query($sql) as $row)
329
+		{
330
+			$this->db->query('
331
+				INSERT INTO ' . $this->tbg_db_prefix . 'issues (id, project_id, title, assigned_to, duplicate_of, posted, last_updated, state, category, resolution, priority, severity, reproducability)
332
+				VALUES (' . $row['id'] . ', ' . $row['project_id'] . ', "' . $row['title'] . '", ' . $row['assigned_to'] . ', ' . $row['duplicate_of'] . ', ' . $row['posted'] . ', ' . $row['last_updated'] . ', ' . $row['state'] . ', ' . $row['category'] . ', ' . $row['category'] . ', ' . $row['resolution'] . ', ' . $row['priority'] . ', ' . $row['severity'] . ', ' . $row['reproducability'] . ')');
333
+
334
+			// @ TODO: Make this detect duplicates.
335
+			$this->db->query('
336
+				INSERT INTO (' . $this->tbg_db_prefix . 'builds (name) VALUES (' . $row['version'] . ')');
337
+
338
+			$this->db->query('
339
+				INSERT INTO (' . $this->tbg_db_prefix . 'issueaffectsbuild (id, build) VALUES(' . $row['id'] . ', ' . $this->db->lastInsertId() . ')');
340
+		}
341
+
342
+		$this->updateSubStep($substep + 500);
343
+		$this->checkTimeout(__FUNCTION__);
344
+	}
345
+
346
+	/**
347
+	* Bug Notes.
348
+	*
349
+	*/
350
+	function doStep6()
351
+	{
352
+	}
243 353
 }
244 354
 
245 355
 
246 356