diff --git a/app/Commands/MergeAccountsCommand.php b/app/Commands/MergeAccountsCommand.php index a1ef3e81..addd1aa4 100644 --- a/app/Commands/MergeAccountsCommand.php +++ b/app/Commands/MergeAccountsCommand.php @@ -129,6 +129,7 @@ class MergeAccountsCommand extends CommandBase } $this->sourceAccount->disabled_at = Carbon::now(); + $this->sourceAccount->redirect_to = $this->destinationAccount->id; $this->sourceAccount->save(); }); diff --git a/app/Http/Controllers/ArtistsController.php b/app/Http/Controllers/ArtistsController.php index 518bc57a..6880ff70 100644 --- a/app/Http/Controllers/ArtistsController.php +++ b/app/Http/Controllers/ArtistsController.php @@ -44,8 +44,17 @@ class ArtistsController extends Controller public function getProfile($slug) { - $user = User::whereSlug($slug)->whereNull('disabled_at')->first(); - if (!$user) { + $user = User::whereSlug($slug)->first(); + + if ($user->redirect_to) { + $newUser = User::find($user->redirect_to)->first(); + + if ($newUser) { + return Redirect::action('ArtistsController@getProfile', [$newUser->slug]); + } + } + + if ($user->disabled_at) { App::abort('404'); } diff --git a/app/Models/User.php b/app/Models/User.php index 1564d90a..bcf40461 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -116,6 +116,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon 'comment_count' => 'integer', 'avatar_id' => 'integer', 'is_archived' => 'boolean', + 'redirect_to' => 'integer' ]; protected $dates = ['created_at', 'updated_at', 'disabled_at']; protected $hidden = ['disabled_at', 'remember_token']; diff --git a/database/migrations/2017_09_20_200156_AddRedirectToUsers.php b/database/migrations/2017_09_20_200156_AddRedirectToUsers.php new file mode 100644 index 00000000..09e4248e --- /dev/null +++ b/database/migrations/2017_09_20_200156_AddRedirectToUsers.php @@ -0,0 +1,32 @@ +integer('redirect_to')->unsigned()->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('redirect_to'); + }); + } +}