From ce3654cb737f5cdf208a4984b042b133dbadbcf7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 8 Jan 2026 16:42:40 +0100 Subject: [PATCH] wait #7930 @1 --- .../AuditLinksOperation.php | 84 +++++++++++++++++-- .../packages/fluidbook/toolbox/css/style.less | 1 + 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php index aa614cc23..ef9229fbc 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php @@ -10,6 +10,8 @@ use Cubist\Excel\Excel; use Cubist\Excel\ExcelToArray; use Cubist\Util\Files\Files; use Cubist\Util\Str; +use Cubist\Util\WebVideo; +use Fluidbook\Tools\Links\Link; use Illuminate\Support\Facades\Route; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Alignment; @@ -28,7 +30,36 @@ trait AuditLinksOperation { Route::match(['get', 'post'], $segment . '/{id}/export_excel', $controller . '@exportExcel')->name("download_audit_links"); Route::match(['get', 'post'], $segment . '/{id}/import_excel', $controller . '@importExcel')->name("import_audit_links"); - Route::match(['get', 'post'], $segment . '/{cid}/import_excel_confirm', $controller . '@importExcel')->name("import_audit_links"); + Route::match(['get', 'post'], $segment . '/{cid}/import_excel_confirm', $controller . '@importExcelConfirm')->name("import_audit_links_confirm"); + } + + + protected function importExcelConfirm($cid) + { + $updates = cache()->get('auditlinks_confirmation_data_' . $cid); + $grouped = []; + foreach ($updates as $update) { + if (!isset($grouped[$update['fluidbook_id']])) { + $grouped[$update['fluidbook_id']] = []; + } + $grouped[$update['fluidbook_id']][$update['link_id']] = $update['new_url']; + } + + foreach ($grouped as $fluidbook_id => $updates) { + LinksData::getLinksAndRulers($fluidbook_id, $links, $rulers); + foreach ($updates as $id => $url) { + $link = $links[$id]; + if ($link['type'] == Link::WEBVIDEO) { + $link['to'] = WebVideo::_findVideoId($url, 'youtube'); + } else { + $link['to'] = $url; + } + $links[$id] = $link; + } + LinksData::saveLinksInFile($fluidbook_id, backpack_user()->id, __('Mise à jour par un fichier d\'audit de liens'), $links, $rulers); + } + + return ['alert' => ['icon' => 'success', 'title' => __('Mise à jour de liens'), 'message' => __(':nb liens mis à jour dans :fb publication', ['nb' => count($updates), 'fb' => count($grouped)])]]; } protected function importExcel($id) @@ -51,16 +82,23 @@ trait AuditLinksOperation $updates = []; $changedFluidbooks = []; + $notInFluidbooks = 0; + $noNewURL = 0; + $total = 0; + foreach ($data as $sheet) { foreach ($sheet as $link) { + $total++; $new_url = $link[$columns['new_url']]; if (!$new_url) { + $noNewURL++; continue; } $fluidbook_id = $link[$columns['fluidbook_id']]; $link_id = $link[$columns['link_id']]; - if (in_array($fluidbook_id, $fluidbooks)) { + if (!in_array($fluidbook_id, $fluidbooks)) { // not in the collection + $notInFluidbooks++; continue; } $changedFluidbooks[] = $fluidbook_id; @@ -75,25 +113,61 @@ trait AuditLinksOperation } $actualUpdates = []; + $notExistingAnymore = 0; + $sameValue = 0; foreach ($updates as $u) { if (!isset($allLinks[$u['fluidbook_id']][$u['link_id']])) { // The links doesnt exists anymore + $notExistingAnymore++; continue; } - if ($allLinks[$u['fluidbook_id']][$u['link_id']]['to'] == $u['new_url']) { + + $l = $allLinks[$u['fluidbook_id']][$u['link_id']]; + if ($l['to'] == $u['new_url']) { + // The links already has the "new url" + $sameValue++; + continue; + } else if ($l['type'] == Link::WEBVIDEO && $l['to'] == WebVideo::_findVideoId($u['new_url'], 'youtube')) { // The links already has the "new url" + $sameValue++; continue; } $actualUpdates[] = $u; } + $details = [__('Parmi les :nb liens présents dans le fichier', ['nb' => '' . $total . ''])]; + if ($noNewURL > 0) { + $details[] = __(':nb n\'ont pas de nouvelle URL à mettre à jour', ['nb' => '' . $noNewURL . '']); + } + if ($notInFluidbooks > 0) { + $details[] = __(':nb concernent des liens de fluidbooks qui n\'appartiennent pas à la collection', ['nb' => '' . $notInFluidbooks . '']); + } + if ($notExistingAnymore > 0) { + $details[] = __(':nb n\'existent plus', ['nb' => '' . $notExistingAnymore . '']); + } + if ($sameValue > 0) { + $details[] = __(':nb ont déjà la valeur indiquée dans le fichier', ['nb' => '' . $sameValue . '']); + } + if (count($details) === 1) { + $details = ''; + } else if (count($details) === 2) { + $details = implode(', ', $details) . '.'; + } else { + $last = array_pop($details); + $details = implode(', ', $details) . ' ' . __('et') . ' ' . $last . '.'; + } + if ($details) { + $details = "

" . $details . ''; + } + + $count = count($actualUpdates); if ($count == 0) { - return ['alert' => __('Ce fichier ne contient aucun lien à modifier')]; + return ['alert' => ['message' => __('Ce fichier ne contient aucun lien à modifier.') . $details, 'title' => __('Mise à jour de liens')]]; } else { $cid = rand(1000, 1000000000); cache()->set('auditlinks_confirmation_data_' . $cid, $actualUpdates, 360); - return ['confirm' => ['message' => __('Vous vous apprêtez à modifier :nb liens. Veuillez confirmer cette opération.', ['nb' => $count]), 'confirm_action' => url('/fluidbookcollection/' . $cid . '/import_excel_confirm')]]; + return ['confirm' => ['message' => __('Vous vous apprêtez à modifier :nb liens. Veuillez confirmer cette opération.', ['nb' => $count]) . $details, 'title' => __('Mise à jour de liens'), 'confirm_action' => url('/fluidbook-collection/' . $cid . '/import_excel_confirm')]]; } } diff --git a/public/packages/fluidbook/toolbox/css/style.less b/public/packages/fluidbook/toolbox/css/style.less index 2d1a6d4e7..72ed112df 100644 --- a/public/packages/fluidbook/toolbox/css/style.less +++ b/public/packages/fluidbook/toolbox/css/style.less @@ -537,4 +537,5 @@ table.dataTable thead .sorting::before, table.dataTable thead .sorting::after, t } + @import 'context-menu'; -- 2.39.5