Index: branches/maintenance-work/maintenance/deleteArchivedFiles.inc |
— | — | @@ -1,56 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Support functions for the deleteArchivedFiles script |
6 | | - * |
7 | | - * @file |
8 | | - * @ingroup Maintenance |
9 | | - * @author Aaron Schulz |
10 | | - */ |
11 | | - |
12 | | -require_once( "$IP/includes/FileStore.php" ); |
13 | | -require_once( "$IP/includes/filerepo/File.php" ); |
14 | | - |
15 | | -function DeleteArchivedFiles( $delete = false ) { |
16 | | - |
17 | | - # Data should come off the master, wrapped in a transaction |
18 | | - $dbw = wfGetDB( DB_MASTER ); |
19 | | - |
20 | | - $transaction = new FSTransaction(); |
21 | | - if( !FileStore::lock() ) { |
22 | | - wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" ); |
23 | | - return false; |
24 | | - } |
25 | | - |
26 | | - $tbl_arch = $dbw->tableName( 'filearchive' ); |
27 | | - |
28 | | - # Get "active" revisions from the filearchive table |
29 | | - echo( "Searching for and deleting archived files...\n" ); |
30 | | - $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" ); |
31 | | - while( $row = $dbw->fetchObject( $res ) ) { |
32 | | - $key = $row->fa_storage_key; |
33 | | - $group = $row->fa_storage_group; |
34 | | - $id = $row->fa_id; |
35 | | - |
36 | | - $store = FileStore::get( $group ); |
37 | | - if( $store ) { |
38 | | - $path = $store->filePath( $key ); |
39 | | - $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); |
40 | | - $inuse = $dbw->selectField( 'oldimage', '1', |
41 | | - array( 'oi_sha1' => $sha1, |
42 | | - 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ), |
43 | | - __METHOD__, array( 'FOR UPDATE' ) ); |
44 | | - if ( $path && file_exists($path) && !$inuse ) { |
45 | | - $transaction->addCommit( FSTransaction::DELETE_FILE, $path ); |
46 | | - $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); |
47 | | - } else { |
48 | | - echo( "Notice - file '$key' not found in group '$group'\n" ); |
49 | | - } |
50 | | - } else { |
51 | | - echo( "Notice - invalid file storage group '$group' for file '$key'\n" ); |
52 | | - } |
53 | | - } |
54 | | - echo( "done.\n" ); |
55 | | - |
56 | | - $transaction->commit(); |
57 | | -} |
Index: branches/maintenance-work/maintenance/dumpSisterSites.php |
— | — | @@ -25,25 +25,33 @@ |
26 | 26 | * @ingroup SpecialPage |
27 | 27 | */ |
28 | 28 | |
29 | | -require_once( 'commandLine.inc' ); |
| 29 | +require_once( "Maintenance.php" ); |
30 | 30 | |
31 | | -$dbr = wfGetDB( DB_SLAVE ); |
32 | | -$dbr->bufferResults( false ); |
33 | | -$result = $dbr->select( 'page', |
34 | | - array( 'page_namespace', 'page_title' ), |
35 | | - array( |
36 | | - 'page_namespace' => NS_MAIN, |
37 | | - 'page_is_redirect' => 0, |
38 | | - ), |
39 | | - 'dumpSisterSites' ); |
| 31 | +class DumpSisterSites extends Maintenance { |
| 32 | + public function __construct() { |
| 33 | + parent::__construct(); |
| 34 | + $this->mDescription = "Quickie page name dump script for SisterSites usage"; |
| 35 | + } |
| 36 | + |
| 37 | + public function execute() { |
| 38 | + $dbr = wfGetDB( DB_SLAVE ); |
| 39 | + $dbr->bufferResults( false ); |
| 40 | + $result = $dbr->select( 'page', |
| 41 | + array( 'page_namespace', 'page_title' ), |
| 42 | + array( 'page_namespace' => NS_MAIN, |
| 43 | + 'page_is_redirect' => 0, |
| 44 | + ), |
| 45 | + __METHOD__ ); |
40 | 46 | |
41 | | -while( $row = $dbr->fetchObject( $result ) ) { |
42 | | - $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
43 | | - $url = $title->getFullUrl(); |
44 | | - $text = $title->getPrefixedText(); |
45 | | - echo "$url $text\n"; |
| 47 | + while( $row = $dbr->fetchObject( $result ) ) { |
| 48 | + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 49 | + $url = $title->getFullUrl(); |
| 50 | + $text = $title->getPrefixedText(); |
| 51 | + $this->output( "$url $text\n" ); |
| 52 | + } |
| 53 | + $dbr->freeResult( $result ); |
| 54 | + } |
46 | 55 | } |
47 | 56 | |
48 | | -$dbr->freeResult( $result ); |
49 | | - |
50 | | - |
| 57 | +$maintClass = "DumpSisterSites"; |
| 58 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/orphans.php |
— | — | @@ -28,179 +28,211 @@ |
29 | 29 | * @ingroup Maintenance |
30 | 30 | */ |
31 | 31 | |
32 | | -$options = array( 'fix' ); |
| 32 | +require_once( "Maintenance.php" ); |
33 | 33 | |
34 | | -/** */ |
35 | | -require_once( 'commandLine.inc' ); |
36 | | -$wgTitle = Title::newFromText( 'Orphan revision cleanup script' ); |
37 | | - |
38 | | -checkOrphans( isset( $options['fix'] ) ); |
39 | | -checkSeparation( isset( $options['fix'] ) ); |
40 | | -#checkWidows( isset( $options['fix'] ) ); |
41 | | - |
42 | | -# ------ |
43 | | - |
44 | | -function checkOrphans( $fix ) { |
45 | | - $dbw = wfGetDB( DB_MASTER ); |
46 | | - $page = $dbw->tableName( 'page' ); |
47 | | - $revision = $dbw->tableName( 'revision' ); |
48 | | - |
49 | | - if( $fix ) { |
50 | | - $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE" ); |
| 34 | +class Orphans extends Maintenance { |
| 35 | + public function __construct() { |
| 36 | + parent::__construct(); |
| 37 | + $this->mDescription = "Look for 'orphan' revisions hooked to pages which don't exist\n" . |
| 38 | + "And 'childless' pages with no revisions\n" . |
| 39 | + "Then, kill the poor widows and orphans\n" . |
| 40 | + "Man this is depressing"; |
| 41 | + $this->addOption( 'fix', 'Actually fix broken entries' ); |
51 | 42 | } |
52 | 43 | |
53 | | - echo "Checking for orphan revision table entries... (this may take a while on a large wiki)\n"; |
54 | | - $result = $dbw->query( " |
55 | | - SELECT * |
56 | | - FROM $revision LEFT OUTER JOIN $page ON rev_page=page_id |
57 | | - WHERE page_id IS NULL |
58 | | - "); |
59 | | - $orphans = $dbw->numRows( $result ); |
60 | | - if( $orphans > 0 ) { |
61 | | - global $wgContLang; |
62 | | - echo "$orphans orphan revisions...\n"; |
63 | | - printf( "%10s %10s %14s %20s %s\n", 'rev_id', 'rev_page', 'rev_timestamp', 'rev_user_text', 'rev_comment' ); |
64 | | - while( $row = $dbw->fetchObject( $result ) ) { |
65 | | - $comment = ( $row->rev_comment == '' ) |
66 | | - ? '' |
67 | | - : '(' . $wgContLang->truncate( $row->rev_comment, 40 ) . ')'; |
68 | | - printf( "%10d %10d %14s %20s %s\n", |
69 | | - $row->rev_id, |
70 | | - $row->rev_page, |
71 | | - $row->rev_timestamp, |
72 | | - $wgContLang->truncate( $row->rev_user_text, 17 ), |
73 | | - $comment ); |
74 | | - if( $fix ) { |
75 | | - $dbw->delete( 'revision', array( 'rev_id' => $row->rev_id ) ); |
76 | | - } |
77 | | - } |
78 | | - if( !$fix ) { |
79 | | - echo "Run again with --fix to remove these entries automatically.\n"; |
80 | | - } |
81 | | - } else { |
82 | | - echo "No orphans! Yay!\n"; |
| 44 | + public function execute() { |
| 45 | + global $wgTitle; |
| 46 | + $wgTitle = Title::newFromText( 'Orphan revision cleanup script' ); |
| 47 | + $this->checkOrphans( $this->hasOption( 'fix' ) ); |
| 48 | + $this->checkSeparation( $this->hasOption( 'fix' ) ); |
| 49 | + # Does not work yet, do not use |
| 50 | + # $this->checkWidows( $this->hasOption( 'fix' ) ); |
83 | 51 | } |
84 | 52 | |
85 | | - if( $fix ) { |
86 | | - $dbw->query( "UNLOCK TABLES" ); |
| 53 | + /** |
| 54 | + * Lock the appropriate tables for the script |
| 55 | + * @param $db Database object |
| 56 | + * @param $extraTable String The name of any extra tables to lock (eg: text) |
| 57 | + */ |
| 58 | + private function lockTables( &$db, $extraTable = null ) { |
| 59 | + $tbls = array( 'page', 'revision' ); |
| 60 | + if( $extraTable ) |
| 61 | + $tbls[] = $extraTable; |
| 62 | + $db->lockTables( array(), $tbls, __METHOD__, false ); |
87 | 63 | } |
88 | | -} |
89 | 64 | |
90 | | -/** |
91 | | - * @todo DON'T USE THIS YET! It will remove entries which have children, |
92 | | - * but which aren't properly attached (eg if page_latest is bogus |
93 | | - * but valid revisions do exist) |
94 | | - */ |
95 | | -function checkWidows( $fix ) { |
96 | | - $dbw = wfGetDB( DB_MASTER ); |
97 | | - $page = $dbw->tableName( 'page' ); |
98 | | - $revision = $dbw->tableName( 'revision' ); |
99 | | - |
100 | | - if( $fix ) { |
101 | | - $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE" ); |
102 | | - } |
103 | | - |
104 | | - echo "\nChecking for childless page table entries... (this may take a while on a large wiki)\n"; |
105 | | - $result = $dbw->query( " |
106 | | - SELECT * |
107 | | - FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id |
108 | | - WHERE rev_id IS NULL |
109 | | - "); |
110 | | - $widows = $dbw->numRows( $result ); |
111 | | - if( $widows > 0 ) { |
112 | | - global $wgContLang; |
113 | | - echo "$widows childless pages...\n"; |
114 | | - printf( "%10s %11s %2s %s\n", 'page_id', 'page_latest', 'ns', 'page_title' ); |
115 | | - while( $row = $dbw->fetchObject( $result ) ) { |
116 | | - printf( "%10d %11d %2d %s\n", |
117 | | - $row->page_id, |
118 | | - $row->page_latest, |
119 | | - $row->page_namespace, |
120 | | - $row->page_title ); |
121 | | - if( $fix ) { |
122 | | - $dbw->delete( 'page', array( 'page_id' => $row->page_id ) ); |
| 65 | + /** |
| 66 | + * Check for orphan revisions |
| 67 | + * @param $fix bool Whether to fix broken revisions when found |
| 68 | + */ |
| 69 | + private function checkOrphans( $fix ) { |
| 70 | + $dbw = wfGetDB( DB_MASTER ); |
| 71 | + $page = $dbw->tableName( 'page' ); |
| 72 | + $revision = $dbw->tableName( 'revision' ); |
| 73 | + |
| 74 | + if( $fix ) { |
| 75 | + $this->lockTables( $dbw ); |
| 76 | + } |
| 77 | + |
| 78 | + $this->output( "Checking for orphan revision table entries... (this may take a while on a large wiki)\n" ); |
| 79 | + $result = $dbw->query( " |
| 80 | + SELECT * |
| 81 | + FROM $revision LEFT OUTER JOIN $page ON rev_page=page_id |
| 82 | + WHERE page_id IS NULL |
| 83 | + "); |
| 84 | + $orphans = $dbw->numRows( $result ); |
| 85 | + if( $orphans > 0 ) { |
| 86 | + global $wgContLang; |
| 87 | + $this->output( "$orphans orphan revisions...\n" ); |
| 88 | + $this->output( sprintf( "%10s %10s %14s %20s %s\n", 'rev_id', 'rev_page', 'rev_timestamp', 'rev_user_text', 'rev_comment' ) ); |
| 89 | + while( $row = $dbw->fetchObject( $result ) ) { |
| 90 | + $comment = ( $row->rev_comment == '' ) |
| 91 | + ? '' |
| 92 | + : '(' . $wgContLang->truncate( $row->rev_comment, 40 ) . ')'; |
| 93 | + $this->output( sprintf( "%10d %10d %14s %20s %s\n", |
| 94 | + $row->rev_id, |
| 95 | + $row->rev_page, |
| 96 | + $row->rev_timestamp, |
| 97 | + $wgContLang->truncate( $row->rev_user_text, 17 ), |
| 98 | + $comment ) ); |
| 99 | + if( $fix ) { |
| 100 | + $dbw->delete( 'revision', array( 'rev_id' => $row->rev_id ) ); |
| 101 | + } |
123 | 102 | } |
| 103 | + if( !$fix ) { |
| 104 | + $this->output( "Run again with --fix to remove these entries automatically.\n" ); |
| 105 | + } |
| 106 | + } else { |
| 107 | + $this->output( "No orphans! Yay!\n" ); |
124 | 108 | } |
125 | | - if( !$fix ) { |
126 | | - echo "Run again with --fix to remove these entries automatically.\n"; |
| 109 | + |
| 110 | + if( $fix ) { |
| 111 | + $dbw->unlockTables(); |
127 | 112 | } |
128 | | - } else { |
129 | | - echo "No childless pages! Yay!\n"; |
130 | 113 | } |
131 | 114 | |
132 | | - if( $fix ) { |
133 | | - $dbw->query( "UNLOCK TABLES" ); |
134 | | - } |
135 | | -} |
| 115 | + /** |
| 116 | + * @param $fix bool |
| 117 | + * @todo DON'T USE THIS YET! It will remove entries which have children, |
| 118 | + * but which aren't properly attached (eg if page_latest is bogus |
| 119 | + * but valid revisions do exist) |
| 120 | + */ |
| 121 | + private function checkWidows( $fix ) { |
| 122 | + $dbw = wfGetDB( DB_MASTER ); |
| 123 | + $page = $dbw->tableName( 'page' ); |
| 124 | + $revision = $dbw->tableName( 'revision' ); |
136 | 125 | |
| 126 | + if( $fix ) { |
| 127 | + $this->lockTables( $dbw ); |
| 128 | + } |
137 | 129 | |
138 | | -function checkSeparation( $fix ) { |
139 | | - $dbw = wfGetDB( DB_MASTER ); |
140 | | - $page = $dbw->tableName( 'page' ); |
141 | | - $revision = $dbw->tableName( 'revision' ); |
142 | | - $text = $dbw->tableName( 'text' ); |
143 | | - |
144 | | - if( $fix ) { |
145 | | - $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE, $text WRITE" ); |
146 | | - } |
147 | | - |
148 | | - echo "\nChecking for pages whose page_latest links are incorrect... (this may take a while on a large wiki)\n"; |
149 | | - $result = $dbw->query( " |
150 | | - SELECT * |
151 | | - FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id |
152 | | - "); |
153 | | - $found = 0; |
154 | | - while( $row = $dbw->fetchObject( $result ) ) { |
155 | | - $result2 = $dbw->query( " |
156 | | - SELECT MAX(rev_timestamp) as max_timestamp |
157 | | - FROM $revision |
158 | | - WHERE rev_page=$row->page_id |
159 | | - " ); |
160 | | - $row2 = $dbw->fetchObject( $result2 ); |
161 | | - $dbw->freeResult( $result2 ); |
162 | | - if( $row2 ) { |
163 | | - if( $row->rev_timestamp != $row2->max_timestamp ) { |
164 | | - if( $found == 0 ) { |
165 | | - printf( "%10s %10s %14s %14s\n", |
166 | | - 'page_id', 'rev_id', 'timestamp', 'max timestamp' ); |
167 | | - } |
168 | | - ++$found; |
169 | | - printf( "%10d %10d %14s %14s\n", |
| 130 | + $this->output( "\nChecking for childless page table entries... (this may take a while on a large wiki)\n" ); |
| 131 | + $result = $dbw->query( " |
| 132 | + SELECT * |
| 133 | + FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id |
| 134 | + WHERE rev_id IS NULL |
| 135 | + "); |
| 136 | + $widows = $dbw->numRows( $result ); |
| 137 | + if( $widows > 0 ) { |
| 138 | + global $wgContLang; |
| 139 | + $this->output( "$widows childless pages...\n" ); |
| 140 | + $this->output( sprintf( "%10s %11s %2s %s\n", 'page_id', 'page_latest', 'ns', 'page_title' ) ); |
| 141 | + while( $row = $dbw->fetchObject( $result ) ) { |
| 142 | + printf( "%10d %11d %2d %s\n", |
170 | 143 | $row->page_id, |
171 | 144 | $row->page_latest, |
172 | | - $row->rev_timestamp, |
173 | | - $row2->max_timestamp ); |
| 145 | + $row->page_namespace, |
| 146 | + $row->page_title ); |
174 | 147 | if( $fix ) { |
175 | | - # ... |
176 | | - $maxId = $dbw->selectField( |
177 | | - 'revision', |
178 | | - 'rev_id', |
179 | | - array( |
180 | | - 'rev_page' => $row->page_id, |
181 | | - 'rev_timestamp' => $row2->max_timestamp ) ); |
182 | | - echo "... updating to revision $maxId\n"; |
183 | | - $maxRev = Revision::newFromId( $maxId ); |
184 | | - $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
185 | | - $article = new Article( $title ); |
186 | | - $article->updateRevisionOn( $dbw, $maxRev ); |
| 148 | + $dbw->delete( 'page', array( 'page_id' => $row->page_id ) ); |
187 | 149 | } |
188 | 150 | } |
| 151 | + if( !$fix ) { |
| 152 | + $this->output( "Run again with --fix to remove these entries automatically.\n" ); |
| 153 | + } |
189 | 154 | } else { |
190 | | - echo "wtf\n"; |
| 155 | + $this->output( "No childless pages! Yay!\n" ); |
191 | 156 | } |
| 157 | + |
| 158 | + if( $fix ) { |
| 159 | + $dbw->unlockTables(); |
| 160 | + } |
192 | 161 | } |
193 | 162 | |
194 | | - if( $found ) { |
195 | | - echo "Found $found pages with incorrect latest revision.\n"; |
196 | | - } else { |
197 | | - echo "No pages with incorrect latest revision. Yay!\n"; |
| 163 | + /** |
| 164 | + * Check for pages where page_latest is wrong |
| 165 | + * @param $fix bool Whether to fix broken entries |
| 166 | + */ |
| 167 | + private function checkSeparation( $fix ) { |
| 168 | + $dbw = wfGetDB( DB_MASTER ); |
| 169 | + $page = $dbw->tableName( 'page' ); |
| 170 | + $revision = $dbw->tableName( 'revision' ); |
| 171 | + $text = $dbw->tableName( 'text' ); |
| 172 | + |
| 173 | + if( $fix ) { |
| 174 | + $dbw->lockTables( $dbw, 'text' ); |
| 175 | + } |
| 176 | + |
| 177 | + $this->output( "\nChecking for pages whose page_latest links are incorrect... (this may take a while on a large wiki)\n" ); |
| 178 | + $result = $dbw->query( " |
| 179 | + SELECT * |
| 180 | + FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id |
| 181 | + "); |
| 182 | + $found = 0; |
| 183 | + while( $row = $dbw->fetchObject( $result ) ) { |
| 184 | + $result2 = $dbw->query( " |
| 185 | + SELECT MAX(rev_timestamp) as max_timestamp |
| 186 | + FROM $revision |
| 187 | + WHERE rev_page=$row->page_id |
| 188 | + " ); |
| 189 | + $row2 = $dbw->fetchObject( $result2 ); |
| 190 | + $dbw->freeResult( $result2 ); |
| 191 | + if( $row2 ) { |
| 192 | + if( $row->rev_timestamp != $row2->max_timestamp ) { |
| 193 | + if( $found == 0 ) { |
| 194 | + $this->output( sprintf( "%10s %10s %14s %14s\n", |
| 195 | + 'page_id', 'rev_id', 'timestamp', 'max timestamp' ) ); |
| 196 | + } |
| 197 | + ++$found; |
| 198 | + $this->output( sprintf( "%10d %10d %14s %14s\n", |
| 199 | + $row->page_id, |
| 200 | + $row->page_latest, |
| 201 | + $row->rev_timestamp, |
| 202 | + $row2->max_timestamp ) ); |
| 203 | + if( $fix ) { |
| 204 | + # ... |
| 205 | + $maxId = $dbw->selectField( |
| 206 | + 'revision', |
| 207 | + 'rev_id', |
| 208 | + array( |
| 209 | + 'rev_page' => $row->page_id, |
| 210 | + 'rev_timestamp' => $row2->max_timestamp ) ); |
| 211 | + $this->output( "... updating to revision $maxId\n" ); |
| 212 | + $maxRev = Revision::newFromId( $maxId ); |
| 213 | + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 214 | + $article = new Article( $title ); |
| 215 | + $article->updateRevisionOn( $dbw, $maxRev ); |
| 216 | + } |
| 217 | + } |
| 218 | + } else { |
| 219 | + $this->output( "wtf\n" ); |
| 220 | + } |
| 221 | + } |
| 222 | + |
| 223 | + if( $found ) { |
| 224 | + $this->output( "Found $found pages with incorrect latest revision.\n" ); |
| 225 | + } else { |
| 226 | + $this->output( "No pages with incorrect latest revision. Yay!\n" ); |
| 227 | + } |
| 228 | + if( !$fix && $found > 0 ) { |
| 229 | + $this->output( "Run again with --fix to remove these entries automatically.\n" ); |
| 230 | + } |
| 231 | + |
| 232 | + if( $fix ) { |
| 233 | + $dbw->unlockTables(); |
| 234 | + } |
198 | 235 | } |
199 | | - if( !$fix && $found > 0 ) { |
200 | | - echo "Run again with --fix to remove these entries automatically.\n"; |
201 | | - } |
202 | | - |
203 | | - if( $fix ) { |
204 | | - $dbw->query( "UNLOCK TABLES" ); |
205 | | - } |
206 | 236 | } |
207 | 237 | |
| 238 | +$maintClass = "Orphans"; |
| 239 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/deleteArchivedFiles.php |
— | — | @@ -9,23 +9,59 @@ |
10 | 10 | * Based on deleteOldRevisions.php by Rob Church |
11 | 11 | */ |
12 | 12 | |
13 | | -$options = array( 'delete', 'help' ); |
14 | | -require_once( 'commandLine.inc' ); |
15 | | -require_once( 'deleteArchivedFiles.inc' ); |
| 13 | +require_once( "Maintenance.php" ); |
16 | 14 | |
17 | | -echo( "Delete Archived Images\n\n" ); |
| 15 | +class DeleteArchivedFiles extends Maintenance { |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Deletes all archived images."; |
| 19 | + $this->addOption( 'delete', 'Perform the deletion' ); |
| 20 | + } |
18 | 21 | |
19 | | -if( @$options['help'] ) { |
20 | | - ShowUsage(); |
21 | | -} else { |
22 | | - DeleteArchivedFiles( @$options['delete'] ); |
23 | | -} |
| 22 | + public function execute() { |
| 23 | + $this->output( "Delete Archived Images\n\n" ); |
24 | 24 | |
25 | | -function ShowUsage() { |
26 | | - echo( "Deletes all archived images.\n\n" ); |
27 | | - echo( "These images will no longer be restorable.\n\n" ); |
28 | | - echo( "Usage: php deleteArchivedRevisions.php [--delete|--help]\n\n" ); |
29 | | - echo( "delete : Performs the deletion\n" ); |
30 | | - echo( " help : Show this usage information\n" ); |
| 25 | + # Data should come off the master, wrapped in a transaction |
| 26 | + $dbw = wfGetDB( DB_MASTER ); |
| 27 | + $transaction = new FSTransaction(); |
| 28 | + if( !$dbw->lock() ) { |
| 29 | + wfDebug( __METHOD__ . ": failed to acquire DB lock, aborting\n" ); |
| 30 | + return false; |
| 31 | + } |
| 32 | + |
| 33 | + $tbl_arch = $dbw->tableName( 'filearchive' ); |
| 34 | + |
| 35 | + # Get "active" revisions from the filearchive table |
| 36 | + $this->output( "Searching for and deleting archived files...\n" ); |
| 37 | + $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" ); |
| 38 | + while( $row = $dbw->fetchObject( $res ) ) { |
| 39 | + $key = $row->fa_storage_key; |
| 40 | + $group = $row->fa_storage_group; |
| 41 | + $id = $row->fa_id; |
| 42 | + |
| 43 | + $store = FileStore::get( $group ); |
| 44 | + if( $store ) { |
| 45 | + $path = $store->filePath( $key ); |
| 46 | + $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); |
| 47 | + $inuse = $dbw->selectField( 'oldimage', '1', |
| 48 | + array( 'oi_sha1' => $sha1, |
| 49 | + 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ), |
| 50 | + __METHOD__, array( 'FOR UPDATE' ) ); |
| 51 | + if ( $path && file_exists($path) && !$inuse ) { |
| 52 | + $transaction->addCommit( FSTransaction::DELETE_FILE, $path ); |
| 53 | + $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); |
| 54 | + } else { |
| 55 | + $this->output( "Notice - file '$key' not found in group '$group'\n" ); |
| 56 | + } |
| 57 | + } else { |
| 58 | + $this->output( "Notice - invalid file storage group '$group' for file '$key'\n" ); |
| 59 | + } |
| 60 | + } |
| 61 | + $this->output( "done.\n" ); |
| 62 | + |
| 63 | + $transaction->commit(); |
| 64 | + } |
31 | 65 | } |
32 | 66 | |
| 67 | +$maintClass = "DeleteArchivedFiles"; |
| 68 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/includes/db/DatabaseMysql.php |
— | — | @@ -315,11 +315,14 @@ |
316 | 316 | return $row->lockstatus; |
317 | 317 | } |
318 | 318 | |
319 | | - public function lockTables( $read, $write, $method ) { |
| 319 | + public function lockTables( $read, $write, $method, $lowPriority = true ) { |
320 | 320 | $items = array(); |
321 | 321 | |
322 | 322 | foreach( $write as $table ) { |
323 | | - $items[] = $this->tableName( $table ) . ' LOW_PRIORITY WRITE'; |
| 323 | + $tbl = $this->tableName( $table ) . |
| 324 | + $lowPriority ? ' LOW_PRIORITY' : '' . |
| 325 | + ' WRITE'; |
| 326 | + $items[] = $tbl; |
324 | 327 | } |
325 | 328 | foreach( $read as $table ) { |
326 | 329 | $items[] = $this->tableName( $table ) . ' READ'; |
Index: branches/maintenance-work/includes/db/DatabaseOracle.php |
— | — | @@ -1069,7 +1069,12 @@ |
1070 | 1070 | public function unlock( $lockName, $method ) { |
1071 | 1071 | return true; |
1072 | 1072 | } |
1073 | | - |
| 1073 | + public function lockTables( $read, $write, $method, $lowPriority = true ) { |
| 1074 | + return true; |
| 1075 | + } |
| 1076 | + public function unlockTables( $method ) { |
| 1077 | + return true; |
| 1078 | + } |
1074 | 1079 | public function getSearchEngine() { |
1075 | 1080 | return "SearchOracle"; |
1076 | 1081 | } |
Index: branches/maintenance-work/includes/db/Database.php |
— | — | @@ -2206,8 +2206,9 @@ |
2207 | 2207 | * @param $read Array of tables to lock for read access |
2208 | 2208 | * @param $write Array of tables to lock for write access |
2209 | 2209 | * @param $method String name of caller |
| 2210 | + * @param $lowPriority bool Whether to indicate writes to be LOW PRIORITY |
2210 | 2211 | */ |
2211 | | - abstract public function lockTables( $read, $write, $method ); |
| 2212 | + abstract public function lockTables( $read, $write, $method, $lowPriority = true ); |
2212 | 2213 | |
2213 | 2214 | /** |
2214 | 2215 | * Unlock specific tables |
Index: branches/maintenance-work/includes/db/DatabaseMssql.php |
— | — | @@ -981,6 +981,12 @@ |
982 | 982 | public function unlock( $lockName, $method ) { |
983 | 983 | return true; |
984 | 984 | } |
| 985 | + public function lockTables( $read, $write, $method, $lowPriority = true ) { |
| 986 | + return true; |
| 987 | + } |
| 988 | + public function unlockTables( $method ) { |
| 989 | + return true; |
| 990 | + } |
985 | 991 | |
986 | 992 | public function getSearchEngine() { |
987 | 993 | return "SearchEngineDummy"; |
Index: branches/maintenance-work/includes/db/DatabaseSqlite.php |
— | — | @@ -455,7 +455,7 @@ |
456 | 456 | /** No-op */ |
457 | 457 | public function setBigSelects( $value = true ) {} |
458 | 458 | |
459 | | - public function lockTables( $read, $write, $method ) {} |
| 459 | + public function lockTables( $read, $write, $method, $lowPriority = true ) {} |
460 | 460 | |
461 | 461 | public function unlockTables( $method ) {} |
462 | 462 | |