Index: trunk/extensions/SwiftMedia/TODO |
— | — | @@ -1,4 +1,3 @@ |
2 | | -4) Of course, append() and appendFinish() need to be implemented. |
3 | 2 | 5) The Upload seems to take more time than I expect, but that could be a function of generating the six thumbnails. |
4 | 3 | 6) There's no 404 handler to generate missing thumbnails. |
5 | 4 | 7) There's no support for remote thumbnailing. |
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php |
— | — | @@ -2453,11 +2453,60 @@ |
2454 | 2454 | return $result; |
2455 | 2455 | } |
2456 | 2456 | |
| 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 | + |
2457 | 2468 | function append( $srcPath, $toAppendPath, $flags = 0 ){ |
2458 | 2469 | 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; |
2459 | 2487 | } |
| 2488 | + /** |
| 2489 | + * Finish the append operation. |
| 2490 | + * @param $toAppendPath String: path to append to. |
| 2491 | + */ |
2460 | 2492 | 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(); |
2462 | 2511 | } |
2463 | 2512 | |
2464 | 2513 | /** |
— | — | @@ -2985,43 +3034,6 @@ |
2986 | 3035 | |
2987 | 3036 | |
2988 | 3037 | 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 | | - |
3026 | 3038 | /** |
3027 | 3039 | * Remove a temporary file or mark it for garbage collection |
3028 | 3040 | * @param $virtualUrl String: the virtual URL returned by storeTemp |
— | — | @@ -3106,4 +3118,3 @@ |
3107 | 3119 | } |
3108 | 3120 | |
3109 | 3121 | } |
3110 | | - |