]> BookStack Code Mirror - bookstack/blob - app/Exports/Controllers/ImportController.php
323ecef268f1700e2dd37f5d46949a03af5540d5
[bookstack] / app / Exports / Controllers / ImportController.php
1 <?php
2
3 namespace BookStack\Exports\Controllers;
4
5 use BookStack\Exports\ZipExports\ZipExportValidator;
6 use BookStack\Http\Controller;
7 use Illuminate\Http\Request;
8
9 class ImportController extends Controller
10 {
11     public function __construct()
12     {
13         $this->middleware('can:content-import');
14     }
15
16     public function start(Request $request)
17     {
18         // TODO - Show existing imports for user (or for all users if admin-level user)
19
20         return view('exports.import', [
21             'zipErrors' => session()->pull('validation_errors') ?? [],
22         ]);
23     }
24
25     public function upload(Request $request)
26     {
27         $this->validate($request, [
28             'file' => ['required', 'file']
29         ]);
30
31         $file = $request->file('file');
32         $zipPath = $file->getRealPath();
33
34         $errors = (new ZipExportValidator($zipPath))->validate();
35         if ($errors) {
36             session()->flash('validation_errors', $errors);
37             return redirect('/import');
38         }
39
40         dd('passed');
41         // TODO - Upload to storage
42         // TODO - Store info/results for display:
43           // - zip_path
44           // - name (From name of thing being imported)
45           // - size
46           // - book_count
47           // - chapter_count
48           // - page_count
49           // - created_by
50           // - created_at/updated_at
51         // TODO - Send user to next import stage
52     }
53 }