mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 06:27:59 +01:00
#25: Hide notifications for deleted content.
This commit is contained in:
parent
a8e81729fb
commit
3f5c0d0f51
8 changed files with 119 additions and 7 deletions
|
@ -21,6 +21,7 @@
|
|||
namespace Poniverse\Ponyfm\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Poniverse\Ponyfm\Models\Activity
|
||||
|
@ -39,6 +40,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property-read mixed $text
|
||||
*/
|
||||
class Activity extends Model {
|
||||
use SoftDeletes;
|
||||
|
||||
public $timestamps = false;
|
||||
protected $dates = ['created_at'];
|
||||
protected $fillable = ['created_at', 'user_id', 'activity_type', 'resource_type', 'resource_id'];
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
namespace Poniverse\Ponyfm\Models;
|
||||
|
||||
use DB;
|
||||
use Exception;
|
||||
use Helpers;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
@ -400,6 +401,7 @@ class Album extends Model implements Searchable, Commentable, Favouritable
|
|||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function getCacheKey($key)
|
||||
{
|
||||
|
@ -417,6 +419,13 @@ class Album extends Model implements Searchable, Commentable, Favouritable
|
|||
return parent::save($options);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
DB::transaction(function () {
|
||||
$this->activities()->delete();
|
||||
parent::delete();
|
||||
});
|
||||
}
|
||||
|
||||
protected function recountTracks() {
|
||||
$this->track_count = $this->tracks->count();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
namespace Poniverse\Ponyfm\Models;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
@ -50,7 +51,6 @@ use Poniverse\Ponyfm\Contracts\Commentable;
|
|||
*/
|
||||
class Comment extends Model
|
||||
{
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'comments';
|
||||
|
@ -131,4 +131,11 @@ class Comment extends Model
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
DB::transaction(function () {
|
||||
$this->activities()->delete();
|
||||
parent::delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,10 +66,11 @@ class Notification extends Model {
|
|||
'activity.resource',
|
||||
'activity.resource.user',
|
||||
])
|
||||
->join('activities', 'notifications.activity_id', '=', 'activities.id')
|
||||
->where('notifications.user_id', $user->id)
|
||||
->select('*', 'notifications.id as id')
|
||||
->orderBy('activities.created_at', 'DESC');
|
||||
->join('activities', 'notifications.activity_id', '=', 'activities.id')
|
||||
->where('notifications.user_id', $user->id)
|
||||
->whereNull('activities.deleted_at')
|
||||
->select('*', 'notifications.id as id')
|
||||
->orderBy('activities.created_at', 'DESC');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
namespace Poniverse\Ponyfm\Models;
|
||||
|
||||
use DB;
|
||||
use Helpers;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
@ -316,6 +317,13 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable
|
|||
return 'playlist-'.$this->id.'-'.$key;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
DB::transaction(function () {
|
||||
$this->activities()->delete();
|
||||
parent::delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this model in Elasticsearch-friendly form. The array returned by
|
||||
* this method should match the current mapping for this model's ES type.
|
||||
|
|
|
@ -859,6 +859,12 @@ class Track extends Model implements Searchable, Commentable, Favouritable
|
|||
return 'track-'.$this->id.'-'.$key;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
DB::transaction(function () {
|
||||
$this->activities()->delete();
|
||||
parent::delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Peter Deltchev
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddDeletedAtColumnToActivities extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('activities', function(Blueprint $table) {
|
||||
$table->softDeletes()->index();
|
||||
});
|
||||
|
||||
// Retroactively fix activities that should be marked as deleted.
|
||||
// Tracks
|
||||
DB::table('activities')
|
||||
->where('resource_type', 2)
|
||||
->join('tracks', 'activities.resource_id', '=', 'tracks.id')
|
||||
->whereNotNull('tracks.deleted_at')
|
||||
->update(['activities.deleted_at' => DB::raw('tracks.deleted_at')]);
|
||||
|
||||
// Albums
|
||||
DB::table('activities')
|
||||
->where('resource_type', 3)
|
||||
->join('albums', 'activities.resource_id', '=', 'albums.id')
|
||||
->whereNotNull('albums.deleted_at')
|
||||
->update(['activities.deleted_at' => DB::raw('albums.deleted_at')]);
|
||||
|
||||
// Playlists
|
||||
DB::table('activities')
|
||||
->where('resource_type', 4)
|
||||
->join('playlists', 'activities.resource_id', '=', 'playlists.id')
|
||||
->whereNotNull('playlists.deleted_at')
|
||||
->update(['activities.deleted_at' => DB::raw('playlists.deleted_at')]);
|
||||
|
||||
// Comments
|
||||
DB::table('activities')
|
||||
->where('resource_type', 5)
|
||||
->join('comments', 'activities.resource_id', '=', 'comments.id')
|
||||
->whereNotNull('comments.deleted_at')
|
||||
->update(['activities.deleted_at' => DB::raw('comments.deleted_at')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('activities', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
[program: ponyfm-worker]
|
||||
process_name = %(program_name)s_%(process_num)02d
|
||||
command = php /vagrant/artisan queue:listen --queue=default,notifications,indexing --sleep=3 --tries=3
|
||||
command = php /vagrant/artisan queue:listen --queue=default,notifications,indexing --sleep=5 --tries=3
|
||||
autostart = true
|
||||
autorestart = true
|
||||
user = www-data
|
||||
numprocs = 4
|
||||
numprocs = 2
|
||||
redirect_stderr = true
|
||||
stdout_logfile = /vagrant/storage/logs/worker.log
|
||||
|
|
Loading…
Reference in a new issue