From 5e8c964f6cc735c49e686022700144307e903dd1 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 27 Sep 2025 15:11:55 +0200 Subject: Stable IDs during SQL import (#7988) * Stable IDs during SQL import Follow-up of https://github.com/FreshRSS/FreshRSS/pull/7949 Make sure that the original category IDs, feed IDs, and label IDs are kept identical during an SQL import. Avoid breaking everything referring to categories, feeds, labels by their IDs such as searches and third-party extensions. * Fix export of default category --- app/Models/DatabaseDAO.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/Models/DatabaseDAO.php') diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index a33d38e76..3cd76ea0a 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -409,19 +409,17 @@ SQL; $userTo->createUser(); $catTo->beginTransaction(); + $catTo->deleteCategory(FreshRSS_CategoryDAO::DEFAULTCATEGORYID); + $catTo->sqlResetSequence(); foreach ($catFrom->selectAll() as $category) { - $cat = $catTo->searchByName($category['name']); //Useful for the default category - if ($cat != null) { - $catId = $cat->id(); - } else { - $catId = $catTo->addCategory($category); - if ($catId == false) { - $error = 'Error during SQLite copy of categories!'; - return self::stdError($error); - } + $catId = $catTo->addCategory($category); + if ($catId === false) { + $error = 'Error during SQLite copy of categories!'; + return self::stdError($error); } $idMaps['c' . $category['id']] = $catId; } + $catTo->sqlResetSequence(); foreach ($feedFrom->selectAll() as $feed) { $feed['category'] = empty($idMaps['c' . $feed['category']]) ? FreshRSS_CategoryDAO::DEFAULTCATEGORYID : $idMaps['c' . $feed['category']]; $feedId = $feedTo->addFeed($feed); @@ -431,6 +429,7 @@ SQL; } $idMaps['f' . $feed['id']] = $feedId; } + $feedTo->sqlResetSequence(); $catTo->commit(); $nbEntries = $entryFrom->count(); @@ -483,6 +482,7 @@ SQL; } } } + $tagTo->sqlResetSequence(); $tagTo->commit(); return true; -- cgit v1.2.3