partkeepr

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

commit fce42fc188ca2b9ebb46b71eaf8f0485ffb93618
parent fb7460bab31c56336a4573f12f6b867b4ada7d0d
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri,  3 Jul 2015 15:25:01 +0200

Moved images to their own bundle, implemented temporary image uploads

Diffstat:
Mapp/AppKernel.php | 2+-
Mapp/config/config.yml | 49+++++++++++++++++++++++++++++++++++++++++++++----
Mapp/config/partkeepr.yml | 5+++--
Mapp/config/routing.yml | 5+++++
Msrc/PartKeepr/FootprintBundle/Entity/FootprintImage.php | 2+-
Msrc/PartKeepr/FootprintBundle/Entity/FootprintService.php | 2+-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js | 7++-----
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/ExceptionWindow.js | 10+++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js | 23++++++++++++++---------
Msrc/PartKeepr/ImageBundle/Controller/ImageController.php | 12++++++------
Asrc/PartKeepr/ImageBundle/Controller/TemporaryImageController.php | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/ImageBundle/DependencyInjection/Configuration.php | 1+
Msrc/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php | 1+
Asrc/PartKeepr/ImageBundle/Entity/Image.php | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/PartKeepr/ImageBundle/Entity/TempImage.php | 19+++++++++++++++++++
Asrc/PartKeepr/ImageBundle/Response/TemporaryImageUploadResponse.php | 31+++++++++++++++++++++++++++++++
Msrc/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php | 2+-
Msrc/backend/PartKeepr/Image/CachedImage.php | 1+
Dsrc/backend/PartKeepr/Image/Image.php | 100-------------------------------------------------------------------------------
Msrc/backend/PartKeepr/Part/PartImage.php | 2+-
Msrc/backend/PartKeepr/PartKeepr.php | 4++--
Msrc/backend/PartKeepr/StorageLocation/StorageLocationImage.php | 2+-
Dsrc/backend/PartKeepr/TempImage/TempImage.php | 21---------------------
Msrc/backend/PartKeepr/TempImage/TempImageService.php | 2+-
Msrc/backend/PartKeepr/UploadedFile/UploadedFile.php | 19+++----------------
Msrc/backend/PartKeepr/Util/BaseEntity.php | 2+-
26 files changed, 307 insertions(+), 174 deletions(-)

diff --git a/app/AppKernel.php b/app/AppKernel.php @@ -58,7 +58,7 @@ class AppKernel extends Kernel new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new PartKeepr\DoctrineReflectionBundle\PartKeeprDoctrineReflectionBundle(), new PartKeepr\RESTBundle\PartKeeprRESTBundle(), - new PartKeepr\ApiDocBundle\PartKeeprApiDocBundle(), + //new PartKeepr\ApiDocBundle\PartKeeprApiDocBundle(), new Dunglas\ApiBundle\DunglasApiBundle(), new Brainbits\FugueIconsBundle\BrainbitsFugueIconsBundle(), ); diff --git a/app/config/config.yml b/app/config/config.yml @@ -133,7 +133,7 @@ services: arguments: - { groups: [ "default" ] } - resource.manufacturer_ic_logo.item_operation.custom_put: + resource.manufacturer_ic_logo.item_operation.custom_get: class: "Dunglas\ApiBundle\Api\Operation\Operation" public: false factory: [ "@api.operation_factory", "createItemOperation" ] @@ -166,7 +166,7 @@ services: tags: [ { name: "api.resource" } ] calls: - method: "initItemOperations" - arguments: [ [ "@resource.manufacturer_ic_logo.item_operation.custom_put", "@resource.manufacturer_ic_logo.item_operation.get", "@resource.manufacturer_ic_logo.item_operation.put" ] ] + arguments: [ [ "@resource.manufacturer_ic_logo.item_operation.custom_get", "@resource.manufacturer_ic_logo.item_operation.get", "@resource.manufacturer_ic_logo.item_operation.put" ] ] - method: "initFilters" arguments: [ [ "@resource.order_filter" ] ] - method: "initNormalizationContext" @@ -241,4 +241,45 @@ services: arguments: [ { groups: [ "default" ] } ] - method: "initDenormalizationContext" arguments: - - { groups: [ "default" ] }- \ No newline at end of file + - { groups: [ "default" ] } + + + resource.tempimage.collection_operation.custom_post: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createCollectionOperation" ] + arguments: + - "@resource.tempimage" # Resource + - [ "POST" ] # Methods + - "/temporaryImage/upload" # Path + - "PartKeeprImageBundle:TemporaryImage:upload" # Controller + - "TemporaryImageUpload" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + + resource.tempimage.item_operation.custom_get: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: + - "@resource.tempimage" # Resource + - [ "GET" ] # Methods + - "/temporaryImage/{id}/getImage" # Path + - "PartKeeprImageBundle:TemporaryImage:getImage" # Controller + - "TemporaryImageGet" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + + resource.tempimage: + parent: "api.resource" + arguments: [ "PartKeepr\\ImageBundle\\Entity\\TempImage" ] + tags: [ { name: "api.resource" } ] + calls: + - method: "initCollectionOperations" + arguments: [ [ "@resource.tempimage.collection_operation.custom_post" ] ] + - method: "initItemOperations" + arguments: [ [ "@resource.tempimage.item_operation.custom_get" ] ]+ \ No newline at end of file diff --git a/app/config/partkeepr.yml b/app/config/partkeepr.yml @@ -1,4 +1,5 @@ partkeepr: image_cache_directory: %kernel.cache_dir%/imagecache/ images: - iclogo: %kernel.root_dir%/../data/images/iclogo/- \ No newline at end of file + iclogo: %kernel.root_dir%/../data/images/iclogo/ + temp: %kernel.root_dir%/../data/temp/+ \ No newline at end of file diff --git a/app/config/routing.yml b/app/config/routing.yml @@ -3,6 +3,11 @@ part_keepr_auth: type: annotation prefix: / +PartKeeprImageBundle: + resource: "@PartKeeprImageBundle/Controller/" + type: annotation + prefix: / + NelmioApiDocBundle: resource: "@NelmioApiDocBundle/Resources/config/routing.yml" prefix: /api/doc diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintImage.php b/src/PartKeepr/FootprintBundle/Entity/FootprintImage.php @@ -2,7 +2,7 @@ namespace PartKeepr\FootprintBundle\Entity; use PartKeepr\Util\Serializable, - PartKeepr\Image\Image, + PartKeepr\ImageBundle\Entity\Image, Doctrine\ORM\Mapping as ORM; /** diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintService.php b/src/PartKeepr/FootprintBundle/Entity/FootprintService.php @@ -1,7 +1,7 @@ <?php namespace PartKeepr\FootprintBundle\Entity; -use PartKeepr\TempImage\TempImage, +use PartKeepr\ImageBundle\Entity\TempImage, \PartKeepr\FootprintBundle\Entity\FootprintCategory, PartKeepr\Service\Service, PartKeepr\Service\RestfulService, diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Manufacturer/ManufacturerEditor.js @@ -8,7 +8,7 @@ Ext.define('PartKeepr.ManufacturerEditor', { this.tpl = new Ext.XTemplate( '<tpl for=".">', - '<div class="dataview-multisort-item iclogo"><img src="{[values["@id"]]}?maxwidth=100&maxheight=100"/></div>', + '<div class="dataview-multisort-item iclogo"><img src="{[values["@id"]]}?maxWidth=100&maxHeight=100"/></div>', '</tpl>'); this.addLogoButton = Ext.create("Ext.button.Button", { @@ -100,10 +100,7 @@ Ext.define('PartKeepr.ManufacturerEditor', { this.iclogoGrid.bindStore(record.icLogos()); }, onFileUploaded: function (response) { - this.iclogoGrid.getStore().add({ - id: "TMP:"+response.id, - manufacturer_id: this.record.get("id") - }); + this.iclogoGrid.getStore().add(response); }, uploadImage: function () { var j = Ext.create("PartKeepr.FileUploadDialog", { imageUpload: true }); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/ExceptionWindow.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/ExceptionWindow.js @@ -179,7 +179,15 @@ Ext.define('PartKeepr.ExceptionWindow', { this.backtraceDetails.setValue("No backtrace available"); } - var requestData = response.request.options.method + " " + response.request.options.url; + if (!response.request) { + response.request = {}; + } + + if (response.request && response.request.options && response.request.options.method && response.request.options.url) { + var requestData = response.request.options.method + " " + response.request.options.url; + } else { + var requestData = ""; + } if (response.request.jsonData) { requestData += "\n\n"+response.request.jsonData; diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Dialogs/FileUploadDialog.js @@ -12,7 +12,7 @@ Ext.define('PartKeepr.FileUploadDialog', { initComponent: function () { if (this.imageUpload) { - this.uploadURL = PartKeepr.getBasePath()+"/TempImage"; + this.uploadURL = PartKeepr.getBasePath() + "/api/temporaryImage/upload"; } this.uploadButton = Ext.create("Ext.button.Button", @@ -33,7 +33,6 @@ Ext.define('PartKeepr.FileUploadDialog', { form.submit({ url: this.uploadURL, params: { - call: "upload", session: PartKeepr.getApplication().getSession() }, success: Ext.bind(function(fp, o) { @@ -41,13 +40,19 @@ Ext.define('PartKeepr.FileUploadDialog', { this.close(); },this), failure: function(form, action) { - var data = Ext.decode(action.response.responseText); - - request = { - response: action.response.responseText - }; - - PartKeepr.ExceptionWindow.showException(data.exception, request); + var exception = { + message: i18n("Critical Error"), + detail: i18n("The server returned a response which we were not able to interpret.") + }; + + + var requestData = { options: {}}; + + request = { + responseText: action.response.responseText + }; + + PartKeepr.ExceptionWindow.showException(exception, request); } }); } diff --git a/src/PartKeepr/ImageBundle/Controller/ImageController.php b/src/PartKeepr/ImageBundle/Controller/ImageController.php @@ -2,18 +2,18 @@ namespace PartKeepr\ImageBundle\Controller; use Doctrine\ORM\EntityManager; +use Dunglas\ApiBundle\Controller\ResourceController; use Imagine\Gd\Imagine; use Imagine\Image\Box; use Imagine\Image\Point; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use PartKeepr\Image\CachedImage; -use PartKeepr\Image\Image as PartKeeprImage; +use PartKeepr\ImageBundle\Entity\Image as PartKeeprImage; use PartKeepr\ImageBundle\Response\ImageNotFoundResponse; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -abstract class ImageController extends Controller +abstract class ImageController extends ResourceController { /** * @@ -46,8 +46,8 @@ abstract class ImageController extends Controller return new ImageNotFoundResponse($request->get("width"), $request->get("height")); } - $width = $request->get("width"); - $height = $request->get("height"); + $width = $request->get("maxWidth"); + $height = $request->get("maxHeight"); if ($width == 0) { $width = 200; @@ -129,7 +129,7 @@ abstract class ImageController extends Controller */ public function getFilename(PartKeeprImage $image) { - return realpath($this->getImageStorageDirectory())."/".$image->getPlainFilename().".png"; + return realpath($this->getImageStorageDirectory())."/".$image->getPlainFilename().".".$image->getExtension(); } /** diff --git a/src/PartKeepr/ImageBundle/Controller/TemporaryImageController.php b/src/PartKeepr/ImageBundle/Controller/TemporaryImageController.php @@ -0,0 +1,70 @@ +<?php +namespace PartKeepr\ImageBundle\Controller; + +use Dunglas\ApiBundle\Controller\ResourceController; +use FOS\RestBundle\Controller\Annotations\RequestParam; +use FOS\RestBundle\Controller\Annotations\View; +use FOS\RestBundle\Controller\FOSRestController; +use Nelmio\ApiDocBundle\Annotation\ApiDoc; +use PartKeepr\ImageBundle\Entity\TempImage; +use PartKeepr\ImageBundle\Response\TemporaryImageUploadResponse; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; + +class TemporaryImageController extends ImageController { + + /** + * Handles a temporary image upload + * + * @RequestParam(name="url",description="An URL where the image is located") + * ApiDoc(section="image",output="PartKeepr\ImageBundle\Response\TemporaryImageUploadResponse") + * @View() + */ + public function uploadAction (Request $request) { + $image = new TempImage(); + + if ($request->files->has('userfile') && $request->files->get('userfile') != null) { + $file = $request->files->get('userfile'); + /** + * @var $file UploadedFile + */ + $image->replace($file->getPathname()); + $image->setOriginalFilename($file->getClientOriginalName()); + } elseif ($request->request->has("url")) { + $image->replaceFromURL($request->request->get("url")); + } else { + throw new \Exception("Error: No valid file given"); + } + + $this->getDoctrine()->getManager()->persist($image); + $this->getDoctrine()->getManager()->flush(); + + $resource = $this->getResource($request); + $serializedData = $this->get('serializer')->normalize( + $image, + 'json-ld', + $resource->getNormalizationContext() + ); + + return new JsonResponse(new TemporaryImageUploadResponse($serializedData)); + } + + /** + * @inheritdoc + */ + public function getImageStorageDirectory() + { + return $this->container->getParameter("partkeepr.images.temp"); + } + + /** + * @inheritdoc + */ + public function getEntityClass() + { + return "PartKeepr\\ImageBundle\\Entity\\TempImage"; + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/ImageBundle/DependencyInjection/Configuration.php b/src/PartKeepr/ImageBundle/DependencyInjection/Configuration.php @@ -27,6 +27,7 @@ class Configuration implements ConfigurationInterface ->addDefaultsIfNotSet() ->children() ->scalarNode('iclogo')->defaultValue('%kernel.root_dir%/../data/images/iclogo/')->cannotBeEmpty()->info('The directory which contains the uploaded ic logos')->end() + ->scalarNode('temp')->defaultValue('%kernel.root_dir%/../data/temp/')->cannotBeEmpty()->info('The directory which contains the temporary images')->end() ->end() ->end() ->end(); diff --git a/src/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php b/src/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php @@ -16,6 +16,7 @@ class PartKeeprExtension extends Extension $container->setParameter('partkeepr.image_cache_directory', $config['image_cache_directory']); $container->setParameter('partkeepr.images.iclogo', $config['images']['iclogo']); + $container->setParameter('partkeepr.images.temp', $config['images']['temp']); } public function getAlias () { diff --git a/src/PartKeepr/ImageBundle/Entity/Image.php b/src/PartKeepr/ImageBundle/Entity/Image.php @@ -0,0 +1,85 @@ +<?php +namespace PartKeepr\ImageBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\Image\CachedImage; +use PartKeepr\Image\Exceptions\InvalidImageTypeException; +use PartKeepr\Image\ImageRenderer; +use PartKeepr\Image\RenderableImage; +use PartKeepr\ImageBundle\Entity\TempImage; +use PartKeepr\UploadedFile\UploadedFile; + +/** + * This is only a storage class; actual image rendering is done by the ImageRenderer. + * + * @ORM\MappedSuperclass + */ +abstract class Image extends UploadedFile { + const IMAGE_ICLOGO = "iclogo"; + const IMAGE_TEMP = "temp"; + const IMAGE_PART = "part"; + const IMAGE_STORAGELOCATION = "storagelocation"; + const IMAGE_FOOTPRINT = "footprint"; + + /** + * Constructs a new image object. + * + * @param string $type The type for the image, one of the IMAGE_ constants. + */ + public function __construct ($type = NULL) { + parent::__construct(); + $this->setType($type); + } + + /** + * Sets the type of the image. Once the type is set, + * it may not be changed later. + * + * @param string $type The type for the image, one of the IMAGE_ constants. + * @throws InvalidImageTypeException + */ + protected function setType ($type) { + switch ($type) { + case Image::IMAGE_ICLOGO: + case Image::IMAGE_TEMP: + case Image::IMAGE_PART: + case Image::IMAGE_FOOTPRINT: + case Image::IMAGE_STORAGELOCATION: + parent::setType($type); + break; + default: + throw new InvalidImageTypeException($type); + } + } + + /** + * Replaces the current image with a new image. + * + * Automatically converts from one format to PNG, + * which is the default when dealing with images + * on the platform. + * + * @param string $path The path to the original image + */ + public function replace ($path) { + parent::replace($path); + + CachedImage::invalidate($this); + } + + /** + * Replaces the file with a given temporary file. + * @param string $id The temporary id (prefixed with TMP:) + */ + public function replaceFromTemporaryFile ($id) { + if (substr($id, 0, 4) === "TMP:") { + $tmpFileId = str_replace("TMP:", "", $id); + $tmpFile = TempImage::loadById($tmpFileId); + + $this->replace($tmpFile->getFilename()); + $this->setOriginalFilename($tmpFile->getOriginalFilename()); + + } + } + +}+ \ No newline at end of file diff --git a/src/PartKeepr/ImageBundle/Entity/TempImage.php b/src/PartKeepr/ImageBundle/Entity/TempImage.php @@ -0,0 +1,18 @@ +<?php +namespace PartKeepr\ImageBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\ImageBundle\Entity\Image; +use PartKeepr\UploadedFile\UploadedFile; + +/** + * Represents a temporary image. Temporary images are used when + * a user uploaded an image, but not attached it to an entity. + * + * @ORM\Entity + */ +class TempImage extends Image { + public function __construct () { + parent::__construct(Image::IMAGE_TEMP); + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/ImageBundle/Response/TemporaryImageUploadResponse.php b/src/PartKeepr/ImageBundle/Response/TemporaryImageUploadResponse.php @@ -0,0 +1,30 @@ +<?php +namespace PartKeepr\ImageBundle\Response; + + +use PartKeepr\ImageBundle\Entity\TempImage; + +class TemporaryImageUploadResponse +{ + /** + * The success property. This is required for ExtJS. + * @var bool + */ + public $success = true; + + /** + * @var object + */ + public $image; + + /** + * Legacy response for ExtJS forms + */ + public $response; + + public function __construct ($image) { + $this->image = $image; + $this->response = $image; + } + +}+ \ No newline at end of file diff --git a/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php b/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php @@ -2,7 +2,7 @@ namespace PartKeepr\ManufacturerBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use PartKeepr\Image\Image; +use PartKeepr\ImageBundle\Entity\Image; use PartKeepr\Util\Deserializable; use PartKeepr\Util\Serializable; diff --git a/src/backend/PartKeepr/Image/CachedImage.php b/src/backend/PartKeepr/Image/CachedImage.php @@ -1,6 +1,7 @@ <?php namespace PartKeepr\Image; +use PartKeepr\ImageBundle\Entity\Image; use PartKeepr\PartKeepr, Doctrine\ORM\Mapping as ORM; diff --git a/src/backend/PartKeepr/Image/Image.php b/src/backend/PartKeepr/Image/Image.php @@ -1,99 +0,0 @@ -<?php -namespace PartKeepr\Image; - -use Doctrine\ORM\Mapping as ORM; -use PartKeepr\Image\Exceptions\InvalidImageTypeException; -use PartKeepr\TempImage\TempImage; -use PartKeepr\UploadedFile\UploadedFile; - -/** - * This is only a storage class; actual image rendering is done by the ImageRenderer. - * - * @ORM\MappedSuperclass - */ -abstract class Image extends UploadedFile implements RenderableImage { - const IMAGE_ICLOGO = "iclogo"; - const IMAGE_TEMP = "temp"; - const IMAGE_PART = "part"; - const IMAGE_STORAGELOCATION = "storagelocation"; - const IMAGE_FOOTPRINT = "footprint"; - - /** - * Holds the image renderer - * @var object - */ - private $renderer; - - /** - * Constructs a new image object. - * - * @param string $type The type for the image, one of the IMAGE_ constants. - */ - public function __construct ($type) { - parent::__construct(); - $this->setType($type); - } - - /** - * Sets the type of the image. Once the type is set, - * it may not be changed later. - * - * @param string $type The type for the image, one of the IMAGE_ constants. - * @throws InvalidImageTypeException - */ - protected function setType ($type) { - switch ($type) { - case Image::IMAGE_ICLOGO: - case Image::IMAGE_TEMP: - case Image::IMAGE_PART: - case Image::IMAGE_FOOTPRINT: - case Image::IMAGE_STORAGELOCATION: - parent::setType($type); - break; - default: - throw new InvalidImageTypeException($type); - } - } - - /** - * Returns the renderer for image manipulations - * @return object - */ - public function getRenderer () { - if (!$this->renderer instanceof ImageRenderer) { - $this->renderer = new ImageRenderer($this); - } - - return $this->renderer; - } - /** - * Replaces the current image with a new image. - * - * Automatically converts from one format to PNG, - * which is the default when dealing with images - * on the platform. - * - * @param string $path The path to the original image - */ - public function replace ($path) { - parent::replace($path); - - CachedImage::invalidate($this); - } - - /** - * Replaces the file with a given temporary file. - * @param string $id The temporary id (prefixed with TMP:) - */ - public function replaceFromTemporaryFile ($id) { - if (substr($id, 0, 4) === "TMP:") { - $tmpFileId = str_replace("TMP:", "", $id); - $tmpFile = TempImage::loadById($tmpFileId); - - $this->replace($tmpFile->getFilename()); - $this->setOriginalFilename($tmpFile->getOriginalFilename()); - - } - } - -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/Part/PartImage.php b/src/backend/PartKeepr/Part/PartImage.php @@ -2,7 +2,7 @@ namespace PartKeepr\Part; use PartKeepr\Util\Serializable, - PartKeepr\Image\Image, + PartKeepr\ImageBundle\Entity\Image, Doctrine\ORM\Mapping as ORM; /** diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php @@ -185,9 +185,9 @@ class PartKeepr { 'PartKeepr\DistributorBundle\Entity\Distributor', - 'PartKeepr\Image\Image', + 'PartKeepr\ImageBundle\Entity\Image', 'PartKeepr\Image\CachedImage', - 'PartKeepr\TempImage\TempImage', + 'PartKeepr\ImageBundle\Entity\TempImage', 'PartKeepr\UploadedFile\TempUploadedFile', diff --git a/src/backend/PartKeepr/StorageLocation/StorageLocationImage.php b/src/backend/PartKeepr/StorageLocation/StorageLocationImage.php @@ -2,7 +2,7 @@ namespace PartKeepr\StorageLocation; use PartKeepr\Util\Serializable, - PartKeepr\Image\Image, + PartKeepr\ImageBundle\Entity\Image, Doctrine\ORM\Mapping as ORM; /** diff --git a/src/backend/PartKeepr/TempImage/TempImage.php b/src/backend/PartKeepr/TempImage/TempImage.php @@ -1,20 +0,0 @@ -<?php -namespace PartKeepr\TempImage; - -use PartKeepr\Image\Exceptions\InvalidImageTypeException, - PartKeepr\Util\Configuration, - PartKeepr\Image\Image, - PartKeepr\PartKeepr, - Doctrine\ORM\Mapping as ORM; - -/** - * Represents a temporary image. Temporary images are used when - * a user uploaded an image, but not attached it to an entity. - * - * @ORM\Entity - */ -class TempImage extends Image { - public function __construct () { - parent::__construct(Image::IMAGE_TEMP); - } -}- \ No newline at end of file diff --git a/src/backend/PartKeepr/TempImage/TempImageService.php b/src/backend/PartKeepr/TempImage/TempImageService.php @@ -2,7 +2,7 @@ namespace PartKeepr\TempImage; use PartKeepr\Service\Service; -use PartKeepr\TempImage\TempImage; +use PartKeepr\ImageBundle\Entity\TempImage; use PartKeepr\PartKeepr; class TempImageService extends Service { diff --git a/src/backend/PartKeepr/UploadedFile/UploadedFile.php b/src/backend/PartKeepr/UploadedFile/UploadedFile.php @@ -13,7 +13,7 @@ use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\MappedSuperclass */ -abstract class UploadedFile extends BaseEntity implements Serializable { +abstract class UploadedFile extends BaseEntity { /** * Specifies the type of the file. * @@ -128,7 +128,7 @@ abstract class UploadedFile extends BaseEntity implements Serializable { * Credit goes to Ryan Rampersad from whom I copied most code. * http://blog.ryanrampersad.com/2008/11/07/get-remote-html-with-curl-and-php/ */ - $curl = curl_init(); + $curl = \curl_init(); $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; @@ -150,7 +150,7 @@ abstract class UploadedFile extends BaseEntity implements Serializable { curl_setopt($curl, CURLOPT_MAXREDIRS, 7); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - $data = curl_exec($curl); + $data = \curl_exec($curl); if ($data === false) { $curlError = curl_error($curl); @@ -308,17 +308,4 @@ abstract class UploadedFile extends BaseEntity implements Serializable { sprintf(PartKeepr::i18n("Unable to write to directory %s"), $this->getFilePath())); } } - - /** - * (non-PHPdoc) - * @see PartKeepr\Util.Serializable::serialize() - */ - public function serialize () { - return array( - "id" => $this->getId(), - "extension" => $this->getExtension(), - "size" => $this->getSize(), - "originalFilename" => $this->getOriginalFilename() - ); - } } diff --git a/src/backend/PartKeepr/Util/BaseEntity.php b/src/backend/PartKeepr/Util/BaseEntity.php @@ -4,7 +4,7 @@ namespace PartKeepr\Util; use Doctrine\ORM\Mapping as ORM; /** @ORM\MappedSuperclass */ -class BaseEntity { +abstract class BaseEntity { /** * @ORM\Id @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO")