Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No more album ID within the history #2242

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/Jobs/ProcessImageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,32 @@ class ProcessImageJob implements ShouldQueue
*/
public function __construct(
ProcessableJobFile $file,
string|AbstractAlbum|null $albumID,
string|AbstractAlbum|null $album,
?int $fileLastModifiedTime,
) {
$this->filePath = $file->getPath();
$this->originalBaseName = $file->getOriginalBasename();
$this->albumID = is_string($albumID) ? $albumID : $albumID?->id;

$this->albumID = null;
$album_name = __('lychee.UNSORTED');

if ($album instanceof AbstractAlbum) {
$this->albumID = $album->id;
$album_name = $album->title;
}

if (is_string($album)) {
$album_name = resolve(AlbumFactory::class)->findAbstractAlbumOrFail($this->albumID)->title;
$this->albumID = $album;
}

$this->userId = Auth::user()->id;
$this->fileLastModifiedTime = $fileLastModifiedTime;

// Set up our new history record.
$this->history = new JobHistory();
$this->history->owner_id = $this->userId;
$this->history->job = Str::limit('Process Image: ' . $this->originalBaseName, 200);
$this->history->parent_id = $this->albumID;
$this->history->job = Str::limit(sprintf('Process Image: %s added to %s.', $this->originalBaseName, $album_name), 200);
$this->history->status = JobStatus::READY;

$this->history->save();
Expand Down
33 changes: 0 additions & 33 deletions app/Models/Builders/JobHistoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace App\Models\Builders;

use App\Eloquent\FixedQueryBuilder;
use App\Exceptions\Internal\QueryBuilderException;
use App\Models\JobHistory;
use Illuminate\Support\Facades\DB;

/**
* Specialized query builder for {@link \App\Models\JobHistory}.
Expand All @@ -14,34 +11,4 @@
*/
class JobHistoryBuilder extends FixedQueryBuilder
{
/**
* Get the hydrated models without eager loading.
*
* @param array<string>|string $columns
*
* @return JobHistory[]
*
* @throws QueryBuilderException
*/
public function getModels($columns = ['*']): array
{
$baseQuery = $this->getQuery();

if ($baseQuery->columns === null || count($baseQuery->columns) === 0) {
$this->select([$baseQuery->from . '.*']);
}

if (
($columns === ['*'] || $columns === ['jobs_history.*']) &&
($baseQuery->columns === ['*'] || $baseQuery->columns === ['jobs_history.*'])
) {
$title = DB::table('base_albums', 'ba')
->selectRaw('ba.title')
->whereColumn('ba.id', '=', 'jobs_history.parent_id');

$this->addSelect(['title' => $title]);
}

return parent::getModels($columns);
}
}
29 changes: 7 additions & 22 deletions app/Models/JobHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property int $id
* @property int $owner_id
* @property User $owner
* @property string $job
* @property string|null $parent_id
* @property Album|null $parent
* @property JobStatus $status
* @property ?string $title
* @property Carbon $created_at
* @property Carbon $updated_at
* @property int $id
* @property int $owner_id
* @property User $owner
* @property string $job
* @property JobStatus $status
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @method static JobHistoryBuilder|JobHistory addSelect($column)
* @method static JobHistoryBuilder|JobHistory join(string $table, string $first, string $operator = null, string $second = null, string $type = 'inner', string $where = false)
Expand All @@ -35,10 +32,8 @@
* @method static JobHistoryBuilder|JobHistory whereJob($value)
* @method static JobHistoryBuilder|JobHistory whereNotIn(string $column, string $values, string $boolean = 'and')
* @method static JobHistoryBuilder|JobHistory whereOwnerId($value)
* @method static JobHistoryBuilder|JobHistory whereParentId($value)
* @method static JobHistoryBuilder|JobHistory whereStatus($value)
* @method static JobHistoryBuilder|JobHistory whereUpdatedAt($value)
* @method static JobHistoryBuilder|JobHistory withAlbumTitleOrNull()
*
* @mixin \Eloquent
*/
Expand Down Expand Up @@ -84,14 +79,4 @@ public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'owner_id', 'id');
}

/**
* Returns the relationship between an Job and its associated album.
*
* @return BelongsTo
*/
public function parent(): BelongsTo
{
return $this->belongsTo(BaseAlbumImpl::class, 'parent_id', 'id');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public const TABLE = 'jobs_history';
public const COLUMN = 'parent_id';
public const RANDOM_ID_LENGTH = 24;

/**
* Run the migrations.
*/
public function up(): void
{
Schema::disableForeignKeyConstraints();
Schema::table(self::TABLE, function (Blueprint $table) {
$table->dropColumn(self::COLUMN);
});
Schema::enableForeignKeyConstraints();
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table(self::TABLE, function (Blueprint $table) {
$table->char(self::COLUMN, self::RANDOM_ID_LENGTH)->nullable(true); // parentId = album ID
});
}
};
2 changes: 1 addition & 1 deletion resources/views/jobs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<body>
<pre>
@forelse($jobs as $job)
{{ $job->created_at }} -- {{ str_pad($job->status->name(), 7) }} -- {{ $job->owner->name }} -- {{ $job->job }} -- {{ $job->title ?? __('lychee.UNSORTED') }}
{{ $job->created_at }} -- {{ str_pad($job->status->name(), 7) }} -- {{ $job->owner->name }} -- {{ $job->job }}
@empty
No Jobs have been executed yet.
@endforelse
Expand Down
1 change: 0 additions & 1 deletion resources/views/livewire/pages/jobs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<span class="mx-2 text-red-700"><pre class="inline">{{ str_pad($job->status->name(), 7) }}</pre></span>
@endif
<span class="mx-2">{{ $job->owner->name }}</span>
<span class="mx-2">{{ $job->title ?? __('lychee.UNSORTED') }}</span>
<span class="mx-2">{{ $job->job }}</span>
<br>
@empty
Expand Down