diff --git a/app/Avatar.php b/app/Avatar.php index a7f8e4e67..b72510765 100644 --- a/app/Avatar.php +++ b/app/Avatar.php @@ -3,8 +3,16 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Avatar extends Model { + use SoftDeletes; + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; } diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 571b41a55..30aecd7e2 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -2,7 +2,7 @@ namespace App\Jobs\StatusPipeline; -use App\{Media, StatusHashtag, Status}; +use App\{Media, Notification, StatusHashtag, Status}; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; @@ -60,6 +60,9 @@ class StatusDelete implements ShouldQueue } $status->likes()->delete(); + Notification::whereItemType('App\Status') + ->whereItemId($status->id) + ->delete(); StatusHashtag::whereStatusId($status->id)->delete(); $status->delete(); diff --git a/app/Like.php b/app/Like.php index a4ce9f0a8..c70b647bc 100644 --- a/app/Like.php +++ b/app/Like.php @@ -3,9 +3,19 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Like extends Model { + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; + public function actor() { return $this->belongsTo(Profile::class, 'profile_id', 'id'); diff --git a/app/Media.php b/app/Media.php index 8cc2ffd1e..7c9138965 100644 --- a/app/Media.php +++ b/app/Media.php @@ -2,11 +2,21 @@ namespace App; -use Illuminate\Database\Eloquent\Model; use Storage; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Media extends Model { + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; + public function url() { $path = $this->media_path; diff --git a/app/Mention.php b/app/Mention.php index 3473c2924..bc76bdc97 100644 --- a/app/Mention.php +++ b/app/Mention.php @@ -3,9 +3,18 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Mention extends Model { + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; public function profile() { diff --git a/app/Notification.php b/app/Notification.php index c40e0a553..9aef5b197 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -3,28 +3,37 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Notification extends Model { - - public function actor() - { - return $this->belongsTo(Profile::class, 'actor_id', 'id'); - } - - public function profile() - { - return $this->belongsTo(Profile::class, 'profile_id', 'id'); - } - - public function item() - { - return $this->morphTo(); - } - - public function status() - { - return $this->belongsTo(Status::class, 'item_id', 'id'); - } + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; + + public function actor() + { + return $this->belongsTo(Profile::class, 'actor_id', 'id'); + } + + public function profile() + { + return $this->belongsTo(Profile::class, 'profile_id', 'id'); + } + + public function item() + { + return $this->morphTo(); + } + + public function status() + { + return $this->belongsTo(Status::class, 'item_id', 'id'); + } } diff --git a/app/Profile.php b/app/Profile.php index b0bcd3da3..009ed2cbf 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -5,9 +5,18 @@ namespace App; use Storage; use App\Util\Lexer\PrettyNumber; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Profile extends Model { + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; protected $hidden = [ 'private_key', ]; diff --git a/app/Status.php b/app/Status.php index 07879f510..fe3fc26d2 100644 --- a/app/Status.php +++ b/app/Status.php @@ -2,12 +2,21 @@ namespace App; -use Illuminate\Database\Eloquent\Model; use Storage; -use Vinkla\Hashids\Facades\Hashids; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Status extends Model { + use SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; + public function profile() { return $this->belongsTo(Profile::class); @@ -43,6 +52,11 @@ class Status extends Model return url($path); } + public function editUrl() + { + return $this->url() . '/edit'; + } + public function mediaUrl() { $media = $this->firstMedia(); diff --git a/app/User.php b/app/User.php index 33297e481..38edc3e9d 100644 --- a/app/User.php +++ b/app/User.php @@ -3,11 +3,19 @@ namespace App; use Illuminate\Notifications\Notifiable; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { - use Notifiable; + use Notifiable, SoftDeletes; + + /** + * The attributes that should be mutated to dates. + * + * @var array + */ + protected $dates = ['deleted_at']; /** * The attributes that are mass assignable. diff --git a/database/migrations/2018_06_14_001318_add_soft_deletes_to_models.php b/database/migrations/2018_06_14_001318_add_soft_deletes_to_models.php new file mode 100644 index 000000000..a839ddf74 --- /dev/null +++ b/database/migrations/2018_06_14_001318_add_soft_deletes_to_models.php @@ -0,0 +1,58 @@ +softDeletes(); + }); + + Schema::table('likes', function ($table) { + $table->softDeletes(); + }); + + Schema::table('media', function ($table) { + $table->softDeletes(); + }); + + Schema::table('mentions', function ($table) { + $table->softDeletes(); + }); + + Schema::table('notifications', function ($table) { + $table->softDeletes(); + }); + + Schema::table('profiles', function ($table) { + $table->softDeletes(); + }); + + Schema::table('statuses', function ($table) { + $table->softDeletes(); + }); + + Schema::table('users', function ($table) { + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}