Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion phpmyfaq/assets/templates/admin/content/orphaned-faqs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
<th>{{ 'msgLanguage' | translate }}</th>
<th>{{ 'msgQuestion' | translate }}</th>
</tr>
</thead>
<tbody>
{% for faq in orphanedFaqs %}
<tr>
<td>{{ faq.faqId }}</td>
<td>{{ faq.language }}</td>
<td>{{ faq.language | getFromLanguageCode }}</td>
<td>
<a href="{{ faq.url }}">{{ faq.question }}</a>
</td>
Expand Down
15 changes: 6 additions & 9 deletions phpmyfaq/src/phpMyFAQ/Administration/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public function getOrphanedFaqs(): array
FROM
%sfaqdata fd
WHERE
fd.lang = '%s'
AND
fd.active = 'yes'
AND
fd.id NOT IN (
Expand All @@ -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;
Expand All @@ -266,8 +265,6 @@ public function getOrphanedFaqs(): array
);
$orphaned[] = $data;
}

$oldId = $row->id;
}

return $orphaned;
Expand Down
8 changes: 6 additions & 2 deletions phpmyfaq/src/phpMyFAQ/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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(),
Expand Down