From 7397b3876379dcc607181f329a99534a56694fef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 27 Jan 2024 11:33:28 -0500 Subject: [PATCH] Ensure identifier uniqueness in Disposable FullTextSearch --- src/Database/DisposableFullTextSearch.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Database/DisposableFullTextSearch.php b/src/Database/DisposableFullTextSearch.php index 3516080f76..fb8ce900d5 100644 --- a/src/Database/DisposableFullTextSearch.php +++ b/src/Database/DisposableFullTextSearch.php @@ -37,12 +37,12 @@ class DisposableFullTextSearch { $this->db = $database; - // Unique identifier generation. Two DisposableFullTextSearch object should never have the same as the first object destruction - // would delete both check-full-text-search rows, before the second object destruction is called, leading to unexpected behavior. - // Maximum value is indicated by the INT UNSIGNED type of the check-full-text-search.pid field - $this->identifier = random_int(0, pow(2, 32) - 1); - - $this->db->insert('check-full-text-search', ['pid' => $this->identifier, 'searchtext' => $haystack], Database::INSERT_UPDATE); + do { + // Unique identifier generation. Two DisposableFullTextSearch object should never have the same as the first object destruction + // would delete both check-full-text-search rows before the second object destruction is called, leading to unexpected behavior. + // Maximum value is indicated by the INT UNSIGNED type of the check-full-text-search.pid field + $this->identifier = random_int(0, pow(2, 32) - 1); + } while($this->db->insert('check-full-text-search', ['pid' => $this->identifier, 'searchtext' => $haystack])); } public function __destruct()