]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7930 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Jan 2026 15:42:40 +0000 (16:42 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Jan 2026 15:42:40 +0000 (16:42 +0100)
app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php
public/packages/fluidbook/toolbox/css/style.less

index aa614cc2337bd6ae40a7572e27c6462ecf64fa0b..ef9229fbcc5845ac8453fea1304c0b6a45deab91 100644 (file)
@@ -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' => '<b>' . $total . '</b>'])];
+        if ($noNewURL > 0) {
+            $details[] = __(':nb n\'ont pas de nouvelle URL à mettre à jour', ['nb' => '<b>' . $noNewURL . '</b>']);
+        }
+        if ($notInFluidbooks > 0) {
+            $details[] = __(':nb concernent des liens de fluidbooks qui n\'appartiennent pas à la collection', ['nb' => '<b>' . $notInFluidbooks . '</b>']);
+        }
+        if ($notExistingAnymore > 0) {
+            $details[] = __(':nb n\'existent plus', ['nb' => '<b>' . $notExistingAnymore . '</b>']);
+        }
+        if ($sameValue > 0) {
+            $details[] = __(':nb ont déjà la valeur indiquée dans le fichier', ['nb' => '<b>' . $sameValue . '</b>']);
+        }
+        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 = "<br><br><em style='font-size: 80%'>" . $details . '</em>';
+        }
+
+
         $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')]];
         }
     }
 
index 2d1a6d4e76c3e104bf9c2b6f2f5e508dd2a54894..72ed112df7fb07ff75217d860f54370741a04bf0 100644 (file)
@@ -537,4 +537,5 @@ table.dataTable thead .sorting::before, table.dataTable thead .sorting::after, t
 }
 
 
+
 @import 'context-menu';