/**
  * testFlush
  *
  * @return void
  */
 public function testFlush()
 {
     $config = StorageManager::config('Local');
     $result = StorageManager::flush('Local');
     $this->assertTrue($result);
     $result = StorageManager::flush('Does not exist');
     $this->assertFalse($result);
     StorageManager::config('Local', $config);
 }
 /**
  * Setup test folders and files
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->_setupListeners();
     $this->testPath = TMP . 'file-storage-test' . DS;
     $this->fileFixtures = Plugin::path('Burzum/FileStorage') . 'tests' . DS . 'Fixture' . DS . 'File' . DS;
     if (!is_dir($this->testPath)) {
         mkdir($this->testPath);
     }
     Configure::write('FileStorage.basePath', $this->testPath);
     Configure::write('FileStorage.imageSizes', array('Test' => array('t50' => array('thumbnail' => array('mode' => 'outbound', 'width' => 50, 'height' => 50)), 't150' => array('thumbnail' => array('mode' => 'outbound', 'width' => 150, 'height' => 150))), 'UserAvatar' => ['small' => array('thumbnail' => array('mode' => 'inbound', 'width' => 80, 'height' => 80))]));
     StorageUtils::generateHashes();
     StorageManager::config('Local', array('adapterOptions' => [$this->testPath, true], 'adapterClass' => '\\Gaufrette\\Adapter\\Local', 'class' => '\\Gaufrette\\Filesystem'));
     $this->FileStorage = TableRegistry::get('Burzum/FileStorage.FileStorage');
     $this->ImageStorage = TableRegistry::get('Burzum/FileStorage.ImageStorage');
 }
 /**
  * afterDelete
  *
  * No need to use an adapter here, just delete the whole folder using cakes Folder class
  *
  * @param Event $event
  * @return boolean|null
  */
 public function afterDelete(Event $event)
 {
     if ($this->_checkEvent($event)) {
         $entity = $event->data['record'];
         $storageConfig = StorageManager::config($entity['adapter']);
         $path = $storageConfig['adapterOptions'][0] . $event->data['record']['path'];
         if (is_dir($path)) {
             $Folder = new Folder($path);
             $Folder->delete();
             $event->stopPropagation();
             $event->result = true;
             return true;
         }
         $event->stopPropagation();
         $event->result = false;
         return false;
     }
 }
 /**
  * Store a local file via command line in any storage backend.
  *
  * @return void
  */
 public function store()
 {
     $model = $this->loadModel($this->params['model']);
     if (empty($this->args[0])) {
         $this->error('No file provided!');
     }
     if (!file_exists($this->args[0])) {
         $this->error('The file does not exist!');
     }
     $adapterConfig = StorageManager::config($this->params['adapter']);
     if (empty($adapterConfig)) {
         $this->error(sprintf('Invalid adapter config `%s` provided!', $this->params['adapter']));
     }
     $fileData = StorageUtils::fileToUploadArray($this->args[0]);
     $entity = $model->newEntity(['adapter' => $this->params['adapter'], 'file' => $fileData, 'filename' => $fileData['name']]);
     if ($model->save($entity)) {
         $this->out('File successfully saved!');
         $this->out('UUID: ' . $entity->id);
         $this->out('Path: ' . $entity->path());
     } else {
         $this->error('Failed to save the file.');
     }
 }
 /**
  * Gets the bucket from the adapter configuration.
  *
  * @param string Storage adapter config name.
  * @return string
  */
 protected function _getBucket($adapter)
 {
     $config = StorageManager::config($adapter);
     return $config['adapterOptions'][1];
 }
 /**
  * Gets the configuration array for an adapter.
  *
  * @param string $adapter
  * @param array $options
  * @return mixed
  */
 public static function config($adapter, $options = array())
 {
     return NewStorageManager::config($adapter, $options);
 }
 /**
  * Wrapper around the singleton call to StorageManager::config
  * Makes it easy to mock the adapter in tests.
  *
  * @param string $configName
  * @return array
  */
 public function getAdapterconfig($configName)
 {
     return StorageManager::config($configName);
 }
 /**
  * Gets the adapter class name from the adapter configuration key
  *
  * @param string
  * @return string|false
  */
 public function getAdapterClassName($adapterConfigName)
 {
     $config = StorageManager::config($adapterConfigName);
     switch ($config['adapterClass']) {
         case '\\Gaufrette\\Adapter\\Local':
             $this->adapterClass = 'Local';
             return $this->adapterClass;
         case '\\Gaufrette\\Adapter\\AwsS3':
             $this->adapterClass = 'AwsS3';
             return $this->adapterClass;
         case '\\Gaufrette\\Adapter\\AmazonS3':
             $this->adapterClass = 'AwsS3';
             return $this->adapterClass;
         case '\\Gaufrette\\Adapter\\AwsS3':
             $this->adapterClass = 'AwsS3';
             return $this->adapterClass;
         default:
             return false;
     }
 }
<?php

use Burzum\FileStorage\Lib\FileStorageUtils;
use Burzum\FileStorage\Storage\Listener\BaseListener;
use Burzum\FileStorage\Storage\StorageManager;
use Cake\Core\Configure;
use Cake\Event\EventManager;
/*
    default thumbnail setup for all
    $entity->model entities for file_storage
*/
Configure::write('ThumbnailVersions', ['huge' => ['thumbnail' => ['width' => 2000, 'height' => 2000]], 'large' => ['thumbnail' => ['width' => 1024, 'height' => 1024]], 'medium' => ['thumbnail' => ['width' => 500, 'height' => 500]], 'small' => ['thumbnail' => ['width' => 150, 'height' => 150]], 'tiny' => ['thumbnail' => ['width' => 50, 'height' => 50]]]);
Configure::write('FileStorage', ['pathBuilderOptions' => ['pathBuilderOptions' => ['pathPrefix' => '/uploads']], 'association' => 'UploadDocuments', 'imageSizes' => ['file_storage' => ['huge' => ['thumbnail' => ['width' => 2000, 'height' => 2000]], 'large' => ['thumbnail' => ['width' => 1024, 'height' => 1024]], 'medium' => ['thumbnail' => ['width' => 500, 'height' => 500]], 'small' => ['thumbnail' => ['width' => 150, 'height' => 150]], 'tiny' => ['thumbnail' => ['width' => 50, 'height' => 50]]]]]);
/**
 * @todo  find if we need this or not
 */
FileStorageUtils::generateHashes();
StorageManager::config('Local', ['adapterOptions' => [WWW_ROOT, true], 'adapterClass' => '\\Gaufrette\\Adapter\\Local', 'class' => '\\Gaufrette\\Filesystem']);
$listener = new BaseListener(Configure::read('FileStorage.pathBuilderOptions'));
EventManager::instance()->on($listener);