]> BookStack Code Mirror - bookstack/blobdiff - app/Exports/Controllers/ImportController.php
ZIP Imports: Finished off core import logic
[bookstack] / app / Exports / Controllers / ImportController.php
index 582fff975d2880a4928e3f884fd320d18071e74d..4d2c83090a3af1cdad41fff01cf532c6a8338f1d 100644 (file)
@@ -23,9 +23,8 @@ class ImportController extends Controller
      * Show the view to start a new import, and also list out the existing
      * in progress imports that are visible to the user.
      */
-    public function start(Request $request)
+    public function start()
     {
-        // TODO - Test visibility access for listed items
         $imports = $this->imports->getVisibleImports();
 
         $this->setPageTitle(trans('entities.import'));
@@ -64,22 +63,44 @@ class ImportController extends Controller
      */
     public function show(int $id)
     {
-        // TODO - Test visibility access
         $import = $this->imports->findVisible($id);
 
         $this->setPageTitle(trans('entities.import_continue'));
 
         return view('exports.import-show', [
             'import' => $import,
+            'data' => $import->decodeMetadata(),
         ]);
     }
 
+    public function run(int $id, Request $request)
+    {
+        // TODO - Test access/visibility
+        $import = $this->imports->findVisible($id);
+        $parent = null;
+
+        if ($import->type === 'page' || $import->type === 'chapter') {
+            $data = $this->validate($request, [
+                'parent' => ['required', 'string']
+            ]);
+            $parent = $data['parent'];
+        }
+
+        $entity = $this->imports->runImport($import, $parent);
+        if ($entity) {
+            $this->logActivity(ActivityType::IMPORT_RUN, $import);
+            return redirect($entity->getUrl());
+        }
+        // TODO - Redirect to result
+        // TODO - Or redirect back with errors
+        return 'failed';
+    }
+
     /**
      * Delete an active pending import from the filesystem and database.
      */
     public function delete(int $id)
     {
-        // TODO - Test visibility access
         $import = $this->imports->findVisible($id);
         $this->imports->deleteImport($import);