1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Meema\MediaConverter\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* MediaConversion Model. |
11
|
|
|
* |
12
|
|
|
* @property int $id |
13
|
|
|
* @property string $model_type |
14
|
|
|
* @property int $model_id |
15
|
|
|
* @property string $job_id |
16
|
|
|
* @property mixed $message |
17
|
|
|
* @property string $status |
18
|
|
|
* @property int|null $percentage_completed |
19
|
|
|
* @property \Illuminate\Support\Carbon|null $created_at |
20
|
|
|
* @property \Illuminate\Support\Carbon|null $updated_at |
21
|
|
|
* |
22
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion newModelQuery() |
23
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion newQuery() |
24
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion query() |
25
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereCreatedAt($value) |
26
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereId($value) |
27
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereJobId($value) |
28
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereMessage($value) |
29
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereModelId($value) |
30
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereModelType($value) |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion wherePercentageCompleted($value) |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereStatus($value) |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|MediaConversion whereUpdatedAt($value) |
34
|
|
|
* @mixin \Eloquent |
35
|
|
|
*/ |
36
|
|
|
class MediaConversion extends Model |
37
|
|
|
{ |
38
|
|
|
protected $guarded = []; |
39
|
|
|
|
40
|
|
|
protected $casts = [ |
41
|
|
|
'message' => 'array', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
public static function createActivity($message) |
45
|
|
|
{ |
46
|
|
|
$status = Str::lower($message['detail']['status']); |
47
|
|
|
|
48
|
|
|
if ($status === 'complete') { |
49
|
|
|
$percentage = 100; |
50
|
|
|
} else { |
51
|
|
|
$percentage = $message['detail']['jobProgress']['jobPercentComplete'] ?? null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$conversion = new MediaConversion(); |
55
|
|
|
$conversion->model_type = config('media-converter.media_model'); |
56
|
|
|
$conversion->model_id = $message['detail']['userMetadata']['model_id']; |
57
|
|
|
$conversion->job_id = $message['detail']['jobId']; |
58
|
|
|
$conversion->message = $message; |
59
|
|
|
$conversion->status = $status; |
60
|
|
|
$conversion->percentage_completed = $percentage; |
61
|
|
|
$conversion->save(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function model(): MorphTo |
65
|
|
|
{ |
66
|
|
|
return $this->morphTo(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function inputDetails() |
70
|
|
|
{ |
71
|
|
|
return $this->message['detail']['inputDetails']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function outputGroupDetails() |
75
|
|
|
{ |
76
|
|
|
return $this->message['detail']['outputGroupDetails']; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|