]> BookStack Code Mirror - bookstack/blob - app/Exports/Controllers/ImportController.php
bbf0ff57d8ca0c52983683551b7780ade16b70cc
[bookstack] / app / Exports / Controllers / ImportController.php
1 <?php
2
3 namespace BookStack\Exports\Controllers;
4
5 use BookStack\Exports\Import;
6 use BookStack\Exports\ZipExports\ZipExportReader;
7 use BookStack\Exports\ZipExports\ZipExportValidator;
8 use BookStack\Http\Controller;
9 use Illuminate\Http\Request;
10
11 class ImportController extends Controller
12 {
13     public function __construct()
14     {
15         $this->middleware('can:content-import');
16     }
17
18     public function start(Request $request)
19     {
20         // TODO - Show existing imports for user (or for all users if admin-level user)
21
22         return view('exports.import', [
23             'zipErrors' => session()->pull('validation_errors') ?? [],
24         ]);
25     }
26
27     public function upload(Request $request)
28     {
29         $this->validate($request, [
30             'file' => ['required', 'file']
31         ]);
32
33         $file = $request->file('file');
34         $zipPath = $file->getRealPath();
35
36         $errors = (new ZipExportValidator($zipPath))->validate();
37         if ($errors) {
38             session()->flash('validation_errors', $errors);
39             return redirect('/import');
40         }
41
42         $zipEntityInfo = (new ZipExportReader($zipPath))->getEntityInfo();
43         $import = new Import();
44         $import->name = $zipEntityInfo['name'];
45         $import->book_count = $zipEntityInfo['book_count'];
46         $import->chapter_count = $zipEntityInfo['chapter_count'];
47         $import->page_count = $zipEntityInfo['page_count'];
48         $import->created_by = user()->id;
49         $import->size = filesize($zipPath);
50         // TODO - Set path
51         // TODO - Save
52
53         // TODO - Split out attachment service to separate out core filesystem/disk stuff
54         //        To reuse for import handling
55
56         dd('passed');
57         // TODO - Upload to storage
58         // TODO - Store info/results for display:
59         // TODO - Send user to next import stage
60     }
61 }