From 531e3600eadd3d9e79d5f2b4b19d762ba60ec40a Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sun, 14 Jan 2024 22:32:47 -0600 Subject: [PATCH] Convert some constants to enums --- README.md | 4 + lib/Artist.php | 2 +- lib/Artwork.php | 70 ++++--- lib/ArtworkStatus.php | 7 + lib/Constants.php | 20 +- ...rtworkImageDimensionsTooSmallException.php | 2 +- lib/Exceptions/TooManyTagsException.php | 2 +- scripts/upsert-to-cover-art-database | 172 ------------------ templates/ArtworkList.php | 2 +- templates/ArtworkStatus.php | 8 +- www/artworks/get.php | 10 +- www/artworks/index.php | 20 +- www/artworks/new.php | 12 +- www/artworks/post.php | 10 +- 14 files changed, 93 insertions(+), 248 deletions(-) create mode 100644 lib/ArtworkStatus.php delete mode 100755 scripts/upsert-to-cover-art-database diff --git a/README.md b/README.md index cd6e5a5a..390d9b86 100644 --- a/README.md +++ b/README.md @@ -134,12 +134,16 @@ Before submitting design contributions, please discuss them with the Standard Eb - Finding a self-hosted replacement for GitHub, like possibly [Gitea](https://gitea.io/) or [GitLab](https://about.gitlab.com/), and figuring out how to reproducably install and update it on the SE server. +- Converting some constants to enums, like `SORT_*` or `SOURCE_*`. + ### Artwork database - Allow submitter or admins to edit unapproved artwork submissions. Approved/in use submissions should not be editable by anyone. - Include in-use ebook slug as a search parameter when searching for artwork by keyword. +- Remove `in_use` status for an artwork; instead, an artwork with an `EbookWwwFilesystemPath` that is not `null` should be considered to be "in use" regardless of its `Status`. + ## PHP code style - Indent with tabs. diff --git a/lib/Artist.php b/lib/Artist.php index 4f045ca4..9cc033d6 100644 --- a/lib/Artist.php +++ b/lib/Artist.php @@ -64,7 +64,7 @@ class Artist extends PropertiesBase{ $error->Add(new Exceptions\ArtistNameRequiredException()); } - if($this->Name !== null && strlen($this->Name) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if($this->Name !== null && strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Artist Name')); } diff --git a/lib/Artwork.php b/lib/Artwork.php index 2ffae717..62495ea5 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -20,6 +20,7 @@ use function Safe\preg_replace; * @property string $ThumbUrl * @property string $Thumb2xUrl * @property string $Dimensions + * @property ArtworkStatus|string|null $Status * @property Ebook $Ebook * @property Museum $Museum * @property User $Submitter @@ -35,7 +36,6 @@ class Artwork extends PropertiesBase{ public bool $CompletedYearIsCirca = false; public ?DateTime $Created = null; public ?DateTime $Updated = null; - public ?string $Status = null; public ?string $EbookWwwFilesystemPath = null; public ?int $SubmitterUserId = null; public ?int $ReviewerUserId = null; @@ -60,6 +60,7 @@ class Artwork extends PropertiesBase{ protected ?User $_Submitter = null; protected ?User $_Reviewer = null; protected ?ImageMimeType $_MimeType = null; + protected ?ArtworkStatus $_Status = null; // ******* // SETTERS @@ -68,7 +69,7 @@ class Artwork extends PropertiesBase{ /** * @param string|null|array $tags */ - protected function SetTags(string|array|null $tags): void{ + protected function SetTags(null|string|array $tags): void{ if($tags === null || is_array($tags)){ $this->_Tags = $tags; } @@ -85,6 +86,30 @@ class Artwork extends PropertiesBase{ } } + protected function SetStatus(null|string|ArtworkStatus $status): void{ + if($status instanceof ArtworkStatus){ + $this->_Status = $status; + } + elseif($status === null){ + $this->_Status = null; + } + else{ + $this->_Status = ArtworkStatus::from($status); + } + } + + protected function SetMimeType(null|string|ImageMimeType $mimeType): void{ + if($mimeType instanceof ImageMimeType){ + $this->_MimeType = $mimeType; + } + elseif($mimeType === null){ + $this->_MimeType = null; + } + else{ + $this->_MimeType = ImageMimeType::tryFrom($mimeType); + } + } + // ******* // GETTERS // ******* @@ -235,15 +260,6 @@ class Artwork extends PropertiesBase{ return $this->_Ebook; } - protected function SetMimeType(null|string|ImageMimeType $mimeType): void{ - if(is_string($mimeType)){ - $this->_MimeType = ImageMimeType::tryFrom($mimeType); - } - else{ - $this->_MimeType = $mimeType; - } - } - // ******* // METHODS // ******* @@ -277,7 +293,7 @@ class Artwork extends PropertiesBase{ $error->Add(new Exceptions\ArtworkNameRequiredException()); } - if($this->Name !== null && strlen($this->Name) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if($this->Name !== null && strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Artwork Name')); } @@ -293,33 +309,33 @@ class Artwork extends PropertiesBase{ $error->Add(new Exceptions\InvalidPublicationYearException()); } - if($this->Status !== null && !in_array($this->Status, [COVER_ARTWORK_STATUS_UNVERIFIED, COVER_ARTWORK_STATUS_APPROVED, COVER_ARTWORK_STATUS_DECLINED, COVER_ARTWORK_STATUS_IN_USE])){ + if($this->Status === null){ $error->Add(new Exceptions\InvalidArtworkException('Invalid status.')); } - if($this->Status === COVER_ARTWORK_STATUS_IN_USE && $this->EbookWwwFilesystemPath === null){ + if($this->Status == ArtworkStatus::InUse && $this->EbookWwwFilesystemPath === null){ $error->Add(new Exceptions\MissingEbookException()); } if(count($this->Tags) == 0){ // In-use artwork doesn't have user-provided tags. - if($this->Status !== COVER_ARTWORK_STATUS_IN_USE){ + if($this->Status != ArtworkStatus::InUse){ $error->Add(new Exceptions\TagsRequiredException()); } } - if(count($this->Tags) > COVER_ARTWORK_MAX_TAGS){ + if(count($this->Tags) > ARTWORK_MAX_TAGS){ $error->Add(new Exceptions\TooManyTagsException()); } foreach($this->Tags as $tag){ - if(strlen($tag->Name) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if(strlen($tag->Name) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Artwork Tag: '. $tag->Name)); } } if($this->MuseumUrl !== null){ - if(strlen($this->MuseumUrl) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if(strlen($this->MuseumUrl) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Link to an approved museum page')); } @@ -333,7 +349,7 @@ class Artwork extends PropertiesBase{ } if($this->PublicationYearPageUrl !== null){ - if(strlen($this->PublicationYearPageUrl) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if(strlen($this->PublicationYearPageUrl) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Link to page with year of publication')); } @@ -351,7 +367,7 @@ class Artwork extends PropertiesBase{ } if($this->CopyrightPageUrl !== null){ - if(strlen($this->CopyrightPageUrl) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if(strlen($this->CopyrightPageUrl) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Link to page with copyright details')); } @@ -369,7 +385,7 @@ class Artwork extends PropertiesBase{ } if($this->ArtworkPageUrl !== null){ - if(strlen($this->ArtworkPageUrl) > COVER_ARTWORK_MAX_STRING_LENGTH){ + if(strlen($this->ArtworkPageUrl) > ARTWORK_MAX_STRING_LENGTH){ $error->Add(new Exceptions\StringTooLongException('Link to page with artwork')); } @@ -437,7 +453,7 @@ class Artwork extends PropertiesBase{ // Check for minimum dimensions list($imageWidth, $imageHeight) = getimagesize($uploadedFile['tmp_name']); - if(!$imageWidth || !$imageHeight || $imageWidth < COVER_ARTWORK_IMAGE_MINIMUM_WIDTH || $imageHeight < COVER_ARTWORK_IMAGE_MINIMUM_HEIGHT){ + if(!$imageWidth || !$imageHeight || $imageWidth < ARTWORK_IMAGE_MINIMUM_WIDTH || $imageHeight < ARTWORK_IMAGE_MINIMUM_HEIGHT){ $error->Add(new Exceptions\ArtworkImageDimensionsTooSmallException()); } } @@ -624,8 +640,8 @@ class Artwork extends PropertiesBase{ // Generate the thumbnails try{ $image = new Image($imageUploadPath); - $image->Resize(WEB_ROOT . $this->ThumbUrl, COVER_THUMBNAIL_WIDTH, COVER_THUMBNAIL_HEIGHT); - $image->Resize(WEB_ROOT . $this->Thumb2xUrl, COVER_THUMBNAIL_WIDTH * 2, COVER_THUMBNAIL_HEIGHT * 2); + $image->Resize(WEB_ROOT . $this->ThumbUrl, ARTWORK_THUMBNAIL_WIDTH, ARTWORK_THUMBNAIL_HEIGHT); + $image->Resize(WEB_ROOT . $this->Thumb2xUrl, ARTWORK_THUMBNAIL_WIDTH * 2, ARTWORK_THUMBNAIL_HEIGHT * 2); } catch(\Safe\Exceptions\FilesystemException | \Safe\Exceptions\ImageException){ throw new Exceptions\InvalidImageUploadException('Failed to generate thumbnail.'); @@ -669,12 +685,6 @@ class Artwork extends PropertiesBase{ ); } - public function MarkInUse(string $ebookWwwFilesystemPath): void{ - $this->EbookWwwFilesystemPath = $ebookWwwFilesystemPath; - $this->Status = COVER_ARTWORK_STATUS_IN_USE; - $this->Save(); - } - public function Delete(): void{ Db::Query(' DELETE diff --git a/lib/ArtworkStatus.php b/lib/ArtworkStatus.php new file mode 100644 index 00000000..2bcfe8cc --- /dev/null +++ b/lib/ArtworkStatus.php @@ -0,0 +1,7 @@ +format('Y')) - 96); define('PD_STRING', 'January 1, ' . (PD_YEAR + 1)); -define('DONATION_HOLIDAY_ALERT_ON', $now > new DateTime('November 15, ' . $now->format('Y'), new DateTimeZone('UTC')) || $now < new DateTime('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y'), new DateTimeZone('UTC'))); +define('DONATION_HOLIDAY_ALERT_ON', $now > new DateTime('November 15, ' . $now->format('Y'), new DateTimeZone('UTC')) || $now < new DateTime('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y'), new DateTimeZone('UTC'))); define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2); // Controls the progress bar donation dialog diff --git a/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php b/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php index 3dae3f4c..a88172d6 100644 --- a/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php +++ b/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php @@ -6,6 +6,6 @@ class ArtworkImageDimensionsTooSmallException extends AppException{ // This has to be initialized in a constructor because we use the number_format() function. public function __construct(){ - $this->message = 'Image dimensions are too small. The minimum image size is ' . number_format(COVER_ARTWORK_IMAGE_MINIMUM_WIDTH) . ' × ' . number_format(COVER_ARTWORK_IMAGE_MINIMUM_HEIGHT) . '.'; + $this->message = 'Image dimensions are too small. The minimum image size is ' . number_format(ARTWORK_IMAGE_MINIMUM_WIDTH) . ' × ' . number_format(ARTWORK_IMAGE_MINIMUM_HEIGHT) . '.'; } } diff --git a/lib/Exceptions/TooManyTagsException.php b/lib/Exceptions/TooManyTagsException.php index 1b182f79..c1561ffc 100644 --- a/lib/Exceptions/TooManyTagsException.php +++ b/lib/Exceptions/TooManyTagsException.php @@ -2,5 +2,5 @@ namespace Exceptions; class TooManyTagsException extends AppException{ - protected $message = 'Too many tags; the maximum is ' . COVER_ARTWORK_MAX_TAGS . '.'; + protected $message = 'Too many tags; the maximum is ' . ARTWORK_MAX_TAGS . '.'; } diff --git a/scripts/upsert-to-cover-art-database b/scripts/upsert-to-cover-art-database deleted file mode 100755 index 9a3f7b5f..00000000 --- a/scripts/upsert-to-cover-art-database +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/php -Mr. Smith' - * to: - * 'Mr. Smith' - */ -function StripInnerTags($elements): ?string{ - if($elements === false){ - return null; - } - - if(isset($elements[0])){ - return strip_tags($elements[0]->asXML()); - } - - return null; -} - -if(!$repoDir || !$workDir || !$ebookWwwFilesystemPath){ - print("Expected usage: upsert-to-cover-art-database [-v] --repoDir --workDir --ebookWwwFilesystemPath \n"); - exit(1); -} - -if($verbose){ - print("\nrepoDir: $repoDir\n"); - print("workDir: $workDir\n"); - print("ebookWwwFilesystemPath: $ebookWwwFilesystemPath\n"); -} - -chdir($repoDir); -$contentOpf = shell_exec("git show HEAD:src/epub/content.opf"); -$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $contentOpf)); -$xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); -$artistName = StripInnerTags($xml->xpath('/package/metadata/dc:contributor[@id="artist"]')); -if($artistName === null){ - // Some ebooks have an artist-1 and artist-2. Take artist-1, which isn't ideal, but is usually correct. - $artistName = StripInnerTags($xml->xpath('/package/metadata/dc:contributor[@id="artist-1"]')); - if($artistName === null){ - print($repoDir . " Error: Could not find artist name in content.opf\n"); - exit($repoDir . " Error: missing artistName\n"); - } -} - -if(!file_exists($ebookWwwFilesystemPath . '/text/colophon.xhtml')){ - exit($repoDir . ' Error: no text/colophon.xhtml at ' . $ebookWwwFilesystemPath . "\n"); -} - -$rawColophon = file_get_contents($ebookWwwFilesystemPath . '/text/colophon.xhtml'); -if(empty($rawColophon)){ - exit($repoDir . ' Error: empty colophon at ' . $ebookWwwFilesystemPath . "\n"); -} - -preg_match('|a painting completed \w+ (\d+)|ius', $rawColophon, $matches); -$completedYear = null; -if(sizeof($matches) == 2){ - $completedYear = (int)$matches[1]; -} - -$colophonXml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $rawColophon)); -$artworkName = StripInnerTags($colophonXml->xpath('/html/body/main/section/p/i[@epub:type="se:name.visual-art.painting"]')); -if($artworkName === null){ - print($repoDir . " Error: Could not find artwork name in colophon.xhtml\n"); - exit($repoDir . " Error: missing artworkName"); -} - -$artistUrlName = Formatter::MakeUrlSafe($artistName); -$artworkUrlName = Formatter::MakeUrlSafe($artworkName); -$artwork = null; - -if($verbose){ - print("artistName: $artistName\n"); - print("artistUrlName: $artistUrlName\n"); - print("completedYear: $completedYear\n"); - print("artworkName: $artworkName\n"); - print("artworkUrlName: $artworkUrlName\n"); -} - -try{ - $artwork = Artwork::GetByUrlAndIsApproved($artistUrlName, $artworkUrlName); -} -catch(Exceptions\ArtworkNotFoundException){ - // $artwork is null by default, just continue -} - -if($artwork === null){ - if($verbose){ - printf($repoDir . " No existing artwork found at %s/%s, inserting new artwork.\n", $artistUrlName, $artworkUrlName); - } - - // The ebook colophon provides the artist's name, but not their death year. - // Prefer matching an existing artist to creating a new record with a null death year if possible. - $artist = Artist::FindMatch($artistName); - if($artist === null){ - $artist = new Artist(); - $artist->Name = $artistName; - } - - $artwork = new Artwork(); - $artwork->Artist = new Artist(); - $artwork->Artist = $artist; - $artwork->Name = $artworkName; - $artwork->CompletedYear = $completedYear; - $artwork->CompletedYearIsCirca = false; - $artwork->Created = new DateTime(); - $artwork->Status = COVER_ARTWORK_STATUS_IN_USE; - $artwork->EbookWwwFilesystemPath = $ebookWwwFilesystemPath; - $artwork->MimeType = ImageMimeType::JPG; - - $coverSourceFile = tempnam($workDir, 'cover.source.'); - // Search for JPEG, PNG, and TIFF source files, in that order. - exec("git show HEAD:images/cover.source.jpg > $coverSourceFile.jpg", $shellOutput, $resultCode); - if($resultCode !== 0){ - // No JPEG, try PNG. - exec("git show HEAD:images/cover.source.png > $coverSourceFile.png", $shellOutput, $resultCode); - if($resultCode == 0){ - // Found PNG, convert it to JPEG. - exec("convert $coverSourceFile.png -resize '3750x>' -sampling-factor 4:2:0 -strip -quality 80 -colorspace RGB -interlace JPEG $coverSourceFile.jpg", $shellOutput, $resultCode); - if($resultCode !== 0){ - exit($repoDir . " Error: Failed to convert images/cover.source.png to JPEG\n"); - } - }else{ - // No JPEG or PNG, try TIFF. - exec("git show HEAD:images/cover.source.tif > $coverSourceFile.tif", $shellOutput, $resultCode); - if($resultCode == 0){ - // Found TIFF, convert it to JPEG. - exec("convert $coverSourceFile.tif -resize '3750x>' -sampling-factor 4:2:0 -strip -quality 80 -colorspace RGB -interlace JPEG $coverSourceFile.jpg", $shellOutput, $resultCode); - if($resultCode !== 0){ - exit($repoDir . " Error: Failed to convert images/cover.source.tif to JPEG\n"); - } - }else{ - exit($repoDir . " Error: no images/cover.source.jpg or images/cover.source.png or images/cover.source.tif\n"); - - } - } - } - - $uploadedFile = ['tmp_name' => $coverSourceFile . '.jpg', 'error' => UPLOAD_ERR_OK]; - $artwork->Create($uploadedFile); -} -else{ - if($verbose){ - printf($repoDir . " Existing artwork found at %s/%s, updating its status.\n", $artistUrlName, $artworkUrlName); - } - - if($artwork->CompletedYear != $completedYear){ - printf($repoDir . " Error: Existing database artwork completed year, %d, does not match ebook colophon completed year, %d. Not updating database.\n", $artwork->CompletedYear, $completedYear); - exit($repoDir . " Error: completed year\n"); - } - - if($artwork->Status === COVER_ARTWORK_STATUS_IN_USE){ - printf($repoDir . " Error: Existing database artwork already marked as 'in_use' by ebook '%s'. Not updating database.\n", $artwork->EbookWwwFilesystemPath); - exit($repoDir . " Error: in_use\n"); - } - - $artwork->MarkInUse($ebookWwwFilesystemPath); -} diff --git a/templates/ArtworkList.php b/templates/ArtworkList.php index d9a533e2..251da6c3 100644 --- a/templates/ArtworkList.php +++ b/templates/ArtworkList.php @@ -3,7 +3,7 @@ $artworks = $artworks ?? []; ?>
    -
  1. Status == COVER_ARTWORK_STATUS_IN_USE){ ?> class="in-use"> +
  2. Status == ArtworkStatus::InUse){ ?> class="in-use"> diff --git a/templates/ArtworkStatus.php b/templates/ArtworkStatus.php index 0832fc42..980f506f 100644 --- a/templates/ArtworkStatus.php +++ b/templates/ArtworkStatus.php @@ -2,8 +2,8 @@ $artwork = $artwork ?? null; ?> -Status === COVER_ARTWORK_STATUS_APPROVED){ ?>Approved -Status === COVER_ARTWORK_STATUS_DECLINED){ ?>Declined -Status === COVER_ARTWORK_STATUS_UNVERIFIED){ ?>Unverified -Status === COVER_ARTWORK_STATUS_IN_USE){ ?>In useEbookWwwFilesystemPath !== null){ ?> for Ebook !== null && $artwork->Ebook->Url !== null){ ?>Ebook->Title) ?>EbookWwwFilesystemPath) ?> (Unreleased) +Status == ArtworkStatus::Approved){ ?>Approved +Status == ArtworkStatus::Declined){ ?>Declined +Status == ArtworkStatus::Unverified){ ?>Unverified +Status == ArtworkStatus::InUse){ ?>In useEbookWwwFilesystemPath !== null){ ?> for Ebook !== null && $artwork->Ebook->Url !== null){ ?>Ebook->Title) ?>EbookWwwFilesystemPath) ?> (Unreleased) diff --git a/www/artworks/get.php b/www/artworks/get.php index 8143dee4..b91cceb9 100644 --- a/www/artworks/get.php +++ b/www/artworks/get.php @@ -11,7 +11,7 @@ try{ $isAdminView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false; // If the artwork is not approved, and we're not an admin, don't show it. - if($artwork->Status != COVER_ARTWORK_STATUS_APPROVED && $artwork->Status != COVER_ARTWORK_STATUS_IN_USE && !$isAdminView){ + if($artwork->Status != ArtworkStatus::Approved && $artwork->Status != ArtworkStatus::InUse && !$isAdminView){ throw new Exceptions\ArtworkNotFoundException(); } @@ -138,10 +138,10 @@ catch(Exceptions\ArtworkNotFoundException){ Artwork approval status diff --git a/www/artworks/index.php b/www/artworks/index.php index 9f781ddf..26ffe141 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -2,7 +2,7 @@ use function Safe\preg_replace; $page = HttpInput::Int(GET, 'page') ?? 1; -$perPage = HttpInput::Int(GET, 'per-page') ?? COVER_ARTWORK_PER_PAGE; +$perPage = HttpInput::Int(GET, 'per-page') ?? ARTWORK_PER_PAGE; $query = HttpInput::Str(GET, 'query', false) ?? ''; $status = HttpInput::Str(GET, 'status', false) ?? null; $sort = HttpInput::Str(GET, 'sort', false); @@ -17,8 +17,8 @@ if($page <= 0){ $page = 1; } -if($perPage != COVER_ARTWORK_PER_PAGE && $perPage != 40 && $perPage != 80){ - $perPage = COVER_ARTWORK_PER_PAGE; +if($perPage != ARTWORK_PER_PAGE && $perPage != 40 && $perPage != 80){ + $perPage = ARTWORK_PER_PAGE; } // If we're passed string values that are the same as the defaults, @@ -37,8 +37,8 @@ if($status == 'all'){ } } -if(!$isAdminView && $status !== 'all' && $status != COVER_ARTWORK_STATUS_APPROVED && $status != COVER_ARTWORK_STATUS_IN_USE){ - $status = COVER_ARTWORK_STATUS_APPROVED; +if(!$isAdminView && $status !== 'all' && $status != ArtworkStatus::Approved->value && $status != ArtworkStatus::InUse->value){ + $status = ArtworkStatus::Approved->value; } $artworks = Library::FilterArtwork($query != '' ? $query : null, $status, $sort); @@ -65,7 +65,7 @@ if($sort !== null){ $queryString .= '&sort=' . urlencode($sort); } -if($perPage !== COVER_ARTWORK_PER_PAGE){ +if($perPage !== ARTWORK_PER_PAGE){ $queryString .= '&per-page=' . urlencode((string)$perPage); } @@ -80,10 +80,10 @@ if($perPage !== COVER_ARTWORK_PER_PAGE){ diff --git a/www/artworks/new.php b/www/artworks/new.php index 70dee094..d8864ef1 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -39,7 +39,7 @@ try{ $artwork->Artist = new Artist(); if($GLOBALS['User']->Benefits->CanReviewOwnArtwork){ - $artwork->Status = COVER_ARTWORK_STATUS_APPROVED; + $artwork->Status = ArtworkStatus::Approved; } } } @@ -140,7 +140,7 @@ catch(Exceptions\InvalidPermissionsException){ diff --git a/www/artworks/post.php b/www/artworks/post.php index 52e32e71..95ac9409 100644 --- a/www/artworks/post.php +++ b/www/artworks/post.php @@ -31,7 +31,7 @@ try{ $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false) ?? false; $artwork->Tags = HttpInput::Str(POST, 'artwork-tags', false) ?? []; - $artwork->Status = HttpInput::Str(POST, 'artwork-status', false, COVER_ARTWORK_STATUS_UNVERIFIED); + $artwork->Status = HttpInput::Str(POST, 'artwork-status', false); $artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false); $artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null; $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us', false); @@ -45,12 +45,12 @@ try{ // Only approved reviewers can set the status to anything but unverified when uploading // The submitter cannot review their own submissions unless they have special permission - if($artwork->Status != COVER_ARTWORK_STATUS_UNVERIFIED && !$GLOBALS['User']->Benefits->CanReviewOwnArtwork){ + if($artwork->Status !== ArtworkStatus::Unverified && !$GLOBALS['User']->Benefits->CanReviewOwnArtwork){ throw new Exceptions\InvalidPermissionsException(); } // If the artwork is approved, set the reviewer - if($artwork->Status != COVER_ARTWORK_STATUS_UNVERIFIED){ + if($artwork->Status !== ArtworkStatus::Unverified){ $artwork->ReviewerUserId = $GLOBALS['User']->UserId; } @@ -95,11 +95,11 @@ try{ $artwork->ReviewerUserId = $GLOBALS['User']->UserId; - $newStatus = HttpInput::Str(POST, 'artwork-status', false); + $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status', false) ?? ''); if($newStatus !== null){ if($artwork->Status != $newStatus){ // Is the user attempting to review their own artwork? - if($artwork->Status != COVER_ARTWORK_STATUS_UNVERIFIED && $GLOBALS['User']->UserId == $artwork->SubmitterUserId && !$GLOBALS['User']->Benefits->CanReviewOwnArtwork){ + if($artwork->Status != ArtworkStatus::Unverified && $GLOBALS['User']->UserId == $artwork->SubmitterUserId && !$GLOBALS['User']->Benefits->CanReviewOwnArtwork){ throw new Exceptions\InvalidPermissionsException(); } }