Index: branches/FileBackend/phase3/includes/filerepo/backend/SwiftFileBackend.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | parent::__construct( $config ); |
43 | 43 | // Required settings |
44 | 44 | $this->auth = new CF_Authentication( |
45 | | - $config['swiftUser'], $config['swiftKey'], $config['swiftAuthUrl'] ); |
| 45 | + $config['swiftUser'], $config['swiftKey'], NULL, $config['swiftAuthUrl'] ); |
46 | 46 | // Optional settings |
47 | 47 | $this->connTTL = isset( $config['connTTL'] ) |
48 | 48 | ? $config['connTTL'] |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | |
84 | 84 | // (b) Check the destination container |
85 | 85 | try { |
86 | | - $dContObj = $conn->get_container( $conn, $dstCont ); |
| 86 | + $dContObj = $conn->get_container( $dstCont ); |
87 | 87 | } catch ( NoSuchContainerException $e ) { |
88 | 88 | $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); |
89 | 89 | return $status; |
— | — | @@ -156,8 +156,8 @@ |
157 | 157 | |
158 | 158 | // (b) Check the source and destination containers |
159 | 159 | try { |
160 | | - $sContObj = $this->get_container( $conn, $srcCont ); |
161 | | - $dContObj = $conn->get_container( $conn, $dstCont ); |
| 160 | + $sContObj = $conn->get_container( $srcCont ); |
| 161 | + $dContObj = $conn->get_container( $dstCont ); |
162 | 162 | } catch ( NoSuchContainerException $e ) { |
163 | 163 | $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); |
164 | 164 | return $status; |
— | — | @@ -220,7 +220,7 @@ |
221 | 221 | |
222 | 222 | // (b) Check the source container |
223 | 223 | try { |
224 | | - $sContObj = $this->get_container( $conn, $srcCont ); |
| 224 | + $sContObj = $conn->get_container( $srcCont ); |
225 | 225 | } catch ( NoSuchContainerException $e ) { |
226 | 226 | $status->fatal( 'backend-fail-delete', $params['src'] ); |
227 | 227 | return $status; |
— | — | @@ -269,7 +269,7 @@ |
270 | 270 | |
271 | 271 | // (b) Check the destination container |
272 | 272 | try { |
273 | | - $dContObj = $conn->get_container( $conn, $dstCont ); |
| 273 | + $dContObj = $conn->get_container( $dstCont ); |
274 | 274 | } catch ( NoSuchContainerException $e ) { |
275 | 275 | $status->fatal( 'backend-fail-create', $params['dst'] ); |
276 | 276 | return $status; |
— | — | @@ -319,8 +319,28 @@ |
320 | 320 | */ |
321 | 321 | function prepare( array $params ) { |
322 | 322 | $status = Status::newGood(); |
323 | | - // @TODO: create containers as needed |
324 | | - return $status; // badgers? We don't need no steenking badgers! |
| 323 | + |
| 324 | + list( $dstCont, $destRel ) = $this->resolveStoragePath( $params['dir'] ); |
| 325 | + if ( $destRel === null ) { |
| 326 | + $status->fatal( 'backend-fail-invalidpath', $params['dir'] ); |
| 327 | + return $status; |
| 328 | + } |
| 329 | + |
| 330 | + // (a) Get a swift proxy connection |
| 331 | + $conn = $this->getConnection(); |
| 332 | + if ( !$conn ) { |
| 333 | + $status->fatal( 'backend-fail-connect' ); |
| 334 | + return $status; |
| 335 | + } |
| 336 | + |
| 337 | + // (b) Create the destination container |
| 338 | + try { |
| 339 | + $conn->create_container( $dstCont ); |
| 340 | + } catch ( Exception $e ) { // some other exception? |
| 341 | + $status->fatal( 'backend-fail-internal' ); |
| 342 | + } |
| 343 | + |
| 344 | + return $status; |
325 | 345 | } |
326 | 346 | |
327 | 347 | /** |
— | — | @@ -343,12 +363,11 @@ |
344 | 364 | |
345 | 365 | $conn = $this->getConnection(); |
346 | 366 | if ( !$conn ) { |
347 | | - $status->fatal( 'backend-fail-connect' ); |
348 | | - return $status; |
| 367 | + return false; // fail vs not exists? |
349 | 368 | } |
350 | 369 | |
351 | 370 | try { |
352 | | - $container = $this->get_container( $conn, $srcCont ); |
| 371 | + $container = $conn->get_container( $srcCont ); |
353 | 372 | $container->get_object( $srcRel ); |
354 | 373 | $exists = true; |
355 | 374 | } catch ( NoSuchContainerException $e ) { |
— | — | @@ -378,7 +397,7 @@ |
379 | 398 | } |
380 | 399 | |
381 | 400 | try { |
382 | | - $container = $this->get_container( $conn, $srcCont); |
| 401 | + $container = $conn->get_container( $srcCont); |
383 | 402 | $obj = $container->get_object( $srcRel ); |
384 | 403 | } catch ( NoSuchContainerException $e ) { |
385 | 404 | $obj = NULL; |
— | — | @@ -389,14 +408,11 @@ |
390 | 409 | } |
391 | 410 | |
392 | 411 | if ( $obj ) { |
393 | | - $thumbTime = $obj->last_modified; |
394 | | - // @FIXME: strptime() UNIX-only (http://php.net/manual/en/function.strptime.php) |
395 | | - $tm = strptime( $thumbTime, '%a, %d %b %Y %H:%M:%S GMT' ); |
396 | | - $thumbGMT = gmmktime( $tm['tm_hour'], $tm['tm_min'], $tm['tm_sec'], |
397 | | - $tm['tm_mon'] + 1, $tm['tm_mday'], $tm['tm_year'] + 1900 ); |
398 | | - return ( gmdate( 'YmdHis', $thumbGMT ) ); |
| 412 | + // Convert "Tue, 03 Jan 2012 22:01:04 GMT" to TS_MW |
| 413 | + $date = DateTime::createFromFormat( 'D, d F Y G:i:s e', $obj->last_modified ); |
| 414 | + return $date ? $date->format( 'YmdHis' ) : false; // fail vs not exists? |
399 | 415 | } else { |
400 | | - return false; // file not found. |
| 416 | + return false; // file not found |
401 | 417 | } |
402 | 418 | } |
403 | 419 | |
— | — | @@ -416,7 +432,7 @@ |
417 | 433 | |
418 | 434 | // @TODO: return an Iterator class that pages via list_objects() |
419 | 435 | try { |
420 | | - $container = $this->get_container( $conn, $dirc ); |
| 436 | + $container = $conn->get_container( $dirc ); |
421 | 437 | $files = $container->list_objects( 0, NULL, $dir ); |
422 | 438 | } catch ( NoSuchContainerException $e ) { |
423 | 439 | $files = array(); |
— | — | @@ -446,7 +462,6 @@ |
447 | 463 | if ( !$tmpFile ) { |
448 | 464 | return null; |
449 | 465 | } |
450 | | - $tmpPath = $tmpFile->getPath(); |
451 | 466 | |
452 | 467 | $conn = $this->getConnection(); |
453 | 468 | if ( !$conn ) { |
— | — | @@ -454,9 +469,9 @@ |
455 | 470 | } |
456 | 471 | |
457 | 472 | try { |
458 | | - $cont = $this->get_container( $conn, $srcCont ); |
| 473 | + $cont = $conn->get_container( $srcCont ); |
459 | 474 | $obj = $cont->get_object( $srcRel ); |
460 | | - $obj->save_to_filename( $tmpPath ); |
| 475 | + $obj->save_to_filename( $tmpFile->getPath() ); |
461 | 476 | } catch ( NoSuchContainerException $e ) { |
462 | 477 | $tmpFile = null; |
463 | 478 | } catch ( NoSuchObjectException $e ) { |