]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6262 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 10:01:47 +0000 (12:01 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 10:01:47 +0000 (12:01 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Models/FluidbookHealthIssues.php [new file with mode: 0644]

index 9771ea2c6d345be11aa50efc41b705fac883b38a..c37d156b743aa2fed9f57ddf206d2e6707163848 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
 use App\Fluidbook\Compiler\Compiler;
 use App\Http\Controllers\Admin\Operations\FluidbookPreviewOperation;
 use App\Http\Middleware\CheckIfAdmin;
+use App\Models\FluidbookHealthIssues;
 use App\Models\FluidbookPublication;
 use App\Models\FluidbookTheme;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
@@ -134,7 +135,8 @@ trait PreviewOperation
 
         $relayPath = $dest . '/' . $path;
         if (!file_exists($relayPath)) {
-            throw new \Exception($relayPath . ' not found');
+            FluidbookHealthIssues::addIssue($fluidbook->id, FluidbookHealthIssues::TYPE_MISSING_FILE, $path);
+            abort(404, __('Ce fichier n\'existe pas'));
         }
         return XSendFileController::sendfile($relayPath);
     }
diff --git a/app/Models/FluidbookHealthIssues.php b/app/Models/FluidbookHealthIssues.php
new file mode 100644 (file)
index 0000000..bffc9fa
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Models;
+
+use App\Fields\FluidbookID;
+use App\Models\Base\ToolboxModel;
+use Cubist\Backpack\Magic\Fields\Integer;
+use Cubist\Backpack\Magic\Fields\Text;
+
+class FluidbookHealthIssues extends ToolboxModel
+{
+    const TYPE_MISSING_FILE = 1;
+
+    protected $table = 'fluidbook_health_issue';
+    protected $_options = ['name' => 'fluidbook-health',
+        'singular' => 'problème',
+        'plural' => 'problèmes'];
+
+    protected static $_permissionBase = 'fluidbook-health-issue';
+
+    public function setFields()
+    {
+        parent::setFields();
+
+        $this->addField('fluidbook', FluidbookID::class, __('Fluidbook'));
+        $this->addField('type', Integer::class, __('Type'));
+        $this->addField('data', Text::class, __('Détails'));
+    }
+
+    public static function addIssue($fluidbookId, $type, $data = '')
+    {
+
+        $issue = self::withoutGlobalScopes()->where('fluidbook', $fluidbookId)->where('type', $type)->where('data', $data)->first();
+        if (!$issue) {
+            $issue = new self(['fluidbook' => $fluidbookId, 'type' => $type, 'data' => $data]);
+        }
+        $issue->updateTimestamps();
+        $issue->save();
+    }
+}