Merging accounts now redirects old URL

This commit is contained in:
Josef Citrine 2017-09-20 22:02:39 +01:00
parent c7c962e91b
commit e844054643
4 changed files with 45 additions and 2 deletions

View file

@ -129,6 +129,7 @@ class MergeAccountsCommand extends CommandBase
}
$this->sourceAccount->disabled_at = Carbon::now();
$this->sourceAccount->redirect_to = $this->destinationAccount->id;
$this->sourceAccount->save();
});

View file

@ -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');
}

View file

@ -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'];

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddRedirectToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('redirect_to')->unsigned()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('redirect_to');
});
}
}