Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Stache/Stores/TaxonomyTermsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function getItem($key)
$this->handleFileChanges();

if ($item = $this->getCachedItem($key)) {
$item->term()->syncOriginal();

return $item;
}

Expand All @@ -87,6 +89,8 @@ public function getItem($key)
->in($site);
}

$item->term()->syncOriginal();

$this->cacheItem($item);

return $item;
Expand Down
62 changes: 62 additions & 0 deletions tests/Listeners/UpdateTermReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,68 @@ public function it_updates_scoped_term_fields_regardless_of_max_items_setting()
$this->assertEquals('topics::norris', $entry->fresh()->get('non_favourites'));
}

#[Test]
public function it_nullifies_references_when_deleting_a_term_loaded_from_its_file()
{
$collection = tap(Facades\Collection::make('articles'))->save();

$this->setInBlueprints('collections/articles', [
'fields' => [
[
'handle' => 'favourites',
'field' => [
'type' => 'terms',
'taxonomies' => ['topics'],
'mode' => 'select',
],
],
],
]);

$entry = tap(Facades\Entry::make()->collection($collection)->data([
'favourites' => ['hoff', 'norris'],
]))->save();

$this->assertEquals(['hoff', 'norris'], $entry->get('favourites'));

Facades\Stache::store('terms')->store('topics')->forgetItem('en::hoff');

Facades\Term::find('topics::hoff')->delete();

$this->assertEquals(['norris'], $entry->fresh()->get('favourites'));
}

/** @see https://github.com/statamic/cms/issues/11264 */
#[Test]
public function it_nullifies_references_when_deleting_a_term_that_only_exists_in_entry_data()
{
$collection = tap(Facades\Collection::make('articles')->taxonomies(['topics']))->save();

$this->setInBlueprints('collections/articles', [
'fields' => [
[
'handle' => 'topics',
'field' => [
'type' => 'terms',
'taxonomies' => ['topics'],
'mode' => 'select',
],
],
],
]);

$entry = tap(Facades\Entry::make()->collection($collection)->data([
'topics' => ['hoff', 'ghost'],
]))->save();

$this->assertEquals(['hoff', 'ghost'], $entry->get('topics'));

Facades\Term::find('topics::ghost')->delete();

$this->assertEquals(['hoff'], $entry->fresh()->get('topics'));
$this->assertNull(Facades\Term::find('topics::ghost'));
}

#[Test]
public function it_nullifies_references_when_deleting_a_scoped_term()
{
Expand Down
Loading