* image upload handling
* old static image migrator implementation as cli command * auth id fix, renew works now * templates refactored to work with uploaded images
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Service\AwardeeManager;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
@@ -15,6 +16,7 @@ use JsonSerializable;
|
||||
* @ORM\Index(name="a_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class Awardee implements JsonSerializable
|
||||
{
|
||||
@@ -45,7 +47,7 @@ class Awardee implements JsonSerializable
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="image_label", type="string", length=255, unique=true)
|
||||
* @ORM\Column(name="image_label", type="string", length=255)
|
||||
* @var string
|
||||
*/
|
||||
private $imageLabel;
|
||||
@@ -165,6 +167,51 @@ class Awardee implements JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasProfileImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('%s/%s-profile.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLegacyProfileImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('public/img/awardees/%s.jpg', $this->getSlug()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAwardImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('%s/%s-award.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLegacyAwardImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('public/img/awardees/%s-atadas.jpg', $this->getSlug()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PreRemove
|
||||
*/
|
||||
public function cleanUpImagesBeforeDelete()
|
||||
{
|
||||
if ($this->hasProfileImage()) {
|
||||
unlink(sprintf('%s/%s-profile.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
if ($this->hasAwardImage()) {
|
||||
unlink(sprintf('%s/%s-award.jpg', AwardeeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -177,6 +224,8 @@ class Awardee implements JsonSerializable
|
||||
'text' => $this->getText(),
|
||||
'imageLabel' => $this->getImageLabel(),
|
||||
'slug' => $this->getSlug(),
|
||||
'hasProfileImage' => $this->hasProfileImage(),
|
||||
'hasAwardImage' => $this->hasAwardImage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Service\JudgeManager;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -17,6 +18,7 @@ use JsonSerializable;
|
||||
* @ORM\Index(name="j_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class Judge implements JsonSerializable
|
||||
{
|
||||
@@ -198,6 +200,26 @@ class Judge implements JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasProfileImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('%s/%s.jpg', JudgeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
|
||||
public function hasLegacyProfileImage(): bool
|
||||
{
|
||||
return file_exists(sprintf('public/img/judges/%s.jpg', $this->getSlug()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PreRemove
|
||||
*/
|
||||
public function cleanUpImagesBeforeDelete()
|
||||
{
|
||||
if ($this->hasProfileImage()) {
|
||||
unlink(sprintf('%s/%s.jpg', JudgeManager::IMAGE_DIRECTORY, $this->getId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -209,6 +231,7 @@ class Judge implements JsonSerializable
|
||||
'prefix' => $this->getPrefix(),
|
||||
'titles' => $this->getTitles()->getValues(),
|
||||
'slug' => $this->getSlug(),
|
||||
'hasProfileImage' => $this->hasProfileImage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user