From 7a3c7ad50389563a7fa975aef974d0930c6a27a0 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 16 Dec 2024 21:31:49 -0600 Subject: [PATCH] Allow VCS URLs to be null in projects --- config/sql/se/Projects.sql | 2 +- lib/Exceptions/VcsUrlRequiredException.php | 7 -- lib/Project.php | 70 +++++++++++++++++-- templates/BulkDownloadTable.php | 2 +- templates/EmailManagerNewProject.php | 16 +++-- templates/EmailManagerNewProjectText.php | 6 +- templates/ProjectForm.php | 2 - templates/ProjectsTable.php | 10 +-- www/bulk-downloads/collection.php | 2 +- ...how-to-choose-and-create-a-cover-image.php | 2 +- www/ebook-placeholders/new.php | 10 +-- www/projects/index.php | 1 + 12 files changed, 94 insertions(+), 36 deletions(-) delete mode 100644 lib/Exceptions/VcsUrlRequiredException.php diff --git a/config/sql/se/Projects.sql b/config/sql/se/Projects.sql index 96e8f37d..9507eff6 100644 --- a/config/sql/se/Projects.sql +++ b/config/sql/se/Projects.sql @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `Projects` ( `ProducerName` varchar(151) NOT NULL DEFAULT '', `ProducerEmail` varchar(80) DEFAULT NULL, `DiscussionUrl` varchar(255) DEFAULT NULL, - `VcsUrl` varchar(255) NOT NULL, + `VcsUrl` varchar(255) DEFAULT NULL, `Created` timestamp NOT NULL DEFAULT current_timestamp(), `Updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `Started` datetime NOT NULL, diff --git a/lib/Exceptions/VcsUrlRequiredException.php b/lib/Exceptions/VcsUrlRequiredException.php deleted file mode 100644 index 678558e4..00000000 --- a/lib/Exceptions/VcsUrlRequiredException.php +++ /dev/null @@ -1,7 +0,0 @@ - $Reminders + * @property ?string $VcsUrlDomain + * @property ?string $DiscussionUrlDomain */ class Project{ use Traits\Accessor; @@ -28,7 +31,7 @@ class Project{ public string $ProducerName; public ?string $ProducerEmail = null; public ?string $DiscussionUrl = null; - public string $VcsUrl; + public ?string $VcsUrl; public DateTimeImmutable $Created; public DateTimeImmutable $Updated; public DateTimeImmutable $Started; @@ -46,12 +49,64 @@ class Project{ protected DateTimeImmutable $_LastActivityTimestamp; /** @var array $_Reminders */ protected array $_Reminders; + protected ?string $_VcsUrlDomain; + protected ?string $_DiscussionUrlDomain; // ******* // GETTERS // ******* + protected function GetVcsUrlDomain(): ?string{ + if(!isset($this->_VcsUrlDomain)){ + if($this->VcsUrl === null){ + $this->_VcsUrlDomain = null; + } + else{ + try{ + $domain = parse_url($this->VcsUrl, PHP_URL_HOST); + + if(is_string($domain)){ + $this->_VcsUrlDomain = strtolower($domain); + } + else{ + $this->_VcsUrlDomain = null; + } + } + catch(\Exception){ + $this->_VcsUrlDomain = null; + } + } + } + + return $this->_VcsUrlDomain; + } + + protected function GetDiscussionUrlDomain(): ?string{ + if(!isset($this->_DiscussionUrlDomain)){ + if($this->DiscussionUrl === null){ + $this->_DiscussionUrlDomain = null; + } + else{ + try{ + $domain = parse_url($this->DiscussionUrl, PHP_URL_HOST); + + if(is_string($domain)){ + $this->_DiscussionUrlDomain = strtolower($domain); + } + else{ + $this->_DiscussionUrlDomain = null; + } + } + catch(\Exception){ + $this->_DiscussionUrlDomain = null; + } + } + } + + return $this->_DiscussionUrlDomain; + } + protected function GetUrl(): string{ if(!isset($this->_Url)){ $this->_Url = '/projects/' . $this->ProjectId; @@ -158,12 +213,15 @@ public function Validate(): void{ } } - $this->VcsUrl = rtrim(trim($this->VcsUrl ?? ''), '/'); + $this->VcsUrl = trim($this->VcsUrl ?? ''); if($this->VcsUrl == ''){ - $error->Add(new Exceptions\VcsUrlRequiredException()); + $this->VcsUrl = null; } - elseif(!preg_match('|^https://github.com/[^/]+/[^/]+|ius', $this->VcsUrl)){ - $error->Add(new Exceptions\InvalidVcsUrlException()); + elseif(preg_match('|^https?://(www\.)?github.com/|ius', $this->VcsUrl)){ + $this->VcsUrl = rtrim($this->VcsUrl, '/'); + if(!preg_match('|^https://github.com/[^/]+/[^/]+|ius', $this->VcsUrl)){ + $error->Add(new Exceptions\InvalidVcsUrlException()); + } } if(!isset($this->ManagerUserId)){ @@ -373,7 +431,7 @@ public function FillFromHttpPost(): void{ * @throws Exceptions\AppException If the operation failed. */ public function FetchLatestCommitTimestamp(?string $apiKey = null): void{ - if(!preg_match('|^https://github\.com/|iu', $this->VcsUrl)){ + if(!preg_match('|^https://github\.com/|iu', $this->VcsUrl ?? '')){ return; } diff --git a/templates/BulkDownloadTable.php b/templates/BulkDownloadTable.php index 5de36427..dd6ed212 100644 --- a/templates/BulkDownloadTable.php +++ b/templates/BulkDownloadTable.php @@ -5,7 +5,7 @@ */ ?> - + diff --git a/templates/EmailManagerNewProject.php b/templates/EmailManagerNewProject.php index 0c7d2e44..a9a5f76c 100644 --- a/templates/EmailManagerNewProject.php +++ b/templates/EmailManagerNewProject.php @@ -36,17 +36,19 @@ Reviewer->DisplayName) ?> - - - - + VcsUrl !== null){ ?> + + + + + DiscussionUrl !== null){ ?> diff --git a/templates/EmailManagerNewProjectText.php b/templates/EmailManagerNewProjectText.php index 346ef804..138c42e0 100644 --- a/templates/EmailManagerNewProjectText.php +++ b/templates/EmailManagerNewProjectText.php @@ -16,10 +16,12 @@ - Reviewer: [Reviewer->DisplayName) ?>](Reviewer->Url . '/projects') ?>) -- Repository: [GitHub](VcsUrl) ?>) +VcsUrl !== null){ ?> +- Repository: [VcsUrlDomain) ?>](VcsUrl) ?>) +DiscussionUrl !== null){ ?> -- Discussion: [Google Groups](DiscussionUrl) ?>) +- Discussion: [DiscussionUrlDomain) ?>](DiscussionUrl) ?>) If you’re unable to this ebook project, [email the Editor-in-Chief](mailto:) and we’ll reassign it. diff --git a/templates/ProjectForm.php b/templates/ProjectForm.php index c98216f4..e2a2f853 100644 --- a/templates/ProjectForm.php +++ b/templates/ProjectForm.php @@ -76,8 +76,6 @@ diff --git a/templates/ProjectsTable.php b/templates/ProjectsTable.php index a9a7352e..aaaf805e 100644 --- a/templates/ProjectsTable.php +++ b/templates/ProjectsTable.php @@ -7,7 +7,7 @@ $includeStatus = $includeStatus ?? true; ?>
Scroll right →
Repository: - GitHub -
Repository: + VcsUrlDomain) ?> +
Discussion: - Google Groups + DiscussionUrlDomain) ?>
- + @@ -20,8 +20,8 @@ - + @@ -56,7 +56,9 @@
Scroll right →
Status - +
- Repository + VcsUrl !== null){ ?> + Repository + DiscussionUrl !== null){ ?> diff --git a/www/bulk-downloads/collection.php b/www/bulk-downloads/collection.php index fa6559ae..78651d82 100644 --- a/www/bulk-downloads/collection.php +++ b/www/bulk-downloads/collection.php @@ -37,7 +37,7 @@

These zip files contain each ebook in every format we offer, and are kept updated with the latest versions of each ebook. Read about which file format to download.

- + $months){ ?> diff --git a/www/contribute/how-tos/how-to-choose-and-create-a-cover-image.php b/www/contribute/how-tos/how-to-choose-and-create-a-cover-image.php index fcf455cf..1ed160b5 100644 --- a/www/contribute/how-tos/how-to-choose-and-create-a-cover-image.php +++ b/www/contribute/how-tos/how-to-choose-and-create-a-cover-image.php @@ -364,7 +364,7 @@
  • I still have questions!

    -

    If you’re unsure about anything, or have a question that isn’t answered here, please ask on the Google Groups mailing list. The experienced producers there can answer any question you might have.

    +

    If you’re unsure about anything, or have a question that isn’t answered here, please ask on our mailing list. The experienced producers there can answer any question you might have.

  • diff --git a/www/ebook-placeholders/new.php b/www/ebook-placeholders/new.php index 8f2638b8..46083e70 100644 --- a/www/ebook-placeholders/new.php +++ b/www/ebook-placeholders/new.php @@ -72,10 +72,12 @@ $exception]) ?> - -

    An ebook placeholder already exists for this ebook, but a a new project was created!

    - -

    Ebook placeholder created: Title) ?>!

    + + +

    An ebook placeholder already exists for this ebook, but a a new project was created!

    + +

    Ebook placeholder created: Title) ?>!

    + diff --git a/www/projects/index.php b/www/projects/index.php index d67c1b4a..1034f90a 100644 --- a/www/projects/index.php +++ b/www/projects/index.php @@ -1,4 +1,5 @@
    Scroll right →