Skip to content

Commit

Permalink
Allow VCS URLs to be null in projects
Browse files Browse the repository at this point in the history
  • Loading branch information
acabal committed Dec 17, 2024
1 parent d902074 commit 7a3c7ad
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 36 deletions.
2 changes: 1 addition & 1 deletion config/sql/se/Projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions lib/Exceptions/VcsUrlRequiredException.php

This file was deleted.

70 changes: 64 additions & 6 deletions lib/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use function Safe\curl_init;
use function Safe\curl_setopt;
use function Safe\json_decode;
use function Safe\parse_url;
use function Safe\preg_match;
use function Safe\preg_match_all;
use function Safe\preg_replace;
Expand All @@ -17,6 +18,8 @@
* @property string $Url
* @property DateTimeImmutable $LastActivityTimestamp The timestamp of the latest activity, whether it's a commit, a discussion post, or simply the started timestamp.
* @property array<ProjectReminder> $Reminders
* @property ?string $VcsUrlDomain
* @property ?string $DiscussionUrlDomain
*/
class Project{
use Traits\Accessor;
Expand All @@ -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;
Expand All @@ -46,12 +49,64 @@ class Project{
protected DateTimeImmutable $_LastActivityTimestamp;
/** @var array<ProjectReminder> $_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;
Expand Down Expand Up @@ -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)){
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion templates/BulkDownloadTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
?>
<table class="data-table bulk-downloads-table">
<caption aria-hidden="hidden">Scroll right →</caption>
<caption aria-hidden="true">Scroll right →</caption>
<thead>
<tr class="mid-header">
<th scope="col"><?= Formatter::EscapeHtml($label) ?></th>
Expand Down
16 changes: 9 additions & 7 deletions templates/EmailManagerNewProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@
<a href="<?= SITE_URL ?><?= $project->Reviewer->Url ?>/projects"><?= Formatter::EscapeHtml($project->Reviewer->DisplayName) ?></a>
</td>
</tr>
<tr>
<td>Repository:</td>
<td>
<a href="<?= Formatter::EscapeHtml($project->VcsUrl) ?>">GitHub</a>
</td>
</tr>
<? if($project->VcsUrl !== null){ ?>
<tr>
<td>Repository:</td>
<td>
<a href="<?= Formatter::EscapeHtml($project->VcsUrl) ?>"><?= Formatter::EscapeHtml($project->VcsUrlDomain) ?></a>
</td>
</tr>
<? } ?>
<? if($project->DiscussionUrl !== null){ ?>
<tr>
<td>Discussion:</td>
<td>
<a href="<?= Formatter::EscapeHtml($project->DiscussionUrl) ?>">Google Groups</a>
<a href="<?= Formatter::EscapeHtml($project->DiscussionUrl) ?>"><?= Formatter::EscapeHtml($project->DiscussionUrlDomain) ?></a>
</td>
</tr>
<? } ?>
Expand Down
6 changes: 4 additions & 2 deletions templates/EmailManagerNewProjectText.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

- Reviewer: [<?= Formatter::EscapeMarkdown($project->Reviewer->DisplayName) ?>](<?= Formatter::EscapeMarkdown(SITE_URL . $project->Reviewer->Url . '/projects') ?>)

- Repository: [GitHub](<?= Formatter::EscapeMarkdown($project->VcsUrl) ?>)
<? if($project->VcsUrl !== null){ ?>
- Repository: [<?= Formatter::EscapeHtml($project->VcsUrlDomain) ?>](<?= Formatter::EscapeMarkdown($project->VcsUrl) ?>)

<? } ?>
<? if($project->DiscussionUrl !== null){ ?>
- Discussion: [Google Groups](<?= Formatter::EscapeMarkdown($project->DiscussionUrl) ?>)
- Discussion: [<?= Formatter::EscapeHtml($project->DiscussionUrlDomain) ?>](<?= Formatter::EscapeMarkdown($project->DiscussionUrl) ?>)

<? } ?>
If you’re unable to <?= $role ?> this ebook project, [email the Editor-in-Chief](mailto:<?= Formatter::EscapeMarkdown(EDITOR_IN_CHIEF_EMAIL_ADDRESS) ?>) and we’ll reassign it.
Expand Down
2 changes: 0 additions & 2 deletions templates/ProjectForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
<input
type="url"
name="project-vcs-url"
placeholder="https://github.com/..."
pattern="^https:\/\/github\.com\/[^\/]+/[^\/]+/?$"
autocomplete="off"
value="<?= Formatter::EscapeHtml($project->VcsUrl ?? '') ?>"
/>
Expand Down
10 changes: 6 additions & 4 deletions templates/ProjectsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$includeStatus = $includeStatus ?? true;
?>
<table class="data-table">
<caption aria-hidden="hidden">Scroll right →</caption>
<caption aria-hidden="true">Scroll right →</caption>
<thead>
<tr class="mid-header">
<? if($includeTitle){ ?>
Expand All @@ -20,8 +20,8 @@
<? if($includeStatus){ ?>
<th scope="col">Status</th>
<? } ?>
<th/>
<th/>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -56,7 +56,9 @@
</td>
<? } ?>
<td>
<a href="<?= Formatter::EscapeHtml($project->VcsUrl) ?>">Repository</a>
<? if($project->VcsUrl !== null){ ?>
<a href="<?= Formatter::EscapeHtml($project->VcsUrl) ?>">Repository</a>
<? } ?>
</td>
<td>
<? if($project->DiscussionUrl !== null){ ?>
Expand Down
2 changes: 1 addition & 1 deletion www/bulk-downloads/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<p>These zip files contain each ebook in every format we offer, and are kept updated with the latest versions of each ebook. Read about <a href="/help/how-to-use-our-ebooks#which-file-to-download">which file format to download</a>.</p>
<? if($class == 'months'){ ?>
<table class="data-table">
<caption aria-hidden="hidden">Scroll right →</caption>
<caption aria-hidden="true">Scroll right →</caption>
<tbody>
<? foreach($collection as $year => $months){ ?>
<? $yearHeader = Formatter::EscapeHtml($year); ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
</li>
<li id="i-still-have-questions">
<h2>I still have questions!</h2>
<p>If you’re unsure about anything, or have a question that isn’t answered here, please ask on the <a href="https://groups.google.com/g/standardebooks">Google Groups mailing list.</a> The experienced producers there can answer any question you might have.</p>
<p>If you’re unsure about anything, or have a question that isn’t answered here, please ask on our <a href="https://groups.google.com/g/standardebooks">mailing list.</a> The experienced producers there can answer any question you might have.</p>
</li>
</ol>
</article>
Expand Down
10 changes: 6 additions & 4 deletions www/ebook-placeholders/new.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@

<?= Template::Error(['exception' => $exception]) ?>

<? if($isOnlyProjectCreated){ ?>
<p class="message success">An ebook placeholder <a href="<?= $createdEbook->Url ?>">already exists</a> for this ebook, but a a new project was created!</p>
<? }elseif($isCreated && isset($createdEbook)){ ?>
<p class="message success">Ebook placeholder created: <a href="<?= $createdEbook->Url ?>"><?= Formatter::EscapeHtml($createdEbook->Title) ?></a>!</p>
<? if(isset($createdEbook)){ ?>
<? if($isOnlyProjectCreated){ ?>
<p class="message success">An ebook placeholder <a href="<?= $createdEbook->Url ?>">already exists</a> for this ebook, but a a new project was created!</p>
<? }elseif($isCreated){ ?>
<p class="message success">Ebook placeholder created: <a href="<?= $createdEbook->Url ?>"><?= Formatter::EscapeHtml($createdEbook->Title) ?></a>!</p>
<? } ?>
<? } ?>

<form class="create-update-ebook-placeholder" method="<?= Enums\HttpMethod::Post->value ?>" action="/ebook-placeholders" autocomplete="off">
Expand Down
1 change: 1 addition & 0 deletions www/projects/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?
use function Safe\session_unset;

try{
if(Session::$User === null){
Expand Down

0 comments on commit 7a3c7ad

Please sign in to comment.