Added a basic theme wrapper and settings handling. Core tbg converter class now handles only the essentials of the conversion while the mbt_to_tbg handles the specifics.
Jeremy D

Jeremy D commited on 2011-10-10 17:59:14
Showing 1 changed files, with 164 additions and 117 deletions.

... ...
@@ -1,4 +1,5 @@
1 1
 <?php
2
+// @NOTE: THIS CONVERTER IS IN DEVELOPMENT AND IS MOSTLY THEORETICAL UNTESTED CODE.
2 3
 
3 4
 /**
4 5
  * Convert Mantis Bug Tracker to The Bug Genie
... ...
@@ -15,7 +16,13 @@
15 16
  *  TBG = The Bug Genie
16 17
  */
17 18
 
18
-class mbt_to_tbg
19
+/*
20
+* @TODO The developers list of things todo.	
21
+* Add js to support ajax
22
+* Add ajax support
23
+*/
24
+
25
+class tbg_coverter
19 26
 {
20 27
 	// Where your config_inc.php is located
21 28
 	//const MBT_PATH = '';
... ...
@@ -61,65 +68,92 @@ class mbt_to_tbg
61 68
 		if (function_exists('apache_reset_timeout'))
62 69
 			apache_reset_timeout();
63 70
 
71
+		// Try to find some settings.
72
+		$this->loadSettings();
73
+		
74
+		// We can't process anymore until this exists.
75
+		if (empty($this->db_user))
76
+		{
77
+		}
78
+		else
79
+		{
64 80
 			$this->setDatabasePrefix();
65 81
 			$this->getDatabaseConnection();
66 82
 		}
83
+	}
67 84
 
68 85
 	/**
69
-	 * Set the prefix that will be used prior to every reference of a table
86
+	* Request these settings during setup.
87
+	*
70 88
 	*/
71
-	function setDatabasePrefix()
89
+	private function converterSettings()
72 90
 	{
73
-		$this->tbg_db_prefix = $this->tbg_db_name . '.' . $this->tbg_db_table_prefix;
74
-		$this->mbt_db_prefix = $this->mbt_db_name . '.' . $this->mbt_db_table_prefix;
91
+		return array(
92
+			'mantis_loc' => array('type' => 'text', 'required' => true, 'validate' => 'return file_exists($data);'),
93
+			'tbg_loc' => array('type' => 'text', 'required' => true, 'default' => dirname(__FILE__), 'validate' => 'return file_exists($data);')
94
+			// @TODO: Make this validate the password.
95
+			'tbg_db_pass' => array('type' => 'password', 'required' => true, 'validate' => true,),
96
+		);
75 97
 	}
76 98
 
77 99
 	/**
78
-	 * Establish a database connection
100
+	* Request these settings during setup.
101
+	*
79 102
 	*/
80
-	function getDatabaseConnection()
103
+	private function loadSettings()
81 104
 	{
82
-		$this->db = new PDO ($this->db_driver . ':host=' . $this->db_host, $this->db_user, $this->db_pass);
105
+		// Lets check our session.
106
+		if (session_id() == '')
107
+			session_start();
108
+
109
+		if (isset($_SESSION['tbg_converter']))
110
+		{
111
+			foreach (unserialize($_SESSION['tbg_converter']) as $key => $data)
112
+				$this->{$key} = $data;
113
+
114
+			return;
115
+		}
83 116
 	}
84 117
 
85 118
 	/**
86
-	 * Sets the list types in TBG to be like MBT
119
+	* Save the settings..
87 120
 	*
88
-	 * @param array $types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status') an array of what types to set
89 121
 	*/
90
-	function setListTypes($types = array())
122
+	private function setSettings()
91 123
 	{
92
-		$allowed_types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status');
93
-		$types = empty($types) ? $allowed_types : array_intersect($allowed_types, $types);
94
-
95
-		$types_conversion = array(
96
-			'category' => array(
97
-				
98
-			),
99
-			'priority' => array(
100
-				
101
-			),
102
-			'reproducability' => array(
103
-				'Always' => 10,
104
-				'Sometimes' => 30,
105
-				'Random' => 50,
106
-				'Have not tried' => 70,
107
-				'Unable to reproduce' => 90,
108
-				'N/A' => 100
109
-			),
110
-			'resolution' => array(
124
+		$settings = $this->converterSettings()
125
+		$new_settings = array();
126
+		foreach ($settings as $key => $details)
127
+		{
128
+			// We are saving then
129
+			if (isset($_POST[$key]))
130
+			{
131
+				if (isset($details['validate']) && eval($details['validate']) !== true)
132
+					$errors[$key] = $key . ' contains invalid_data';
111 133
 
112
-			),
113
-			'severity' => array(
134
+				$new_settings[$key] = $_POST[$key];
135
+			}
136
+		}
114 137
 
115
-			),
116
-			'status' => array(
138
+		// Save these.
139
+		$_SESSION['tbg_converter'] = serialize($new_settings);
140
+	}
117 141
 
118
-			));
119
-		foreach ($types as $type)
142
+	/**
143
+	 * Set the prefix that will be used prior to every reference of a table
144
+	 */
145
+	private function setDatabasePrefix()
120 146
 	{
121
-			
147
+		$this->tbg_db_prefix = $this->tbg_db_name . '.' . $this->tbg_db_table_prefix;
148
+		$this->mbt_db_prefix = $this->mbt_db_name . '.' . $this->mbt_db_table_prefix;
122 149
 	}
150
+
151
+	/**
152
+	 * Establish a database connection
153
+	 */
154
+	function getDatabaseConnection()
155
+	{
156
+		$this->db = new PDO ($this->db_driver . ':host=' . $this->db_host, $this->db_user, $this->db_pass);
123 157
 	}
124 158
 
125 159
 	/**
... ...
@@ -200,6 +234,49 @@ class mbt_to_tbg
200 234
 		// @ !!! If this is all done via ajax, it should be a json or xml return.
201 235
 		// @ !!! Will need to strip doStep from the function name and cast as a int for security.
202 236
 	}
237
+}
238
+
239
+class mbt_to_tbg extends tbg_converter
240
+{
241
+	/**
242
+	 * Sets the list types in TBG to be like MBT
243
+	 * 
244
+	 * @param array $types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status') an array of what types to set
245
+	 */
246
+	function setListTypes($types = array())
247
+	{
248
+		$allowed_types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status');
249
+		$types = empty($types) ? $allowed_types : array_intersect($allowed_types, $types);
250
+
251
+		$types_conversion = array(
252
+			'category' => array(
253
+				
254
+			),
255
+			'priority' => array(
256
+				
257
+			),
258
+			'reproducability' => array(
259
+				'Always' => 10,
260
+				'Sometimes' => 30,
261
+				'Random' => 50,
262
+				'Have not tried' => 70,
263
+				'Unable to reproduce' => 90,
264
+				'N/A' => 100
265
+			),
266
+			'resolution' => array(
267
+				
268
+			),
269
+			'severity' => array(
270
+				
271
+			),
272
+			'status' => array(
273
+				
274
+			));
275
+		foreach ($types as $type)
276
+		{
277
+			
278
+		}
279
+	}
203 280
 
204 281
 	/**
205 282
 	* Empty the tables prior to the conversion.
... ...
@@ -477,98 +554,68 @@ class mbt_to_tbg
477 554
 	}
478 555
 }
479 556
 
480
-
481
-
482
-
483
-// Not sure if these classes will be used.
484
-// @ Why do we need these?  Its a converter only for mantis to TBG.  Don't need to make things complicated.
485
-class tbg extends mbt_to_tbg
486
-{
487
-	function setReproducability()
488
-	{
489
-		// Delete from listtypes where itemtype = reproducability
490
-		// Insert into listtypes, get the item
491
-		// Update issues with reproducability number
492
-		
493
-	}
494
-
495
-	function setCategory()
557
+/*
558
+* Theme wrapper.
559
+*
560
+*/
561
+class tbg_converter_wrapper
496 562
 {
563
+	protected $page_title = 'Mantis to The Bug Genie converter';
497 564
 
498
-	}
499
-
500
-	function removeListType($type, $id = 0)
565
+	/*
566
+	* Set the title.
567
+	* @param $title: The page title to set
568
+	*/
569
+	public static function setHeader($title)
501 570
 	{
502
-		// Don't allow them to remove a bad type.
503
-		if (!in_array($type, array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status')))
504
-			return;
505
-
506
-		if (empty($id))
507
-			return $this->db->query('
508
-				DELETE FROM ' . $this->tbg_db_prefix . 'listtype
509
-				WHERE itemtype=\'' . $type . '\'');
510
-		else
511
-			return $this->db->query('
512
-				DELETE FROM ' . $this->tbg_db_prefix . 'listtype
513
-				WHERE itemtype=\'' . $type . '\')
514
-					AND id=\'' . (int) $id . '\'');	
571
+		self:$page_title = $title;
515 572
 	}
516
-}
517
-/*Severity: feature = 10; trivial = 20; text = 30; tweak = 40; minor = 50; major = 60; crash = 70; block = 80;
518 573
 
519
-Priority: none = 10; low = 20; normal = 30; high = 40; urgent = 50; immediate = 60;*/
520
-class mtb extends mbt_to_tbg
521
-{
522
-	function getAdmins()
523
-	{
524
-		$result = $this->db->query('
525
-			SELECT MAX(' . $this->mbt_db_prefix . 'user_table.access_level)
526
-		');
527
-	}
528
-	function getReproducability()
574
+	/*
575
+	* Any custom header()s
576
+	*
577
+	*/
578
+	public static function header()
529 579
 	{
530
-		return array(
531
-			'Always' => 10,
532
-			'Sometimes' => 30,
533
-			'Random' => 50,
534
-			'Have not tried' => 70,
535
-			'Unable to reproduce' => 90,
536
-			'N/A' => 100
537
-		);
538
-	}
539 580
 
540
-	function getSeverity()
541
-	{
542
-		return array(
543
-			'Feature' => 10,
544
-			'Trivial' => 20,
545
-			'Text' => 30,
546
-			'Tweak' => 40,
547
-			'Minor' => 50,
548
-			'Major' => 60,
549
-			'Crash' => 70,
550
-			'Block' => 80
551
-		);
552 581
 	}
553 582
 
554
-	function getPriority()
555
-	{
556
-		return array(
557
-			'None' => 10,
558
-			'Low' => 20,
559
-			'Normal' => 30,
560
-			'High' => 40,
561
-			'Urgent' => 50,
562
-			'Immediate' => 60
563
-		);
583
+	/*
584
+	* The upper part of the theme.
585
+	*
586
+	*/
587
+	public static function upper()
588
+	{
589
+		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
590
+<html xmlns="http://www.w3.org/1999/html">
591
+<head>
592
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
593
+	<title>', self:$page_title, '</title>
594
+	<style type="text/css">
595
+	<!--
596
+	-->
597
+	</style>' : ''), '
598
+</head>
599
+<body>
600
+	<div>
601
+		<div style="padding: 10px; padding-right: 0px; padding-left: 0px; width:98% ">
602
+			<div style="padding-left: 200px; padding-right: 0px;">
603
+				<h1>', self:$page_title, '</h1>
604
+				<div class="panel" style="padding-right: 0px;  white-space: normal; overflow: hidden;">';
564 605
 	}
565 606
 
566
-	// TBG cannot do categories by project or user so ignore those.
567
-	function getCategory()
568
-	{
569 607
 	/*
570
-		 * 	SELECT *
571
-		 * 	FROM {mtb}category_table
608
+	* The lower part of the theme.
609
+	*
572 610
 	*/
611
+	public static function lower();
612
+	{
613
+		echo '
614
+				</div>
615
+			</div>
616
+		</div>
617
+	</div>
618
+</body></html>';
619
+
573 620
 	}
574 621
 }
575 622
\ No newline at end of file
576 623