Skip to content

Commit

Permalink
refactor: migrated admin export page to controller (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Nov 23, 2024
1 parent 8333161 commit 3cf01e8
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 160 deletions.
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ server {
rewrite admin/api/(.*) /admin/api/index.php last;

# Administration pages
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) /admin/front.php last;
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) /admin/front.php last;

# REST API v3.0 and v3.1
rewrite ^api/v3\.[01]/(.*) /api/index.php last;
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
# Administration API
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
# Administration pages
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) admin/front.php [L,QSA]
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) admin/front.php [L,QSA]
# Private APIs
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
# Setup APIs
Expand Down
74 changes: 0 additions & 74 deletions phpmyfaq/admin/export.php

This file was deleted.

2 changes: 1 addition & 1 deletion phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
'importcsv',
'msgImportRecords'
);
$secLevelEntries['imports_exports'] .= $adminHelper->addMenuEntry('export', 'export', 'ad_menu_export');
$secLevelEntries['imports_exports'] .= $adminHelper->addMenuEntry('export', 'export', 'ad_menu_export', 'export');

$secLevelEntries['backup'] = $adminHelper->addMenuEntry('editconfig', 'backup', 'ad_menu_backup', 'backup');

Expand Down
3 changes: 0 additions & 3 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,6 @@
case 'importcsv':
require 'import.csv.php';
break;
case 'export':
require 'export.php';
break;
// Config administration
case 'forms':
require 'forms.php';
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

<!-- Exports -->
{% if secondLevelEntries['imports_exports'] != '' %}
<a class="nav-link {{ exportsPage ? '' : 'collapsed' }}" href="?action=export" data-bs-toggle="collapse"
<a class="nav-link {{ exportsPage ? '' : 'collapsed' }}" href="./export" data-bs-toggle="collapse"
data-bs-target="#collapseExports" aria-expanded="false" aria-controls="collapseExports">
<div class="pmf-admin-nav-link-icon">
<i aria-hidden="true" class="bi bi-archive h6"></i>
Expand Down
152 changes: 78 additions & 74 deletions phpmyfaq/assets/templates/admin/import-export/export.twig
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-book bi-fw"></i>
{{ adminHeaderExport }}
</h1>
</div>
{% extends '@admin/index.twig' %}

<div class="row">
<div class="col-12">
<div class="card shadow">
<div class="card-body">
{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-book bi-fw"></i>
{{ adminHeaderExport }}
</h1>
</div>

{% if hasNoFaqs %}
<div class="alert alert-warning" role="alert">
{{ errorMessageNoFaqs }}
</div>
{% endif %}
<div class="row">
<div class="col-12">
<div class="card shadow">
<div class="card-body">

{% if hasCategories %}
<form action="./api/export/file" method="post" accept-charset="utf-8">
<h5>{{ headerCategories }}</h5>
<div class="row mb-2">
<label class="col-lg-2 col-form-label" for="categoryId">
{{ msgCategory }}
</label>
<div class="col-lg-4">
<select name="categoryId" id="categoryId" class="form-select">
<option value="0">{{ msgAllCategories }}</option>
{{ categoryOptions | raw }}
</select>
</div>
</div>
<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="downwards" name="downwards" checked>
<label class="form-check-label" for="downwards">{{ msgWithSubCategories }}</label>
</div>
</div>
{% if hasNoFaqs %}
<div class="alert alert-warning" role="alert">
{{ errorMessageNoFaqs }}
</div>
{% endif %}

<h5>{{ headerExportType }}</h5>
<div class="row mb-2">
<div class="offset-lg-2 col-lg-8">
<p>{{ msgChooseExportType }}</p>
<div class="form-check">
<input class="form-check-input" type="radio" name="export-type" id="json" value="json" checked>
<label class="form-check-label" for="json">JSON</label>
{% if hasCategories %}
<form action="./api/export/file" method="post" accept-charset="utf-8">
<h5>{{ headerCategories }}</h5>
<div class="row mb-2">
<label class="col-lg-2 col-form-label" for="categoryId">
{{ msgCategory }}
</label>
<div class="col-lg-4">
<select name="categoryId" id="categoryId" class="form-select">
<option value="0">{{ msgAllCategories }}</option>
{{ categoryOptions | raw }}
</select>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="export-type" id="pdf" value="pdf">
<label class="form-check-label" for="pdf">PDF</label>
</div>
<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="downwards" name="downwards" checked>
<label class="form-check-label" for="downwards">{{ msgWithSubCategories }}</label>
</div>
</div>
</div>
</div>

<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<p>{{ msgViewType }}</p>
<div class="form-check">
<input class="form-check-input" type="radio" name="disposition" id="{{ msgDownloadType }}"
value="{{ msgDownloadType }}" checked>
<label class="form-check-label" for="{{ msgDownloadType }}">{{ msgDownload }}</label>
<h5>{{ headerExportType }}</h5>
<div class="row mb-2">
<div class="offset-lg-2 col-lg-8">
<p>{{ msgChooseExportType }}</p>
<div class="form-check">
<input class="form-check-input" type="radio" name="export-type" id="json" value="json" checked>
<label class="form-check-label" for="json">JSON</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="export-type" id="pdf" value="pdf">
<label class="form-check-label" for="pdf">PDF</label>
</div>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="disposition"
id="{{ msgInlineType }}" value="{{ msgInlineType }}">
<label class="form-check-label" for="{{ msgInlineType }}">
{{ msgInline }}
</label>
</div>

<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<p>{{ msgViewType }}</p>
<div class="form-check">
<input class="form-check-input" type="radio" name="disposition" id="{{ msgDownloadType }}"
value="{{ msgDownloadType }}" checked>
<label class="form-check-label" for="{{ msgDownloadType }}">{{ msgDownload }}</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="disposition"
id="{{ msgInlineType }}" value="{{ msgInlineType }}">
<label class="form-check-label" for="{{ msgInlineType }}">
{{ msgInline }}
</label>
</div>
</div>
</div>
</div>

<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<button class="btn btn-secondary" type="reset" name="resetExport">
{{ buttonReset }}
</button>
<button class="btn btn-primary" type="submit" name="submitExport" formtarget="_blank">
{{ buttonExport }}
</button>
<div class="row mb-2">
<div class="offset-lg-2 col-lg-4">
<button class="btn btn-secondary" type="reset" name="resetExport">
{{ buttonReset }}
</button>
<button class="btn btn-primary" type="submit" name="submitExport" formtarget="_blank">
{{ buttonExport }}
</button>
</div>
</div>
</div>

</form>
{% endif %}
</form>
{% endif %}

</div>
</div>
</div>

</div>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

<!-- Exports -->
{% if secondLevelEntries['imports_exports'] != '' %}
<a class="nav-link {{ exportsPage ? '' : 'collapsed' }}" href="?action=export" data-bs-toggle="collapse"
<a class="nav-link {{ exportsPage ? '' : 'collapsed' }}" href="./export" data-bs-toggle="collapse"
data-bs-target="#collapseExports" aria-expanded="false" aria-controls="collapseExports">
<div class="pmf-admin-nav-link-icon">
<i aria-hidden="true" class="bi bi-archive h6"></i>
Expand Down
6 changes: 6 additions & 0 deletions phpmyfaq/src/admin-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use phpMyFAQ\Controller\Administration\BackupController;
use phpMyFAQ\Controller\Administration\ConfigurationController;
use phpMyFAQ\Controller\Administration\ElasticsearchController;
use phpMyFAQ\Controller\Administration\ExportController;
use phpMyFAQ\Controller\Administration\InstanceController;
use phpMyFAQ\Controller\Administration\SessionKeepAliveController;
use phpMyFAQ\Controller\Administration\StopWordsController;
Expand Down Expand Up @@ -60,6 +61,11 @@
'controller' => [ElasticsearchController::class, 'index'],
'methods' => 'GET'
],
'admin.export' => [
'path' => '/export',
'controller' => [ExportController::class, 'index'],
'methods' => 'GET'
],
'admin.instance.edit' => [
'path' => '/instance/edit/{id}',
'controller' => [InstanceController::class, 'edit'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ protected function getHeader(Request $request): array
$secLevelEntries['imports_exports'] .= $adminHelper->addMenuEntry(
'export',
'export',
'ad_menu_export'
'ad_menu_export',
'export'
);

$secLevelEntries['backup'] = $adminHelper->addMenuEntry('editconfig', 'backup', 'ad_menu_backup', 'backup');
Expand Down Expand Up @@ -227,7 +228,6 @@ protected function getHeader(Request $request): array
case 'reportview':
$statisticsPage = true;
break;
case 'export':
case 'importcsv':
$exportsPage = true;
break;
Expand All @@ -246,6 +246,9 @@ protected function getHeader(Request $request): array
case 'admin.attachments':
$contentPage = true;
break;
case 'admin.export':
$exportsPage = true;
break;
case 'admin.backup':
case 'admin.backup.export':
case 'admin.backup.restore':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace phpMyFAQ\Controller\Administration;

use finfo;
use phpMyFAQ\Core\Exception;
use phpMyFAQ\Database;
use phpMyFAQ\Database\DatabaseHelper;
Expand Down Expand Up @@ -130,6 +129,7 @@ public function export(Request $request): Response

/**
* @throws \Exception
* @todo: Refactor this method
*/
#[Route('/backup/restore', name: 'admin.backup.restore', methods: ['POST'])]
public function restore(Request $request): Response
Expand Down
Loading

0 comments on commit 3cf01e8

Please sign in to comment.