예제 #1
0
파일: touch.php 프로젝트: pneff/binarypool
 protected function touch($bucket, $uri)
 {
     $storage = new binarypool_storage($bucket);
     $assetFile = $uri;
     if (!$storage->isFile($assetFile)) {
         $assetFile .= '/index.xml';
         if (!$storage->isFile($assetFile)) {
             return false;
         }
     }
     // Get TTL from request
     $buckets = binarypool_config::getBuckets();
     $ttl = $buckets[$bucket]['ttl'];
     if ($this->request->getParam('TTL')) {
         $newttl = intval($this->request->getParam('TTL'));
         if ($newttl <= $ttl) {
             // Don't allow higher TTL than bucket configuration
             $ttl = $newttl;
         }
     }
     // Set TTL
     $oldAsset = $storage->getAssetObject($assetFile);
     $asset = $storage->getAssetObject($assetFile);
     $asset->setExpiry(time() + $ttl * 24 * 60 * 60);
     $storage->saveAsset($asset, $assetFile);
     // Update views
     binarypool_views::updated($bucket, $assetFile, $oldAsset);
     $this->setResponseCode(204);
     return true;
 }
예제 #2
0
파일: create.php 프로젝트: pneff/binarypool
 protected function upload($bucket)
 {
     $this->checkInput();
     // Get params
     $type = $this->request->getParam('Type');
     $callback = $this->request->getParam('Callback', '');
     $files = $this->getFiles();
     $url = $this->request->getParam('URL');
     $created = true;
     $storage = new binarypool_storage($bucket);
     // 304 not modified
     if (0 == count($files) && !empty($url)) {
         $symlink = binarypool_views::getDownloadedViewPath($bucket, $url);
         $asset = $storage->getAssetForLink($symlink);
         $this->log->info("Unmodified file %s", $asset);
         $created = false;
     } else {
         // Save file
         $asset = $storage->save($type, $files);
         $this->log->info("Created file %s", $asset);
     }
     foreach ($files as $rendition => $file) {
         unlink($file['file']);
     }
     if ($callback !== '') {
         $storage->addCallback($asset, $callback);
     }
     $metadata = array();
     $metadata['URL'] = $url;
     if ($created) {
         binarypool_views::created($bucket, $asset, $metadata);
     } else {
         $assetObj = $storage->getAssetObject($asset);
         binarypool_views::updated($bucket, $asset, $assetObj, $metadata);
     }
     $this->setResponseCode(201);
     $this->response->setHeader('Location', $asset);
     $this->response->setHeader('X-Asset', $asset);
     $xml = "<status method='post'><asset>" . htmlspecialchars($asset) . "</asset></status>";
     array_push($this->data, new api_model_xml($xml));
 }
예제 #3
0
 /**
  * Checks the correct behaviour when updating an asset's expiry date.
  * The old symbolic link should be deleted and the new one created.
  */
 function testUpdateExpireDateView()
 {
     // Paths to assert against
     $date = date('Y/m/d', strtotime('+2 days'));
     $viewExpires2Days = self::$BUCKET . 'expiry/' . $date . '/' . $this->assetId;
     $date = date('Y/m/d', strtotime('+9 days'));
     $viewExpires9Days = self::$BUCKET . 'expiry/' . $date . '/' . $this->assetId;
     $asset = new binarypool_asset($this->getDummyStorage(), $this->assetFile);
     $asset->setExpiry(strtotime('+2 days'));
     file_put_contents(binarypool_config::getRoot() . $this->assetFile, $asset->getXML());
     // First view correctly created?
     binarypool_views::created('test', $this->assetFile, array());
     $this->assertTrue(file_exists($viewExpires2Days), 'Asset was not put into the first expiration date view.');
     $this->assertTrue(file_exists($viewExpires2Days . '/index.xml'), 'Asset file does not exist in the first expiration date view.');
     // Update
     $oldAsset = new binarypool_asset($this->getDummyStorage(), $this->assetFile);
     $asset = new binarypool_asset($this->getDummyStorage(), $this->assetFile);
     $asset->setExpiry(strtotime('+9 days'));
     file_put_contents(binarypool_config::getRoot() . $this->assetFile, $asset->getXML());
     // Second view correctly created?
     binarypool_views::updated('test', $this->assetFile, $oldAsset);
     $this->assertTrue(file_exists($viewExpires9Days), 'Asset was not put into the new expiration date view.');
     $this->assertTrue(file_exists($viewExpires9Days . '/index.xml'), 'Asset file does not exist in the new expiration date view.');
     // First view correctly deleted?
     binarypool_views::created('test', $this->assetFile, array());
     $this->assertFalse(file_exists($viewExpires2Days), 'Asset was not deleted from the first expiration date view.');
 }