Skip to content

Commit

Permalink
fix old default update
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Aug 4, 2021
1 parent 3fa97fb commit 2304abb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Fixed

- Fixed an error when creating a new term and no default glossary exists.
- If the current user in the CP has only permissions to edit terms, the redirect will respect this now and redirects the user to the terms instead of the glossaries.
- In some circumstances you could have more than one default glossary. This is fixed.

## 1.0.0 - 2021-07-20

Expand Down
10 changes: 7 additions & 3 deletions src/elements/Glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,16 @@ public function afterSave(bool $isNew): void

// Update old default glossary
if ($this->default) {
$oldDefault = GlossaryPlugin::getInstance()->glossaries->getDefaultGlossary()->id;
if ($oldDefault !== null && $this->id !== $oldDefault) {
$oldDefault = Glossary::find()
->default(true)
->id('not '.$this->id)
->one();

if ($oldDefault) {
Db::update('{{%glossary_glossaries}}', [
'default' => false,
], [
'id' => $oldDefault,
'id' => $oldDefault->id,
]);
}
}
Expand Down

0 comments on commit 2304abb

Please sign in to comment.