Skip to content
This repository has been archived by the owner on Aug 20, 2023. It is now read-only.

Commit

Permalink
Upgrade Laravel 9 (#516)
Browse files Browse the repository at this point in the history
* Update configs

* Fix migrations

* Fix proxy error

* Fix media path

* Update types by valid tags

* Move lang files

* Return type
  • Loading branch information
francoism90 authored Feb 13, 2022
1 parent a97229f commit ed32ea3
Show file tree
Hide file tree
Showing 60 changed files with 1,077 additions and 3,237 deletions.
11 changes: 7 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.php]
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
11 changes: 8 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
6 changes: 3 additions & 3 deletions app/Actions/Media/UpdateMediaDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class UpdateMediaDetails
{
public function __invoke(Media $media, array $data): Media
{
$collect = collect($data);
$value = fn (string $key, mixed $default = null) => data_get($data, $key, $default);

$media
->setAttribute('name', $collect->get('name', $media->name))
->setCustomProperty('thumbnail', $collect->get('thumbnail', $media->thumbnail))
->setAttribute('name', $value('name', $media->name))
->setCustomProperty('thumbnail', $value('thumbnail', $media->thumbnail))
->saveOrFail();

MediaHasBeenUpdated::dispatch($media);
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Tag/CreateNewTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class CreateNewTag
{
public function __invoke(array $data = []): Tag
{
$collect = collect($data);
$value = fn (string $key, mixed $default = null) => data_get($data, $key, $default);

return Tag::findOrCreate(
$collect->get('name'),
$collect->get('type', 'genre'),
$collect->get('locale', 'en'),
$value('name'),
$value('type', 'genre'),
$value('locale', 'en'),
);
}
}
29 changes: 14 additions & 15 deletions app/Actions/Tag/SyncTagsWithTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@

namespace App\Actions\Tag;

use App\Models\Tag;
use Illuminate\Database\Eloquent\Model;

class SyncTagsWithTypes
{
public function __invoke(Model $model, array $tags = []): void
public function __invoke(Model $model, array $values = null): void
{
$collect = collect($tags);
$model->detachTags($model->tags);

$types = $this->getTypes();
$tags = collect($values)->map(function ($value) {
if ($value instanceof Tag) {
return $value;
}

foreach ($types as $type) {
$items = $collect
->where('type', $type)
->pluck('name')
->unique()
->toArray();
return Tag::findByHashid($value);
});

$model->syncTagsWithType($items, $type);
}
}
$names = fn ($type) => $tags->where('type', $type)->pluck('name')->unique()->all();

protected function getTypes(): ?array
{
return config('api.tag.types');
$tags
?->pluck('type')
?->unique()
?->each(fn ($type) => $model->syncTagsWithType($names($type), $type));
}
}
4 changes: 3 additions & 1 deletion app/Actions/User/DeleteUserToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class DeleteUserToken
{
public function __invoke(User $user, string $token): void
{
$user->tokens()?->firstWhere('token', $token)?->delete();
$user->tokens
?->firstWhere('token', $token)
?->delete();
}
}
10 changes: 5 additions & 5 deletions app/Actions/User/UpdateUserSettings.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

namespace App\Actions\Video;
namespace App\Actions\User;

use App\Events\User\UserHasBeenUpdated;
use App\Models\User;

class UpdateVideoDetails
class UpdateUserSettings
{
public function __invoke(User $user, array $data): void
{
$collect = collect($data);
$value = fn (string $key, mixed $default = null) => data_get($data, $key, $default);

// Update attributes
$locale = $collect->get('locale', $user->preferredLocale());
$locale = $value('locale', $user->preferredLocale());

$user->extra_attributes
->set('locale', $collect->get('locale', $locale));
->set('locale', $value('locale', $locale));

$user->saveOrFail();

Expand Down
20 changes: 10 additions & 10 deletions app/Actions/Video/UpdateVideoDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ class UpdateVideoDetails
{
public function __invoke(Video $video, array $data): void
{
$collect = collect($data);
$value = fn (string $key, mixed $default = null) => data_get($data, $key, $default);

// Update attributes
$locale = $collect->get('locale', app()->getLocale());
$locale = $value('locale', app()->getLocale());

$video
->setTranslation('name', $locale, $collect->get('name', $video->name))
->setTranslation('overview', $locale, $collect->get('overview', $video->overview))
->setAttribute('status', $collect->get('status', $video->status))
->setAttribute('episode_number', $collect->get('episode_number', $video->episode_number))
->setAttribute('season_number', $collect->get('season_number', $video->season_number));
->setTranslation('name', $locale, $value('name', $video->name))
->setTranslation('overview', $locale, $value('overview', $video->overview))
->setAttribute('status', $value('status', $video->status))
->setAttribute('episode_number', $value('episode_number', $video->episode_number))
->setAttribute('season_number', $value('season_number', $video->season_number));

$video->extra_attributes
->set('thumbnail', $collect->get('thumbnail', $video->thumbnail));
->set('thumbnail', $value('thumbnail', $video->thumbnail));

$video->saveOrFail();

// Update clips attributes
app(UpdateVideoClips::class)($video, [
'thumbnail' => $collect->get('thumbnail', $video->thumbnail),
'thumbnail' => $value('thumbnail', $video->thumbnail),
]);

// Sync tags
app(SyncTagsWithTypes::class)($video, $collect->get('tags', []));
app(SyncTagsWithTypes::class)($video, $value('tags.*.id'));

// Dispatch event
VideoHasBeenUpdated::dispatch(
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Kernel extends HttpKernel
*
* These middleware are run during every request to your application.
*
* @var array
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
Expand All @@ -26,7 +26,7 @@ class Kernel extends HttpKernel
/**
* The application's route middleware groups.
*
* @var array
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
Expand All @@ -41,7 +41,7 @@ class Kernel extends HttpKernel

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
// 'throttle:api',
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
Expand All @@ -51,14 +51,12 @@ class Kernel extends HttpKernel
*
* These middleware may be assigned to groups or used individually.
*
* @var array
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \App\Http\Middleware\SetCacheHeaders::class,
// 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\CheckForAuthentication::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
Expand Down
10 changes: 10 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ class EventServiceProvider extends ServiceProvider
public function boot(): void
{
}

/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents(): bool
{
return false;
}
}
25 changes: 7 additions & 18 deletions app/Support/MediaLibrary/UrlGenerator/DefaultUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use DateTimeInterface;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use League\Flysystem\Adapter\AbstractAdapter;
use Spatie\MediaLibrary\Support\UrlGenerator\BaseUrlGenerator;

class DefaultUrlGenerator extends BaseUrlGenerator
Expand Down Expand Up @@ -35,29 +34,14 @@ public function getTemporaryUrl(DateTimeInterface $expiration, array $options =
);
}

public function getBaseMediaDirectoryUrl()
public function getBaseMediaDirectoryUrl(): string
{
return $this->getDisk()->url('/');
}

public function getPath(): string
{
$adapter = $this->getDisk()->getAdapter();

$cachedAdapter = '\League\Flysystem\Cached\CachedAdapter';

if ($adapter instanceof $cachedAdapter) {
$adapter = $adapter->getAdapter();
}

$pathPrefix = '';

if ($adapter instanceof AbstractAdapter) {
/** @var AbstractAdapter $pathPrefix */
$pathPrefix = $adapter->getPathPrefix();
}

return $pathPrefix.$this->getPathRelativeToRoot();
return $this->getRootOfDisk().$this->getPathRelativeToRoot();
}

public function getResponsiveImagesDirectoryUrl(): string
Expand All @@ -68,4 +52,9 @@ public function getResponsiveImagesDirectoryUrl(): string

return Str::finish(url($base.$path), '/');
}

protected function getRootOfDisk(): string
{
return config("filesystems.disks.{$this->getDiskName()}.root").'/';
}
}
53 changes: 23 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,49 @@
"license": "MIT",
"require": {
"php": "^8.0",
"elegantweb/sanitizer": "^1.1",
"fideloper/proxy": "^4.4",
"elegantweb/sanitizer": "^2.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"http-interop/http-factory-guzzle": "^1.2",
"laravel/framework": "^8.82",
"laravel/framework": "^9.0",
"laravel/horizon": "^5.8",
"laravel/octane": "^1.2",
"laravel/sanctum": "^2.14",
"laravel/scout": "^9.4",
"laravel/telescope": "^4.7",
"laravel/tinker": "^2.6",
"laravel/tinker": "^2.7",
"meilisearch/meilisearch-php": "^0.21.0",
"multicaret/laravel-acquaintances": "^3.5",
"php-ffmpeg/php-ffmpeg": "^0.19.0",
"php-ffmpeg/php-ffmpeg": "^1.0",
"pusher/pusher-php-server": "^7.0",
"rennokki/laravel-eloquent-query-cache": "^3.2",
"spatie/eloquent-sortable": "^4.0",
"spatie/laravel-backup": "^7.7",
"spatie/laravel-backup": "^8.0",
"spatie/laravel-collection-macros": "^7.10",
"spatie/laravel-db-snapshots": "^2.2",
"spatie/laravel-health": "^1.8",
"spatie/laravel-medialibrary": "^9.10",
"spatie/laravel-medialibrary": "^10.0",
"spatie/laravel-permission": "^5.5",
"spatie/laravel-rate-limited-job-middleware": "^2.1",
"spatie/laravel-schedule-monitor": "^2.4",
"spatie/laravel-rate-limited-job-middleware": "^2.2",
"spatie/laravel-schedule-monitor": "^3.0",
"spatie/laravel-schemaless-attributes": "^2.3",
"spatie/laravel-sluggable": "^3.2",
"spatie/laravel-tags": "^4.2",
"spatie/laravel-translatable": "^5.0",
"spatie/laravel-sluggable": "^3.3",
"spatie/laravel-tags": "^4.3",
"spatie/laravel-translatable": "^5.2",
"spatie/laravel-validation-rules": "^3.2",
"spatie/temporary-directory": "^2.0",
"vinkla/hashids": "^9.1"
"vinkla/hashids": "^10.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.12",
"facade/ignition": "^2.12",
"fakerphp/faker": "^1.16",
"laravel/sail": "^1.13",
"mockery/mockery": "^1.4",
"nunomaduro/collision": "^5.9",
"nunomaduro/collision": "^6.1",
"phpstan/phpstan": "^1.1",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.12.15"
"rector/rector": "^0.12.15",
"spatie/laravel-ignition": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -72,30 +71,24 @@
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
"@php artisan horizon:publish --ansi",
"@php artisan telescope:publish --ansi",
"@php artisan ide-helper:generate",
"@php artisan ide-helper:meta"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"post-install-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi",
"@php artisan ide-helper:generate",
"@php artisan ide-helper:meta"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi",
"@php artisan ide-helper:generate",
"@php artisan ide-helper:meta"
]
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
}
"sort-packages": true
},
"extra": {
"laravel": {
Expand Down
Loading

0 comments on commit ed32ea3

Please sign in to comment.