r107973 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107972‎ | r107973 | r107974 >
Date:00:26, 4 January 2012
Author:aaron
Status:deferred (Comments)
Tags:
Comment:
* Deal with strptime() fixme comment
* Various fixes after some testing using the backend on a wiki install
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/backend/SwiftFileBackend.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/SwiftFileBackend.php
@@ -41,7 +41,7 @@
4242 parent::__construct( $config );
4343 // Required settings
4444 $this->auth = new CF_Authentication(
45 - $config['swiftUser'], $config['swiftKey'], $config['swiftAuthUrl'] );
 45+ $config['swiftUser'], $config['swiftKey'], NULL, $config['swiftAuthUrl'] );
4646 // Optional settings
4747 $this->connTTL = isset( $config['connTTL'] )
4848 ? $config['connTTL']
@@ -82,7 +82,7 @@
8383
8484 // (b) Check the destination container
8585 try {
86 - $dContObj = $conn->get_container( $conn, $dstCont );
 86+ $dContObj = $conn->get_container( $dstCont );
8787 } catch ( NoSuchContainerException $e ) {
8888 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
8989 return $status;
@@ -156,8 +156,8 @@
157157
158158 // (b) Check the source and destination containers
159159 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 );
162162 } catch ( NoSuchContainerException $e ) {
163163 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
164164 return $status;
@@ -220,7 +220,7 @@
221221
222222 // (b) Check the source container
223223 try {
224 - $sContObj = $this->get_container( $conn, $srcCont );
 224+ $sContObj = $conn->get_container( $srcCont );
225225 } catch ( NoSuchContainerException $e ) {
226226 $status->fatal( 'backend-fail-delete', $params['src'] );
227227 return $status;
@@ -269,7 +269,7 @@
270270
271271 // (b) Check the destination container
272272 try {
273 - $dContObj = $conn->get_container( $conn, $dstCont );
 273+ $dContObj = $conn->get_container( $dstCont );
274274 } catch ( NoSuchContainerException $e ) {
275275 $status->fatal( 'backend-fail-create', $params['dst'] );
276276 return $status;
@@ -319,8 +319,28 @@
320320 */
321321 function prepare( array $params ) {
322322 $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;
325345 }
326346
327347 /**
@@ -343,12 +363,11 @@
344364
345365 $conn = $this->getConnection();
346366 if ( !$conn ) {
347 - $status->fatal( 'backend-fail-connect' );
348 - return $status;
 367+ return false; // fail vs not exists?
349368 }
350369
351370 try {
352 - $container = $this->get_container( $conn, $srcCont );
 371+ $container = $conn->get_container( $srcCont );
353372 $container->get_object( $srcRel );
354373 $exists = true;
355374 } catch ( NoSuchContainerException $e ) {
@@ -378,7 +397,7 @@
379398 }
380399
381400 try {
382 - $container = $this->get_container( $conn, $srcCont);
 401+ $container = $conn->get_container( $srcCont);
383402 $obj = $container->get_object( $srcRel );
384403 } catch ( NoSuchContainerException $e ) {
385404 $obj = NULL;
@@ -389,14 +408,11 @@
390409 }
391410
392411 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?
399415 } else {
400 - return false; // file not found.
 416+ return false; // file not found
401417 }
402418 }
403419
@@ -416,7 +432,7 @@
417433
418434 // @TODO: return an Iterator class that pages via list_objects()
419435 try {
420 - $container = $this->get_container( $conn, $dirc );
 436+ $container = $conn->get_container( $dirc );
421437 $files = $container->list_objects( 0, NULL, $dir );
422438 } catch ( NoSuchContainerException $e ) {
423439 $files = array();
@@ -446,7 +462,6 @@
447463 if ( !$tmpFile ) {
448464 return null;
449465 }
450 - $tmpPath = $tmpFile->getPath();
451466
452467 $conn = $this->getConnection();
453468 if ( !$conn ) {
@@ -454,9 +469,9 @@
455470 }
456471
457472 try {
458 - $cont = $this->get_container( $conn, $srcCont );
 473+ $cont = $conn->get_container( $srcCont );
459474 $obj = $cont->get_object( $srcRel );
460 - $obj->save_to_filename( $tmpPath );
 475+ $obj->save_to_filename( $tmpFile->getPath() );
461476 } catch ( NoSuchContainerException $e ) {
462477 $tmpFile = null;
463478 } catch ( NoSuchObjectException $e ) {

Comments

#Comment by Nikerabbit (talk | contribs)   10:18, 4 January 2012

NULL should be in lowercase.

Status & tagging log