Skip to content

Commit

Permalink
Improve generate smil assets cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Stefanos Georgopoulos <[email protected]>
  • Loading branch information
stefanosgeo committed Nov 26, 2024
1 parent baffaca commit f4a7359
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
23 changes: 19 additions & 4 deletions app/Console/Commands/InsertSmilAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class InsertSmilAssets extends Command
*
* @var string
*/
protected $signature = 'smil:insert';
protected $signature = 'smil:insert clip{--override : Override existing Smils}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Insert SMIL file paths to database. It does not create smil files';
protected $description = 'Insert SMIL file paths to database,optionally overriding existing ones.';

/**
* Execute the console command.
Expand All @@ -32,15 +32,30 @@ class InsertSmilAssets extends Command
*/
public function handle(WowzaService $wowzaService): int
{
// Retrieve the 'override' option
$override = $this->option('override');

if ($override) {
$this->info('Override option enabled. Existing SMILs will be replaced.');
} else {
$this->info('Override option not enabled. Existing SMILs will be skipped.');
}
Cache::put('insert_smil_command', true);
$this->info('Counting clips...');
$bar = $this->output->createProgressBar(Clip::count());

$bar->start();

Clip::lazy()->each(function ($clip) use ($wowzaService) {
Clip::orderBy('id', 'desc')->lazy()->each(function ($clip) use ($wowzaService, $override) {
//do not generate smil files if a clip has already
if ($override) {
if ($clip->assets()
->formatSmil()
->count() > 0) {
return;
}
}
$wowzaService->createSmilFile($clip);

$this->info("Finish clip ID {$clip->id}");
$this->newLine(2);
});
Expand Down
14 changes: 5 additions & 9 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,25 @@ public function geoCount(): HasMany
return $this->hasMany(AssetGeoCount::class, 'resourceid');
}

/**
* Return assets download path
*/
public function downloadPath(): string
{
return Storage::disk('videos')->path($this->path);
}

/**
* Scope a query to only include video assets
*/
public function scopeFormatVideo($query): mixed
{
return $query->where('type', Content::PRESENTER())
->orWhere('type', Content::PRESENTATION())
->orWhere('type', Content::COMPOSITE());
}

/**
* Scope a query to only include audio assets
*/
public function scopeFormatAudio($query): mixed
{
return $query->where('type', Content::AUDIO());
}

public function scopeFormatSmil($query): mixed
{
return $query->where('type', Content::SMIL);
}
}
17 changes: 3 additions & 14 deletions app/Models/Traits/RecordsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@

trait RecordsActivity
{
/**
* The models old attributes
*/
public array $oldAttributes = [];

//a list for attributes to check in updated event
public array $checkedAttributes = [
'title', 'description', 'image_id', 'episode', 'name', 'organization_id', 'language_id', 'context_id',
'format_id', 'type_id', 'password', 'owner_id', 'allow_comments', 'is_public', 'is_livestream',
'academic_degree_id', 'first_name', 'last_name', 'username', 'email', 'title_en', 'title_de', 'is_published',
]; //a list for attributes to check in updated event
];

/**
* Boot the trait
*/
public static function bootRecordsActivity(): void
{
foreach (self::recordableEvents() as $event) {
Expand Down Expand Up @@ -52,14 +47,11 @@ protected static function recordableEvents(): array
return (isset(static::$recordableEvents)) ? static::$recordableEvents : ['created', 'updated', 'deleted'];
}

/**
* Record activity for the given model
*/
public function recordActivity($description, array $changes = []): void
{

$user = (auth()->user()) ?? $this->owner;
$changes = (empty($changes['before']) && empty($changes['after'])) ? $this->activityChanges() : $changes;

if (! Cache::has('insert_smil_command')) {
Activity::create([
'user_id' => ($user?->id) ?? 0,
Expand All @@ -73,9 +65,6 @@ public function recordActivity($description, array $changes = []): void
}
}

/**
* Fetch all activities for a given model
*/
public function activities(): Builder
{
return Activity::where('object_id', $this->id)->where('content_type', lcfirst(class_basename(static::class)));
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
it('has audio format scope', function () {
expect(Asset::FormatAudio())->toBeInstanceOf(Builder::class);
});

it('has smil format scope', function () {
expect(Asset::FormatSmil())->toBeInstanceOf(Builder::class);
});

0 comments on commit f4a7359

Please sign in to comment.