|
@@ -61,8 +61,17 @@ class FreshRSS_Import_Service {
|
|
|
// existing categories later.
|
|
// existing categories later.
|
|
|
$categories = $this->catDAO->listCategories(prePopulateFeeds: false);
|
|
$categories = $this->catDAO->listCategories(prePopulateFeeds: false);
|
|
|
$categories_by_names = [];
|
|
$categories_by_names = [];
|
|
|
|
|
+ $highest_position = PHP_INT_MIN; // To order the numbers as best as possible in case of negative positions, we choose the lowest possible number first
|
|
|
foreach ($categories as $category) {
|
|
foreach ($categories as $category) {
|
|
|
$categories_by_names[$category->name()] = $category;
|
|
$categories_by_names[$category->name()] = $category;
|
|
|
|
|
+ $position = $category->attributeInt('position') ?? PHP_INT_MIN;
|
|
|
|
|
+ if ($position > $highest_position) {
|
|
|
|
|
+ $highest_position = $position;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($highest_position === PHP_INT_MIN) {
|
|
|
|
|
+ // If it's still the same number, default to -1 instead
|
|
|
|
|
+ $highest_position = -1; // will be incremented to 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get current numbers of categories and feeds, and the limits to
|
|
// Get current numbers of categories and feeds, and the limits to
|
|
@@ -91,7 +100,8 @@ class FreshRSS_Import_Service {
|
|
|
$can_create_category = FreshRSS_Context::$isCli || !$limit_reached;
|
|
$can_create_category = FreshRSS_Context::$isCli || !$limit_reached;
|
|
|
|
|
|
|
|
if ($can_create_category) {
|
|
if ($can_create_category) {
|
|
|
- $category = $this->createCategory($category_element, $dry_run);
|
|
|
|
|
|
|
+ // Import category in the exact order as the outline's placement in the OPML, at the end of positioned categories
|
|
|
|
|
+ $category = $this->createCategory($category_element, $dry_run, ++$highest_position);
|
|
|
if ($category !== null) {
|
|
if ($category !== null) {
|
|
|
$categories_by_names[$category->name()] = $category;
|
|
$categories_by_names[$category->name()] = $category;
|
|
|
$nb_categories++;
|
|
$nb_categories++;
|
|
@@ -371,7 +381,7 @@ class FreshRSS_Import_Service {
|
|
|
* @param bool $dry_run true to not create the category in database.
|
|
* @param bool $dry_run true to not create the category in database.
|
|
|
* @return FreshRSS_Category|null The created category, or null if it failed.
|
|
* @return FreshRSS_Category|null The created category, or null if it failed.
|
|
|
*/
|
|
*/
|
|
|
- private function createCategory(array $category_element, bool $dry_run): ?FreshRSS_Category {
|
|
|
|
|
|
|
+ private function createCategory(array $category_element, bool $dry_run, int $position): ?FreshRSS_Category {
|
|
|
$name = $category_element['text'] ?? $category_element['title'] ?? '';
|
|
$name = $category_element['text'] ?? $category_element['title'] ?? '';
|
|
|
$name = Minz_Helper::htmlspecialchars_utf8($name);
|
|
$name = Minz_Helper::htmlspecialchars_utf8($name);
|
|
|
$category = new FreshRSS_Category($name);
|
|
$category = new FreshRSS_Category($name);
|
|
@@ -384,6 +394,8 @@ class FreshRSS_Import_Service {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $category->_attribute('position', $position);
|
|
|
|
|
+
|
|
|
if ($dry_run) {
|
|
if ($dry_run) {
|
|
|
return $category;
|
|
return $category;
|
|
|
}
|
|
}
|