partkeepr

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

commit b538aa126eda776685d4c0a21fc917da2f676d1d
parent b062928a078443667d0c6ce7ed02f6e5d203a572
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 18 Jul 2015 01:10:42 +0200

Moved description property to UploadedFile

Diffstat:
Msrc/PartKeepr/FootprintBundle/Entity/FootprintAttachment.php | 32+-------------------------------
Msrc/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php | 30+++++++++++++++++++++++++++++-
Msrc/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php | 1+
Msrc/backend/PartKeepr/Part/PartAttachment.php | 227+++++++++++++++++++------------------------------------------------------------
Msrc/backend/PartKeepr/Project/ProjectAttachment.php | 131++++++++++++++++++++++++-------------------------------------------------------
5 files changed, 123 insertions(+), 298 deletions(-)

diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintAttachment.php b/src/PartKeepr/FootprintBundle/Entity/FootprintAttachment.php @@ -3,7 +3,6 @@ namespace PartKeepr\FootprintBundle\Entity; use Doctrine\ORM\Mapping as ORM; use PartKeepr\UploadedFileBundle\Entity\UploadedFile; -use Symfony\Component\Serializer\Annotation\Groups; /** * Holds a footprint attachment @@ -13,14 +12,6 @@ use Symfony\Component\Serializer\Annotation\Groups; class FootprintAttachment extends UploadedFile { /** - * The description of this attachment - * @ORM\Column(type="text") - * @Groups({"default"}) - * @var string - */ - private $description; - - /** * Creates a new footprint attachment */ public function __construct() @@ -56,24 +47,4 @@ class FootprintAttachment extends UploadedFile { return $this->footprint; } - - /** - * Sets the description for this attachment - * - * @param string $description The attachment description - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * Returns the description for this attachment - * - * @return string The description - */ - public function getDescription() - { - return $this->description; - } -}- \ No newline at end of file +} diff --git a/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php b/src/PartKeepr/UploadedFileBundle/Entity/UploadedFile.php @@ -62,13 +62,21 @@ abstract class UploadedFile extends BaseEntity /** * Holds the extension of the given file - * @ORM\Column(type="string") + * @ORM\Column(type="string",nullable=true) * @Groups({"default"}) * * @var string */ private $extension; + /** + * The description of this attachment + * @ORM\Column(type="text") + * @Groups({"default"}) + * @var string + */ + private $description; + public function __construct() { $this->filename = Uuid::uuid1()->toString(); @@ -193,6 +201,26 @@ abstract class UploadedFile extends BaseEntity } /** + * Sets the description for this attachment + * + * @param string $description The attachment description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * Returns the description for this attachment + * + * @return string The description + */ + public function getDescription() + { + return $this->description; + } + + /** * Returns the extension for the given mime type. * * This function simply extracts that information from the mime type; diff --git a/src/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php b/src/PartKeepr/UploadedFileBundle/EventListener/TemporaryFileEventListener.php @@ -75,6 +75,7 @@ class TemporaryFileEventListener $this->uploadedFileService->replaceFromUploadedFile($newFile, $item); $newFile->setOriginalFilename($item->getOriginalFilename()); + $newFile->setDescription($item->getDescription()); // Find the setter for the association $inverseSideReflection = new \ReflectionClass($newFile); diff --git a/src/backend/PartKeepr/Part/PartAttachment.php b/src/backend/PartKeepr/Part/PartAttachment.php @@ -1,190 +1,70 @@ <?php namespace PartKeepr\Part; -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\UploadedFileBundle\Entity\UploadedFile, - Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\UploadedFileBundle\Entity\UploadedFile; /** * Holds a part attachment + * * @ORM\Entity **/ -class PartAttachment extends UploadedFile implements Serializable, Deserializable { - /** - * The description of this attachment - * @ORM\Column(type="text") - * @var string - */ - private $description; - - /** - * Defines if the attachment is an image. - * @ORM\Column(type="boolean",nullable=true) - * @var boolean - */ - private $isImage; - - /** - * Creates a new part attachment - */ - public function __construct () { - parent::__construct(); - $this->setType("PartAttachment"); - $this->isImage = null; - } - - /** - * The part object - * @ORM\ManyToOne(targetEntity="PartKeepr\Part\Part", inversedBy="attachments") - * @var Part - */ - private $part = null; - - /** - * Sets the part - * @param Part $part The part to set - */ - public function setPart (Part $part) { - $this->part = $part; - } - - /** - * Returns the part - * @return Part the part - */ - public function getPart () { - return $this->part; - } - - /** - * Sets the description for this attachment - * @param string $description The attachment description - */ - public function setDescription ($description) { - $this->description = $description; - } - - /** - * Returns the description for this attachment - * @return string The description - */ - public function getDescription () { - return $this->description; - } - - /** - * - * Serializes this part attachment - * @return array The serialized part attachment - */ - public function serialize () { - return array( - "id" => $this->getId(), - "part_id" => $this->getPart()->getId(), - "originalFilename" => $this->getOriginalFilename(), - "mimetype" => $this->getMimetype(), - "extension" => $this->getExtension(), - "size" => $this->getSize(), - "description" => $this->getDescription(), - "image" => $this->isImage()); - } +class PartAttachment extends UploadedFile +{ + /** + * Defines if the attachment is an image. + * @ORM\Column(type="boolean",nullable=true) + * + * @var boolean + */ + private $isImage; - /** - * Deserializes the part attachment - * @param array $parameters The array with the parameters to set - */ - public function deserialize (array $parameters) { - if (array_key_exists("id", $parameters)) { - if (substr($parameters["id"], 0, 4) === "TMP:") { - $this->replaceFromTemporaryFile($parameters["id"]); - } else { - // In case the part has been copied, the ID doesn't match. In that case we copy the attachment - if (intval($this->getId()) != intval($parameters["id"])) { - $otherAttachment = PartAttachment::loadById($parameters["id"]); - $this->replace($otherAttachment->getFilename()); - $this->setOriginalFilename($otherAttachment->getOriginalFilename()); - } - } - } + /** + * Creates a new part attachment + */ + public function __construct() + { + parent::__construct(); + $this->setType("PartAttachment"); + $this->isImage = null; + } - foreach ($parameters as $key => $value) { - switch ($key) { - case "description": - $this->setDescription($value); - break; - } - } - } - - /** - * Returns if the attachment is an image or not. - * - * @return True if the attachment is an image, false otherwise - */ - public function isImage () { - if ($this->isImage === null) { - $this->isImage = $this->canImagickParseImage(); - } - - return $this->isImage; - } - - /** - * Checks if ImageMagick can parse the image. - * - * This method uses ImageMagick to find out if this is an image. Limitations apply; if ImageMagick doesn't support - * the image format, this method would return false, even if it is an image. - * - * @return boolean true if ImageMagick can parse the file, false otherwise - */ - private function canImagickParseImage () { - /** - * Special case: Check if it's a PDF. If yes, return immediately. - * This is because ImageMagick outputs warning messages for malformed PDF files, and halts the execution - * of the script for several seconds. DO NOT REMOVE! - */ - if ($this->getMimeType() == "application/pdf") { - return false; - } - - try { - $im = new \Imagick($this->getFilename()); - return true; - } catch (\ImagickException $e) { - return false; - } - } - - /** - * Replaces the current file with a new file. - * - * @param string $path The path to the original file - */ - public function replace ($path) { - parent::replace($path); - $this->isImage = $this->canImagickParseImage(); - } - - /** - * Replaces the file from an URL. Does some tricks to avoid 403 forbidden on some sites. - * @param string $url - */ - public function replaceFromURL ($url) { - parent::replaceFromURL($url); - $this->isImage = $this->canImagickParseImage(); - } + /** + * The part object + * @ORM\ManyToOne(targetEntity="PartKeepr\Part\Part", inversedBy="attachments") + * + * @var Part + */ + private $part = null; /** - * Replaces the file with a given temporary file. + * Sets the part * - * Additionally checks if the attachment is an image and flags the attachment as such. + * @param Part $part The part to set + */ + public function setPart(Part $part) + { + $this->part = $part; + } + + /** + * Returns the part * - * @param string $id The temporary id (prefixed with TMP:) + * @return Part the part */ - public function replaceFromTemporaryFile ($id) { - parent::replaceFromTemporaryFile($id); + public function getPart() + { + return $this->part; + } - $this->isImage = $this->canImagickParseImage(); + /** + * Returns if the attachment is an image or not. + * + * @return True if the attachment is an image, false otherwise + */ + public function isImage() + { + //@todo: Reimplement check if attachment is an image + return false; } -}- \ No newline at end of file +} diff --git a/src/backend/PartKeepr/Project/ProjectAttachment.php b/src/backend/PartKeepr/Project/ProjectAttachment.php @@ -1,102 +1,50 @@ <?php namespace PartKeepr\Project; -use PartKeepr\Util\Deserializable, - PartKeepr\Util\Serializable, - PartKeepr\UploadedFileBundle\Entity\UploadedFile, - Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping as ORM; +use PartKeepr\UploadedFileBundle\Entity\UploadedFile; /** * Holds a project attachment + * * @ORM\Entity **/ -class ProjectAttachment extends UploadedFile implements Serializable, Deserializable { - /** - * The description of this attachment - * @ORM\Column(type="text") - * @var string - */ - private $description; - - /** - * Creates a new project attachment - */ - public function __construct () { - parent::__construct(); - $this->setType("ProjectAttachment"); - } - /** - * The project object - * @ORM\ManyToOne(targetEntity="PartKeepr\Project\Project", inversedBy="attachments") - * @var Project - */ - private $project = null; +class ProjectAttachment extends UploadedFile +{ + /** + * Creates a new project attachment + */ + public function __construct() + { + parent::__construct(); + $this->setType("ProjectAttachment"); + } - /** - * Sets the project - * @param Project $project The project to set - */ - public function setProject (Project $project) { - $this->project = $project; - } + /** + * The project object + * @ORM\ManyToOne(targetEntity="PartKeepr\Project\Project", inversedBy="attachments") + * + * @var Project + */ + private $project = null; - /** - * Returns the roject - * @return Project the project - */ - public function getProject () { - return $this->project; - } - - /** - * Sets the description for this attachment - * @param string $description The attachment description - */ - public function setDescription ($description) { - $this->description = $description; - } - - /** - * Returns the description for this attachment - * @return string The description - */ - public function getDescription () { - return $this->description; - } + /** + * Sets the project + * + * @param Project $project The project to set + */ + public function setProject(Project $project) + { + $this->project = $project; + } - /** - * - * Serializes this project attachment - * @return array The serialized project attachment - */ - public function serialize () { - return array( - "id" => $this->getId(), - "project_id" => $this->getProject()->getId(), - "originalFilename" => $this->getOriginalFilename(), - "mimetype" => $this->getMimetype(), - "extension" => $this->getExtension(), - "size" => $this->getSize(), - "description" => $this->getDescription()); - } - - /** - * Deserializes the project attachment - * @param array $parameters The array with the parameters to set - */ - public function deserialize (array $parameters) { - if (array_key_exists("id", $parameters)) { - if (substr($parameters["id"], 0, 4) === "TMP:") { - $this->replaceFromTemporaryFile($parameters["id"]); - } - } - - foreach ($parameters as $key => $value) { - switch ($key) { - case "description": - $this->setDescription($value); - break; - } - } - } -}- \ No newline at end of file + /** + * Returns the roject + * + * @return Project the project + */ + public function getProject() + { + return $this->project; + } +}