]> BookStack Code Mirror - bookstack/blob - app/Exports/Import.php
ZIP Import: Added model+migration, and reader class
[bookstack] / app / Exports / Import.php
1 <?php
2
3 namespace BookStack\Exports;
4
5 use Carbon\Carbon;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
8
9 /**
10  * @property string $path
11  * @property string $name
12  * @property int $size - ZIP size in bytes
13  * @property int $book_count
14  * @property int $chapter_count
15  * @property int $page_count
16  * @property int $created_by
17  * @property Carbon $created_at
18  * @property Carbon $updated_at
19  */
20 class Import extends Model
21 {
22     use HasFactory;
23
24     public const TYPE_BOOK = 'book';
25     public const TYPE_CHAPTER = 'chapter';
26     public const TYPE_PAGE = 'page';
27
28     /**
29      * Get the type (model) that this import is intended to be.
30      */
31     public function getType(): string
32     {
33         if ($this->book_count === 1) {
34             return self::TYPE_BOOK;
35         } elseif ($this->chapter_count === 1) {
36             return self::TYPE_CHAPTER;
37         }
38
39         return self::TYPE_PAGE;
40     }
41 }