Skip to content

Commit

Permalink
🚑 Item: set id to null in clone function
Browse files Browse the repository at this point in the history
This is done to set the id to null BEFORE resetting the updated fields.
The purpose of this is to avoid explicitly adding a NULL id into the DB,
which provokes an error in some DBMS (like postgres).

Fixes #1375
  • Loading branch information
mnassabain committed Jun 12, 2021
1 parent 9410228 commit 1c4512a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/Db/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public function __construct()

public function __clone()
{
$this->setId(null);

/**
* Removes 'id' from updatedFields; this will avoid explicitly
* inserting the value NULL into the DB, and will instead allow a new
* id to be generated.
* */
$this->resetUpdatedFields();
$this->markFieldUpdated('contentHash');
$this->markFieldUpdated('guidHash');
Expand Down
1 change: 0 additions & 1 deletion lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function shareItemWithUser(string $userId, int $itemId, string $shareReci

// Duplicate item & initialize fields
$sharedItem = clone $item;
$sharedItem->setId(null);
$sharedItem->setUnread(true);
$sharedItem->setStarred(false);
$sharedItem->setSharedBy($userId);
Expand Down

0 comments on commit 1c4512a

Please sign in to comment.