Jeremy D commited on 2011-11-07 12:28:53
Showing 1 changed files, with 50 additions and 73 deletions.
... | ... |
@@ -98,6 +98,9 @@ class tbg_converter |
98 | 98 |
// Open a new theme. |
99 | 99 |
$theme = new tbg_converter_wrapper($this->steps, array($this->main_credits, $this->credits)); |
100 | 100 |
|
101 |
+ if ($this->is_cli); |
|
102 |
+ ob_end_clean(); |
|
103 |
+ |
|
101 | 104 |
// We can't process anymore until this exists. |
102 | 105 |
if (empty($this->db_user)) |
103 | 106 |
$this->converterSetup(); |
... | ... |
@@ -113,6 +116,8 @@ class tbg_converter |
113 | 116 |
{ |
114 | 117 |
$this->is_cli = true; |
115 | 118 |
|
119 |
+ print ("Checking Settings: "); |
|
120 |
+ |
|
116 | 121 |
// First off, clean the buffers and buy us some time. |
117 | 122 |
@ob_end_clean(); |
118 | 123 |
ob_implicit_flush(true); |
... | ... |
@@ -183,15 +188,22 @@ class tbg_converter |
183 | 188 |
{ |
184 | 189 |
$data = $this->steps[$this->step]; |
185 | 190 |
|
186 |
- $this->updateSubStep($this->substep); |
|
187 |
- $this->updateStep($data[1]); |
|
191 |
+ // Update some step info. |
|
188 | 192 |
$this->step_size = $data[2]; |
189 | 193 |
|
190 |
- $count = $this->$data[1](); |
|
194 |
+ // This actually runs the process. |
|
195 |
+ $count = $this->$data[1]($this->step_size, $this->substep); |
|
196 |
+ |
|
197 |
+ // We are on the next step. |
|
198 |
+ if ($count < $this->step_size) |
|
199 |
+ $this->updateStep($data[1]); |
|
200 |
+ else |
|
201 |
+ // Update the current step. |
|
202 |
+ $this->updateSubStep($this->substep + $this->step_size); |
|
191 | 203 |
|
192 |
- $this->checkTimeout($data[1], $this->substep, $data[2], $count); |
|
204 |
+ $this->checkTimeout($data[1], $this->substep, $this->step_size, $count); |
|
193 | 205 |
} |
194 |
- while ($this->step < count($this->steps) + 1); |
|
206 |
+ while ($this->step < count($this->steps)); |
|
195 | 207 |
} |
196 | 208 |
|
197 | 209 |
/** |
... | ... |
@@ -392,6 +404,10 @@ class tbg_converter |
392 | 404 |
{ |
393 | 405 |
$step = str_replace('doStep', '', $step) + 1; |
394 | 406 |
|
407 |
+ // Don't do this if we changed nothing. |
|
408 |
+ if ($step == $this->step) |
|
409 |
+ return; |
|
410 |
+ |
|
395 | 411 |
$_GET['step'] = (int) $step; |
396 | 412 |
|
397 | 413 |
$this->step = (int) $step; |
... | ... |
@@ -399,18 +415,22 @@ class tbg_converter |
399 | 415 |
// Reset. |
400 | 416 |
$this->updateSubStep(0); |
401 | 417 |
|
418 |
+ // Let the CLI know. |
|
419 |
+ if ($this->is_cli) |
|
420 |
+ { |
|
421 |
+ print ("Done!"); |
|
422 |
+ |
|
423 |
+ // Hold on, We are done! |
|
424 |
+ if ($this->step < count($this->steps)) |
|
425 |
+ print ("\nStep: " . $this->step . ") ". $this->steps[$this->step][0] . ' '); |
|
426 |
+ else |
|
427 |
+ exit ("\n\n"); |
|
428 |
+ |
|
402 | 429 |
return true; |
403 | 430 |
} |
404 | 431 |
|
405 |
- /** |
|
406 |
- * |
|
407 |
- * Gets the current substep |
|
408 |
- * |
|
409 |
- * @param string $step The current function we are on. |
|
410 |
- */ |
|
411 |
- function getSubStep($step) |
|
412 |
- { |
|
413 |
- return $this->substep; |
|
432 |
+ |
|
433 |
+ return true; |
|
414 | 434 |
} |
415 | 435 |
|
416 | 436 |
/** |
... | ... |
@@ -423,8 +443,6 @@ class tbg_converter |
423 | 443 |
{ |
424 | 444 |
$_GET['substep'] = (int) $substep; |
425 | 445 |
$this->substep = (int) $substep; |
426 |
- |
|
427 |
- return true; |
|
428 | 446 |
} |
429 | 447 |
|
430 | 448 |
/** |
... | ... |
@@ -437,8 +455,6 @@ class tbg_converter |
437 | 455 |
{ |
438 | 456 |
global $theme; |
439 | 457 |
|
440 |
- $this->updateSubStep($substep + $max_step_size); |
|
441 |
- |
|
442 | 458 |
// Hold on, we had less results than we should have. |
443 | 459 |
if ($max_step_size > $count) |
444 | 460 |
$this->updateStep($function); |
... | ... |
@@ -446,9 +462,8 @@ class tbg_converter |
446 | 462 |
// CLI conversions can just continue. |
447 | 463 |
if ($this->is_cli) |
448 | 464 |
{ |
449 |
- if (time() - $this->start_time > 1) |
|
450 |
- print (".\r"); |
|
451 |
- $this->$function(); |
|
465 |
+ print ("."); |
|
466 |
+ return true; |
|
452 | 467 |
} |
453 | 468 |
|
454 | 469 |
// Try to buy us more time. |
... | ... |
@@ -458,7 +473,7 @@ class tbg_converter |
458 | 473 |
|
459 | 474 |
// if we can pass go, collect $200. |
460 | 475 |
if (time() - $this->start_time < 10) |
461 |
- $this->$function(); |
|
476 |
+ return true; |
|
462 | 477 |
|
463 | 478 |
// @ TODO: Add in timeout stuff here. |
464 | 479 |
// @ !!! If this is all done via ajax, it should be a json or xml return. |
... | ... |
@@ -496,9 +511,10 @@ class mbt_to_tbg extends tbg_converter |
496 | 511 |
// What steps shall we take. |
497 | 512 |
protected $steps = array( |
498 | 513 |
// Key => array('Descriptive', 'functionName', (int) step_size), |
514 |
+ 0 => array('Checking Settings', false, -1), |
|
499 | 515 |
1 => array('Users', 'doStep1', 500), |
500 | 516 |
array('Projects', 'doStep2', 500), |
501 |
- array('Project Permissions', 'doStep3', 1), |
|
517 |
+ array('Project Permissions', 'doStep3', 999), |
|
502 | 518 |
array('Categories', 'doStep4', 500), |
503 | 519 |
array('Versions', 'doStep5', 500), |
504 | 520 |
array('Issues', 'doStep6', 500), |
... | ... |
@@ -609,7 +625,7 @@ class mbt_to_tbg extends tbg_converter |
609 | 625 |
* @Should it empty the tables prior to conversion or just dump over? |
610 | 626 |
* @Should we do this in each step? |
611 | 627 |
*/ |
612 |
- function doStep0() |
|
628 |
+ function doStep0($step_size, $substep) |
|
613 | 629 |
{ |
614 | 630 |
} |
615 | 631 |
|
... | ... |
@@ -617,11 +633,8 @@ class mbt_to_tbg extends tbg_converter |
617 | 633 |
* Convert users. |
618 | 634 |
* |
619 | 635 |
*/ |
620 |
- function doStep1() |
|
636 |
+ function doStep1($step_size, $substep) |
|
621 | 637 |
{ |
622 |
- $step_size = 500; |
|
623 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
624 |
- |
|
625 | 638 |
$query = ' |
626 | 639 |
SELECT |
627 | 640 |
id, username, username AS buddyname, realname, email, password, |
... | ... |
@@ -651,11 +664,8 @@ class mbt_to_tbg extends tbg_converter |
651 | 664 |
* Convert Projects. |
652 | 665 |
* |
653 | 666 |
*/ |
654 |
- function doStep2() |
|
667 |
+ function doStep2($step_size, $substep) |
|
655 | 668 |
{ |
656 |
- $step_size = 500; |
|
657 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
658 |
- |
|
659 | 669 |
$query = ' |
660 | 670 |
SELECT |
661 | 671 |
id, name, description, |
... | ... |
@@ -686,7 +696,7 @@ class mbt_to_tbg extends tbg_converter |
686 | 696 |
* Add in default permissions. |
687 | 697 |
* |
688 | 698 |
*/ |
689 |
- function doStep3() |
|
699 |
+ function doStep3($step_size, $substep) |
|
690 | 700 |
{ |
691 | 701 |
// Clean up the projects permissions index. |
692 | 702 |
$query = ' |
... | ... |
@@ -731,18 +741,15 @@ class mbt_to_tbg extends tbg_converter |
731 | 741 |
AND itemtype = "category"'); |
732 | 742 |
|
733 | 743 |
// We are done. |
734 |
- return 2; |
|
744 |
+ return 1; |
|
735 | 745 |
} |
736 | 746 |
|
737 | 747 |
/** |
738 | 748 |
* Convert Categories. |
739 | 749 |
* WARNING: RUNNING THIS MULTIPLE TIMES MAY CAUSE DUPLICATE ENTRIES. |
740 | 750 |
*/ |
741 |
- function doStep4() |
|
751 |
+ function doStep4($step_size, $substep) |
|
742 | 752 |
{ |
743 |
- $step_size = 500; |
|
744 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
745 |
- |
|
746 | 753 |
$query = ' |
747 | 754 |
SELECT |
748 | 755 |
name |
... | ... |
@@ -770,11 +777,8 @@ class mbt_to_tbg extends tbg_converter |
770 | 777 |
* Convert Versions. |
771 | 778 |
* |
772 | 779 |
*/ |
773 |
- function doStep5() |
|
780 |
+ function doStep5($step_size, $substep) |
|
774 | 781 |
{ |
775 |
- $step_size = 500; |
|
776 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
777 |
- |
|
778 | 782 |
// Obtain any current builds. |
779 | 783 |
$query = ' |
780 | 784 |
SELECT |
... | ... |
@@ -812,11 +816,8 @@ class mbt_to_tbg extends tbg_converter |
812 | 816 |
* Normally we want to fix them, but in this case we want to convert bugs. |
813 | 817 |
* |
814 | 818 |
*/ |
815 |
- function doStep6() |
|
819 |
+ function doStep6($step_size, $substep) |
|
816 | 820 |
{ |
817 |
- $step_size = 500; |
|
818 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
819 |
- |
|
820 | 821 |
// Obtain any current builds. |
821 | 822 |
$query = ' |
822 | 823 |
SELECT |
... | ... |
@@ -882,11 +883,8 @@ class mbt_to_tbg extends tbg_converter |
882 | 883 |
* Bug Notes. |
883 | 884 |
* |
884 | 885 |
*/ |
885 |
- function doStep7() |
|
886 |
+ function doStep7($step_size, $substep) |
|
886 | 887 |
{ |
887 |
- $step_size = 500; |
|
888 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
889 |
- |
|
890 | 888 |
$query = ' |
891 | 889 |
SELECT |
892 | 890 |
bn.id, bn.bug_id AS target_id, bn.last_modified AS updated, bn.date_submitted AS posted, |
... | ... |
@@ -895,16 +893,9 @@ class mbt_to_tbg extends tbg_converter |
895 | 893 |
INNER JOIN ' . $this->mbt_db_prefix . 'bugnote_text_table AS bnt ON (bn.bugnote_text_id = bnt.id) |
896 | 894 |
LIMIT ' . $step_size . ' OFFSET ' . $substep; |
897 | 895 |
|
898 |
-// The converter doesn't seem to go past 1k comments. WHY! |
|
899 |
-var_dump($substep); echo "\n"; |
|
900 |
- |
|
901 | 896 |
$i = 0; |
902 | 897 |
foreach ($this->mantis_db->query($query) as $row) |
903 | 898 |
{ |
904 |
-// A random comment we are looking for. Just contains "*bump*". |
|
905 |
-if ($row['id'] == 2433) |
|
906 |
- var_dump($row); |
|
907 |
- |
|
908 | 899 |
$row['content'] = $this->tbg_db->quote($row['content']); |
909 | 900 |
|
910 | 901 |
|
... | ... |
@@ -912,11 +903,6 @@ if ($row['id'] == 2433) |
912 | 903 |
REPLACE INTO ' . $this->tbg_db_prefix . 'comments (id, target_id, target_type, content, posted, updated, updated_by, posted_by) |
913 | 904 |
VALUES (' . $row['id'] . ', ' . $row['target_id'] . ', 1, "' . $row['content'] . '", ' . $row['posted'] . ', ' . $row['updated'] . ', ' . $row['updated_by'] . ', ' . $row['posted_by'] . ')'); |
914 | 905 |
++$i; |
915 |
- |
|
916 |
-// Only trying to error if we got one. |
|
917 |
-if ($this->tbg_db->errorCode() != '00000') |
|
918 |
- exit(var_dump($this->tbg_db->errorInfo())); |
|
919 |
- |
|
920 | 906 |
} |
921 | 907 |
|
922 | 908 |
return $i; |
... | ... |
@@ -926,14 +912,8 @@ if ($this->tbg_db->errorCode() != '00000') |
926 | 912 |
* Relationships are great. |
927 | 913 |
* |
928 | 914 |
*/ |
929 |
- function doStep8() |
|
915 |
+ function doStep8($step_size, $substep) |
|
930 | 916 |
{ |
931 |
-// @ TODO REMOVE :P |
|
932 |
-exit('got done'); |
|
933 |
- |
|
934 |
- $step_size = 500; |
|
935 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
936 |
- |
|
937 | 917 |
$query = ' |
938 | 918 |
SELECT |
939 | 919 |
source_bug_id AS parent_id, destination_bug_id AS child_id |
... | ... |
@@ -957,11 +937,8 @@ exit('got done'); |
957 | 937 |
* Attachments, the pain of our every existence) |
958 | 938 |
* |
959 | 939 |
*/ |
960 |
- function doStep9() |
|
940 |
+ function doStep9($step_size, $substep) |
|
961 | 941 |
{ |
962 |
- $step_size = 100; |
|
963 |
- $substep = $this->getSubStep(__FUNCTION__); |
|
964 |
- |
|
965 | 942 |
// @TODO: GET THE ATTACHMENT LOCATION |
966 | 943 |
/* |
967 | 944 |
// TGB appears to allow storage of files in the database. The source code appears to work it out properly whether it is in the database or local storage. |
968 | 945 |