/** * @param FileEvent $event */ public function doPermissionsCheck(FileEvent $event) { if ($this->adapter->isFileReadableByAnonymous($event->getFile())) { return; } $this->publisher->unpublishAllVersions($event->getFile()); }
/** * @test */ public function unpublishShouldUnpublishFileVersion() { $adapter = new CopyFilesystemPublisherAdapter(ROOT_TESTS . '/data/publisher/public', "600", "700", ''); $publisher = new Publisher($adapter, new UniversalSequentialLinker()); $publisher->attachTo($this->filelib); $file = $this->filelib->uploadFile(ROOT_TESTS . '/data/self-lussing-manatee.jpg'); $publisher->publishVersion($file, Version::get('original')); $path = ROOT_TESTS . '/data/publisher/public/' . $publisher->getUrl($file, Version::get('original')); $this->assertFileExists($path); $this->assertFalse(is_link($path)); $publisher->unpublishVersion($file, Version::get('original')); $this->assertFileNotExists($path); }
public function setUp() { /* if (!extension_loaded('mongo')) { $this->markTestSkipped('MongoDB extension is not loaded.'); } try { $mongoClient = new MongoClient(MONGO_DNS); } catch (MongoConnectionException $e) { return $this->markTestSkipped('Can not connect to MongoDB.'); } $this->mongo = $mongoClient->selectDb('filelib_tests'); */ $stopwatch = new Stopwatch(); $ed = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch); $this->conn = DriverManager::getConnection(array('driver' => 'pdo_' . PDO_DRIVER, 'dbname' => PDO_DBNAME, 'user' => PDO_USERNAME, 'password' => PDO_PASSWORD, 'host' => PDO_HOST)); $filelib = new FileLibrary(new FilesystemStorageAdapter(ROOT_TESTS . '/data/files'), new DoctrineDbalBackendAdapter($this->conn), $ed); $memcached = new Memcached(); $memcached->addServer('localhost', 11211); $this->memcached = $memcached; $this->memcached->flush(); $filelib->addPlugin(new RandomizeNamePlugin()); $authorizationAdapter = new SimpleAuthorizationAdapter(); $authorizationPlugin = new AuthorizationPlugin($authorizationAdapter); $filelib->addPlugin($authorizationPlugin, array('default')); $authorizationAdapter->setFolderWritable(true)->setFileReadableByAnonymous(true)->setFileReadable(true); $this->authorizationAdapter = $authorizationAdapter; $publisher = new Publisher(new SymlinkFilesystemPublisherAdapter(ROOT_TESTS . '/data/publisher/public', '600', '700', 'files'), new BeautifurlLinker()); $publisher->attachTo($filelib); $this->publisher = $publisher; $originalPlugin = new OriginalVersionPlugin('original'); $filelib->addPlugin($originalPlugin, array('default')); $versionPlugin = new VersionPlugin(array('cinemascope' => array(array(array('setImageCompression', Imagick::COMPRESSION_JPEG), array('setImageFormat', 'jpg'), array('setImageCompressionQuality', 50), array('cropThumbnailImage', array(800, 200)), array('sepiaToneImage', 90), 'Xi\\Filelib\\Plugin\\Image\\Command\\WatermarkCommand' => array(ROOT_TESTS . '/data/watermark.png', 'se', 10))), 'croppo' => array(array(array('setImageCompression', Imagick::COMPRESSION_JPEG), array('setImageFormat', 'jpg'), array('setImageCompressionQuality', 80), array('cropThumbnailImage', array(400, 400)), 'Xi\\Filelib\\Plugin\\Image\\Command\\WatermarkCommand' => array(ROOT_TESTS . '/data/watermark.png', 'se', 10))))); $filelib->addPlugin($versionPlugin, array('default')); $this->filelib = $filelib; }