Compare commits
1 Commits
c744863094
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd88be717e |
@@ -11,6 +11,7 @@ use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\Database\DatabaseDriver;
|
||||
use EIS\Component\EIS\Administrator\Helper\SettingsHelper;
|
||||
use EIS\Component\EIS\Administrator\Service\DocumentScanner;
|
||||
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
@@ -19,50 +20,29 @@ class DisplayController extends BaseController
|
||||
/**
|
||||
* Button-Aktion: PDF-Verzeichnis scannen und in Datenbank speichern
|
||||
*/
|
||||
|
||||
public function scan(): void
|
||||
{
|
||||
{
|
||||
// CSRF prüfen (Form hat Token)
|
||||
if (!Session::checkToken('post')) {
|
||||
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
/** @var DatabaseDriver $db */
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Pfad aus Settings laden (Key/Value); Default /var/www/pdf
|
||||
$path = SettingsHelper::getSetting('document_root', '/var/www/pdf');
|
||||
try {
|
||||
$newIds = DocumentScanner::run();
|
||||
|
||||
if (!$path || !is_dir($path)) {
|
||||
$app->enqueueMessage(
|
||||
Text::sprintf('COM_EIS_MSG_PATH_NOT_EXISTS', $path) ?: ('Pfad ungültig oder nicht gesetzt: ' . $path),
|
||||
'error'
|
||||
);
|
||||
$this->setRedirect(Route::_('index.php?option=com_eis&view=main', false));
|
||||
return;
|
||||
}
|
||||
|
||||
// Verzeichnis rekursiv scannen
|
||||
$data = $this->scanFolder($path);
|
||||
|
||||
// Alte Einträge löschen (Hinweis: Dann sind ALLE eingefügten „neu“)
|
||||
$db->truncateTable('#__eis_documents');
|
||||
|
||||
// In Datenbank speichern und neue IDs sammeln (nur Dateien)
|
||||
$newIds = $this->saveToDb($data, null, $db);
|
||||
|
||||
// Neue IDs im UserState für die View -> virtueller Ordner "Neue Dokumente"
|
||||
// Wie bisher: New IDs für die View (virtueller Ordner "Neue Dokumente")
|
||||
$app->setUserState('com_eis.new_ids', $newIds);
|
||||
|
||||
// NEU: dauerhaft speichern (für das Frontend-Modul)
|
||||
SettingsHelper::setSetting('last_new_ids', json_encode($newIds, JSON_UNESCAPED_SLASHES));
|
||||
SettingsHelper::setSetting('last_scan_at', date('Y-m-d H:i:s'));
|
||||
|
||||
// Erfolgsmeldung
|
||||
$app->enqueueMessage(Text::_('COM_EIS_MSG_SCAN_DONE') ?: 'PDF-Struktur erfolgreich gespeichert.', 'message');
|
||||
$this->setRedirect(Route::_('index.php?option=com_eis&view=main', false));
|
||||
} catch (\Throwable $e) {
|
||||
$app->enqueueMessage($e->getMessage(), 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_eis&view=main', false));
|
||||
}
|
||||
/**
|
||||
* Rekursive Verzeichnisanalyse
|
||||
*/
|
||||
|
||||
Binary file not shown.
53
plugins/task/eisdocumentenscan/eisdocumentscan.php
Normal file
53
plugins/task/eisdocumentenscan/eisdocumentscan.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
|
||||
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
|
||||
use Joomla\Component\Scheduler\Administrator\Task\Status;
|
||||
|
||||
use EIS\Component\EIS\Administrator\Service\DocumentScanner;
|
||||
|
||||
final class PlgTaskEisdocumentscan extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
use TaskPluginTrait;
|
||||
|
||||
|
||||
protected const TASKS_MAP = [
|
||||
'eisdocumentscan.documentscan' => [
|
||||
'langConstPrefix' => 'PLG_TASK_EISDOCUMENTSCAN_TASK_DOCUMENTSCAN',
|
||||
'method' => 'documentscan',
|
||||
'form' => 'documentscan',
|
||||
],
|
||||
];
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
// Wichtig: auf Trait-Methoden mappen!
|
||||
'onTaskOptionsList' => 'advertiseRoutines',
|
||||
'onExecuteTask' => 'standardRoutineHandler',
|
||||
'onContentPrepareForm' => 'enhanceTaskItemForm',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Muss int Status zurückgeben
|
||||
*/
|
||||
public function documentscan(ExecuteTaskEvent $event): int
|
||||
{
|
||||
try {
|
||||
DocumentScanner::run();
|
||||
|
||||
$this->logTask('EIS Dokumentenscan erfolgreich', 'info');
|
||||
|
||||
return Status::OK;
|
||||
} catch (\Throwable $e) {
|
||||
$this->logTask('EIS Dokumentenscan FEHLER: ' . $e->getMessage(), 'error');
|
||||
|
||||
return Status::KNOCKOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
plugins/task/eisdocumentenscan/eisdocumentscan.xml
Normal file
18
plugins/task/eisdocumentenscan/eisdocumentscan.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="plugin" group="task" method="upgrade">
|
||||
<name>plg_task_eisdocumentscan</name>
|
||||
<author>TS-IT24</author>
|
||||
<version>1.0.2</version>
|
||||
<description>Task Plugin: EIS Dokumentenscan</description>
|
||||
|
||||
<files>
|
||||
<filename plugin="eisdocumentscan">eisdocumentscan.php</filename>
|
||||
<folder>forms</folder>
|
||||
<folder>language</folder>
|
||||
</files>
|
||||
|
||||
<languages>
|
||||
<language tag="de-DE">language/de-DE/de-DE.plg_task_eisdocumentscan.ini</language>
|
||||
<language tag="de-DE">language/de-DE/de-DE.plg_task_eisdocumentscan.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
BIN
plugins/task/eisdocumentenscan/eisdocumentscan.zip
Normal file
BIN
plugins/task/eisdocumentenscan/eisdocumentscan.zip
Normal file
Binary file not shown.
5
plugins/task/eisdocumentenscan/forms/documentscan.xml
Normal file
5
plugins/task/eisdocumentenscan/forms/documentscan.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="params" label="PLG_TASK_EISDOCUMENTSCAN_FIELDSET_PARAMS">
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -0,0 +1,4 @@
|
||||
PLG_TASK_EISDOCUMENTSCAN_FIELDSET_PARAMS="Parameter"
|
||||
|
||||
PLG_TASK_EISDOCUMENTSCAN_TASK_DOCUMENTSCAN_TITLE="EIS: Dokumente scannen"
|
||||
PLG_TASK_EISDOCUMENTSCAN_TASK_DOCUMENTSCAN_DESC="Scannt das PDF-Verzeichnis und aktualisiert die EIS-Datenbank."
|
||||
@@ -0,0 +1,2 @@
|
||||
PLG_TASK_EISDOCUMENTSCAN="Task - EIS Dokumentenscan"
|
||||
PLG_TASK_EISDOCUMENTSCAN_XML_DESCRIPTION="Scheduler-Task: scannt das PDF-Verzeichnis und aktualisiert die EIS-Datenbank."
|
||||
Reference in New Issue
Block a user