Index: trunk/phase3/maintenance/populateRevisionLength.php |
— | — | @@ -26,7 +26,6 @@ |
27 | 27 | public function __construct() { |
28 | 28 | parent::__construct(); |
29 | 29 | $this->mDescription = "Populates the rev_len field"; |
30 | | - $this->setBatchSize( 200 ); |
31 | 30 | } |
32 | 31 | |
33 | 32 | protected function getUpdateKey() { |
— | — | @@ -37,10 +36,6 @@ |
38 | 37 | return 'rev_len column of revision table already populated.'; |
39 | 38 | } |
40 | 39 | |
41 | | - protected function updatelogFailedMessage() { |
42 | | - return 'Could not insert rev_len population row.'; |
43 | | - } |
44 | | - |
45 | 40 | public function doDBUpdates() { |
46 | 41 | $db = $this->getDB( DB_MASTER ); |
47 | 42 | if ( !$db->tableExists( 'revision' ) ) { |
Index: trunk/phase3/maintenance/populateParentId.php |
— | — | @@ -24,28 +24,32 @@ |
25 | 25 | |
26 | 26 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
27 | 27 | |
28 | | -class PopulateParentId extends Maintenance { |
| 28 | +class PopulateParentId extends LoggedUpdateMaintenance { |
29 | 29 | public function __construct() { |
30 | 30 | parent::__construct(); |
31 | 31 | $this->mDescription = "Populates rev_parent_id"; |
32 | | - $this->setBatchSize( 200 ); |
33 | 32 | } |
34 | 33 | |
35 | | - public function execute() { |
| 34 | + protected function getUpdateKey() { |
| 35 | + return 'populate rev_parent_id'; |
| 36 | + } |
| 37 | + |
| 38 | + protected function updateSkippedMessage() { |
| 39 | + return 'rev_parent_id column of revision table already populated.'; |
| 40 | + } |
| 41 | + |
| 42 | + protected function doDBUpdates() { |
36 | 43 | $db = wfGetDB( DB_MASTER ); |
37 | 44 | if ( !$db->tableExists( 'revision' ) ) { |
38 | | - $this->error( "revision table does not exist", true ); |
| 45 | + $this->error( "revision table does not exist" ); |
| 46 | + return false; |
39 | 47 | } |
40 | 48 | $this->output( "Populating rev_parent_id column\n" ); |
41 | 49 | $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ ); |
42 | 50 | $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ ); |
43 | 51 | if ( is_null( $start ) || is_null( $end ) ) { |
44 | | - $this->output( "...revision table seems to be empty.\n" ); |
45 | | - $db->insert( 'updatelog', |
46 | | - array( 'ul_key' => 'populate rev_parent_id' ), |
47 | | - __METHOD__, |
48 | | - 'IGNORE' ); |
49 | | - return; |
| 52 | + $this->output( "...revision table seems to be empty, nothing to do.\n" ); |
| 53 | + return true; |
50 | 54 | } |
51 | 55 | # Do remaining chunk |
52 | 56 | $blockStart = intval( $start ); |
— | — | @@ -100,17 +104,8 @@ |
101 | 105 | $blockEnd += $this->mBatchSize; |
102 | 106 | wfWaitForSlaves(); |
103 | 107 | } |
104 | | - $logged = $db->insert( 'updatelog', |
105 | | - array( 'ul_key' => 'populate rev_parent_id' ), |
106 | | - __METHOD__, |
107 | | - 'IGNORE' ); |
108 | | - if ( $logged ) { |
109 | | - $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" ); |
110 | | - return true; |
111 | | - } else { |
112 | | - $this->output( "Could not insert rev_parent_id population row.\n" ); |
113 | | - return false; |
114 | | - } |
| 108 | + $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" ); |
| 109 | + return true; |
115 | 110 | } |
116 | 111 | } |
117 | 112 | |
Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -1224,6 +1224,9 @@ |
1225 | 1225 | } |
1226 | 1226 | } |
1227 | 1227 | |
| 1228 | +/** |
| 1229 | + * Fake maintenance wrapper, mostly used for the web installer/updater |
| 1230 | + */ |
1228 | 1231 | class FakeMaintenance extends Maintenance { |
1229 | 1232 | protected $mSelf = "FakeMaintenanceScript"; |
1230 | 1233 | public function execute() { |
— | — | @@ -1231,10 +1234,15 @@ |
1232 | 1235 | } |
1233 | 1236 | } |
1234 | 1237 | |
| 1238 | +/** |
| 1239 | + * Class for scripts that perform database maintenance and want to log the |
| 1240 | + * update in `updatelog` so we can later skip it |
| 1241 | + */ |
1235 | 1242 | abstract class LoggedUpdateMaintenance extends Maintenance { |
1236 | 1243 | public function __construct() { |
1237 | 1244 | parent::__construct(); |
1238 | 1245 | $this->addOption( 'force', 'Run the update even if it was completed already' ); |
| 1246 | + $this->setBatchSize( 200 ); |
1239 | 1247 | } |
1240 | 1248 | |
1241 | 1249 | public function execute() { |
— | — | @@ -1244,7 +1252,7 @@ |
1245 | 1253 | if ( !$this->hasOption( 'force' ) && |
1246 | 1254 | $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) ) |
1247 | 1255 | { |
1248 | | - $this->output( $this->updateSkippedMessage() . "\n" ); |
| 1256 | + $this->output( "..." . $this->updateSkippedMessage() . "\n" ); |
1249 | 1257 | return true; |
1250 | 1258 | } |
1251 | 1259 | |
— | — | @@ -1263,6 +1271,15 @@ |
1264 | 1272 | } |
1265 | 1273 | |
1266 | 1274 | /** |
| 1275 | + * Message to show the the update log was unable to log the completion of this update |
| 1276 | + * @return String |
| 1277 | + */ |
| 1278 | + protected function updatelogFailedMessage() { |
| 1279 | + $key = $this->getUpdateKey(); |
| 1280 | + return "Unable to log update '{$key}' as completed."; |
| 1281 | + } |
| 1282 | + |
| 1283 | + /** |
1267 | 1284 | * Do the actual work. All child classes will need to implement this. |
1268 | 1285 | * Return true to log the update as done or false (usually on failure). |
1269 | 1286 | * @return Bool |
— | — | @@ -1280,10 +1297,4 @@ |
1281 | 1298 | * @return String |
1282 | 1299 | */ |
1283 | 1300 | abstract protected function updateSkippedMessage(); |
1284 | | - |
1285 | | - /** |
1286 | | - * Message to show the the update log was unable to log the completion of this update |
1287 | | - * @return String |
1288 | | - */ |
1289 | | - abstract protected function updatelogFailedMessage(); |
1290 | 1301 | } |
Index: trunk/phase3/maintenance/populateLogUsertext.php |
— | — | @@ -25,14 +25,22 @@ |
26 | 26 | |
27 | 27 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
28 | 28 | |
29 | | -class PopulateLogUsertext extends Maintenance { |
| 29 | +class PopulateLogUsertext extends LoggedUpdateMaintenance { |
30 | 30 | public function __construct() { |
31 | 31 | parent::__construct(); |
32 | | - $this->mDescription = "Populates the log_user_text"; |
| 32 | + $this->mDescription = "Populates the log_user_text field"; |
33 | 33 | $this->setBatchSize( 100 ); |
34 | 34 | } |
35 | 35 | |
36 | | - public function execute() { |
| 36 | + protected function getUpdateKey() { |
| 37 | + return 'populate log_usertext'; |
| 38 | + } |
| 39 | + |
| 40 | + protected function updateSkippedMessage() { |
| 41 | + return 'log_user_text column of logging table already populated.'; |
| 42 | + } |
| 43 | + |
| 44 | + protected function doDBUpdates() { |
37 | 45 | $db = $this->getDB( DB_MASTER ); |
38 | 46 | $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ ); |
39 | 47 | if ( !$start ) { |
— | — | @@ -61,19 +69,8 @@ |
62 | 70 | $blockEnd += $this->mBatchSize; |
63 | 71 | wfWaitForSlaves(); |
64 | 72 | } |
65 | | - if ( $db->insert( |
66 | | - 'updatelog', |
67 | | - array( 'ul_key' => 'populate log_usertext' ), |
68 | | - __METHOD__, |
69 | | - 'IGNORE' |
70 | | - ) |
71 | | - ) { |
72 | | - $this->output( "log_usertext population complete.\n" ); |
73 | | - return true; |
74 | | - } else { |
75 | | - $this->output( "Could not insert log_usertext population row.\n" ); |
76 | | - return false; |
77 | | - } |
| 73 | + $this->output( "Done populating log_user_text field.\n" ); |
| 74 | + return true; |
78 | 75 | } |
79 | 76 | } |
80 | 77 | |
Index: trunk/phase3/maintenance/populateImageSha1.php |
— | — | @@ -29,7 +29,6 @@ |
30 | 30 | $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" . |
31 | 31 | "\t\tdefault uses Database class", false, true ); |
32 | 32 | $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true ); |
33 | | - $this->setBatchSize( 200 ); |
34 | 33 | } |
35 | 34 | |
36 | 35 | protected function getUpdateKey() { |
— | — | @@ -40,10 +39,6 @@ |
41 | 40 | return 'img_sha1 column of image table already populated.'; |
42 | 41 | } |
43 | 42 | |
44 | | - protected function updatelogFailedMessage() { |
45 | | - return 'Could not insert img_sha1 population row.'; |
46 | | - } |
47 | | - |
48 | 43 | public function doDBUpdates() { |
49 | 44 | $method = $this->getOption( 'method', 'normal' ); |
50 | 45 | $file = $this->getOption( 'file' ); |
Index: trunk/phase3/maintenance/populateLogSearch.php |
— | — | @@ -23,21 +23,28 @@ |
24 | 24 | |
25 | 25 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
26 | 26 | |
27 | | -class PopulateLogSearch extends Maintenance { |
28 | | - |
29 | | - const LOG_SEARCH_BATCH_SIZE = 100; |
30 | | - |
| 27 | +class PopulateLogSearch extends LoggedUpdateMaintenance { |
31 | 28 | static $tableMap = array( 'rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive' ); |
32 | 29 | |
33 | 30 | public function __construct() { |
34 | 31 | parent::__construct(); |
35 | 32 | $this->mDescription = "Migrate log params to new table and index for searching"; |
| 33 | + $this->setBatchSize( 100 ); |
36 | 34 | } |
37 | 35 | |
38 | | - public function execute() { |
| 36 | + protected function getUpdateKey() { |
| 37 | + return 'populate log_search'; |
| 38 | + } |
| 39 | + |
| 40 | + protected function updateSkippedMessage() { |
| 41 | + return 'log_search table already populated.'; |
| 42 | + } |
| 43 | + |
| 44 | + protected function doDBUpdates() { |
39 | 45 | $db = $this->getDB( DB_MASTER ); |
40 | 46 | if ( !$db->tableExists( 'log_search' ) ) { |
41 | | - $this->error( "log_search does not exist", true ); |
| 47 | + $this->error( "log_search does not exist" ); |
| 48 | + return false; |
42 | 49 | } |
43 | 50 | $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ ); |
44 | 51 | if ( !$start ) { |
— | — | @@ -47,9 +54,9 @@ |
48 | 55 | $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ ); |
49 | 56 | |
50 | 57 | # Do remaining chunk |
51 | | - $end += self::LOG_SEARCH_BATCH_SIZE - 1; |
| 58 | + $end += $this->mBatchSize - 1; |
52 | 59 | $blockStart = $start; |
53 | | - $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1; |
| 60 | + $blockEnd = $start + $this->mBatchSize - 1; |
54 | 61 | |
55 | 62 | $delTypes = array( 'delete', 'suppress' ); // revisiondelete types |
56 | 63 | while ( $blockEnd <= $end ) { |
— | — | @@ -128,23 +135,12 @@ |
129 | 136 | $log->addRelations( 'target_author_ip', $userIPs, $row->log_id ); |
130 | 137 | } |
131 | 138 | } |
132 | | - $blockStart += self::LOG_SEARCH_BATCH_SIZE; |
133 | | - $blockEnd += self::LOG_SEARCH_BATCH_SIZE; |
| 139 | + $blockStart += $this->mBatchSize; |
| 140 | + $blockEnd += $this->mBatchSize; |
134 | 141 | wfWaitForSlaves(); |
135 | 142 | } |
136 | | - if ( $db->insert( |
137 | | - 'updatelog', |
138 | | - array( 'ul_key' => 'populate log_search' ), |
139 | | - __FUNCTION__, |
140 | | - 'IGNORE' |
141 | | - ) |
142 | | - ) { |
143 | | - $this->output( "log_search population complete.\n" ); |
144 | | - return true; |
145 | | - } else { |
146 | | - $this->output( "Could not insert log_search population row.\n" ); |
147 | | - return false; |
148 | | - } |
| 143 | + $this->output( "Done populating log_search table.\n" ); |
| 144 | + return true; |
149 | 145 | } |
150 | 146 | } |
151 | 147 | |
Index: trunk/phase3/includes/installer/DatabaseUpdater.php |
— | — | @@ -519,33 +519,25 @@ |
520 | 520 | } |
521 | 521 | |
522 | 522 | protected function doLogUsertextPopulation() { |
523 | | - if ( $this->updateRowExists( 'populate log_usertext' ) ) { |
524 | | - $this->output( "...log_user_text field already populated.\n" ); |
525 | | - return; |
526 | | - } |
527 | | - |
528 | | - $this->output( |
| 523 | + if ( !$this->updateRowExists( 'populate log_usertext' ) ) { |
| 524 | + $this->output( |
529 | 525 | "Populating log_user_text field, printing progress markers. For large\n" . |
530 | 526 | "databases, you may want to hit Ctrl-C and do this manually with\n" . |
531 | 527 | "maintenance/populateLogUsertext.php.\n" ); |
| 528 | + } |
532 | 529 | $task = $this->maintenance->runChild( 'PopulateLogUsertext' ); |
533 | 530 | $task->execute(); |
534 | | - $this->output( "Done populating log_user_text field.\n" ); |
535 | 531 | } |
536 | 532 | |
537 | 533 | protected function doLogSearchPopulation() { |
538 | | - if ( $this->updateRowExists( 'populate log_search' ) ) { |
539 | | - $this->output( "...log_search table already populated.\n" ); |
540 | | - return; |
| 534 | + if ( !$this->updateRowExists( 'populate log_search' ) ) { |
| 535 | + $this->output( |
| 536 | + "Populating log_search table, printing progress markers. For large\n" . |
| 537 | + "databases, you may want to hit Ctrl-C and do this manually with\n" . |
| 538 | + "maintenance/populateLogSearch.php.\n" ); |
541 | 539 | } |
542 | | - |
543 | | - $this->output( |
544 | | - "Populating log_search table, printing progress markers. For large\n" . |
545 | | - "databases, you may want to hit Ctrl-C and do this manually with\n" . |
546 | | - "maintenance/populateLogSearch.php.\n" ); |
547 | 540 | $task = $this->maintenance->runChild( 'PopulateLogSearch' ); |
548 | 541 | $task->execute(); |
549 | | - $this->output( "Done populating log_search table.\n" ); |
550 | 542 | } |
551 | 543 | |
552 | 544 | protected function doUpdateTranscacheField() { |
Index: trunk/phase3/includes/installer/MysqlUpdater.php |
— | — | @@ -747,11 +747,12 @@ |
748 | 748 | } |
749 | 749 | |
750 | 750 | protected function doPopulateParentId() { |
751 | | - if ( $this->updateRowExists( 'populate rev_parent_id' ) ) { |
752 | | - $this->output( "...rev_parent_id column already populated.\n" ); |
753 | | - return; |
| 751 | + if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) { |
| 752 | + $this->output( |
| 753 | + "Populating rev_parent_id fields, printing progress markers. For large\n" . |
| 754 | + "databases, you may want to hit Ctrl-C and do this manually with\n" . |
| 755 | + "maintenance/populateParentId.php.\n" ); |
754 | 756 | } |
755 | | - |
756 | 757 | $task = $this->maintenance->runChild( 'PopulateParentId' ); |
757 | 758 | $task->execute(); |
758 | 759 | } |