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

(Update) Save timestamps of when torrents are added to playlists #4337

Draft
wants to merge 1 commit into
base: 8.x.x
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion app/Http/Controllers/PlaylistController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public function show(Request $request, Playlist $playlist): \Illuminate\Contract
$randomTorrent?->category?->movie_meta => Movie::find($randomTorrent->tmdb),
default => null,
},
'torrents' => $torrents,
'latestPlaylistTorrent' => $playlist->torrents()->orderByPivot('created_at', 'desc')->first(),
'torrents' => $torrents,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function torrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Torrent::class, 'playlist_torrents')->using(PlaylistTorrent::class)->withPivot('id');
return $this->belongsToMany(Torrent::class, 'playlist_torrents')->using(PlaylistTorrent::class)->withPivot('id')->withTimestamps();
}

/**
Expand Down
7 changes: 0 additions & 7 deletions app/Models/PlaylistTorrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class PlaylistTorrent extends Pivot
/** @use HasFactory<\Database\Factories\PlaylistTorrentFactory> */
use HasFactory;

/**
* Indicates If The Model Should Be Timestamped.
*
* @var bool
*/
public $timestamps = false;

/**
* Indicates if the IDs are auto-incrementing.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <[email protected]>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

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.
*/
public function up(): void
{
Schema::table('playlist_torrents', function (Blueprint $table): void {
$table->timestamps();
});

DB::table('playlist_torrents')
->join('playlists', 'playlist_torrents.playlist_id', '=', 'playlists.id')
->update([
'playlist_torrents.created_at' => DB::raw('playlists.created_at'),
'playlist_torrents.updated_at' => DB::raw('playlists.created_at'),
]);
}
};
1 change: 1 addition & 0 deletions lang/en/playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
'title' => 'Title',
'titles' => 'Titles',
'update-success' => 'Your Playlist Has Successfully Been Updated!',
'last-addition-at' => 'Last addition at',
];
40 changes: 40 additions & 0 deletions resources/views/playlist/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,46 @@ class="form__button form__button--filled form__button--centered"
</p>
</div>
</section>
<section class="panelV2">
<h2 class="panel__heading">{{ __('common.info') }}</h2>
<dl class="key-value">
<div class="key-value__group">
<dt>{{ __('common.created_at') }}</dt>
<dd>
<time
datetime="{{ $playlist->created_at }}"
title="{{ $playlist->created_at }}"
>
{{ $playlist->created_at->diffForHumans() }}
</time>
</dd>
</div>
<div class="key-value__group">
<dt>{{ __('torrent.updated_at') }}</dt>
<dd>
<time
datetime="{{ $playlist->updated_at }}"
title="{{ $playlist->updated_at }}"
>
{{ $playlist->updated_at->diffForHumans() }}
</time>
</dd>
</div>
@if ($latestPlaylistTorrent !== null)
<div class="key-value__group">
<dt>{{ __('playlist.last-addition-at') }}</dt>
<dd>
<time
datetime="{{ $latestPlaylistTorrent->pivot->created_at }}"
title="{{ $latestPlaylistTorrent->pivot->created_at }}"
>
{{ $latestPlaylistTorrent->pivot->created_at->diffForHumans() }}
</time>
</dd>
</div>
@endif
</dl>
</section>
@endsection

@section('main')
Expand Down
Loading