Update existing draft articles instead of erroring on a repeat Micropub post
If a Micropub h-entry post's title matches an existing article that's still a draft, update that article in place rather than trying to insert a duplicate. If it matches one that's already published, reject the request with a clear error instead of silently colliding. Also set includeTrashed on Article's slug config as a safety net: this model soft-deletes, and Sluggable's uniqueness check ignores trashed rows by default, so a previously-deleted article's title could crash new inserts with a raw unique constraint violation (this is exactly what surfaced in Flare as a UniqueConstraintViolationException on articles_titleurl_unique once the prior swallowed-exception fix shipped). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
6727138f43
commit
eb35a0aa2d
4 changed files with 92 additions and 2 deletions
|
|
@ -74,6 +74,17 @@ class ArticlesTest extends TestCase
|
|||
$this->assertEquals(config('app.url').$article->link, $article->uri);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function slug_is_suffixed_when_a_trashed_article_already_used_it(): void
|
||||
{
|
||||
$original = Article::create(['title' => 'My Title', 'main' => 'Content']);
|
||||
$original->delete();
|
||||
|
||||
$newArticle = Article::create(['title' => 'My Title', 'main' => 'Other content']);
|
||||
|
||||
$this->assertEquals('my-title-2', $newArticle->titleurl);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function date_scope_returns_expected_articles(): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue