Pony.fm/app/Models/Album.php

480 lines
15 KiB
PHP
Raw Normal View History

2015-08-30 14:29:12 +02:00
<?php
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Feld0.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2021-02-14 03:34:58 +01:00
namespace App\Models;
2015-08-31 14:35:47 +02:00
use App\Contracts\Commentable;
use App\Contracts\Favouritable;
use App\Contracts\Searchable;
use App\Exceptions\TrackFileNotFoundException;
use App\Traits\IndexedInElasticsearchTrait;
use App\Traits\SlugTrait;
use App\Traits\TrackCollection;
use Auth;
use Cache;
use DB;
2015-08-31 14:35:47 +02:00
use Exception;
use Gate;
2015-11-01 17:49:28 +01:00
use Helpers;
2021-02-14 20:11:44 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2015-08-30 14:29:12 +02:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
2015-08-30 14:29:12 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
use Venturecraft\Revisionable\RevisionableTrait;
2015-08-30 14:29:12 +02:00
2016-01-01 01:36:08 +01:00
/**
* App\Models\Album.
2016-01-01 01:36:08 +01:00
*
* @property int $id
* @property int $user_id
2016-01-01 01:36:08 +01:00
* @property string $title
* @property string $slug
* @property string $description
* @property int $cover_id
* @property int $track_count
* @property int $view_count
* @property int $download_count
* @property int $favourite_count
* @property int $comment_count
2016-01-01 01:36:08 +01:00
* @property \Carbon\Carbon $created_at
* @property string $updated_at
* @property \Carbon\Carbon $deleted_at
2021-02-14 03:34:58 +01:00
* @property-read \App\Models\User $user
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ResourceUser[] $users
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Favourite[] $favourites
* @property-read \App\Models\Image $cover
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Track[] $tracks
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Comment[] $comments
2016-01-01 01:36:08 +01:00
* @property-read mixed $url
* @property-read \Illuminate\Database\Eloquent\Collection|\Venturecraft\Revisionable\Revision[] $revisionHistory
2021-02-14 03:34:58 +01:00
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album userDetails()
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Activity[] $activities
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereId($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereTitle($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereSlug($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereDescription($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereCoverId($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereTrackCount($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereViewCount($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereDownloadCount($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereFavouriteCount($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereCommentCount($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album whereDeletedAt($value)
2016-12-10 17:47:49 +01:00
* @mixin \Eloquent
* @method static bool|null forceDelete()
2021-02-14 03:34:58 +01:00
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album onlyTrashed()
* @method static bool|null restore()
2021-02-14 03:34:58 +01:00
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Album withoutTrashed()
2016-01-01 01:36:08 +01:00
*/
class Album extends Model implements Searchable, Commentable, Favouritable
2015-08-30 14:29:12 +02:00
{
2021-02-14 20:11:17 +01:00
use HasFactory;
use SoftDeletes, SlugTrait, TrackCollection, RevisionableTrait, IndexedInElasticsearchTrait;
2016-01-07 19:16:37 +01:00
protected $elasticsearchType = 'album';
2015-08-30 14:29:12 +02:00
protected $fillable = ['user_id', 'title', 'slug'];
2015-08-30 14:29:12 +02:00
public static function summary()
{
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
return self::select(
'id',
'title',
'user_id',
'slug',
'created_at',
'cover_id',
'comment_count',
'download_count',
'view_count',
'favourite_count'
);
2015-08-30 14:29:12 +02:00
}
public function scopeUserDetails($query)
{
if (Auth::check()) {
$query->with([
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
'users' => function ($query) {
2015-08-30 14:29:12 +02:00
$query->whereUserId(Auth::user()->id);
},
2016-05-28 21:53:18 +02:00
]);
2015-08-30 14:29:12 +02:00
}
2017-11-28 17:44:28 +01:00
return $query;
2015-08-30 14:29:12 +02:00
}
protected $table = 'albums';
public function user()
{
2016-06-06 08:15:56 +02:00
return $this->belongsTo(User::class);
2015-08-30 14:29:12 +02:00
}
public function users()
{
2016-06-06 08:15:56 +02:00
return $this->hasMany(ResourceUser::class);
2015-08-30 14:29:12 +02:00
}
public function favourites():HasMany
2015-08-30 14:29:12 +02:00
{
2016-06-06 08:15:56 +02:00
return $this->hasMany(Favourite::class);
2015-08-30 14:29:12 +02:00
}
public function cover()
{
2016-06-06 08:15:56 +02:00
return $this->belongsTo(Image::class);
2015-08-30 14:29:12 +02:00
}
public function tracks()
{
2016-06-06 08:15:56 +02:00
return $this->hasMany(Track::class)->orderBy('track_number', 'asc');
2015-08-30 14:29:12 +02:00
}
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function trackFiles()
{
$trackIds = $this->tracks->pluck('id');
return TrackFile::join('tracks', 'tracks.current_version', '=', 'track_files.version')->whereIn('track_id', $trackIds);
}
public function comments():HasMany
2015-08-30 14:29:12 +02:00
{
2016-06-06 08:15:56 +02:00
return $this->hasMany(Comment::class)->orderBy('created_at', 'desc');
2015-08-30 14:29:12 +02:00
}
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function activities():MorphMany
{
return $this->morphMany(Activity::class, 'resource');
}
public static function mapPublicAlbumShow(self $album)
2015-08-30 14:29:12 +02:00
{
$tracks = [];
foreach ($album->tracks as $track) {
$tracks[] = Track::mapPublicTrackSummary($track);
}
$formats = [];
foreach (Track::$Formats as $name => $format) {
if (in_array($name, Track::$LosslessFormats) && ! $album->hasLosslessTracksOnly() && ! $album->hasLosslessTracks()) {
continue;
}
2015-08-30 14:29:12 +02:00
$formats[] = [
'name' => $name,
'extension' => $format['extension'],
'url' => $album->getDownloadUrl($name),
2015-10-29 15:36:13 +01:00
'size' => Helpers::formatBytes($album->getFilesize($name)),
'isCacheable' => (in_array($name, Track::$CacheableFormats) ? true : false),
'isMixedLosslessness' => (in_array($name, Track::$LosslessFormats) && ! $album->hasLosslessTracksOnly() && $album->hasLosslessTracks()),
2015-08-30 14:29:12 +02:00
];
}
2015-08-30 14:29:12 +02:00
$comments = [];
foreach ($album->comments as $comment) {
$comments[] = Comment::mapPublic($comment);
}
$is_downloadable = 0;
foreach ($album->tracks as $track) {
if ($track->is_downloadable == 1) {
$is_downloadable = 1;
break;
}
}
$data = self::mapPublicAlbumSummary($album);
$data['tracks'] = $tracks;
$data['comments'] = $comments;
$data['formats'] = $formats;
$data['description'] = $album->description;
$data['is_downloadable'] = $is_downloadable;
$data['share'] = [
'url' => action('AlbumsController@getShortlink', ['id' => $album->id]),
'tumblrUrl' => 'http://www.tumblr.com/share/link?url='.urlencode($album->url).'&name='.urlencode($album->title).'&description='.urlencode($album->description),
'twitterUrl' => 'https://platform.twitter.com/widgets/tweet_button.html?text='.$album->title.' by '.$album->user->display_name.' on Pony.fm',
2015-08-30 14:29:12 +02:00
];
return $data;
}
public static function mapPublicAlbumSummary(self $album)
2015-08-30 14:29:12 +02:00
{
$userData = [
'stats' => [
'views' => 0,
'downloads' => 0,
2015-08-30 14:29:12 +02:00
],
'is_favourited' => false,
2015-08-30 14:29:12 +02:00
];
if (Auth::check() && $album->users->count()) {
$userRow = $album->users[0];
$userData = [
'stats' => [
'views' => (int) $userRow->view_count,
'downloads' => (int) $userRow->download_count,
2015-08-30 14:29:12 +02:00
],
'is_favourited' => (bool) $userRow->is_favourited,
2015-08-30 14:29:12 +02:00
];
}
return [
'id' => (int) $album->id,
'track_count' => (int) $album->track_count,
2015-08-30 14:29:12 +02:00
'title' => $album->title,
'slug' => $album->slug,
'created_at' => $album->created_at->format('c'),
2015-08-30 14:29:12 +02:00
'stats' => [
'views' => (int) $album->view_count,
'downloads' => (int) $album->download_count,
'comments' => (int) $album->comment_count,
'favourites' => (int) $album->favourite_count,
2015-08-30 14:29:12 +02:00
],
'covers' => [
'small' => $album->getCoverUrl(Image::SMALL),
2015-12-13 14:42:37 +01:00
'normal' => $album->getCoverUrl(Image::NORMAL),
'original' => $album->getCoverUrl(Image::ORIGINAL),
2015-08-30 14:29:12 +02:00
],
'url' => $album->url,
'user' => [
'id' => (int) $album->user->id,
2015-08-30 14:29:12 +02:00
'name' => $album->user->display_name,
'slug' => $album->user->slug,
2015-08-30 14:29:12 +02:00
'url' => $album->user->url,
],
'user_data' => $userData,
'permissions' => [
2016-05-18 02:27:59 +02:00
'delete' => Gate::allows('delete', $album),
'edit' => Gate::allows('edit', $album),
],
2015-08-30 14:29:12 +02:00
];
}
public function hasCover()
{
return $this->cover_id != null;
}
public function getUrlAttribute()
{
return action('AlbumsController@getShow', ['id' => $this->id, 'slug' => $this->slug]);
2015-08-30 14:29:12 +02:00
}
public function getDownloadUrl($format)
{
return action('AlbumsController@getDownload', ['id' => $this->id, 'extension' => Track::$Formats[$format]['extension']]);
2015-08-30 14:29:12 +02:00
}
public function getCoverUrl($type = Image::NORMAL)
{
if (! $this->hasCover()) {
2015-08-30 14:29:12 +02:00
return $this->user->getAvatarUrl($type);
}
return $this->cover->getUrl($type);
}
public function getDirectory()
{
$dir = (string) (floor($this->id / 100) * 100);
2015-08-30 14:29:12 +02:00
return \Config::get('ponyfm.files_directory').'/tracks/'.$dir;
2015-08-30 14:29:12 +02:00
}
public function getDates()
{
return ['created_at', 'deleted_at', 'published_at'];
}
public function getFilenameFor($format)
{
if (! isset(Track::$Formats[$format])) {
2015-08-30 14:29:12 +02:00
throw new Exception("$format is not a valid format!");
}
$format = Track::$Formats[$format];
return "{$this->id}.{$format['extension']}.zip";
}
public function updateTrackNumbers()
{
$tracks = Track::whereAlbumId($this->id)->get();
$index = 1;
foreach ($tracks as $track) {
/** @var $track Track */
2015-08-30 14:29:12 +02:00
$track->track_number = $index;
$index++;
$track->updateTags();
$track->save();
}
}
public function syncTrackIds($trackIds)
{
$trackIdsInAlbum = [];
foreach ($this->tracks as $track) {
$trackIdsInAlbum[] = $track->id;
}
$trackIdsCount = count($trackIds);
$trackIdsInAlbumCount = count($trackIdsInAlbum);
$isSame = true;
if ($trackIdsInAlbumCount != $trackIdsCount) {
$isSame = false;
} else {
for ($i = 0; $i < $trackIdsInAlbumCount; $i++) {
if ($i >= $trackIdsCount || $trackIdsInAlbum[$i] != $trackIds[$i]) {
$isSame = false;
break;
}
}
}
if ($isSame) {
return;
}
$index = 1;
$tracksToRemove = [];
$albumsToFix = [];
foreach ($this->tracks as $track) {
$tracksToRemove[$track->id] = $track;
}
foreach ($trackIds as $trackId) {
if (! strlen(trim($trackId))) {
2015-08-30 14:29:12 +02:00
continue;
}
/** @var $track Track */
2015-08-30 14:29:12 +02:00
$track = Track::find($trackId);
2015-08-30 14:29:12 +02:00
if ($track->album_id != null && $track->album_id != $this->id) {
$albumsToFix[] = $track->album;
}
$track->album_id = $this->id;
$track->track_number = $index;
$track->updateTags();
$track->save();
unset($tracksToRemove[$track->id]);
$index++;
}
foreach ($tracksToRemove as $track) {
/** @var $track Track */
2015-08-30 14:29:12 +02:00
$track->album_id = null;
$track->track_number = null;
$track->updateTags();
$track->save();
}
foreach ($albumsToFix as $album) {
/** @var $album Album */
2015-08-30 14:29:12 +02:00
$album->updateTrackNumbers();
}
foreach (Track::$Formats as $name => $format) {
Cache::forget($this->getCacheKey('filesize'.$name));
2015-08-30 14:29:12 +02:00
}
}
/**
* @param string $key
* @return string
*/
2015-11-01 17:49:28 +01:00
public function getCacheKey($key)
2015-08-30 14:29:12 +02:00
{
return 'album-'.$this->id.'-'.$key;
2015-08-30 14:29:12 +02:00
}
/**
* The number of tracks in an album will always be in sync.
*
* @param array $options
* @return bool
*/
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function save(array $options = [])
{
$this->recountTracks();
return parent::save($options);
}
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function delete()
{
DB::transaction(function () {
$this->activities()->delete();
parent::delete();
});
}
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
protected function recountTracks()
{
$this->track_count = $this->tracks->count();
}
2016-01-07 19:16:37 +01:00
/**
* Returns this model in Elasticsearch-friendly form. The array returned by
* this method should match the current mapping for this model's ES type.
*
* @return array
*/
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function toElasticsearch():array
{
2016-01-07 19:16:37 +01:00
return [
'title' => $this->title,
'artist' => $this->user->display_name,
'tracks' => $this->tracks->pluck('title'),
];
}
/**
* {@inheritdoc}
*/
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function shouldBeIndexed():bool
{
return $this->track_count > 0 && ! $this->trashed();
}
/**
* Returns the corresponding resource type ID from the Activity class for
* this resource.
*
* @return string
*/
Laravel 5.2 Update (#106) * Adopt PSR-2 coding style The Laravel framework adopts the PSR-2 coding style in version 5.1. Laravel apps *should* adopt this coding style as well. Read the [PSR-2 coding style guide][1] for more details and check out [PHPCS][2] to use as a code formatting tool. [1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md [2]: https://github.com/squizlabs/PHP_CodeSniffer * Adopt PHP short array syntax Laravel 5 adopted the short array syntax which became available in PHP 5.4. * Remove SelfHandling from Jobs Jobs are self handling by default in Laravel 5.2. * Add new exceptions to `$dontReport` property * Shift core files * Shift Middleware Laravel 5.2 adjusts the `Guard` object used within middleware. In addition, new `can` and `throttles` middleware were added. * Shift Input to Request facade Laravel 5.2 no longer registers the `Input` facade by default. Laravel now prefers using the `Request` facade or the `$request` object within *Controllers* instead. Review the [HTTP Requests][1] documentation for more details. [1]: https://laravel.com/docs/5.2/requests * Shift configuration Laravel 5.2 introduces the `env` app configuration option and removes the `pretend` mail configuration option. In addition, a few of the default `providers` and `aliases` bindings were removed. * Shift Laravel dependencies * Shift cleanup * Updated composer.lock * Updated Middleware to 5.2 * Config update for Laravel 5.2 * [Laravel 5.2] Updated validation strings * Updated auth config * Updated to use middleware groups * Added laravel 5.2 sessions migration
2016-09-30 00:26:31 +02:00
public function getResourceType():string
{
return 'album';
}
}