Skip to content

Commit

Permalink
Remove language paramater from Version::delete
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jun 5, 2024
1 parent 1e146b5 commit 0673b36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
26 changes: 5 additions & 21 deletions src/Content/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,21 @@ public function create(array $fields, string $language = 'default'): void
}

/**
* Deletes a version by language or for any language
*
* @param string|null $language If null, all available languages will be deleted
* Deletes a version with all its languages
*/
public function delete(string|null $language = null): void
public function delete(): void
{
// delete a single language
// delete the default language in single-language mode
if ($this->model->kirby()->multilang() === false) {
$this->deleteLanguage('default');
}

// delete a specific language
if ($language !== null) {
$this->deleteLanguage($language);
return;
$this->model->storage()->delete($this->id, $this->language('default'));
}

// delete all languages
foreach ($this->model->kirby()->languages() as $language) {
$this->deleteLanguage($language);
$this->model->storage()->delete($this->id, $language);
}
}

/**
* Deletes a version by a specific language
*/
public function deleteLanguage(string $language = 'default'): void
{
$this->model->storage()->delete($this->id, $this->language($language));
}

/**
* Ensure that the version exists and otherwise
* throw an exception
Expand Down
15 changes: 11 additions & 4 deletions tests/Content/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,22 @@ public function testDeleteMultiLanguage(): void
);

$this->assertContentFileDoesNotExist('de');
$this->assertContentFileDoesNotExist('en');

$version->create([
Data::write($this->contentFile('en'), [
'title' => 'Test'
], 'de');
]);

Data::write($this->contentFile('de'), [
'title' => 'Test'
]);

$this->assertContentFileExists('en');
$this->assertContentFileExists('de');

$version->delete('de');
$version->delete();

$this->assertContentFileDoesNotExist('en');
$this->assertContentFileDoesNotExist('de');
}

Expand All @@ -252,7 +259,7 @@ public function testDeleteSingleLanguage(): void

$this->assertContentFileDoesNotExist();

$version->create([
Data::write($this->contentFile(), [
'title' => 'Test'
]);

Expand Down

0 comments on commit 0673b36

Please sign in to comment.