partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 6cd35acf4c8210fd17ce3454d66d8e4fa7d85209
parent 032041e7b97c623fb384abe6d3933c7562138c89
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 31 Oct 2015 15:41:48 +0100

Added gaufrette bundle

Diffstat:
Mapp/AppKernel.php | 3++-
Mapp/config/config.yml | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mapp/config/config_dev.yml | 2+-
Mapp/config/config_prod.yml | 2+-
Mcomposer.json | 3++-
Mcomposer.lock | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/PartKeepr/UploadedFileBundle/Controller/FileController.php | 19++++---------------
Msrc/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php | 4++++
Msrc/PartKeepr/UploadedFileBundle/Services/UploadedFileService.php | 14+++++++++++++-
9 files changed, 235 insertions(+), 27 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -30,7 +30,8 @@ class AppKernel extends Kernel new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new JMS\TranslationBundle\JMSTranslationBundle(), new \PartKeepr\RemoteFileLoader\PartKeeprRemoteFileLoaderBundle(), - new \FR3D\LdapBundle\FR3DLdapBundle() + new \FR3D\LdapBundle\FR3DLdapBundle(), + new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), ); // Developer bundles diff --git a/app/config/config.yml b/app/config/config.yml @@ -116,3 +116,62 @@ services: calls: - method: "setCircularReferenceLimit" arguments: [ [ 5 ] ] + +knp_gaufrette: + adapters: + iclogo: + local: + directory: %kernel.root_dir%/../data/images/iclogo/ + temp: + local: + directory: %kernel.root_dir%/../data/temp/ + tempfile: + local: + directory: %kernel.root_dir%/../data/files/Temporary/ + footprintattachment: + local: + directory: %kernel.root_dir%/../data/files/FootprintAttachment/ + footprint: + local: + directory: %kernel.root_dir%/../data/images/footprint/ + partattachment: + local: + directory: %kernel.root_dir%/../data/files/PartAttachment/ + storagelocation: + local: + directory: %kernel.root_dir%/../data/images/storagelocation/ + mimetype_icons: + local: + directory: %kernel.root_dir%/../src/PartKeepr/MimetypeIconsBundle/Resources/public/images/mimes/ + projectattachment: + local: + directory: %kernel.root_dir%/../data/files/ProjectAttachment/ + filesystems: + iclogo: + adapter: iclogo + alias: filesystem_iclogo + temp: + adapter: temp + alias: filesystem_temp + tempfile: + adapter: tempfile + alias: filesystem_tempfile + footprintattachment: + adapter: footprintattachment + alias: filesystem_footprintattachment + footprint: + adapter: footprint + alias: filesystem_footprint + partattachment: + adapter: partattachment + alias: filesystem_partattachment + storagelocation: + adapter: storagelocation + alias: filesystem_storagelocation + mimetype_icons: + adapter: mimetype_icons + alias: filesystem_mimetype_icons + projectattachment: + adapter: projectattachment + alias: filesystem_projectattachment + diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml @@ -15,7 +15,7 @@ monolog: handlers: main: type: stream - path: %kernel.logs_dir%/%kernel.environment%.log + path: "%kernel.logs_dir%/dev.log" level: debug console: type: console diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml @@ -19,7 +19,7 @@ monolog: handler: nested nested: type: stream - path: %kernel.logs_dir%/%kernel.environment%.log + path: %kernel.logs_dir%/%database_name%.log level: debug console: type: console diff --git a/composer.json b/composer.json @@ -68,7 +68,8 @@ "nfq-alpha/sprite-bundle": "^1.0", "ddeboer/data-import": "@stable", "symfony/property-access": "^2.7", - "sonata-project/exporter": "^1.4" + "sonata-project/exporter": "^1.4", + "knplabs/knp-gaufrette-bundle": "^0.2.0" }, "require-dev": { "phpunit/phpunit": "4.8.*", diff --git a/composer.lock b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9c4f10cbc6134adaf0a2ef4388ce50e8", + "hash": "a8eb88fdebee0215597c2f5662e769fa", "packages": [ { "name": "atelierspierrot/famfamfam-silk-sprite", @@ -1217,7 +1217,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/migrations/zipball/f4f5bdf6cc84011513ca6b582f85330a09a5037b", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/68cc7bf629a7c1fc0696e583cc8ed46f897d0afb", "reference": "d196ddc229f50c66c5a015c158adb78a2dfb4351", "shasum": "" }, @@ -1361,7 +1361,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/7b96ac54a52616309f964bdced38b20ed2d1a66a", + "url": "https://api.github.com/repos/dunglas/DunglasApiBundle/zipball/67c47de48bbc0fce39b67c90a35f5192f1c43da7", "reference": "b30de689f94410c7dc0e449f2ecc15cfa8e70f54", "shasum": "" }, @@ -2109,6 +2109,148 @@ "time": "2014-10-29 13:23:47" }, { + "name": "knplabs/gaufrette", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/Gaufrette.git", + "reference": "9d52413665284f9c96e0cef399fc14e68ac0aa5a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/Gaufrette/zipball/9d52413665284f9c96e0cef399fc14e68ac0aa5a", + "reference": "9d52413665284f9c96e0cef399fc14e68ac0aa5a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "amazonwebservices/aws-sdk-for-php": "1.5.*", + "aws/aws-sdk-php": "~2", + "doctrine/dbal": ">=2.3", + "dropbox-php/dropbox-php": "*", + "google/apiclient": "~1.1", + "herzult/php-ssh": "*", + "microsoft/windowsazure": "dev-master", + "mikey179/vfsstream": "~1.2.0", + "phpseclib/phpseclib": "dev-master", + "phpspec/phpspec": "2.0.*", + "phpunit/phpunit": "3.7.*", + "rackspace/php-opencloud": "1.9.*" + }, + "suggest": { + "amazonwebservices/aws-sdk-for-php": "to use the legacy Amazon S3 adapters", + "aws/aws-sdk-php": "to use the Amazon S3 adapter", + "doctrine/dbal": "to use the Doctrine DBAL adapter", + "dropbox-php/dropbox-php": "to use the Dropbox adapter", + "ext-apc": "to use the APC adapter", + "ext-curl": "*", + "ext-fileinfo": "This extension is used to automatically detect the content-type of a file in the AwsS3, OpenCloud, AzureBlogStorage and GoogleCloudStorage adapters", + "ext-mbstring": "*", + "ext-mongo": "*", + "ext-zip": "to use the Zip adapter", + "google/apiclient": "to use GoogleCloudStorage adapter", + "herzult/php-ssh": "to use SFtp adapter", + "knplabs/knp-gaufrette-bundle": "to use with Symfony2", + "microsoft/windowsazure": "to use Microsoft Azure Blob Storage adapter", + "phpseclib/phpseclib": "to use PhpseclibSftp adapter", + "rackspace/php-opencloud": "to use Opencloud adapter" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Gaufrette": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "The contributors", + "homepage": "http://github.com/knplabs/Gaufrette/contributors" + }, + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + } + ], + "description": "PHP5 library that provides a filesystem abstraction layer", + "homepage": "http://knplabs.com", + "keywords": [ + "abstraction", + "file", + "filesystem", + "media" + ], + "time": "2015-05-26 08:25:40" + }, + { + "name": "knplabs/knp-gaufrette-bundle", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/KnpGaufretteBundle.git", + "reference": "7edea6cfcc4718573f9cbd7bd1adcaf3c2319e8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/KnpGaufretteBundle/zipball/7edea6cfcc4718573f9cbd7bd1adcaf3c2319e8b", + "reference": "7edea6cfcc4718573f9cbd7bd1adcaf3c2319e8b", + "shasum": "" + }, + "require": { + "knplabs/gaufrette": "~0.1.7|0.2.*@dev", + "symfony/framework-bundle": "2.*" + }, + "require-dev": { + "phpunit/phpunit": "~4.2", + "symfony/console": "2.*", + "symfony/yaml": "2.*" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "0.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Bundle\\GaufretteBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "The contributors", + "homepage": "https://github.com/knplabs/KnpGaufretteBundle/contributors" + }, + { + "name": "Antoine Hérault", + "email": "antoine.herault@gmail.com" + } + ], + "description": "Allows to easily use the Gaufrette library in a Symfony project", + "homepage": "http://knplabs.com", + "keywords": [ + "abstraction", + "file", + "filesystem", + "media" + ], + "time": "2015-09-18 12:09:25" + }, + { "name": "kriswallsmith/assetic", "version": "v1.3.0", "source": { @@ -2360,7 +2502,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nelmio/NelmioApiDocBundle/zipball/9af37448fa2f82856d068205afa96e9874527672", + "url": "https://api.github.com/repos/nelmio/NelmioApiDocBundle/zipball/be90e8aad60b7701097b900c4a3a971a50f9862e", "reference": "9af37448fa2f82856d068205afa96e9874527672", "shasum": "" }, @@ -2812,7 +2954,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/5a397dddee79edc15d1f88f421d51603277d8576", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/823f8bca6983d1af99c060ba96fc3ddf647d0589", "reference": "2fb164fd889120a9d9ba19d825e270e5293eecc5", "shasum": "" }, @@ -3380,7 +3522,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/doctrine-bridge/zipball/067bb642fa5f9e42e272e74514803fa8e0a7e3b7", + "url": "https://api.github.com/repos/symfony/doctrine-bridge/zipball/f8d7fcbbe5997942dbce9b9487daeaa4acb3e272", "reference": "e5ed757d6dcd6fd60dde5da8b7cbec2fab7cb48a", "shasum": "" }, @@ -4155,7 +4297,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/codeclimate/php-test-reporter/zipball/85b5de950678a25f3e85adb6bc26de7f7f231d18", + "url": "https://api.github.com/repos/codeclimate/php-test-reporter/zipball/892163d67e3bd9c190d43655acb69657da765c7b", "reference": "85b5de950678a25f3e85adb6bc26de7f7f231d18", "shasum": "" }, diff --git a/src/PartKeepr/UploadedFileBundle/Controller/FileController.php b/src/PartKeepr/UploadedFileBundle/Controller/FileController.php @@ -2,6 +2,7 @@ namespace PartKeepr\UploadedFileBundle\Controller; use Doctrine\ORM\EntityManager; +use Gaufrette\Filesystem; use PartKeepr\UploadedFileBundle\Entity\UploadedFile; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; @@ -9,20 +10,6 @@ use Symfony\Component\HttpFoundation\Response; abstract class FileController extends Controller { /** - * Returns the full path for the file - * - * @param UploadedFile $file - * - * @return string - */ - protected function getFilename(UploadedFile $file) - { - $storageDirectory = $this->get("partkeepr_uploadedfile_service")->getStorageDirectory($file); - - return $storageDirectory."/".$file->getFilename().".".$file->getExtension(); - } - - /** * Returns the mimetype icon for an uploaded file * * @param integer $id The ID of the entity @@ -65,8 +52,10 @@ abstract class FileController extends Controller */ $file = $em->find($this->getEntityClass(), $id); + $storage = $this->get("partkeepr_uploadedfile_service")->getStorage($file); + return new Response( - file_get_contents($this->getFilename($file)), + $storage->read($file->getFullFilename()), 200, array("Content-Type" => $file->getMimeType()) ); diff --git a/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php b/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php @@ -269,4 +269,8 @@ abstract class UploadedFile extends BaseEntity return "undefined"; } } + + public function getFullFilename () { + return $this->getFilename().".".$this->getExtension(); + } } diff --git a/src/PartKeepr/UploadedFileBundle/Services/UploadedFileService.php b/src/PartKeepr/UploadedFileBundle/Services/UploadedFileService.php @@ -3,6 +3,7 @@ namespace PartKeepr\UploadedFileBundle\Services; +use Gaufrette\Filesystem; use PartKeepr\UploadedFileBundle\Entity\UploadedFile; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAware; @@ -44,7 +45,8 @@ class UploadedFileService extends ContainerAware $file->setMimeType($filesystemFile->getMimeType()); $file->setSize($filesystemFile->getSize()); - copy($filesystemFile->getPathname(), $this->getFullPath($file)); + $storage = $this->getStorage($file); + $storage->write($file->getFullFilename(), file_get_contents($filesystemFile->getPathname())); } public function replaceFromData(UploadedFile $file, $data, $filename) @@ -155,4 +157,14 @@ class UploadedFileService extends ContainerAware { return $this->container->getParameter("partkeepr.directories.".$file->getType()); } + + /** + * @param UploadedFile $file + * + * @return Filesystem + */ + public function getStorage (UploadedFile $file) { + $type = strtolower($file->getType()); + return $this->container->get("filesystem_".$type); + } }