2024-11-03 01:17:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Exports;
|
|
|
|
|
2024-11-03 22:13:05 +08:00
|
|
|
use BookStack\Activity\Models\Loggable;
|
2024-11-04 01:28:18 +08:00
|
|
|
use BookStack\Users\Models\User;
|
2024-11-03 01:17:34 +08:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-11-04 01:28:18 +08:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2024-11-03 01:17:34 +08:00
|
|
|
|
|
|
|
/**
|
2024-11-04 01:28:18 +08:00
|
|
|
* @property int $id
|
2024-11-03 01:17:34 +08:00
|
|
|
* @property string $path
|
|
|
|
* @property string $name
|
|
|
|
* @property int $size - ZIP size in bytes
|
|
|
|
* @property int $book_count
|
|
|
|
* @property int $chapter_count
|
|
|
|
* @property int $page_count
|
|
|
|
* @property int $created_by
|
|
|
|
* @property Carbon $created_at
|
|
|
|
* @property Carbon $updated_at
|
2024-11-04 01:28:18 +08:00
|
|
|
* @property User $createdBy
|
2024-11-03 01:17:34 +08:00
|
|
|
*/
|
2024-11-03 22:13:05 +08:00
|
|
|
class Import extends Model implements Loggable
|
2024-11-03 01:17:34 +08:00
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
public const TYPE_BOOK = 'book';
|
|
|
|
public const TYPE_CHAPTER = 'chapter';
|
|
|
|
public const TYPE_PAGE = 'page';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the type (model) that this import is intended to be.
|
|
|
|
*/
|
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
if ($this->book_count === 1) {
|
|
|
|
return self::TYPE_BOOK;
|
|
|
|
} elseif ($this->chapter_count === 1) {
|
|
|
|
return self::TYPE_CHAPTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::TYPE_PAGE;
|
|
|
|
}
|
2024-11-03 22:13:05 +08:00
|
|
|
|
|
|
|
public function getSizeString(): string
|
|
|
|
{
|
|
|
|
$mb = round($this->size / 1000000, 2);
|
|
|
|
return "{$mb} MB";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL to view/continue this import.
|
|
|
|
*/
|
|
|
|
public function getUrl(string $path = ''): string
|
|
|
|
{
|
|
|
|
$path = ltrim($path, '/');
|
|
|
|
return url("/import/{$this->id}" . ($path ? '/' . $path : ''));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logDescriptor(): string
|
|
|
|
{
|
|
|
|
return "({$this->id}) {$this->name}";
|
|
|
|
}
|
2024-11-04 01:28:18 +08:00
|
|
|
|
|
|
|
public function createdBy(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
|
|
}
|
2024-11-03 01:17:34 +08:00
|
|
|
}
|