Ejemplo n.º 1
0
 protected function _copyKeys(array $keys, $xml)
 {
     foreach ($keys as $key) {
         $this->_countKeys++;
         try {
             $this->_print('set-acl: ' . $key);
             $exclude = false;
             foreach ($this->_excludePatterns as $pattern) {
                 if (preg_match($pattern, $key)) {
                     $exclude = true;
                 }
             }
             if ($exclude) {
                 $this->_print(" -> EXCLUDED\n");
                 $this->_countExcluded++;
                 continue;
             }
             require_once 'Sitengine/Amazon/S3/Object.php';
             $object = new Sitengine_Amazon_S3_Object($this->_connection, $this->_bucket->getName(), $key);
             $head = null;
             $response = $object->acl($xml);
             if ($response->isError()) {
                 # try again
                 $response = $object->acl($xml);
                 if ($response->isError()) {
                     #print $response->getErrorMessage()."\n";
                     require_once 'Sitengine/Amazon/S3/Utils/Exception.php';
                     throw new Sitengine_Amazon_S3_Utils_Exception('Set Acl Error');
                 }
             }
             $this->_countOk++;
             $this->_print(" -> SET-ACL OK\n");
             #$this->_countCopied++;
             #$this->_print(" -> OK\n");
             #$response = $object->head($key);
             #print $response->getHttpResponse()->asString();
         } catch (Exception $exception) {
             $this->_countErrors++;
             $msg = " -> ERROR (" . $exception->getMessage() . ")\n";
             $this->_print($msg);
         }
     }
 }
Ejemplo n.º 2
0
 public function check($prefix)
 {
     $this->_countExisting = 0;
     $this->_countMissing = 0;
     $this->_countChanged = 0;
     $this->_countErrors = 0;
     $this->_countKeys = 0;
     $uploadDir = dir($this->_pathName);
     while (false !== ($file = $uploadDir->read())) {
         if (preg_match('/^\\.(\\.|DS_Store)?$/', $file)) {
             continue;
         }
         try {
             $this->_countKeys++;
             $key = $prefix ? $prefix . '/' . $file : $file;
             $inFile = $this->_pathName . '/' . $file;
             $this->_print('checking: ' . $file . ' -> ' . $key);
             require_once 'Sitengine/Amazon/S3/Object.php';
             $object = new Sitengine_Amazon_S3_Object($this->_connection, $this->_bucketName, $key);
             $head = $object->head();
             if ($head->getHttpResponse()->getStatus() == 200) {
                 $size = $head->getClient()->getLastResponse()->getHeader('Content-length');
                 if ($size !== null && $size == filesize($inFile)) {
                     $this->_print(" -> EXISTS\n");
                     $this->_countExisting++;
                     continue;
                 }
                 $this->_print(" -> CHANGED\n");
                 $this->_countChanged++;
                 continue;
             }
             if ($head->getHttpResponse()->getStatus() == 404) {
                 $this->_print(" -> MISSING\n");
                 $this->_countMissing++;
                 continue;
             }
             if ($head->getHttpResponse()->isError()) {
                 require_once 'Sitengine/Amazon/S3/Utils/Exception.php';
                 throw new Sitengine_Amazon_S3_Utils_Exception('Check Upload Error');
             }
         } catch (Exception $exception) {
             $this->_countErrors++;
             $msg = " -> ERROR (" . $exception->getMessage() . ")\n";
             $this->_print($msg);
         }
     }
     $uploadDir->close();
     return array('existing' => $this->_countExisting, 'missing' => $this->_countMissing, 'changed' => $this->_countChanged, 'errors' => $this->_countErrors, 'keys' => $this->_countKeys);
 }
Ejemplo n.º 3
0
 public function handleInsertUploads($id)
 {
     try {
         $upload = new Sitengine_Upload(self::FILE1ORIGINAL_ID);
         if (!$upload->isFile()) {
             # upload comes from spinelab flash applet
             $upload = new Sitengine_Upload('Filedata');
         }
         if ($upload->isFile()) {
             require_once 'Sitengine/Mime/Type.php';
             $suffix = Sitengine_Mime_Type::getSuffix($upload->getMime());
             if (!$suffix) {
                 # fix suffix if file is being uploaded through spinelab flash app
                 $suffix = '.' . preg_replace('/.*\\.(\\w+)$/', "\$1", $upload->getName());
             }
             $file1OriginalName = $this->makeFileName(self::FILE1ORIGINAL_ID, $id, $suffix);
             #$key = $this->_configs[self::FILE1ORIGINAL_ID]['prefix'].'/'.$file1OriginalName;
             #$object = $this->_configs[self::FILE1ORIGINAL_ID]['object'];
             require_once 'Sitengine/Amazon/S3/Object.php';
             $object = new Sitengine_Amazon_S3_Object($this->_configs[self::FILE1ORIGINAL_ID]['connection'], $this->_configs[self::FILE1ORIGINAL_ID]['bucket'], $this->_configs[self::FILE1ORIGINAL_ID]['prefix'] . '/' . $file1OriginalName, $this->_configs[self::FILE1ORIGINAL_ID]['cname'], $this->_configs[self::FILE1ORIGINAL_ID]['ssl']);
             $response = $object->head();
             if ($response->getHttpResponse()->getStatus() == 200) {
                 require_once 'Sitengine/Newsletter/Exception.php';
                 throw new Sitengine_Newsletter_Exception('insert upload error on file1 (duplicate id)');
             }
             $this->_saveUploadedFile(self::FILE1ORIGINAL_ID, $upload, $file1OriginalName);
         }
     } catch (Exception $exception) {
         $this->_rollback();
         require_once 'Sitengine/Newsletter/Exception.php';
         throw new Sitengine_Newsletter_Exception('handle insert upload error', $exception);
     }
 }
Ejemplo n.º 4
0
 protected function _copyKeys(array $keys, $targetPrefix, array $headers = array(), array $amzHeaders = array())
 {
     foreach ($keys as $key) {
         $currAmzHeaders = $amzHeaders;
         $this->_countKeys++;
         require_once 'Sitengine/Mime/Type.php';
         $mime = Sitengine_Mime_Type::get($key);
         $targetKey = $targetPrefix . $key;
         if ($this->_targetRenamePatternFind !== null && $this->_targetRenamePatternReplace !== null) {
             $targetKey = preg_replace($this->_targetRenamePatternFind, $this->_targetRenamePatternReplace, $targetKey);
         }
         try {
             $this->_print('copying: ' . $key . ' -> ' . $targetKey);
             $exclude = false;
             foreach ($this->_excludePatterns as $pattern) {
                 if (preg_match($pattern, $key)) {
                     $exclude = true;
                 }
             }
             if ($exclude) {
                 $this->_print(" -> EXCLUDED\n");
                 $this->_countExcluded++;
                 continue;
             }
             require_once 'Sitengine/Amazon/S3/Object.php';
             $targetObject = new Sitengine_Amazon_S3_Object($this->_connection, $this->_targetBucketName, $targetKey);
             $head = null;
             if (!$this->_force) {
                 # check if target exists
                 $head = $targetObject->head();
                 if ($head->getHttpResponse()->getStatus() == 200) {
                     $eTag = $head->getClient()->getLastResponse()->getHeader('Etag');
                     if ($eTag !== null) {
                         # set pre-condition
                         $currAmzHeaders[] = "x-amz-copy-source-if-none-match: {$eTag}";
                     }
                     /*
                     $this->_print(" -> TARGET EXISTS (SKIPPED)\n");
                     $this->_countSkipped++;
                     continue;
                     */
                 }
             }
             $response = $targetObject->copy($this->_sourceBucket->getName(), $key, $mime, $headers, $currAmzHeaders);
             $code = $response->getHttpResponse()->extractCode($response->getHttpResponse()->getHeadersAsString());
             if ($code == 412) {
                 $this->_print(" -> SKIPPED (EXISTS)\n");
                 $this->_countSkipped++;
                 continue;
             }
             if ($response->isError()) {
                 # try again
                 $response = $targetObject->copy($this->_sourceBucket->getName(), $key, $mime, $headers, $currAmzHeaders);
                 if ($response->isError()) {
                     #print $response->getErrorMessage()."\n";
                     require_once 'Sitengine/Amazon/S3/Utils/Exception.php';
                     throw new Sitengine_Amazon_S3_Utils_Exception('Copy Error');
                 }
             }
             if ($head !== null && $head->getHttpResponse()->getStatus() == 200) {
                 $this->_countReplaced++;
                 $this->_print(" -> REPLACE OK\n");
             } else {
                 $this->_countCopied++;
                 $this->_print(" -> COPY OK\n");
             }
             #$this->_countCopied++;
             #$this->_print(" -> OK\n");
             #$response = $targetObject->head($key);
             #print $response->getHttpResponse()->asString();
         } catch (Exception $exception) {
             $this->_countErrors++;
             $msg = " -> ERROR (" . $exception->getMessage() . ")\n";
             $this->_print($msg);
         }
     }
 }
Ejemplo n.º 5
0
 public function deleteRowAndFiles(Zend_Db_Table_Row_Abstract $row)
 {
     try {
         $row = $row->toArray();
         $where = self::FIELD_ID . ' = ' . $this->getAdapter()->quote($row[self::FIELD_ID]);
         $affectedRows = $this->getAdapter()->delete($this->_name, $where);
         if ($affectedRows > 0) {
             foreach ($this->_files as $fileId => $v) {
                 if ($row[$fileId . self::FILETAG_NAME]) {
                     #$key = $this->_configs[$fileId]['prefix'].'/'.$row[$fileId.self::FILETAG_NAME];
                     #$object = $this->_configs[$fileId]['object'];
                     require_once 'Sitengine/Amazon/S3/Object.php';
                     $object = new Sitengine_Amazon_S3_Object($this->_configs[$fileId]['connection'], $this->_configs[$fileId]['bucket'], $this->_configs[$fileId]['prefix'] . '/' . $row[$fileId . self::FILETAG_NAME], $this->_configs[$fileId]['cname'], $this->_configs[$fileId]['ssl']);
                     $response = $object->delete();
                 }
             }
         }
         return $affectedRows;
     } catch (Exception $exception) {
         require_once 'Sitengine/Exception.php';
         throw new Sitengine_Exception('delete row and s3 files error', $exception);
     }
 }