Development

Changeset 5802

You must first sign up to be able to contribute.

Changeset 5802

Show
Ignore:
Timestamp:
11/01/07 23:46:59 (6 years ago)
Author:
Jonathan.Todd
Message:

sfAmazonS3FSPlugin: Added s3 module to browse s3 files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfAmazonS3FSPlugin/lib/BasesfAmazonS3.class.php

    r5782 r5802  
    961961  protected function validateResponseCode($successCode) 
    962962  { 
     963    //echo $this->responseCode.' - '.$this->responseString."<br>"; 
    963964    if ($this->responseCode == $successCode) 
    964965    { 
    965966      return true; 
    966967    } 
    967     elseif($this->responseCode == 404) 
    968     { 
    969       return false; 
    970     } 
    971     else 
    972     { 
    973       throw new sfException($this->responseCode.' - '.$this->responseString); 
    974     } 
     968    // elseif($this->responseCode == 404) 
     969    // { 
     970    //   return false; 
     971    // } 
     972    // else 
     973    // { 
     974    //   throw new sfException($this->responseCode.' - '.$this->responseString); 
     975    // } 
     976    if (sfConfig::get('sf_logging_enabled')) 
     977      sfLogger::getInstance()->warning("S3 Warning: ".$this->responseCode.' - '.$this->responseString); 
    975978    return false; 
    976979  } 
     
    10521055    } 
    10531056 
     1057    // TODO: Fix return 
     1058    return $this->parsedXml; 
    10541059    return $bucketKeys; 
    10551060  } 
  • plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObject.php

    r5784 r5802  
    1717  protected $localFilePath = null; 
    1818   
     19  // On save this determines whether or not to update existing file based 
     20  // on file name and path 
     21  protected $updateExistingFile = false; 
     22   
    1923  public function __toString() 
    2024  { 
     
    6771 
    6872      // TODO: Fix this hack. Fileinfo method above should work on servers 
    69       $this->setMimeType("image/png"); 
     73      $this->setMimeType("image/jpeg"); 
    7074 
    7175    } 
     
    132136  } 
    133137   
    134    
     138  /** 
     139   * Save will take object, try putting file in S3, if successful, add object to db. 
     140   * If not successful it will return 0. 
     141   *  
     142   * updateExistingFile 
     143   * If updateExistingFile is set to true save will attempt to find the existing file 
     144   * in S3 based on path and filename.  
     145   * - If the file exists in S3 and is older then the new file is added to S3.  
     146   * - If the file exists in S3 but is newer then the file on S3 does not get updated. 
     147   * - If the file doens't exist on S3 it will get added as usual. 
     148   *  
     149   * @return number of affected rows, 0 may mean error, -1 if update existing is set 
     150   * and file on s3 was newer or same 
     151   */ 
    135152  public function save($con = null) 
    136153  { 
     
    142159      $file = $this->getLocalFilePath(); 
    143160     
     161    // File is valid, add it 
    144162    if($file) 
    145163    { 
     164      // Update existing? 
     165      if($this->updateExistingFile) 
     166      { 
     167        $existingBucketObject = sfAmazonS3BucketObjectPeer::retrieveByFilePath($this->getPath(),$this->getFileName()); 
     168         
     169        // Existing file found 
     170        if($existingBucketObject) 
     171        { 
     172          // Existing file is older, we will update it 
     173          if($this->getMtime() > $existingBucketObject->getMtime()) 
     174          { 
     175            $this->setId($existingBucketObject->getId());  
     176          } 
     177          // Exiting file is newer, no need to update 
     178          else 
     179            return -1; 
     180        } 
     181      } 
     182       
    146183      $sfAmazonS3 = new sfAmazonS3(sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key')); 
    147184       
     
    172209  } 
    173210   
     211  /* 
     212   * Delete S3 bucket object 
     213   *  
     214   * Will only delete from DB if delete from S3 is successful 
     215   */ 
     216  public function delete($con = null) 
     217  { 
     218    $sfAmazonS3 = new sfAmazonS3(sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key')); 
     219    $result = $sfAmazonS3->deleteBucketObject($this->getBucketName(), $this->getKeyName()); 
     220     
     221    if($result) 
     222      return parent::delete(); 
     223    return false; 
     224  } 
     225   
     226  /* 
     227   * Id path creates a path from an ID which has a limit of 1000 files per directory 
     228   */ 
    174229  public function getIdPath() 
    175230  { 
     
    244299    return parent::setMtime($v); 
    245300  } 
     301   
     302  public function setUpdateExistingFile($v) 
     303  { 
     304    $this->updateExistingFile = $v ? true : false; 
     305  } 
    246306} 
  • plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObjectPeer.php

    r5755 r5802  
    1010class sfAmazonS3BucketObjectPeer extends BasesfAmazonS3BucketObjectPeer 
    1111{ 
     12  public function retrieveByFilePath($path, $file, $con = null) 
     13  { 
     14    if ($con === null) { 
     15      $con = Propel::getConnection(self::DATABASE_NAME); 
     16    } 
     17 
     18    $criteria = new Criteria(sfAmazonS3BucketObjectPeer::DATABASE_NAME); 
     19 
     20    $criteria->add(sfAmazonS3BucketObjectPeer::PATH, $path, Criteria::LIKE); 
     21    $criteria->add(sfAmazonS3BucketObjectPeer::FILE_NAME, $file, Criteria::LIKE); 
     22 
     23    $v = sfAmazonS3BucketObjectPeer::doSelect($criteria, $con); 
     24 
     25    if(count($v) > 1) 
     26      throw new sfException("Assert Failed: There shouldn't be multiple rows with the same path and file_name\n"); 
     27       
     28    return !empty($v) > 0 ? $v[0] : null; 
     29  } 
     30   
    1231} 
  • plugins/sfAmazonS3FSPlugin/modules/s3_bucket_object/templates/showSuccess.php

    r5755 r5802  
    5656</table> 
    5757<hr /> 
    58 <?php echo link_to('edit', 's3_bucket_object/edit?id='.$sf_amazon_s3_bucket_object->getId()) ?> 
     58<?php echo link_to('delete', 's3_bucket_object/delete?id='.$sf_amazon_s3_bucket_object->getId(), 'post=true&confirm=Are you sure?') ?> 
    5959&nbsp;<?php echo link_to('list', 's3_bucket_object/list') ?>