Skip to content

Commit

Permalink
fix(Step): Use largest possible 32-bit int value for transition
Browse files Browse the repository at this point in the history
The value used before (largest possible MySQL BIGINT value) was too big
for PHP int. Since we still support 32-bit platforms on Nextcloud, let's
stick to the largest possible 32-bit PHP integer value.

Besides, setting the value as default for `Step::version` doesn't work
as `QBMapper->insert()` doesn't recognize the `version` field as changed
in that case. So let's default to `0` again and set it using
`Step->setVersion()` later.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Nov 9, 2023
1 parent f671311 commit 4e2d178
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Db/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class Step extends Entity implements JsonSerializable {
/*
* Transition: We now use the auto-incrementing id as the version.
* To ensure that new steps always have a larger version than those that
* used the version field, use the largest possible value for BIGINT.
* used the version field, use the largest possible 32-bit integer value.
*/
public const VERSION_STORED_IN_ID = 18446744073709551615;
public const VERSION_STORED_IN_ID = 2147483647;

public $id = null;
protected string $data = '';
protected int $version = self::VERSION_STORED_IN_ID;
protected int $version = 0;
protected int $sessionId = 0;
protected int $documentId = 0;

Expand Down
1 change: 1 addition & 0 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ private function insertSteps($documentId, $sessionId, $steps, $version): int {
$step->setData($stepsJson);
$step->setSessionId($sessionId);
$step->setDocumentId($documentId);
$step->setVersion(Step::VERSION_STORED_IN_ID);
$step = $this->stepMapper->insert($step);
$newVersion = $step->getId();
$this->logger->debug("Adding steps to " . $documentId . ": bumping version from $stepsVersion to $newVersion");
Expand Down

0 comments on commit 4e2d178

Please sign in to comment.