Skip to content

Commit 8476276

Browse files
committed
Merge branch '4.0' into 'main'
2 parents a2d7be2 + 218d8ea commit 8476276

File tree

5 files changed

+65
-37
lines changed

5 files changed

+65
-37
lines changed

phpmyfaq/faq.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
$multiCategories = $category->getCategoriesFromFaq($faqId);
189189
if ((is_countable($multiCategories) ? count($multiCategories) : 0) > 1) {
190190
foreach ($multiCategories as $multiCategory) {
191-
$path = $category->getPath($multiCategory['id'], ' » ', true, 'breadcrumb-related-categories');
191+
$path = $category->getPath($multiCategory['id'], ' » ', true, 'list-unstyled');
192192
if ('' === trim($path)) {
193193
continue;
194194
}

phpmyfaq/src/phpMyFAQ/Category.php

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,9 @@ public function buildAdminCategoryTree(array $categories, int $parentId = 0): ar
389389
$result = [];
390390

391391
foreach ($categories as $category) {
392-
if ($category['parent_id'] == $parentId) {
392+
if ($category['parent_id'] === $parentId) {
393393
$categoryId = $category['id'];
394-
$children = $this->buildAdminCategoryTree($categories, $categoryId);
395-
$result[$categoryId] = [];
394+
$result[$categoryId] = $this->buildAdminCategoryTree($categories, $categoryId);
396395
}
397396
}
398397

@@ -456,18 +455,35 @@ private function getSymbol(int $categoryId, int $parentId): string
456455
*/
457456
private function getNodes(int $categoryId): array
458457
{
459-
if (($categoryId > 0) && (isset($this->categoryName[$categoryId]['level']))) {
460-
$thisLevel = $this->categoryName[$categoryId]['level'];
461-
$temp = [];
462-
for ($i = $thisLevel; $i > 0; --$i) {
463-
$categoryId = $this->categoryName[$categoryId]['parent_id'];
464-
array_unshift($temp, $categoryId);
458+
$nodes = [];
459+
460+
if ($categoryId <= 0) {
461+
return $nodes;
462+
}
463+
464+
$nodes[] = $categoryId;
465+
466+
$currentCategoryId = $categoryId;
467+
while ($currentCategoryId > 0) {
468+
if (!isset($this->categoryName[$currentCategoryId])) {
469+
break;
470+
}
471+
472+
$parentId = (int)$this->categoryName[$currentCategoryId]['parent_id'];
473+
474+
if ($parentId <= 0 || $parentId === $currentCategoryId) {
475+
break;
465476
}
466477

467-
return $temp;
478+
if (!isset($this->categoryName[$parentId])) {
479+
break;
480+
}
481+
482+
array_unshift($nodes, $parentId);
483+
$currentCategoryId = $parentId;
468484
}
469485

470-
return [];
486+
return $nodes;
471487
}
472488

473489
/**
@@ -620,26 +636,21 @@ public function getPath(
620636

621637
$ids = $this->getNodes($catId);
622638

623-
$num = count($ids);
624639
$tempName = [];
625640
$categoryId = [];
626641
$description = [];
627642
$breadcrumb = [];
628643

629-
630-
for ($i = 0; $i < $num; ++$i) {
631-
$lineCategory = $this->getLineCategory($ids[$i]);
632-
if (array_key_exists($lineCategory, $this->treeTab)) {
633-
$tempName[] = $this->treeTab[$this->getLineCategory($ids[$i])]['name'];
634-
$categoryId[] = $this->treeTab[$this->getLineCategory($ids[$i])]['id'];
635-
$description[] = $this->treeTab[$this->getLineCategory($ids[$i])]['description'];
644+
foreach ($ids as $id) {
645+
if (isset($this->categoryName[$id])) {
646+
$tempName[] = $this->categoryName[$id]['name'];
647+
$categoryId[] = $id;
648+
$description[] = $this->categoryName[$id]['description'] ?? '';
636649
}
637650
}
638651

639-
if (isset($this->treeTab[$this->getLineCategory($catId)]['name'])) {
640-
$tempName[] = $this->treeTab[$this->getLineCategory($catId)]['name'];
641-
$categoryId[] = $this->treeTab[$this->getLineCategory($catId)]['id'];
642-
$description[] = $this->treeTab[$this->getLineCategory($catId)]['description'];
652+
if (empty($tempName)) {
653+
return '';
643654
}
644655

645656
// @todo Maybe this should be done somewhere else ...

phpmyfaq/src/phpMyFAQ/Category/Order.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,11 @@ public function setCategoryTree(
121121
public function getCategoryTree(array $categories, int $parentId = 0): array
122122
{
123123
$result = [];
124-
$stack = [[$parentId, &$result]];
125124

126-
while (!empty($stack)) {
127-
$popped = array_pop($stack);
128-
$currentParentId = $popped[0];
129-
$currentResult = &$popped[1];
130-
131-
foreach ($categories as $category) {
132-
if ((int)$category['parent_id'] === $parentId) {
133-
$childCategories = $this->getCategoryTree($categories, (int)$category['category_id']);
134-
$result[$category['category_id']] = $childCategories;
135-
}
125+
foreach ($categories as $category) {
126+
if ((int)$category['parent_id'] === $parentId) {
127+
$childCategories = $this->getCategoryTree($categories, (int)$category['category_id']);
128+
$result[$category['category_id']] = $childCategories;
136129
}
137130
}
138131

phpmyfaq/src/phpMyFAQ/Instance/Database/Pgsql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Pgsql extends Database implements Driver
292292
PRIMARY KEY (id, lang))',
293293

294294
'faqseo' => 'CREATE TABLE %sfaqseo (
295-
id INTEGER NOT NULL,
295+
id SERIAL NOT NULL,
296296
type VARCHAR(32) NOT NULL,
297297
reference_id INTEGER NOT NULL,
298298
reference_language VARCHAR(5) NOT NULL,

phpmyfaq/src/phpMyFAQ/Setup/Update.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function applyUpdates(): bool
167167
$this->applyUpdates400Beta2();
168168
$this->applyUpdates405();
169169
$this->applyUpdates407();
170+
$this->applyUpdates409();
170171

171172
// 4.1 updates
172173
$this->applyUpdates410Alpha();
@@ -901,7 +902,7 @@ private function applyUpdates405(): void
901902
break;
902903
case 'pgsql':
903904
$this->queries[] = sprintf(
904-
'ALTER TABLE %sfaqforms ALTER COLUMN input_label TYPE VARCHAR(500)',
905+
'ALTER TABLE %sfaqforms ALTER COLUMN input_label SET TYPE VARCHAR(500)',
905906
Database::getTablePrefix()
906907
);
907908
$this->queries[] = sprintf(
@@ -1069,6 +1070,29 @@ private function applyUpdates407(): void
10691070
}
10701071
}
10711072

1073+
private function applyUpdates409(): void
1074+
{
1075+
if (version_compare($this->version, '4.0.9', '<')) {
1076+
if (Database::getType() === 'pgsql') {
1077+
$this->queries[] = sprintf(
1078+
'CREATE SEQUENCE %sfaqseo_id_seq',
1079+
Database::getTablePrefix()
1080+
);
1081+
$this->queries[] = sprintf(
1082+
'ALTER TABLE %sfaqseo ALTER COLUMN id SET DEFAULT nextval(\'faqseo_id_seq\')',
1083+
Database::getTablePrefix()
1084+
);
1085+
$this->queries[] = sprintf(
1086+
'SELECT setval(\'faqseo_id_seq\', (SELECT MAX(id) FROM %sfaqseo));',
1087+
Database::getTablePrefix()
1088+
);
1089+
$this->queries[] = sprintf(
1090+
'ALTER TABLE %sfaqseo ALTER COLUMN id SET NOT NULL',
1091+
Database::getTablePrefix()
1092+
);
1093+
}
1094+
}
1095+
}
10721096
private function applyUpdates410Alpha(): void
10731097
{
10741098
if (version_compare($this->version, '4.1.0-alpha', '<')) {

0 commit comments

Comments
 (0)