-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrated admin import page to controller (#3257)
- Loading branch information
Showing
10 changed files
with
178 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
phpmyfaq/assets/templates/admin/import-export/import.csv.twig
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{% extends '@admin/index.twig' %} | ||
|
||
{% 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-upload"></i> | ||
{{ adminHeaderImport }} | ||
</h1> | ||
</div> | ||
|
||
<div class="card shadow mb-4" id="divImportColumns"> | ||
<h5 class="card-header py-3"> | ||
{{ adminHeaderCSVImportColumns }} | ||
</h5> | ||
<div class="card-body"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<p>{{ msgImportRecordsColumnStructure }}</p> | ||
<ul> | ||
<li>{{ categoryId }} *</li> | ||
<li>{{ question }} *</li> | ||
<li>{{ answer }} *</li> | ||
<li>{{ keywords }} {{ seperateWithCommas }}</li> | ||
<li>{{ languageCode }} *</li> | ||
<li>{{ author }} *</li> | ||
<li>{{ email }} *</li> | ||
<li>{{ is_active }} {{ trueFalse }} *</li> | ||
<li>{{ is_sticky }} {{ trueFalse }} *</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="card shadow mb-4"> | ||
<form id="uploadCSVFileForm" method="post" action="./api/faqs/import" | ||
enctype="multipart/form-data" data-pmf-csrf="{{ csrfToken }}"> | ||
<h5 class="card-header py-3"> | ||
{{ adminHeaderCSVImport }} | ||
</h5> | ||
<div class="card-body"> | ||
<p>{{ adminBodyCSVImport }}</p> | ||
<div class="row"> | ||
<label class="col-lg-4 col-form-label">{{ adminImportLabel }}:</label> | ||
<div class="col-lg-8"> | ||
<input type="file" id="fileInputCSVUpload" name="userfile"> | ||
</div> | ||
</div> | ||
<div class="form-row row"> | ||
<div class="d-flex justify-content-center"> | ||
<button class="btn btn-primary btn-lg m-2" type="submit" id="submitButton"> | ||
<i aria-hidden="true" class="bi bi-upload"></i> {{ adminCSVImport }} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
phpmyfaq/src/phpMyFAQ/Controller/Administration/ImportController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* The Administration Import Controller | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-11-23 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpMyFAQ\Controller\Administration; | ||
|
||
use phpMyFAQ\Core\Exception; | ||
use phpMyFAQ\Enums\PermissionType; | ||
use phpMyFAQ\Session\Token; | ||
use phpMyFAQ\Translation; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Twig\Error\LoaderError; | ||
|
||
class ImportController extends AbstractAdministrationController | ||
{ | ||
/** | ||
* @throws Exception | ||
* @throws LoaderError | ||
* @throws \Exception | ||
*/ | ||
#[Route('/import', name: 'admin.import', methods: ['GET'])] | ||
public function index(Request $request): Response | ||
{ | ||
$this->userHasPermission(PermissionType::FAQ_ADD); | ||
|
||
return $this->render( | ||
'@admin/import-export/import.twig', | ||
[ | ||
... $this->getHeader($request), | ||
... $this->getFooter(), | ||
'adminHeaderImport' => Translation::get('msgImportRecords'), | ||
'adminHeaderCSVImport' => Translation::get('msgImportCSVFile'), | ||
'adminBodyCSVImport' => Translation::get('msgImportCSVFileBody'), | ||
'adminImportLabel' => Translation::get('ad_csv_file'), | ||
'adminCSVImport' => Translation::get('msgImport'), | ||
'adminHeaderCSVImportColumns' => Translation::get('msgColumnStructure'), | ||
'categoryId' => Translation::get('ad_categ_categ'), | ||
'question' => Translation::get('ad_entry_topic'), | ||
'answer' => Translation::get('ad_entry_content'), | ||
'keywords' => Translation::get('ad_entry_keywords'), | ||
'author' => Translation::get('ad_entry_author'), | ||
'email' => Translation::get('msgEmail'), | ||
'languageCode' => Translation::get('msgLanguageCode'), | ||
'seperateWithCommas' => Translation::get('msgSeperateWithCommas'), | ||
'tags' => Translation::get('ad_entry_tags'), | ||
'msgImportRecordsColumnStructure' => Translation::get('msgImportRecordsColumnStructure'), | ||
'csrfToken' => Token::getInstance($this->container->get('session'))->getTokenString('importfaqs'), | ||
'is_active' => Translation::get('ad_entry_active'), | ||
'is_sticky' => Translation::get('ad_entry_sticky'), | ||
'trueFalse' => Translation::get('msgCSVImportTrueOrFalse') | ||
] | ||
); | ||
} | ||
} |