Index: trunk/phase3/maintenance/storage/trackBlobs.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | function run() { |
| 39 | + $this->checkIntegrity(); |
39 | 40 | $this->initTrackingTable(); |
40 | 41 | $this->trackRevisions(); |
41 | 42 | $this->trackOrphanText(); |
— | — | @@ -43,6 +44,47 @@ |
44 | 45 | } |
45 | 46 | } |
46 | 47 | |
| 48 | + function checkIntegrity() { |
| 49 | + echo "Doing integrity check...\n"; |
| 50 | + $dbr = wfGetDB( DB_SLAVE ); |
| 51 | + |
| 52 | + // Scan for HistoryBlobStub objects in the text table (bug 20757) |
| 53 | + |
| 54 | + $exists = $dbr->selectField( 'text', 1, |
| 55 | + 'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\' ' . |
| 56 | + 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'', |
| 57 | + __METHOD__ |
| 58 | + ); |
| 59 | + |
| 60 | + if ( $exists ) { |
| 61 | + echo "Integrity check failed: found HistoryBlobStub objects in your text table.\n". |
| 62 | + "This script could destroy these objects if it continued. Run resolveStubs.php\n" . |
| 63 | + "to fix this.\n"; |
| 64 | + exit( 1 ); |
| 65 | + } |
| 66 | + |
| 67 | + // Scan the archive table for HistoryBlobStub objects or external flags (bug 22624) |
| 68 | + $flags = $dbr->selectField( 'archive', 'ar_flags', |
| 69 | + 'ar_flags LIKE \'%external%\' OR (' . |
| 70 | + 'ar_flags LIKE \'%object%\' ' . |
| 71 | + 'AND LOWER(CONVERT(LEFT(ar_text,22) USING latin1)) = \'o:15:"historyblobstub"\' )', |
| 72 | + __METHOD__ |
| 73 | + ); |
| 74 | + |
| 75 | + if ( strpos( $flags, 'external' ) !== false ) { |
| 76 | + echo "Integrity check failed: found external storage pointers in your archive table.\n" . |
| 77 | + "Run normaliseArchiveTable.php to fix this.\n"; |
| 78 | + exit( 1 ); |
| 79 | + } elseif ( $flags ) { |
| 80 | + echo "Integrity check failed: found HistoryBlobStub objects in your archive table.\n" . |
| 81 | + "These objects are probably already broken, continuing would make them\n" . |
| 82 | + "unrecoverable. Run \"normaliseArchiveTable.php --fix-cgz-bug\" to fix this.\n"; |
| 83 | + exit( 1 ); |
| 84 | + } |
| 85 | + |
| 86 | + echo "Integrity check OK\n"; |
| 87 | + } |
| 88 | + |
47 | 89 | function initTrackingTable() { |
48 | 90 | $dbw = wfGetDB( DB_MASTER ); |
49 | 91 | if ( $dbw->tableExists( 'blob_tracking' ) ) { |