diff --git a/phpmyfaq/assets/templates/admin/content/orphaned-faqs.twig b/phpmyfaq/assets/templates/admin/content/orphaned-faqs.twig index a882daef98..844e059c5a 100644 --- a/phpmyfaq/assets/templates/admin/content/orphaned-faqs.twig +++ b/phpmyfaq/assets/templates/admin/content/orphaned-faqs.twig @@ -19,11 +19,12 @@ {{ 'msgLanguage' | translate }} {{ 'msgQuestion' | translate }} + {% for faq in orphanedFaqs %} {{ faq.faqId }} - {{ faq.language }} + {{ faq.language | getFromLanguageCode }} {{ faq.question }} diff --git a/phpmyfaq/src/phpMyFAQ/Administration/Faq.php b/phpmyfaq/src/phpMyFAQ/Administration/Faq.php index 5d540e3432..afaf664ad0 100644 --- a/phpmyfaq/src/phpMyFAQ/Administration/Faq.php +++ b/phpmyfaq/src/phpMyFAQ/Administration/Faq.php @@ -227,8 +227,6 @@ public function getOrphanedFaqs(): array FROM %sfaqdata fd WHERE - fd.lang = '%s' - AND fd.active = 'yes' AND fd.id NOT IN ( @@ -242,18 +240,19 @@ public function getOrphanedFaqs(): array GROUP BY fd.id, fd.lang, fd.thema ORDER BY - fd.id DESC", + fd.lang ASC, fd.id DESC", Database::getTablePrefix(), - $this->configuration->getLanguage()->getLanguage(), Database::getTablePrefix(), ); $result = $this->configuration->getDb()->query($query); $orphaned = []; - - $oldId = 0; + $seen = []; while ($row = $this->configuration->getDb()->fetchObject($result)) { - if ($oldId !== $row->id) { + $key = $row->id . '-' . $row->lang; + + if (!isset($seen[$key])) { + $seen[$key] = true; $data = new stdClass(); $data->faqId = $row->id; $data->language = $row->lang; @@ -266,8 +265,6 @@ public function getOrphanedFaqs(): array ); $orphaned[] = $data; } - - $oldId = $row->id; } return $orphaned; diff --git a/phpmyfaq/src/phpMyFAQ/Category.php b/phpmyfaq/src/phpMyFAQ/Category.php index 794e606353..04037a2a37 100755 --- a/phpmyfaq/src/phpMyFAQ/Category.php +++ b/phpmyfaq/src/phpMyFAQ/Category.php @@ -90,11 +90,15 @@ public function __construct( private readonly Configuration $configuration, array $groups = [], bool $withPermission = true, + ?string $faqLanguage = null, ) { $this->categoryCache = new CategoryCache(); $this->categoryPermissionContext = new CategoryPermissionContext($groups); - $this->setLanguage($this->configuration->getLanguage()->getLanguage()); - + $languageToUse = + $faqLanguage !== null && $faqLanguage !== '' + ? $faqLanguage + : $this->configuration->getLanguage()->getLanguage(); + $this->setLanguage($languageToUse); $this->getOrderedCategories($withPermission); foreach ($this->categoryCache->getCategoryNames() as $categoryName) { diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php index 65fd006429..5b703ee0f5 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php @@ -239,14 +239,18 @@ public function addInCategory(Request $request): Response * @throws \Exception * @todo refactor Twig template variables */ - #[Route(path: '/faq/edit/{faqId}/{faqLanguage}', name: 'admin.faq.edit', methods: ['GET'])] + #[Route(path: '/faq/edit/{faqId}/{faqLanguage}', name: 'admin.faq.edit', methods: ['GET', 'POST'])] public function edit(Request $request): Response { $this->userHasPermission(PermissionType::FAQ_EDIT); [$currentAdminUser, $currentAdminGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser); - $category = new Category($this->configuration, $currentAdminGroups, true); + $faqId = (int) Filter::filterVar($request->attributes->get('faqId'), FILTER_VALIDATE_INT); + $faqLanguage = Filter::filterVar($request->attributes->get('faqLanguage'), FILTER_SANITIZE_SPECIAL_CHARS); + $selectedRevisionId = Filter::filterVar($request->request->get('selectedRevisionId'), FILTER_VALIDATE_INT); + + $category = new Category($this->configuration, $currentAdminGroups, true, $faqLanguage); $category->setUser($currentAdminUser); $category->setGroups($currentAdminGroups); $category->buildCategoryTree(); @@ -258,10 +262,6 @@ public function edit(Request $request): Response $faq = $this->container->get(id: 'phpmyfaq.faq'); $userHelper = $this->container->get(id: 'phpmyfaq.helper.user-helper'); - $faqId = (int) Filter::filterVar($request->attributes->get('faqId'), FILTER_VALIDATE_INT); - $faqLanguage = Filter::filterVar($request->attributes->get('faqLanguage'), FILTER_SANITIZE_SPECIAL_CHARS); - $selectedRevisionId = Filter::filterVar($request->attributes->get('selectedRevisionId'), FILTER_VALIDATE_INT); - $this->adminLog->log($this->currentUser, AdminLogType::FAQ_EDIT->value . ':' . $faqId); $categories = $categoryRelation->getCategories($faqId, $faqLanguage); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/OrphanedFaqsController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/OrphanedFaqsController.php index 3e0be0804d..863d8a4ec6 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/OrphanedFaqsController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/OrphanedFaqsController.php @@ -21,10 +21,12 @@ use phpMyFAQ\Core\Exception; use phpMyFAQ\Enums\PermissionType; +use phpMyFAQ\Twig\Extensions\LanguageCodeTwigExtension; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Twig\Error\LoaderError; +use Twig\Extension\AttributeExtension; final class OrphanedFaqsController extends AbstractAdministrationController { @@ -40,6 +42,8 @@ public function index(Request $request): Response $faq = $this->container->get(id: 'phpmyfaq.admin.faq'); + $this->addExtension(new AttributeExtension(LanguageCodeTwigExtension::class)); + return $this->render('@admin/content/orphaned-faqs.twig', [ ...$this->getHeader($request), ...$this->getFooter(),