From 4752d5e1050dfa894687881b7bd4d9930adc96d7 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Fri, 20 Sep 2024 11:09:11 +0200 Subject: [PATCH] #70 [Tools] fix: missing ref for exportshortener --- .../exportshortenerdocument/index.php | 2 + .../mod_exportshortenerdocument_standard.php | 42 +++++++++++++++++++ .../easyurl/easyurldocuments/index.php | 2 + core/modules/modEasyURL.class.php | 3 ++ view/easyurltools.php | 41 +++++++++--------- 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 core/modules/easyurl/easyurldocuments/exportshortenerdocument/index.php create mode 100644 core/modules/easyurl/easyurldocuments/exportshortenerdocument/mod_exportshortenerdocument_standard.php create mode 100644 core/modules/easyurl/easyurldocuments/index.php diff --git a/core/modules/easyurl/easyurldocuments/exportshortenerdocument/index.php b/core/modules/easyurl/easyurldocuments/exportshortenerdocument/index.php new file mode 100644 index 0000000..17927e6 --- /dev/null +++ b/core/modules/easyurl/easyurldocuments/exportshortenerdocument/index.php @@ -0,0 +1,2 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * \file core/modules/easyurl/easyurldocuments/exportshortenerdocument/mod_exportshortenerdocument_standard.php + * \ingroup easyurl + * \brief File of class to manage export shortener document numbering rules standard + */ + +// Load Saturne libraries +require_once __DIR__ . '/../../../../../../saturne/core/modules/saturne/modules_saturne.php'; + +/** + * Class to manage export shortener document numbering rules standard + */ +class mod_exportshortenerdocument_standard extends ModeleNumRefSaturne +{ + /** + * @var string Numbering module ref prefix + */ + public string $prefix = 'ESD'; + + /** + * @var string Name + */ + public string $name = 'Titan'; +} diff --git a/core/modules/easyurl/easyurldocuments/index.php b/core/modules/easyurl/easyurldocuments/index.php new file mode 100644 index 0000000..17927e6 --- /dev/null +++ b/core/modules/easyurl/easyurldocuments/index.php @@ -0,0 +1,2 @@ + ['EASYURL_SHORTENER_ADDON', 'chaine', 'mod_shortener_standard', '', 0, 'current'], + // CONST EXPORT SHORTENER DOCUMENT + $i++ => ['EASYURL_EXPORTSHORTENERDOCUMENT_ADDON', 'chaine', 'mod_exportshortenerdocument_standard', '', 0, 'current'], + // CONST DOLIBARR $i++ => ['CONTRACT_ALLOW_ONLINESIGN', 'integer', 1, '', 0, 'current'], $i => ['FICHINTER_ALLOW_ONLINE_SIGN', 'integer', 1, '', 0, 'current'] diff --git a/view/easyurltools.php b/view/easyurltools.php index 543ac98..123bcf0 100644 --- a/view/easyurltools.php +++ b/view/easyurltools.php @@ -44,6 +44,10 @@ // Get parameters $action = (GETPOSTISSET('action') ? GETPOST('action', 'aZ09') : 'view'); +// Initialize technical objects +$shortener = new Shortener($db); +$exportShortenerDocument = new ExportShortenerDocument($db); + // Initialize view objects $form = new Form($db); @@ -65,7 +69,6 @@ $urlParameters = $data['url_parameters']; if (dol_strlen($originalUrl) > 0 || dol_strlen(getDolGlobalString('EASYURL_DEFAULT_ORIGINAL_URL')) > 0) { - $shortener = new Shortener($db); $shortener->ref = $shortener->getNextNumRef(); if (dol_strlen($originalUrl) > 0) { $shortener->original_url = $originalUrl . $urlParameters; @@ -92,11 +95,15 @@ } if ($action == 'generate_export' && $permissionToAdd) { - $export = new ExportShortenerDocument($db); + $numberingModules = [$exportShortenerDocument->module . 'documents/' . $exportShortenerDocument->element => getDolGlobalString('EASYURL_EXPORTSHORTENERDOCUMENT_ADDON')]; + list($refModName) = saturne_require_objects_mod($numberingModules, 'easyurl'); + $objectDocumentRef = $refModName->getNextValue($exportShortenerDocument); + + $exportShortenerDocument->ref = $objectDocumentRef; + + $exportShortenerDocument->create($user); - $export->create($user); $nbUrl = GETPOST('nb_url'); - $shortener = new Shortener($db); $shorteners = $shortener->fetchAll('DESC', 'rowid', $nbUrl); if (is_array($shorteners) && !empty($shorteners)) { $data = [ @@ -105,8 +112,9 @@ 'first_shortener_id' => end($shorteners)->id, 'number_shortener_url' => $nbUrl ]; - $export->json = json_encode($data); - $export->generateFile(); + $exportShortenerDocument->ref = $objectDocumentRef; + $exportShortenerDocument->json = json_encode($data); + $exportShortenerDocument->generateFile(); } header('Location: ' . $_SERVER['PHP_SELF'] . '?success=true&successType=export'); exit; @@ -134,11 +142,11 @@ $langs->transnoentities('ExportGenerating'), - 'ExportError' => $langs->transnoentities('ExportError'), - 'ExportSuccess' => $langs->transnoentities('ExportSuccess'), - 'Success' => $langs->transnoentities('Success'), - 'Error' => $langs->transnoentities('Error'), + 'ExportGenerating' => $langs->transnoentities('ExportGenerating'), + 'ExportError' => $langs->transnoentities('ExportError'), + 'ExportSuccess' => $langs->transnoentities('ExportSuccess'), + 'Success' => $langs->transnoentities('Success'), + 'Error' => $langs->transnoentities('Error'), ]; print saturne_show_notice('', '', 'success', 'notice-infos', 0, 1, '', $translations); @@ -202,19 +210,12 @@ print '' . $langs->trans('Action') . ''; print ''; -$exportShortenerDocument = new ExportShortenerDocument($db); $exportShortenerDocuments = $exportShortenerDocument->fetchAll('DESC', 'rowid', 0, 0, ['customsql' => 't.type="' . $exportShortenerDocument->element . '"']); - if (is_array($exportShortenerDocuments) && !empty($exportShortenerDocuments)) { - - $shortener = new Shortener($db); - foreach ($exportShortenerDocuments as $exportShortenerDocument) { - $data = json_decode($exportShortenerDocument->json, true); $shorteners = $shortener->fetchAll('', '', $data['number_shortener_url'], 0, ['customsql' => 't.rowid >=' . $data['first_shortener_id']]); - if (is_array($shorteners) && !empty($shorteners)) { print ''; print '' . $exportShortenerDocument->ref . ''; @@ -226,10 +227,10 @@ print '' . count(array_filter($shorteners, function ($elem) {return $elem->status == Shortener::STATUS_ASSIGN;})) . ''; $uploadDir = $conf->easyurl->multidir_output[$conf->entity ?? 1]; - $fileDir = $uploadDir . '/' . $exportShortenerDocument->element; + $fileDir = $uploadDir . '/' . $exportShortenerDocument->element; if (dol_is_file($fileDir . '/' . $exportShortenerDocument->last_main_doc)) { $documentUrl = DOL_URL_ROOT . '/document.php'; - $fileUrl = $documentUrl . '?modulepart=easyurl&file=' . urlencode($exportShortenerDocument->element . '/' . $exportShortenerDocument->last_main_doc); + $fileUrl = $documentUrl . '?modulepart=easyurl&file=' . urlencode($exportShortenerDocument->element . '/' . $exportShortenerDocument->last_main_doc); print '
' . img_picto($langs->trans('File') . ' : ' . $exportShortenerDocument->last_main_doc, 'fa-file-csv') . '
'; } print '';