3 namespace BookStack\Exports;
5 use BookStack\Activity\Models\Loggable;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Model;
11 * @property string $path
12 * @property string $name
13 * @property int $size - ZIP size in bytes
14 * @property int $book_count
15 * @property int $chapter_count
16 * @property int $page_count
17 * @property int $created_by
18 * @property Carbon $created_at
19 * @property Carbon $updated_at
21 class Import extends Model implements Loggable
25 public const TYPE_BOOK = 'book';
26 public const TYPE_CHAPTER = 'chapter';
27 public const TYPE_PAGE = 'page';
30 * Get the type (model) that this import is intended to be.
32 public function getType(): string
34 if ($this->book_count === 1) {
35 return self::TYPE_BOOK;
36 } elseif ($this->chapter_count === 1) {
37 return self::TYPE_CHAPTER;
40 return self::TYPE_PAGE;
43 public function getSizeString(): string
45 $mb = round($this->size / 1000000, 2);
50 * Get the URL to view/continue this import.
52 public function getUrl(string $path = ''): string
54 $path = ltrim($path, '/');
55 return url("/import/{$this->id}" . ($path ? '/' . $path : ''));
58 public function logDescriptor(): string
60 return "({$this->id}) {$this->name}";