/**
  * The getExpired call should return an empty array if there
  * are no expired assets.
  */
 function testGetExpiredEmpty()
 {
     // Empty Binary Pool
     $this->assertEqual(array(), binarypool_browser::getExpired('test'));
     // Binary Pool with one asset which has not been put in a view
     $asset = $this->storage->save('IMAGE', array('_' => array('file' => $this->testfile)));
     $this->assertEqual(array(), binarypool_browser::getExpired('test'));
     // Binary Pool with one asset which has not expired
     binarypool_views::created('test', $asset);
     $this->assertEqual(array(), binarypool_browser::getExpired('test'));
 }
Example #2
0
 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));
 }
Example #3
0
function walk_callback($bucket, $root, $file)
{
    global $processed, $storage, $max;
    if ($max > 0 && $processed >= $max) {
        printf("[%10s] Processed %d files. Terminating.\n", $bucket, $processed);
        exit(0);
    }
    if (is_link(rtrim($root . $file, '/'))) {
        // Ignore symlinks
        return;
    }
    if (!file_exists($root . $file . 'index.xml')) {
        return;
    }
    if (!assert_filemtime($root . $file . 'index.xml', $bucket)) {
        return false;
    }
    printf("[%10s]   %s\n", $bucket, $file);
    $processed++;
    try {
        $asset = $storage->getAssetObject($file . 'index.xml');
        if (file_exists($asset->getOriginal())) {
            printf("[%10s]     Uploading file.\n", $bucket);
            $files = array('_' => array('file' => $asset->getOriginal()));
            foreach ($asset->getRenditions() as $key => $rendition) {
                if (file_exists($rendition)) {
                    // Local file
                    $files[$key] = array('file' => $rendition);
                }
            }
            $type = $asset->getType();
            if (!$storage->save($type, $files, true)) {
                printf("[%10s]     ERROR: Could not save asset.\n", $bucket);
                return;
            }
        } else {
            $asset->setBasePath($asset->getBasePath(), false);
            if (!$storage->saveAsset($asset, $file . 'index.xml')) {
                printf("[%10s]     ERROR: Could not save asset.\n", $bucket);
                return;
            }
            printf("[%10s]     Saved asset.\n", $bucket);
            binarypool_views::created($bucket, $file . 'index.xml', array('URL' => ''));
        }
    } catch (Exception $e) {
        printf("[%10s]     ERROR: Got exception while saving asset.\n", $bucket);
        return;
    }
    // Move to trash
    $basepath = $asset->getBasePath();
    $date = date('Y/m/d');
    $trashDir = 'Trash/' . $date . '/' . $basepath;
    $trashDirAbs = $root . $trashDir;
    $idx = 0;
    while (file_exists($trashDirAbs)) {
        $trashDirAbs = $root . $trashDir . '-' . $idx;
        $idx++;
    }
    printf("[%10s]     Moving file version to trash: %s\n", $bucket, $trashDirAbs);
    $trashParent = dirname($trashDirAbs);
    if (!file_exists($trashParent)) {
        mkdir($trashParent, 0755, true);
    }
    rename($root . $file, $trashDirAbs);
    symlink($trashDirAbs, rtrim($root . $file, '/'));
}
Example #4
0
 function testUpdatedSymlink()
 {
     $this->assignLastModified();
     $cache_age = binarypool_config::getCacheRevalidate('test') + 1;
     binarypool_views::$lastModified->setReturnValue('lastModified', array('cache_age' => $cache_age));
     $asset = $this->createMockAsset();
     $storage = $this->createMockStorage($asset);
     $storage->expectCallCount('symlink', 2);
     $storage->expectCallCount('relink', 1);
     $this->assignMockStorageFactory($storage);
     binarypool_views::created('test', 'foo', array('URL' => 'http://local.ch/foo.gif'));
 }