Added initial converter based off Joshs work and my additions
Jeremy D

Jeremy D commited on 2011-09-27 21:43:25
Showing 1 changed files, with 286 additions and 0 deletions.

... ...
@@ -0,0 +1,286 @@
1
+<?php
2
+
3
+/**
4
+ * Convert Mantis Bug Tracker to The Bug Genie
5
+ * 
6
+ * @author Joshua Dickerson
7
+ * @author Jeremy Darwood
8
+ * @copyright Joshua Dickerson & Jeremy Darwood 2011
9
+ * @license BSD
10
+ * 
11
+ * The gist of the license is that you may do whatever you like, just give credit where it's due.
12
+ * 
13
+ * Throughout this I use some acronyms:
14
+ *  MBT = Mantis Bug Tracker
15
+ *  TBG = The Bug Genie
16
+ */
17
+
18
+class mbt_to_tbg
19
+{
20
+	// Where your config_inc.php is located
21
+	//const MBT_PATH = '';
22
+	// Where your b2db_boostrap.inc.php is located
23
+	//const TBG_PATH = '';
24
+
25
+	// The host, user, and pass must be on the same server
26
+	protected $db_driver = 'mysql';
27
+	protected $db_host = 'localhost';
28
+	protected $db_user = '';
29
+	protected $db_pass = '';
30
+
31
+	protected $mbt_db_name = 'mantis';
32
+	protected $mbt_db_table_prefix = 'mantis_';
33
+
34
+	protected $tbg_db_name = 'tbg';
35
+	protected $tbg_db_table_prefix = 'tbg3_';
36
+
37
+	// Scope (usually just 1)
38
+	protected $tbg_scope = 1;
39
+
40
+	// The database prefixes (including the database).
41
+	protected $mbt_db_prefix;
42
+	protected $tbg_db_prefix;
43
+
44
+	// The database connection resource.
45
+	protected $db;
46
+
47
+	function __construct()
48
+	{
49
+		// Don't timeout!
50
+		set_time_limit(0);
51
+
52
+		if (function_exists('apache_reset_timeout'))
53
+			apache_reset_timeout();
54
+
55
+		$this->setDatabasePrefix();
56
+		$this->getDatabaseConnection();
57
+	}
58
+
59
+	/**
60
+	 * Set the prefix that will be used prior to every reference of a table
61
+	 */
62
+	function setDatabasePrefix()
63
+	{
64
+		$this->tbg_db_prefix = $this->tbg_db_name . '.' . $this->tbg_db_table_prefix;
65
+		$this->mbt_db_prefix = $this->mbt_db_name . '.' . $this->mbt_db_table_prefix;
66
+	}
67
+
68
+	/**
69
+	 * Establish a database connection
70
+	 */
71
+	function getDatabaseConnection()
72
+	{
73
+		$this->db = new PDO ($this->db_driver . ':host=' . $this->db_host, $this->db_user, $this->db_pass);
74
+	}
75
+
76
+	/**
77
+	 * Sets the list types in TBG to be like MBT
78
+	 * 
79
+	 * @param array $types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status') an array of what types to set
80
+	 */
81
+	function setListTypes($types = array())
82
+	{
83
+		$allowed_types = array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status');
84
+		$types = empty($types) ? $allowed_types : array_intersect($allowed_types, $types);
85
+
86
+		$types_conversion = array(
87
+			'category' => array(
88
+				
89
+			),
90
+			'priority' => array(
91
+				
92
+			),
93
+			'reproducability' => array(
94
+				'Always' => 10,
95
+				'Sometimes' => 30,
96
+				'Random' => 50,
97
+				'Have not tried' => 70,
98
+				'Unable to reproduce' => 90,
99
+				'N/A' => 100
100
+			),
101
+			'resolution' => array(
102
+				
103
+			),
104
+			'severity' => array(
105
+				
106
+			),
107
+			'status' => array(
108
+				
109
+			));
110
+		foreach ($types as $type)
111
+		{
112
+			
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * Get a random string for passwords
118
+	 * 
119
+	 * @param int $min_length = 8 The minimum length of the string
120
+	 * @param int $max_length = 12 The maximum length of the string
121
+	 * @return string A randomly generate string of letters, numbers, and special characters.
122
+	 */
123
+	function getRandomString($min_length = 8, $max_length = 12)
124
+	{
125
+		// @ Why don't we simply create sha1(mt_rand() . time() . uniqueid());
126
+		$length = rand($min_length, $max_length);
127
+
128
+		// All of the possible characters we will allow.
129
+		$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*_=+.,?/[]{}|';
130
+		$chars_len = strlen($chars);
131
+
132
+		$random_string = '';
133
+
134
+		for ($i = 0; $i !== $length; $i++)
135
+			$random_string .= $chars[rand(0, $chars_len)];
136
+
137
+		return $random_string;
138
+	}
139
+
140
+	/**
141
+	*
142
+	* Gets the current substep
143
+	*
144
+	* @param init $step The current step we should be on, if this changes substep is ignored and reset
145
+	*/
146
+	function getSubStep($step)
147
+	{
148
+		if (!isset($_GET['step']) || !isset($_GET['substep']) || $step != $_GET['step'])
149
+			return 0;
150
+		else
151
+			return (int) $_GET['substep'];
152
+	}
153
+
154
+	/**
155
+	* Empty the tables prior to the conversion.
156
+	*
157
+	* @Should it empty the tables prior to conversion or just dump over?
158
+	* @Should we do this in each step?
159
+	*/
160
+	function doStep0()
161
+	{
162
+	}
163
+
164
+	/**
165
+	* Convert users.
166
+	*
167
+	*/
168
+	function doStep1()
169
+	{
170
+		$substep = $this->getSubStep(1);
171
+
172
+		$query = '
173
+			SELECT
174
+				id, username, username AS buddyname, realname, email, password,
175
+				enabled, last_vist AS lastseen, date_created AS joined
176
+			FROM
177
+				' . $this->mbt_db_prefix . 'user_table
178
+			LIMIT ' . $substep . ' 500');
179
+
180
+		// We could let this save up a few inserts then do them at once, but are we really worried about saving queries here?
181
+		foreach ($this->db->query($sql) as $row)
182
+		{
183
+			$password = $this->getRandomString();
184
+
185
+			$his->db->query('
186
+				INSERT INTO ' . $this->tbg_db_prefix . 'users (id, username, buddyname, realname, email, password, enabled, lastseen, joined)
187
+				VALUES (' . $row['id'] . ', "' . $row['username'] . '", "' . $row['buddyname'] . '", "' . $row['realname'] . '", "' . $row['email'] . '", "' . $password . '", ' . $row['enabled'] . ', ' . $row['username'] . ', ' . $row['joined'] . ')');
188
+		}
189
+	}
190
+}
191
+
192
+
193
+
194
+
195
+// Not sure if these classes will be used.
196
+// @ Why do we need these?  Its a converter only for mantis to TBG.  Don't need to make things complicated.
197
+class tbg extends mbt_to_tbg
198
+{
199
+	function setReproducability()
200
+	{
201
+		// Delete from listtypes where itemtype = reproducability
202
+		// Insert into listtypes, get the item
203
+		// Update issues with reproducability number
204
+		
205
+	}
206
+
207
+	function setCategory()
208
+	{
209
+		
210
+	}
211
+
212
+	function removeListType($type, $id = 0)
213
+	{
214
+		// Don't allow them to remove a bad type.
215
+		if (!in_array($type, array('category', 'priority', 'reproducability', 'resolution', 'severity', 'status')))
216
+			return;
217
+
218
+		if (empty($id))
219
+			return $this->db->query('
220
+				DELETE FROM ' . $this->tbg_db_prefix . 'listtype
221
+				WHERE itemtype=\'' . $type . '\'');
222
+		else
223
+			return $this->db->query('
224
+				DELETE FROM ' . $this->tbg_db_prefix . 'listtype
225
+				WHERE itemtype=\'' . $type . '\')
226
+					AND id=\'' . (int) $id . '\'');	
227
+	}
228
+}
229
+/*Severity: feature = 10; trivial = 20; text = 30; tweak = 40; minor = 50; major = 60; crash = 70; block = 80;
230
+
231
+Priority: none = 10; low = 20; normal = 30; high = 40; urgent = 50; immediate = 60;*/
232
+class mtb extends mbt_to_tbg
233
+{
234
+	function getAdmins()
235
+	{
236
+		$result = $this->db->query('
237
+			SELECT MAX(' . $this->mbt_db_prefix . 'user_table.access_level)
238
+		');
239
+	}
240
+	function getReproducability()
241
+	{
242
+		return array(
243
+			'Always' => 10,
244
+			'Sometimes' => 30,
245
+			'Random' => 50,
246
+			'Have not tried' => 70,
247
+			'Unable to reproduce' => 90,
248
+			'N/A' => 100
249
+		);
250
+	}
251
+
252
+	function getSeverity()
253
+	{
254
+		return array(
255
+			'Feature' => 10,
256
+			'Trivial' => 20,
257
+			'Text' => 30,
258
+			'Tweak' => 40,
259
+			'Minor' => 50,
260
+			'Major' => 60,
261
+			'Crash' => 70,
262
+			'Block' => 80
263
+		);
264
+	}
265
+
266
+	function getPriority()
267
+	{
268
+		return array(
269
+			'None' => 10,
270
+			'Low' => 20,
271
+			'Normal' => 30,
272
+			'High' => 40,
273
+			'Urgent' => 50,
274
+			'Immediate' => 60
275
+		);
276
+	}
277
+
278
+	// TBG cannot do categories by project or user so ignore those.
279
+	function getCategory()
280
+	{
281
+		/*
282
+		 * 	SELECT *
283
+		 * 	FROM {mtb}category_table
284
+		 */ 
285
+	}
286
+} 
0 287
\ No newline at end of file
1 288