/** * Create a test asset file. * * @param $callbacks: Array of callbacks to register. * @param $age: Age of item in days. */ function createAsset($callbacks = array(), $age = 30) { // Create asset file $asset = new binarypool_asset($this->getDummyStorage()); $asset->setBasePath('test/somehashhere'); $asset->setOriginal($this->testfile); $asset->setExpiry(time() - $age * 24 * 60 * 60); foreach ($callbacks as $callback) { $asset->addCallback($callback); } $xml = $asset->getXML(); mkdir(self::$BUCKET . 'somehashhere', 0755, true); copy($this->testfile, self::$BUCKET . 'somehashhere/vw_golf.jpg'); file_put_contents(self::$BUCKET . 'somehashhere/index.xml', $xml); return 'test/somehashhere/index.xml'; }
public function listDir($dir) { $files = array(); $absDir = $this->absolutize($dir); if (is_dir($absDir)) { if ($dirhandle = opendir($absDir)) { while (($file = readdir($dirhandle)) !== false) { if ($file != '.' && $file != '..') { $assetFile = $dir . '/' . $file . '/index.xml'; if ($this->isFile($assetFile)) { $asset = new binarypool_asset($this, $assetFile); array_push($files, $asset->getBasePath() . 'index.xml'); } } } closedir($dirhandle); } } return $files; }
public function listDir($dir) { $dir = rtrim($dir, '/') . '/'; $s3_bucket = $this->cfg['bucket']; $files = $this->client->getBucket($s3_bucket, $dir); $retval = array(); foreach ($files as $file) { $path = $file['name']; if (strrpos($path, '.link') === strlen($path) - 5) { $path = $this->resolveSymlink($path); } if (strpos($path, 'index.xml') !== false) { $asset = new binarypool_asset($this, $path); array_push($retval, $asset->getBasePath() . 'index.xml'); } } return $retval; }
private function createAssetFile($assetFile, $assetObj, $dir, $originalFile, $renditions, $type) { $asset = null; if ($originalFile === null || $renditions === null) { // Nothing to save, just writing an existing file return $assetFile; } if (!is_null($assetObj)) { $asset = $assetObj; } else { if ($this->storage->isFile($assetFile)) { // Load existing asset file $asset = $this->getAssetObject($assetFile); } else { $asset = new binarypool_asset($this); } } $storeAbsolute = $this->storage->isAbsoluteStorage(); $asset->setBasePath($dir, $storeAbsolute); $asset->setOriginal($this->storage->absolutize($originalFile)); foreach ($renditions as $rendition => $filename) { $asset->setRendition($rendition, $this->absolutize($filename)); } // Expiry date if (!isset($this->bucketConfig['ttl'])) { throw new BinaryPoolException(116, 500, 'Bucket does not have a defined TTL: ' . $this->bucketName); } $asset->setExpiry(time() + intval($this->bucketConfig['ttl']) * 24 * 60 * 60); $asset->setType($type); // Done $this->saveAsset($asset, $assetFile); return $assetFile; }
function testPDFAssetWithoutRenditions() { // Create asset file $asset = new binarypool_asset($this->getDummyStorage()); $asset->setBasePath('test/somehashhere'); $asset->setOriginal(realpath(dirname(__FILE__) . '/../res/emil_frey_logo_2.pdf')); $xml = $asset->getXML(); // Load XML $dom = DOMDocument::loadXML($xml); $xp = new DOMXPath($dom); // Test $this->assertXPath($xp, '/registry/@version', '3.0'); $this->assertXPath($xp, '/registry/items/item/@type', 'IMAGE'); $this->assertXPath($xp, '/registry/items/item/@isRendition', 'false'); $this->assertXPath($xp, '/registry/items/item/webobject/@unit', 'mm'); $this->assertXPath($xp, '/registry/items/item/webobject/objectWidth', '203'); $this->assertXPath($xp, '/registry/items/item/webobject/objectHeight', '40'); $this->assertXPath($xp, '/registry/items/item/imageinfo/@isLandscape', 'true'); $this->assertXPath($xp, '/registry/items/item/imageinfo/@unit', 'mm'); $this->assertXPath($xp, '/registry/items/item/imageinfo/width', '203'); $this->assertXPath($xp, '/registry/items/item/imageinfo/height', '40'); $this->assertXPath($xp, '/registry/items/item/location', 'test/somehashhere/emil_frey_logo_2.pdf'); $this->assertXPath($xp, '/registry/items/item/mimetype', 'application/pdf'); $this->assertXPath($xp, '/registry/items/item/size', '28216'); }
/** * 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.'); }