Skip to content

Commit

Permalink
User Preferences : Fix saving preferences with value 0 when the optio…
Browse files Browse the repository at this point in the history
…n does not exist in the db.

Fixes xibosignage/xibo#2975
  • Loading branch information
PeterMis committed Jan 6, 2023
1 parent 0bcf081 commit 5fa92fc
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/Entity/UserOption.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (c) 2022 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand All @@ -19,11 +19,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Xibo\Entity;

use Xibo\Service\LogServiceInterface;
use Xibo\Storage\StorageServiceInterface;


/**
* Class UserOption
* @package Xibo\Entity
Expand Down Expand Up @@ -74,16 +75,18 @@ public function __toString()

public function save()
{
if (!$this->hasPropertyChanged('value')) {
return;
// when the option is not in the database and default is on, switching option value to off
// would not insert the record, hence the additional condition here xibosignage/xibo#2975
if ($this->hasPropertyChanged('value')
|| ($this->getOriginalValue('value') === null && $this->value !== null)
) {
$this->getStore()->insert('INSERT INTO `useroption` (`userId`, `option`, `value`) VALUES (:userId, :option, :value) ON DUPLICATE KEY UPDATE `value` = :value2', [
'userId' => $this->userId,
'option' => $this->option,
'value' => $this->value,
'value2' => $this->value,
]);
}

$this->getStore()->insert('INSERT INTO `useroption` (`userId`, `option`, `value`) VALUES (:userId, :option, :value) ON DUPLICATE KEY UPDATE `value` = :value2', [
'userId' => $this->userId,
'option' => $this->option,
'value' => $this->value,
'value2' => $this->value,
]);
}

public function delete()
Expand All @@ -93,4 +96,4 @@ public function delete()
'option' => $this->option
]);
}
}
}

0 comments on commit 5fa92fc

Please sign in to comment.