Changeset 5802
- Timestamp:
- 11/01/07 23:46:59 (6 years ago)
- Files:
-
- plugins/sfAmazonS3FSPlugin/lib/BasesfAmazonS3.class.php (modified) (2 diffs)
- plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObject.php (modified) (6 diffs)
- plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObjectPeer.php (modified) (1 diff)
- plugins/sfAmazonS3FSPlugin/modules/s3 (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/actions (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/actions/actions.class.php (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/templates (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/templates/listAllBucketKeysSuccess.php (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/templates/listBucketKeysSuccess.php (added)
- plugins/sfAmazonS3FSPlugin/modules/s3/templates/listBucketsSuccess.php (added)
- plugins/sfAmazonS3FSPlugin/modules/s3_bucket_object/templates/showSuccess.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfAmazonS3FSPlugin/lib/BasesfAmazonS3.class.php
r5782 r5802 961 961 protected function validateResponseCode($successCode) 962 962 { 963 //echo $this->responseCode.' - '.$this->responseString."<br>"; 963 964 if ($this->responseCode == $successCode) 964 965 { 965 966 return true; 966 967 } 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); 975 978 return false; 976 979 } … … 1052 1055 } 1053 1056 1057 // TODO: Fix return 1058 return $this->parsedXml; 1054 1059 return $bucketKeys; 1055 1060 } plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObject.php
r5784 r5802 17 17 protected $localFilePath = null; 18 18 19 // On save this determines whether or not to update existing file based 20 // on file name and path 21 protected $updateExistingFile = false; 22 19 23 public function __toString() 20 24 { … … 67 71 68 72 // TODO: Fix this hack. Fileinfo method above should work on servers 69 $this->setMimeType("image/ png");73 $this->setMimeType("image/jpeg"); 70 74 71 75 } … … 132 136 } 133 137 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 */ 135 152 public function save($con = null) 136 153 { … … 142 159 $file = $this->getLocalFilePath(); 143 160 161 // File is valid, add it 144 162 if($file) 145 163 { 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 146 183 $sfAmazonS3 = new sfAmazonS3(sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key')); 147 184 … … 172 209 } 173 210 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 */ 174 229 public function getIdPath() 175 230 { … … 244 299 return parent::setMtime($v); 245 300 } 301 302 public function setUpdateExistingFile($v) 303 { 304 $this->updateExistingFile = $v ? true : false; 305 } 246 306 } plugins/sfAmazonS3FSPlugin/lib/model/sfAmazonS3BucketObjectPeer.php
r5755 r5802 10 10 class sfAmazonS3BucketObjectPeer extends BasesfAmazonS3BucketObjectPeer 11 11 { 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 12 31 } plugins/sfAmazonS3FSPlugin/modules/s3_bucket_object/templates/showSuccess.php
r5755 r5802 56 56 </table> 57 57 <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?') ?> 59 59 <?php echo link_to('list', 's3_bucket_object/list') ?>