Skip to content

Commit

Permalink
[7.x] Prevent infinite loop when published column is missing (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Jul 10, 2024
1 parent b0dfcd9 commit 2d01762
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Exceptions/PublishedColumnMissingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace StatamicRadPack\Runway\Exceptions;

class PublishedColumnMissingException extends \Exception
{
public function __construct(public string $table, public string $column)
{
parent::__construct("The [{$this->column}] publish column is missing from the {$this->table} table.");
}
}
9 changes: 8 additions & 1 deletion src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Statamic\Fields\Blueprint;
use Statamic\Fields\Field;
use Statamic\Statamic;
use StatamicRadPack\Runway\Exceptions\PublishedColumnMissingException;
use StatamicRadPack\Runway\Fieldtypes\BelongsToFieldtype;
use StatamicRadPack\Runway\Fieldtypes\HasManyFieldtype;

Expand Down Expand Up @@ -150,9 +151,15 @@ public function publishedColumn(): ?string
return null;
}

return is_string($this->config->get('published'))
$column = is_string($this->config->get('published'))
? $this->config->get('published')
: 'published';

if (! in_array($column, $this->databaseColumns())) {
throw new PublishedColumnMissingException($this->databaseTable(), $column);
}

return $column;
}

/**
Expand Down

0 comments on commit 2d01762

Please sign in to comment.