Skip to content

Commit

Permalink
Migrate to Laravel 11 (#2464)
Browse files Browse the repository at this point in the history
* Fix timezone warning. (#2477)
* Minor speed improvements (#2478)
* disable livewire hack (#2479)
* add option to disable login requirements on albums (#2480)
  • Loading branch information
ildyria authored Jun 25, 2024
1 parent 446432b commit 4935468
Show file tree
Hide file tree
Showing 100 changed files with 1,254 additions and 1,701 deletions.
10 changes: 0 additions & 10 deletions app/Actions/Db/BaseOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ protected function getDriverType(array &$ret): DbDriverType|null
return $driverName;
}

/**
* get the list of tables in the Database.
*
* @return array<int,string>
*/
protected function getTables(): array
{
return $this->connection->getDoctrineSchemaManager()->listTableNames();
}

/**
* Do the stuff.
*
Expand Down
6 changes: 4 additions & 2 deletions app/Actions/Db/OptimizeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Actions\Db;

use App\Enum\DbDriverType;
use Illuminate\Support\Facades\Schema;

class OptimizeDb extends BaseOptimizer
{
Expand All @@ -13,7 +14,8 @@ public function do(): array
{
$ret = ['Optimizing Database.'];
$driverName = $this->getDriverType($ret);
$tables = $this->getTables();
/** @var array{name:string,schema:?string,size:int,comment:?string,collation:?string,engine:?string}[] */
$tables = Schema::getTables();

/** @var string|null $sql */
$sql = match ($driverName) {
Expand All @@ -25,7 +27,7 @@ public function do(): array

if ($driverName === DbDriverType::MYSQL) {
foreach ($tables as $table) {
$this->execStatement($sql . $table, $table . ' optimized.', $ret);
$this->execStatement($sql . $table['name'], $table['name'] . ' optimized.', $ret);
}
} elseif ($driverName !== null) {
$this->execStatement($sql, 'DB optimized.', $ret);
Expand Down
6 changes: 4 additions & 2 deletions app/Actions/Db/OptimizeTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Actions\Db;

use App\Enum\DbDriverType;
use Illuminate\Support\Facades\Schema;

class OptimizeTables extends BaseOptimizer
{
Expand All @@ -13,7 +14,8 @@ public function do(): array
{
$ret = ['Optimizing tables.'];
$driverName = $this->getDriverType($ret);
$tables = $this->getTables();
/** @var array{name:string,schema:?string,size:int,comment:?string,collation:?string,engine:?string}[] */
$tables = Schema::getTables();

/** @var string|null $sql */
$sql = match ($driverName) {
Expand All @@ -30,7 +32,7 @@ public function do(): array
}

foreach ($tables as $table) {
$this->execStatement($sql . $table, $table . ' analyzed.', $ret);
$this->execStatement($sql . $table['name'], $table['name'] . ' analyzed.', $ret);
}

return $ret;
Expand Down
5 changes: 3 additions & 2 deletions app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ class TimezoneCheck implements DiagnosticPipe
*/
public function handle(array &$data, \Closure $next): array
{
$timezone = CarbonTimeZone::create();
if ($timezone === false) {
$timezone = CarbonTimeZone::create(config('app.timezone'));
if ($timezone === null) {
// @codeCoverageIgnoreStart
$data[]
= 'Error: Could not retrieve timezone; you might experience strange results when importing photos without explicit EXIF timezone';

return $next($data);
// @codeCoverageIgnoreEnd
}
// @phpstan-ignore-next-line : create returns null or object.
$timezoneName = $timezone->getName();
$tzArray = explode('/', $timezoneName);

Expand Down
5 changes: 3 additions & 2 deletions app/Actions/Diagnostics/Pipes/Infos/SystemInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public function handle(array &$data, \Closure $next): array
$data[] = Diagnostics::line('System:', PHP_OS);
$data[] = Diagnostics::line('PHP Version:', phpversion());
$data[] = Diagnostics::line('PHP User agent:', ini_get('user_agent'));
$timeZone = CarbonTimeZone::create();
$data[] = Diagnostics::line('Timezone:', ($timeZone !== false ? $timeZone : null)?->getName());
/** @var CarbonTimeZone|null $timeZone */
$timeZone = CarbonTimeZone::create(config('app.timezone'));
$data[] = Diagnostics::line('Timezone:', $timeZone?->getName() ?? 'undefined');
$data[] = Diagnostics::line('Max uploaded file size:', ini_get('upload_max_filesize'));
$data[] = Diagnostics::line('Max post size:', ini_get('post_max_size'));
$this->getUploadLimit($data);
Expand Down
36 changes: 0 additions & 36 deletions app/Console/Commands/Laravel/MigrateFresh.php

This file was deleted.

36 changes: 0 additions & 36 deletions app/Console/Commands/Laravel/MigrateRefresh.php

This file was deleted.

47 changes: 0 additions & 47 deletions app/Console/Commands/Laravel/MigrateReset.php

This file was deleted.

28 changes: 21 additions & 7 deletions app/Http/Middleware/LoginRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Exceptions\ConfigurationException;
use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\FrameworkException;
use App\Exceptions\Internal\LycheeLogicException;
use App\Models\Configs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand All @@ -19,32 +20,45 @@
*/
class LoginRequired
{
public const ROOT = 'root';
public const ALBUM = 'album';

/**
* Handle an incoming request.
*
* @param Request $request
* @param \Closure $next
*
* @return mixed
* @param Request $request the incoming request to serve
* @param \Closure $next the next operation to be applied to the
* request
* @param string $requiredStatus the required login status; either
* {@link self::ROOT} or
* {@link self::ALBUM}
*
* @throws ConfigurationException
* @throws FrameworkException
*/
public function handle(Request $request, \Closure $next): mixed
public function handle(Request $request, \Closure $next, string $requiredStatus): mixed
{
// We are logged in. Proceed.
if (Auth::user() !== null) {
return $next($request);
}

$dir_url = config('app.dir_url');
if (Features::inactive('livewire') && !Str::startsWith($request->getRequestUri(), $dir_url . '/livewire/')) {
return $next($request);
}

if ($requiredStatus !== self::ALBUM && $requiredStatus !== self::ROOT) {
throw new LycheeLogicException($requiredStatus . ' is not a valid login requirement.');
}

try {
if (!Configs::getValueAsBool('login_required')) {
// Login is not required. Proceed.
return $next($request);
}

if (Auth::user() !== null) {
// We are logged in. Proceed.
if ($requiredStatus === self::ALBUM && Configs::getValueAsBool('login_required_root_only')) {
return $next($request);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/Models/PhotoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ private function preformatted(?SizeVariant $original): array
'resolution' => $original?->width . ' x ' . $original?->height,
'latitude' => Helpers::decimalToDegreeMinutesSeconds($this->resource->latitude, true),
'longitude' => Helpers::decimalToDegreeMinutesSeconds($this->resource->longitude, false),
'altitude' => round($this->resource->altitude, 1) . 'm',
'altitude' => $this->resource->altitude !== null ? round($this->resource->altitude, 1) . 'm' : '',
'license' => $this->resource->license !== LicenseType::NONE ? $this->resource->license->localization() : '',
'description' => ($this->resource->description ?? '') === '' ? '' : Markdown::convert($this->resource->description)->getContent(),
];
}

/**
* @return array<string,mixed>
* @return array<string,bool>
*/
private function precomputed(): array
{
Expand Down
4 changes: 4 additions & 0 deletions app/Legacy/BaseConfigMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*/
abstract class BaseConfigMigration extends Migration
{
public const BOOL = '0|1';
public const POSITIVE = 'positive';
public const INT = 'int';

/**
* @return array<int,array{key:string,value:string,confidentiality:string,cat:string,type_range:string,description:string}>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Components/Menus/LeftMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ private function loadDevMenu(): void
$this->doc_api_url = Route::has('scramble.docs.api') ? route('scramble.docs.api') : null;

// Double check to avoid showing an empty section.
$this->has_dev_tools = $this->doc_api_url !== null && $this->clockwork_url !== null;
$this->has_dev_tools = $this->doc_api_url !== null || $this->clockwork_url !== null;
}
}
6 changes: 1 addition & 5 deletions app/Livewire/Components/Pages/Gallery/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use Livewire\Attributes\Locked;
use Livewire\Attributes\On;
use Livewire\Attributes\Renderless;

Expand All @@ -42,8 +41,6 @@ class Album extends BaseAlbumComponent implements Reloadable
{
private AlbumFactory $albumFactory;
private AlbumFormatted $formatted;

#[Locked] public bool $is_search_accessible = false;
public ?AbstractAlbum $album = null;

/**
Expand Down Expand Up @@ -134,8 +131,7 @@ public function reloadPage(): void
{
$this->album = $this->albumFactory->findAbstractAlbumOrFail($this->albumId);
$this->flags->is_base_album = $this->album instanceof BaseAlbum;
$this->is_search_accessible = Auth::check() || Configs::getValueAsBool('search_public');
$this->is_search_accessible = $this->is_search_accessible && $this->album instanceof ModelsAlbum;
$this->flags->is_search_accessible = $this->flags->is_search_accessible && $this->album instanceof ModelsAlbum;
$this->flags->is_accessible = Gate::check(AlbumPolicy::CAN_ACCESS, [ModelsAlbum::class, $this->album]);

if (!$this->flags->is_accessible) {
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/DTO/AlbumFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public function __construct(
public bool $is_map_accessible = false,
public bool $is_base_album = false,
public bool $is_mod_frame_enabled = false,
public bool $is_search_accessible = false,
public string $album_thumb_css_aspect_ratio = '',
public string|null $cover_id = null,
) {
$this->is_map_accessible = Configs::getValueAsBool('map_display');
$this->is_map_accessible = $this->is_map_accessible && (Auth::check() || Configs::getValueAsBool('map_display_public'));
$this->is_mod_frame_enabled = Configs::getValueAsBool('mod_frame_enabled');
$this->album_thumb_css_aspect_ratio = Configs::getValueAsEnum('default_album_thumb_aspect_ratio', AspectRatioType::class)->css();
$this->is_search_accessible = Auth::check() || Configs::getValueAsBool('search_public');
}
}
2 changes: 1 addition & 1 deletion app/Models/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function newEloquentBuilder($query): AlbumBuilder
*/
protected function getAlbumThumbAspectRatioAttribute(): ?AspectRatioType
{
return AspectRatioType::tryFrom($this->attributes['album_thumb_aspect_ratio']);
return AspectRatioType::tryFrom($this->attributes['album_thumb_aspect_ratio'] ?? '1/1');
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Extensions/BaseConfigMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

abstract class BaseConfigMigration extends Migration
{
public const BOOL = '0|1';
public const POSITIVE = 'positive';
public const INT = 'int';

/**
* @return array<int,array{key:string,value:string,is_secret:bool,cat:string,type_range:string,description:string}>
*/
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Extensions/ToArrayThrowsNotImplemented.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ abstract protected function _toArray(): array;
*/
final public function toArray(): array
{
if (Route::is('livewire_index') || Route::is('livewire.message')) {
return $this->_toArray();
}
$details = Route::getCurrentRoute()?->getName() ?? '';
$details .= ($details !== '' ? ':' : '') . get_called_class();
throw new NotImplementedException($details . '->toArray() is deprecated, use Resources instead.');
Expand Down
Loading

0 comments on commit 4935468

Please sign in to comment.