Ooops, some debug stuff.
Jeremy D

Jeremy D commited on 2011-10-30 16:23:33
Showing 1 changed files, with 37 additions and 38 deletions.

... ...
@@ -1,5 +1,7 @@
1 1
 <?php
2 2
 // @NOTE: THIS CONVERTER IS IN DEVELOPMENT AND IS MOSTLY THEORETICAL UNTESTED CODE.
3
+error_reporting(E_ALL);
4
+ini_set('display_errors', 1);
3 5
 
4 6
 /**
5 7
  * Convert Mantis Bug Tracker to The Bug Genie
... ...
@@ -50,8 +52,8 @@ class tbg_converter
50 52
 	protected $start_time = 0;
51 53
 
52 54
 	// Step info.
53
-	private $substep = 0;
54
-	private $step = 0;
55
+	protected $substep = 0;
56
+	protected $step = 0;
55 57
 
56 58
 	// Is this CLI?
57 59
 	protected $is_cli = false;
... ...
@@ -94,7 +96,7 @@ class tbg_converter
94 96
 	* Actually does the conversion process
95 97
 	*
96 98
 	*/
97
-	private function processCLI()
99
+	public function processCLI()
98 100
 	{
99 101
 		$this->is_cli = true;
100 102
 
... ...
@@ -156,14 +158,11 @@ class tbg_converter
156 158
 	* Actually does the conversion process
157 159
 	*
158 160
 	*/
159
-	private function doConversion()
161
+	public function doConversion()
160 162
 	{
161 163
 		$this->setDatabasePrefix();
162 164
 		$this->getDatabaseConnection();
163 165
 
164
-		// Fire this thing off.
165
-		$this->loadSettings();
166
-
167 166
 		// Now restart.
168 167
 		do
169 168
 		{
... ...
@@ -173,7 +172,7 @@ class tbg_converter
173 172
 			$this->updateStep($data[1]);
174 173
 			$this->step_size = $data[2];
175 174
 
176
-			$count = $data[1]();
175
+			$count = $this->$data[1]();
177 176
 
178 177
 			$this->checkTimeout($data[1], $this->substep, $data[2], $count);
179 178
 		}
... ...
@@ -184,7 +183,7 @@ class tbg_converter
184 183
 	* Ask the user for some settings, validate and then start conversion.
185 184
 	*
186 185
 	*/
187
-	private function converterSetup()
186
+	public function converterSetup()
188 187
 	{
189 188
 		global $theme;
190 189
 
... ...
@@ -193,11 +192,7 @@ class tbg_converter
193 192
 			$errors = $this->setSettings();
194 193
 
195 194
 			if ($errors === null)
196
-			{
197
-				// From here on, its all automatic.
198
-				$this->updateStep('doStep1');
199 195
 				$this->doConversion();
200
-			}
201 196
 			else
202 197
 				$theme->errors($errors);
203 198
 		}
... ...
@@ -215,9 +210,9 @@ class tbg_converter
215 210
 	public function converterSettings()
216 211
 	{
217 212
 		return array(
218
-			'tbg_loc' => array('name' => 'The Bug Genie location', 'type' => 'text', 'required' => true, 'default' => dirname(__FILE__), 'validate' => 'return file_exists($data);'),
213
+			'tbg_loc' => array('name' => 'The Bug Genie location', 'type' => 'text', 'required' => true, 'default' => dirname(__FILE__), 'validate' => 'return file_exists($data) && file_exists($data . \'/index.php\');'),
219 214
 			// @TODO: Make this validate the password.
220
-			'tbg_db_pass' => array('name' => 'The Bug Genie database password', 'type' => 'password', 'required' => true, 'validate' => true,),
215
+			'tbg_db_pass' => array('name' => 'The Bug Genie database password', 'type' => 'password', 'required' => true, 'validate' => 'return true;',),
221 216
 		);
222 217
 	}
223 218
 
... ...
@@ -225,7 +220,7 @@ class tbg_converter
225 220
 	* Request these settings during setup.
226 221
 	*
227 222
 	*/
228
-	private function loadSettings()
223
+	public function loadSettings()
229 224
 	{
230 225
 		// Lets check our session.
231 226
 		if (session_id() == '')
... ...
@@ -235,20 +230,19 @@ class tbg_converter
235 230
 		{
236 231
 			foreach (unserialize($_SESSION['tbg_converter']) as $key => $data)
237 232
 				$this->{$key} = $data;
238
-
239
-			return;
240 233
 		}
241 234
 
242 235
 		// Load some from the url.
243 236
 		$this->step = (int) $_GET['step'];
244
-		$this->substep = (int) $_GET['substep'];
237
+
238
+		$this->substep = isset($_GET['substep']) ? (int) $_GET['substep'] : 0;
245 239
 	}
246 240
 
247 241
 	/**
248 242
 	* Save the settings..
249 243
 	*
250 244
 	*/
251
-	private function setSettings()
245
+	public function setSettings()
252 246
 	{
253 247
 		$settings = $this->converterSettings();
254 248
 		$new_settings = array();
... ...
@@ -259,8 +253,13 @@ class tbg_converter
259 253
 			// We are saving then
260 254
 			if (isset($_POST[$key]))
261 255
 			{
262
-				if (isset($details['validate']) && eval($details['validate']) !== true)
263
-					$errors[$key] = $key . ' contains invalid_data';
256
+				if (isset($details['validate']))
257
+				{
258
+					$temp = create_function('$data', $details['validate']);
259
+
260
+					if ($temp($_POST[$key]) === false)
261
+						$errors[$key] = '"' . $details['name'] . '" contains invalid_data';
262
+				}
264 263
 
265 264
 				$new_settings[$key] = $_POST[$key];
266 265
 			}
... ...
@@ -278,7 +277,7 @@ class tbg_converter
278 277
 	/**
279 278
 	 * Set the prefix that will be used prior to every reference of a table
280 279
 	 */
281
-	private function setTBGDatabasePrefix()
280
+	public function setTBGDatabasePrefix()
282 281
 	{
283 282
 		$this->tbg_db_prefix = $this->tbg_db_name . '.' . $this->tbg_db_table_prefix;
284 283
 
... ...
@@ -438,7 +437,7 @@ class mbt_to_tbg extends tbg_converter
438 437
 	/**
439 438
 	 * Set the prefix that will be used prior to every reference of a table
440 439
 	 */
441
-	private function setDatabasePrefix()
440
+	public function setDatabasePrefix()
442 441
 	{
443 442
 		$this->setTBGDatabasePrefix();
444 443
 		$this->mbt_db_prefix = $this->mbt_db_name . '.' . $this->mbt_db_table_prefix;
... ...
@@ -454,7 +453,7 @@ class mbt_to_tbg extends tbg_converter
454 453
 
455 454
 		// As long as we don't overwrite, this should work.
456 455
 		return $settings + array(
457
-			'mantis_loc' => array('name' => 'Mantis Location', 'type' => 'text', 'required' => true, 'validate' => 'return file_exists($data);'),
456
+			'mantis_loc' => array('name' => 'Mantis Location', 'type' => 'text', 'required' => true, 'validate' => 'return file_exists($data) && file_exists($data . \'/config_inc.php\');'),
458 457
 		);
459 458
 	}
460 459
 
... ...
@@ -527,7 +526,7 @@ class mbt_to_tbg extends tbg_converter
527 526
 
528 527
 		// We could let this save up a few inserts then do them at once, but are we really worried about saving queries here?
529 528
 		$i = 0;
530
-		foreach ($this->db->query($sql) as $row)
529
+		foreach ($this->db->query($query) as $row)
531 530
 		{
532 531
 			$password = $this->getRandomString();
533 532
 
... ...
@@ -558,7 +557,7 @@ class mbt_to_tbg extends tbg_converter
558 557
 			LIMIT ' . $substep . ' ' . $step_size;
559 558
 
560 559
 		$i = 0;
561
-		foreach ($this->db->query($sql) as $row)
560
+		foreach ($this->db->query($query) as $row)
562 561
 		{
563 562
 			$this->db->query('
564 563
 				INSERT INTO ' . $this->tbg_db_prefix . 'projects (id, name, locked, description)
... ...
@@ -586,7 +585,7 @@ class mbt_to_tbg extends tbg_converter
586 585
 			LIMIT ' . $substep . ' ' . $step_size;
587 586
 
588 587
 		$i = 0;
589
-		foreach ($this->db->query($sql) as $row)
588
+		foreach ($this->db->query($query) as $row)
590 589
 		{
591 590
 			$this->db->query('
592 591
 				INSERT INTO ' . $this->tbg_db_prefix . 'listtypes (name, itemtype, scope)
... ...
@@ -623,7 +622,7 @@ class mbt_to_tbg extends tbg_converter
623 622
 			LIMIT ' . $substep . ' ' . $step_size;
624 623
 
625 624
 		$i = 0;
626
-		foreach ($this->db->query($sql) as $row)
625
+		foreach ($this->db->query($query) as $row)
627 626
 		{
628 627
 			if (isset($builds[$version]))
629 628
 				continue;
... ...
@@ -655,7 +654,7 @@ class mbt_to_tbg extends tbg_converter
655 654
 				id, name
656 655
 				FROM ' . $this->mbt_db_prefix . 'builds';
657 656
 		$builds = array();
658
-		foreach ($this->db->query($sql) as $row)
657
+		foreach ($this->db->query($query) as $row)
659 658
 			$builds[$row['name']] = $row['id'];
660 659
 
661 660
 		$query = '
... ...
@@ -721,7 +720,7 @@ class mbt_to_tbg extends tbg_converter
721 720
 			LIMIT ' . $substep . ' ' . $step_size;
722 721
 
723 722
 		$i = 0;
724
-		foreach ($this->db->query($sql) as $row)
723
+		foreach ($this->db->query($query) as $row)
725 724
 		{
726 725
 			$this->db->query('
727 726
 				INSERT INTO ' . $this->tbg_db_prefix . 'comments (id, target_id, updated, posted, updated_by, posted_by, content)
... ...
@@ -749,7 +748,7 @@ class mbt_to_tbg extends tbg_converter
749 748
 			LIMIT ' . $substep . ' ' . $step_size;
750 749
 
751 750
 		$i = 0;
752
-		foreach ($this->db->query($sql) as $row)
751
+		foreach ($this->db->query($query) as $row)
753 752
 		{
754 753
 			$this->db->query('
755 754
 				INSERT INTO ' . $this->tbg_db_prefix . 'issuerelations (parent_id, child_id)
... ...
@@ -785,7 +784,7 @@ class mbt_to_tbg extends tbg_converter
785 784
 			LIMIT ' . $substep . ' ' . $step_size;
786 785
 
787 786
 		$i = 0;
788
-		foreach ($this->db->query($sql) as $row)
787
+		foreach ($this->db->query($query) as $row)
789 788
 		{
790 789
 			$this->db->query('
791 790
 				INSERT INTO ' . $this->tbg_db_prefix . 'files (id, uid, scope, real_filename, original_filename, content_type, content, uploaded_at, description)
... ...
@@ -798,7 +797,7 @@ class mbt_to_tbg extends tbg_converter
798 797
 	}
799 798
 
800 799
 	// @ TODO: Duplicate function, merge or remove.
801
-	private function getIssues()
800
+	public function getIssues()
802 801
 	{
803 802
 		// Get the basics - we'll fix it up in a minute.
804 803
 		$this->db->query('
... ...
@@ -869,7 +868,7 @@ class mbt_to_tbg extends tbg_converter
869 868
 	}
870 869
 
871 870
 	// @ TODO: Duplicate function, merge or remove.
872
-	private function getComments()
871
+	public function getComments()
873 872
 	{
874 873
 		$this->db->query('
875 874
 			INSERT INTO ' . $this->tbg_prefix . 'comments
... ...
@@ -883,7 +882,7 @@ class mbt_to_tbg extends tbg_converter
883 882
 	}
884 883
 
885 884
 	// @ TODO: Duplicate function, merge or remove.
886
-	private function getProjects()
885
+	public function getProjects()
887 886
 	{
888 887
 		$this->db->query('
889 888
 			INSERT INTO ' . $this->tbg_prefix . 'projects
... ...
@@ -1236,7 +1235,7 @@ class tbg_converter_wrapper
1236 1235
 	public function showSettings($settings)
1237 1236
 	{
1238 1237
 		echo '
1239
-				<form action="', $_SERVER['PHP_SELF'], '" method="post">
1238
+				<form action="', $_SERVER['PHP_SELF'], '?step=1" method="post">
1240 1239
 					<dl>';
1241 1240
 
1242 1241
 		foreach ($settings as $key => $data)
... ...
@@ -1261,7 +1260,7 @@ class tbg_converter_wrapper
1261 1260
 			elseif ($data['type'] == 'password')
1262 1261
 				echo '<input type="password" name="', $key, '" />';
1263 1262
 			else
1264
-				echo '<input type="text" name="', $key, '"', isset($data['default']) ? ' value="' . $data['default'] . '"' : '', ' />';
1263
+				echo '<input type="text" name="', $key, '"', isset($data['default']) ? ' value="' . $data['default'] . '"' : (isset($_POST[$key]) ? $_POST[$key] : ''), ' />';
1265 1264
 
1266 1265
 			echo '</dd>';
1267 1266
 		}
1268 1267