r89081 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89080‎ | r89081 | r89082 >
Date:02:18, 29 May 2011
Author:nelson
Status:deferred
Tags:
Comment:
Added append() and appendFinish()
Modified paths:
  • /trunk/extensions/SwiftMedia/SwiftMedia.body.php (modified) (history)
  • /trunk/extensions/SwiftMedia/TODO (modified) (history)

Diff [purge]

Index: trunk/extensions/SwiftMedia/TODO
@@ -1,4 +1,3 @@
2 -4) Of course, append() and appendFinish() need to be implemented.
32 5) The Upload seems to take more time than I expect, but that could be a function of generating the six thumbnails.
43 6) There's no 404 handler to generate missing thumbnails.
54 7) There's no support for remote thumbnailing.
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php
@@ -2453,11 +2453,60 @@
24542454 return $result;
24552455 }
24562456
 2457+
 2458+ /**
 2459+ * Append the contents of the source path to the given file, OR queue
 2460+ * the appending operation in anticipation of a later appendFinish() call.
 2461+ * @param $srcPath String: location of the source file
 2462+ * @param $toAppendPath String: path to append to.
 2463+ * @param $flags Integer: bitfield, may be FileRepo::DELETE_SOURCE to indicate
 2464+ * that the source file should be deleted if possible
 2465+ * @return mixed Status or false
 2466+ */
 2467+
24572468 function append( $srcPath, $toAppendPath, $flags = 0 ){
24582469 throw new MWException( __METHOD__.": Not yet implemented." );
 2470+ // I think we need to count the number of files whose names
 2471+ // start with $toAppendPath, then add that count (with leading zeroes) to
 2472+ // the end of $toAppendPath and write the chunk there.
 2473+
 2474+ // Count the number of files whose names start with $toAppendPath
 2475+ $conn = $this->connect();
 2476+ $container = $this->repo->get_container($conn,$this->repo->container . "%2Ftemp");
 2477+ $nextone = count($container->list_objects(0, NULL, $srcPath));
 2478+
 2479+ // Do the append to the next name
 2480+ $status = $this->store( $srcPath, 'temp', sprintf("%s.%05d", $toAppendPath, $nextone) );
 2481+
 2482+ if ( $flags & self::DELETE_SOURCE ) {
 2483+ unlink( $srcPath );
 2484+ }
 2485+
 2486+ return $status;
24592487 }
 2488+ /**
 2489+ * Finish the append operation.
 2490+ * @param $toAppendPath String: path to append to.
 2491+ */
24602492 function appendFinish( $toAppendPath ){
2461 - throw new MWException( __METHOD__.": Not yet implemented." );
 2493+ $conn = $this->connect();
 2494+ $container = $this->repo->get_container( $conn,$this->repo->container . "%2Ftemp" );
 2495+ $parts = $container->list_objects( 0, NULL, $srcPath );
 2496+ // list_objects() returns a sorted list.
 2497+
 2498+ // The first object as the same name as the destination, so
 2499+ // we read it into memory and then write it out as the first chunk.
 2500+ $obj = $container->get_object( array_shift($parts) );
 2501+ $first = $obj->read();
 2502+
 2503+ $biggie = $container->create_object( $toAppendPath );
 2504+ $biggie->write( $first );
 2505+
 2506+ foreach ( $parts as $part ) {
 2507+ $obj = $container->get_object( $part );
 2508+ $biggie->write( $obj->read() );
 2509+ }
 2510+ return newGood();
24622511 }
24632512
24642513 /**
@@ -2985,43 +3034,6 @@
29863035
29873036
29883037 class Junkyjunk {
2989 - function append( $srcPath, $toAppendPath, $flags = 0 ) {
2990 - $status = $this->newGood();
2991 -
2992 - // Resolve the virtual URL
2993 - if ( self::isVirtualUrl( $srcPath ) ) {
2994 - $srcPath = $this->resolveVirtualUrl( $srcPath );
2995 - }
2996 - // Make sure the files are there
2997 - if ( !is_file( $srcPath ) )
2998 - $status->fatal( 'filenotfound', $srcPath );
2999 -
3000 - if ( !is_file( $toAppendPath ) )
3001 - $status->fatal( 'filenotfound', $toAppendPath );
3002 -
3003 - if ( !$status->isOk() ) return $status;
3004 -
3005 - // Do the append
3006 - $chunk = file_get_contents( $toAppendPath );
3007 - if( $chunk === false ) {
3008 - $status->fatal( 'fileappenderrorread', $toAppendPath );
3009 - }
3010 -
3011 - if( $status->isOk() ) {
3012 - if ( file_put_contents( $srcPath, $chunk, FILE_APPEND ) ) {
3013 - $status->value = $srcPath;
3014 - } else {
3015 - $status->fatal( 'fileappenderror', $toAppendPath, $srcPath);
3016 - }
3017 - }
3018 -
3019 - if ( $flags & self::DELETE_SOURCE ) {
3020 - unlink( $toAppendPath );
3021 - }
3022 -
3023 - return $status;
3024 - }
3025 -
30263038 /**
30273039 * Remove a temporary file or mark it for garbage collection
30283040 * @param $virtualUrl String: the virtual URL returned by storeTemp
@@ -3106,4 +3118,3 @@
31073119 }
31083120
31093121 }
3110 -

Status & tagging log