3 namespace BookStack\Exports;
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Users\Models\User;
8 use Illuminate\Database\Eloquent\Factories\HasFactory;
9 use Illuminate\Database\Eloquent\Model;
10 use Illuminate\Database\Eloquent\Relations\BelongsTo;
14 * @property string $path
15 * @property string $name
16 * @property int $size - ZIP size in bytes
17 * @property int $book_count
18 * @property int $chapter_count
19 * @property int $page_count
20 * @property int $created_by
21 * @property Carbon $created_at
22 * @property Carbon $updated_at
23 * @property User $createdBy
25 class Import extends Model implements Loggable
29 public const TYPE_BOOK = 'book';
30 public const TYPE_CHAPTER = 'chapter';
31 public const TYPE_PAGE = 'page';
34 * Get the type (model) that this import is intended to be.
36 public function getType(): string
38 if ($this->book_count === 1) {
39 return self::TYPE_BOOK;
40 } elseif ($this->chapter_count === 1) {
41 return self::TYPE_CHAPTER;
44 return self::TYPE_PAGE;
47 public function getSizeString(): string
49 $mb = round($this->size / 1000000, 2);
54 * Get the URL to view/continue this import.
56 public function getUrl(string $path = ''): string
58 $path = ltrim($path, '/');
59 return url("/import/{$this->id}" . ($path ? '/' . $path : ''));
62 public function logDescriptor(): string
64 return "({$this->id}) {$this->name}";
67 public function createdBy(): BelongsTo
69 return $this->belongsTo(User::class, 'created_by');