r88880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88879‎ | r88880 | r88881 >
Date:01:48, 26 May 2011
Author:nelson
Status:deferred
Tags:
Comment:
delete and restore are working.
Modified paths:
  • /trunk/extensions/SwiftMedia/LocalSettings.php (modified) (history)
  • /trunk/extensions/SwiftMedia/SwiftMedia.body.php (modified) (history)
  • /trunk/extensions/SwiftMedia/copyover (modified) (history)

Diff [purge]

Index: trunk/extensions/SwiftMedia/LocalSettings.php
@@ -126,8 +126,6 @@
127127 # End of automatically generated settings.
128128 # Add more configuration options below.
129129
130 -if (1) {
131 -
132130 require_once( "$IP/extensions/SwiftMedia/SwiftMedia.php" );
133131
134132 $wgUploadDirectory = "$IP/images/swift";
@@ -135,24 +133,24 @@
136134 $wgUploadPath = "http://alsted.wikimedia.org/images/swift";
137135
138136 $wgLocalFileRepo = array(
139 - 'class' => 'SwiftRepo',
140 - 'name' => 'swift',
141 - #'directory' => 'http://alsted.wikimedia.org/images', #$wgUploadDirectory,
142 - 'directory' => $wgUploadDirectory,
 137+ 'class' => 'SwiftRepo',
 138+ // $wgLocalFileRepo must be named 'local' for $repo->isLocal() to work
 139+ 'name' => 'local',
 140+ #'directory' => 'http://alsted.wikimedia.org/images', #$wgUploadDirectory,
 141+ 'directory' => $wgUploadDirectory,
143142 'user' => 'system:media',
144 - 'key' => '8lksg0p',
 143+ 'key' => 'secret',
145144 'authurl' => 'http://alsted.wikimedia.org/auth/v1.0',
146145 'container' => 'images%2Fswift',
147 - 'scriptDirUrl' => $wgScriptPath,
148 - 'scriptExtension' => $wgScriptExtension,
149 - 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
150 - 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
151 - 'thumbScriptUrl' => $wgThumbnailScriptPath,
152 - 'transformVia404' => !$wgGenerateThumbnailOnParse,
153 - #'deletedDir' => $wgDeletedDirectory,
154 - #'deletedHashLevels' => 3
 146+ 'scriptDirUrl' => $wgScriptPath,
 147+ 'scriptExtension' => $wgScriptExtension,
 148+ 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
 149+ 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
 150+ 'thumbScriptUrl' => $wgThumbnailScriptPath,
 151+ 'transformVia404' => !$wgGenerateThumbnailOnParse,
 152+ 'deletedDir' => $wgDeletedDirectory,
 153+ 'deletedHashLevels' => 3
155154 );
156 -}
157155
158156 $wgDebugLogFile = "/var/www/debug/abcd";
159157 $wgShowExceptionDetails = true;
Index: trunk/extensions/SwiftMedia/copyover
@@ -4,3 +4,4 @@
55 scp rnelson@alsted.wikimedia.org:/etc/swift/proxy-server.conf .
66 scp rnelson@ersch.wikimedia.org:/var/www/extensions/SwiftMedia/{SwiftMedia.body.php,SwiftMedia.i18n.php,SwiftMedia.php} .
77 scp rnelson@alsted.wikimedia.org:/usr/local/lib/python2.6/dist-packages/wmf/{client.py,__init__.py,rewrite.py} wmf/
 8+perl -pi -e "s/'key' => '.*'/'key' => 'secret'/" LocalSettings.php
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php
@@ -1171,6 +1171,7 @@
11721172 foreach ( $result as $row ) {
11731173 $batch->addOld( $row->oi_archive_name );
11741174 }
 1175+ //wfDebug(__METHOD__ . var_export($batch, true) . "\n");
11751176 $status = $batch->execute();
11761177
11771178 if ( $status->ok ) {
@@ -2410,43 +2411,18 @@
24112412 */
24122413 function deleteBatch( $sourceDestPairs ) {
24132414 wfDebug( __METHOD__ . " deleting " . var_export($sourceDestPairs, true) . "\n");
2414 - $status = $this->newGood();
24152415
24162416 /**
2417 - * Validate filenames and create archive directories
 2417+ * Move the files
24182418 */
 2419+ $triplets = array();
24192420 foreach ( $sourceDestPairs as $pair ) {
24202421 list( $srcRel, $archiveRel ) = $pair;
2421 - if ( !$this->validateFilename( $srcRel ) ) {
2422 - throw new MWException( __METHOD__.':Validation error in $srcRel' );
2423 - }
2424 - if ( !$this->validateFilename( $archiveRel ) ) {
2425 - throw new MWException( __METHOD__.':Validation error in $archiveRel' );
2426 - }
2427 - }
2428 - if ( !$status->ok ) {
2429 - // Abort early
2430 - return $status;
2431 - }
24322422
2433 - /**
2434 - * Move the files
2435 - * We're now committed to returning an OK result, which will lead to
2436 - * the files being moved in the DB also.
2437 - */
2438 - foreach ( $sourceDestPairs as $pair ) {
2439 - list( $srcRel, $archiveRel ) = $pair;
2440 - $srcPath = "{$this->directory}/$srcRel";
2441 - $archivePath = "{$this->deletedDir}/$archiveRel";
2442 - $good = true;
2443 - // FIXME we need to copy $this->container/$srcPath to $this->container%2Fdeleted/$archivePath
2444 - // FIXME then delete $this->container/$srcPath
2445 - if ( $good ) {
2446 - $status->successCount++;
2447 - } else {
2448 - $status->failCount++;
2449 - }
 2423+ $triplets[] = array( "mwrepo://{$this->name}/public/$srcRel", 'deleted', $archiveRel );
 2424+
24502425 }
 2426+ $status = $this->storeBatch( $triplets, FileRepo::OVERWRITE_SAME | FileRepo::DELETE_SOURCE );
24512427 return $status;
24522428 }
24532429
@@ -2499,14 +2475,14 @@
25002476 }
25012477 function newFile( $title, $time = false ) {
25022478 if ( empty($title) ) { return null; }
2503 - wfDebug( __METHOD__ . " $title, $time " . var_export($this->fileFactory, true) ."\n" );
 2479+ //wfDebug( __METHOD__ . " $title, $time " . var_export($this->fileFactory, true) ."\n" );
25042480 $f = parent::newFile( $title, $time );
25052481 return $f;
25062482 }
25072483 function findFile( $title, $options = array() ) {
2508 - wfDebug( __METHOD__ . " finding $title" . var_export($options, true) . "\n" );
 2484+ //wfDebug( __METHOD__ . " finding $title" . var_export($options, true) . "\n" );
25092485 $found = parent::findFile( $title, $options );
2510 - wfDebug( __METHOD__ . " found " . var_export($found, true) . "\n" );
 2486+ //wfDebug( __METHOD__ . " found " . var_export($found, true) . "\n" );
25112487 return $found;
25122488 }
25132489
@@ -2540,9 +2516,6 @@
25412517 #wfDebug( "Bytes stored in container: " . $container->bytes_used . "\n" );
25422518 #wfDebug( "Object: " . var_export($pic, true) . "\n" );
25432519
2544 - # Delete specific object
2545 - #$container->delete_object("disco_dancing.jpg");
2546 -
25472520 # paranoia
25482521 $status = $this->newGood( array() );
25492522 foreach ( $triplets as $i => $triplet ) {
@@ -2645,7 +2618,58 @@
26462619 $container->delete_object($rel);
26472620 }
26482621 }
 2622+
26492623 /**
 2624+ * Delete files in the deleted directory if they are not referenced in the
 2625+ * filearchive table. This needs to be done in the repo because it needs to
 2626+ * interleave database locks with file operations, which is potentially a
 2627+ * remote operation.
 2628+ * @return FileRepoStatus
 2629+ */
 2630+ function cleanupDeletedBatch( $storageKeys ) {
 2631+ $auth = new CF_Authentication($this->swiftuser, $this->key, NULL, $this->authurl);
 2632+ $auth->authenticate();
 2633+ $conn = new CF_Connection($auth);
 2634+ $cont = $this->getZoneContainer( 'deleted' );
 2635+ $container = $conn->get_container($cont);
 2636+
 2637+ $dbw = $this->getMasterDB();
 2638+ $status = $this->newGood();
 2639+ $storageKeys = array_unique($storageKeys);
 2640+ foreach ( $storageKeys as $key ) {
 2641+ $hashPath = $this->getDeletedHashPath( $key );
 2642+ $rel = "$hashPath$key";
 2643+ $dbw->begin();
 2644+ $inuse = $dbw->selectField( 'filearchive', '1',
 2645+ array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
 2646+ __METHOD__, array( 'FOR UPDATE' ) );
 2647+ if( !$inuse ) {
 2648+ $sha1 = self::getHashFromKey( $key );
 2649+ $ext = substr( $key, strcspn( $key, '.' ) + 1 );
 2650+ $ext = File::normalizeExtension($ext);
 2651+ $inuse = $dbw->selectField( 'oldimage', '1',
 2652+ array( 'oi_sha1' => $sha1,
 2653+ 'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(), ".$ext" ),
 2654+ $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
 2655+ __METHOD__, array( 'FOR UPDATE' ) );
 2656+ }
 2657+ if ( !$inuse ) {
 2658+ wfDebug( __METHOD__ . ": deleting $key\n" );
 2659+ $container->delete_object($rel);
 2660+ if ( 0 ) {
 2661+ $status->error( 'undelete-cleanup-error', $rel );
 2662+ $status->failCount++;
 2663+ }
 2664+ } else {
 2665+ wfDebug( __METHOD__ . ": $key still in use\n" );
 2666+ $status->successCount++;
 2667+ }
 2668+ $dbw->commit();
 2669+ }
 2670+ return $status;
 2671+ }
 2672+
 2673+ /**
26502674 * Makes no sense in our context -- don't let anybody call it.
26512675 */
26522676 function getZonePath( $zone ) {
@@ -2912,6 +2936,7 @@
29132937 }
29142938 }
29152939
 2940+
29162941 class Junkyjunk {
29172942 function __construct( $info ) {
29182943 parent::__construct( $info );

Status & tagging log