Skip to content

Commit eb454af

Browse files
committed
Merge branch 'master' into webshop/backend-more
2 parents 805a07a + 51d5182 commit eb454af

File tree

4 files changed

+449
-707
lines changed

4 files changed

+449
-707
lines changed

app/Http/Resources/Traits/HasHeaderUrl.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,30 @@ private function getByQuery(AbstractAlbum $album): ?string
5454
return $header_size_variant->url;
5555
}
5656

57-
$query_ratio = SizeVariant::query()->select('photo_id');
58-
5957
/** @var Collection<int,Photo>|LengthAwarePaginator<int,Photo> $photos */
6058
$photos = $album->get_photos();
61-
if ($photos instanceof LengthAwarePaginator) {
62-
$photo_ids = collect($photos->items())->pluck('id')->all();
63-
$query_ratio = $query_ratio->whereIn('photo_id', $photo_ids);
64-
} else {
65-
$query_ratio = $query_ratio->whereBelongsTo($photos);
66-
}
67-
$query_ratio = $query_ratio->where('ratio', '>', 1)->whereIn('type', [SizeVariantType::MEDIUM, SizeVariantType::SMALL2X, SizeVariantType::SMALL]);
59+
$query_ratio = SizeVariant::query()->select('photo_id')
60+
->when($photos instanceof LengthAwarePaginator, function ($query) use ($photos): void {
61+
$photo_ids = collect($photos->items())->pluck('id')->all();
62+
$query->whereIn('photo_id', $photo_ids);
63+
})
64+
->when($photos instanceof Collection, function ($query) use ($photos): void {
65+
$query->whereBelongsTo($photos);
66+
})
67+
->where('ratio', '>', 1)->whereIn('type', [SizeVariantType::MEDIUM, SizeVariantType::SMALL2X, SizeVariantType::SMALL]);
6868
$num = $query_ratio->count() - 1;
6969
$photo = $num >= 0 ? $query_ratio->skip(rand(0, $num))->first() : null;
7070

7171
if ($photo === null) {
7272
$query = SizeVariant::query()
7373
->select('photo_id')
74-
->whereBelongsTo($album->get_photos())
74+
->when($photos instanceof LengthAwarePaginator, function ($query) use ($photos): void {
75+
$photo_ids = collect($photos->items())->pluck('id')->all();
76+
$query->whereIn('photo_id', $photo_ids);
77+
})
78+
->when($photos instanceof Collection, function ($query) use ($photos): void {
79+
$query->whereBelongsTo($photos);
80+
})
7581
->whereIn('type', [SizeVariantType::MEDIUM, SizeVariantType::SMALL2X, SizeVariantType::SMALL]);
7682
$num = $query->count() - 1;
7783
$photo = $query->skip(rand(0, $num))->first();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
use Illuminate\Support\Facades\Artisan;
11+
use Illuminate\Support\Facades\DB;
12+
use Symfony\Component\Console\Output\ConsoleOutput;
13+
use Symfony\Component\Console\Output\ConsoleSectionOutput;
14+
15+
return new class() extends Migration {
16+
private ConsoleOutput $output;
17+
private ConsoleSectionOutput $msg_section;
18+
19+
public function __construct()
20+
{
21+
$this->output = new ConsoleOutput();
22+
$this->msg_section = $this->output->section();
23+
}
24+
25+
/**
26+
* Run the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function up(): void
31+
{
32+
DB::table('configs')->where('key', 'version')->update(['value' => '061002']);
33+
try {
34+
Artisan::call('cache:clear');
35+
} catch (\Throwable $e) {
36+
$this->msg_section->writeln('<error>Warning:</error> Failed to clear cache for version 6.10.2');
37+
38+
return;
39+
}
40+
$this->msg_section->writeln('<info>Info:</info> Cleared cache for version 6.10.2');
41+
}
42+
43+
/**
44+
* Reverse the migrations.
45+
*
46+
* @return void
47+
*/
48+
public function down(): void
49+
{
50+
DB::table('configs')->where('key', 'version')->update(['value' => '061001']);
51+
}
52+
};

0 commit comments

Comments
 (0)