From 017baef7d361742266ebdedfd53f5a5b8f5ecbdc Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sun, 7 Jan 2024 14:01:41 -0600 Subject: [PATCH] Artwork system: More options for reviewers submitting new artwork --- lib/Artwork.php | 9 ++++++++ lib/Library.php | 26 +++++++++++++++-------- templates/ArtworkStatus.php | 2 +- www/artworks/new.php | 41 ++++++++++++++++++++++--------------- www/artworks/post.php | 20 ++++++++---------- www/css/core.css | 5 +++++ 6 files changed, 66 insertions(+), 37 deletions(-) diff --git a/lib/Artwork.php b/lib/Artwork.php index 68eea602..63bbc9c3 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -309,6 +309,15 @@ class Artwork extends PropertiesBase{ $error->Add(new Exceptions\InvalidMimeTypeException()); } + // Check the ebook www filesystem path. + // We don't check if it exists, because the book might not be published yet. + // But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry + if($this->EbookWwwFilesystemPath !== null){ + if(mb_stripos($this->EbookWwwFilesystemPath, '_') === false){ + $error->Add(new Exceptions\InvalidEbookException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.')); + } + } + // Check for existing Artwork objects with the same URL but different Artwork IDs. try{ $existingArtwork = Artwork::GetByUrl($this->Artist->UrlName, $this->UrlName); diff --git a/lib/Library.php b/lib/Library.php index f617afa3..a89c0520 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -273,21 +273,27 @@ class Library{ try{ $results = apcu_fetch($variable); } - catch(Safe\Exceptions\ApcuException){ - Library::RebuildCache(); + catch(Safe\Exceptions\ApcuException $ex){ try{ - $results = apcu_fetch($variable); + // If we can't fetch this variable, rebuild the whole cache. + apcu_fetch('is-cache-fresh'); } - catch(Safe\Exceptions\ApcuException){ - // We can get here if the cache is currently rebuilding from a different process. - // Nothing we can do but wait, so wait 20 seconds before retrying - sleep(20); - + catch(Safe\Exceptions\ApcuException $ex){ + Library::RebuildCache(); try{ $results = apcu_fetch($variable); } catch(Safe\Exceptions\ApcuException){ - // Cache STILL rebuilding... give up silently for now + // We can get here if the cache is currently rebuilding from a different process. + // Nothing we can do but wait, so wait 20 seconds before retrying + sleep(20); + + try{ + $results = apcu_fetch($variable); + } + catch(Safe\Exceptions\ApcuException){ + // Cache STILL rebuilding... give up silently for now + } } } } @@ -686,6 +692,8 @@ class Library{ } apcu_delete($lockVar); + + apcu_store('is-cache-fresh', true); } /** diff --git a/templates/ArtworkStatus.php b/templates/ArtworkStatus.php index d2989e46..478c5f88 100644 --- a/templates/ArtworkStatus.php +++ b/templates/ArtworkStatus.php @@ -5,5 +5,5 @@ $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 useEbook !== null && $artwork->Ebook->Url !== null){ ?> for Ebook->Title) ?> +Status === COVER_ARTWORK_STATUS_IN_USE){ ?>In useEbookWwwFilesystemPath !== null){ ?> for Ebook !== null && $artwork->Ebook->Url !== null){ ?>Ebook->Title) ?>EbookWwwFilesystemPath) ?> diff --git a/www/artworks/new.php b/www/artworks/new.php index 4903dced..c69576c7 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -173,6 +173,15 @@ catch(Exceptions\InvalidPermissionsException){ value="PublicationYear ?>" /> + -