Fixes #9
- add FK on arcadia_links to media.id and remove orphans - Refactored ArcadiaLinkController - Added comments on ArcadiaLink model - refactored arcadialinks.index
This commit is contained in:
parent
c5d8ea542f
commit
eb212215a8
5 changed files with 101 additions and 27 deletions
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ArcadiaLink;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
class ArcadiaLinkController extends Controller
|
||||
{
|
||||
|
|
@ -17,9 +17,14 @@ class ArcadiaLinkController extends Controller
|
|||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
$user->authorizeRoles(config('roles.const.ADMIN'));
|
||||
$dt = Carbon::now('Europe/Paris')->subMinutes(15)->toDateTimeString();
|
||||
$ano = ArcadiaLink::where('created_at', '<', $dt)->orderBy('id', 'DESC')->get();
|
||||
return view('arcadialinks.index', ['ano' => $ano]);
|
||||
|
||||
// * ArcadiaLink->Media is nullable
|
||||
$arcadiaLinkList = ArcadiaLink::query()
|
||||
->with('media', fn (Builder $q) => $q->withTrashed())
|
||||
->where('created_at', '<', now()->subMinutes(15))
|
||||
->orderBy('id', 'DESC')->get();
|
||||
|
||||
return view('arcadialinks.index', compact('arcadiaLinkList'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,6 +5,13 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @property integer $arcadia_id The ID on Arcadia side, Defaults to 0 (not linked).
|
||||
* @property string $filename
|
||||
*
|
||||
* @property-read \App\Models\Media $media Media BelongsTo relationship.
|
||||
* @package App\Models
|
||||
*/
|
||||
class ArcadiaLink extends Model
|
||||
{
|
||||
// * GETTERS
|
||||
|
|
|
|||
|
|
@ -42,11 +42,13 @@ class RouteServiceProvider extends ServiceProvider
|
|||
});
|
||||
|
||||
Route::bind('media', function ($value) {
|
||||
return Media::whereUid($value)->firstOrFail();
|
||||
return Media::query()
|
||||
->where('uid', $value)
|
||||
->firstOrFail();
|
||||
});
|
||||
Route::bind('basket_uuid', function ($value) {
|
||||
return Panier::where('uid', $value)
|
||||
->with('owner')->firstOrFail();
|
||||
->with('owner')->firstOrFail();
|
||||
});
|
||||
|
||||
// * API
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$linkedMediaIdList = DB::table('arcadia_links')->pluck('media_id');
|
||||
$existingMediaIdList = DB::table('media')->whereIn('id', $linkedMediaIdList)->pluck('id');
|
||||
$linkIdListToRemove = $linkedMediaIdList->filter(fn (int $media_id) =>
|
||||
!$existingMediaIdList->contains($media_id));
|
||||
|
||||
// * Remove Orphan links
|
||||
DB::transaction(fn () => DB::table('arcadia_links')->whereIn('media_id', $linkIdListToRemove)->delete());
|
||||
|
||||
// * Add foreign Key
|
||||
Schema::table('arcadia_links', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('media_id')->nullable(false)->default(null)->change();
|
||||
});
|
||||
Schema::table('arcadia_links', function (Blueprint $table) {
|
||||
$table->foreign('media_id')->references('id')->on('media');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('arcadia_links', function (Blueprint $table) {
|
||||
$table->dropForeign(['media_id']);
|
||||
});
|
||||
Schema::table('arcadia_links', function (Blueprint $table) {
|
||||
$table->bigInteger('media_id')->default(0)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -1,36 +1,48 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@include('layouts.header')
|
||||
|
||||
@section('content')
|
||||
<main class="user_index template_2col">
|
||||
@include('modules.param-sideMenu')
|
||||
<div class="main_content">
|
||||
<div class="heading">
|
||||
<h1>Anomalies du lien Arcadia</h1>
|
||||
<h1>{{ __('Anomalies du lien Arcadia') }}</h1>
|
||||
</div>
|
||||
<table class="datatable">
|
||||
<thead>
|
||||
<table class="datatable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Media ID (DAM ID)</th>
|
||||
<th>Arcadia ID</th>
|
||||
<th>Filename</th>
|
||||
<th>Date création ZIP</th>
|
||||
<th>{{ __('ID') }}</th>
|
||||
<th>{{ __('Media ID (DAM ID)') }}</th>
|
||||
<th>{{ __('Arcadia ID') }}</th>
|
||||
<th>{{ __('Filename') }}</th>
|
||||
<th>{{ __('Date création ZIP') }}</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach ($ano as $line)
|
||||
<tr class="data_row">
|
||||
<td>{{$line->id}}</td>
|
||||
<td>{{$line->media_id}}</td>
|
||||
<td>{{$line->arcadia_id}}</td>
|
||||
<td>{{$line->filename}}</td>
|
||||
<td>{{$line->date_f}}</td>
|
||||
<td><a href="/media/{{$line->media_uuid}}" target="_blank">Ouvrir la fiche média</a></td>
|
||||
<td><a href="{{route('arcadialinks.destroy', ['id' => $line->id])}}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette anomalie ?');"><i class="fas fa-times" style="color: red"></i></a></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
</thead>
|
||||
@foreach ($arcadiaLinkList as $arcadiaLink)
|
||||
<tr class="data_row">
|
||||
<td>{{ $arcadiaLink->id }}</td>
|
||||
<td>{{ $arcadiaLink->media->id }}</td>
|
||||
<td>{{ $arcadiaLink->arcadia_id }}</td>
|
||||
<td>{{ $arcadiaLink->filename }}</td>
|
||||
<td>{{ $arcadiaLink->date_f }}</td>
|
||||
<td>
|
||||
<a href="{{ route('media.show', $arcadiaLink->media) }}"
|
||||
title="{{ __('Ouvrir la fiche média dans un nouvel onglet') }}" target="_blank">
|
||||
{{ __('Ouvrir la fiche média') }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ route('arcadialinks.destroy', $arcadiaLink) }}" title="{{ __('Supprimer le lien arcadia') }}"
|
||||
onclick="return confirm('{{ __('Êtes-vous sûr de vouloir supprimer cette anomalie ?') }}');">
|
||||
<i class="fas fa-times" style="color: red"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue