Enforce to use tid_skin
This commit is contained in:
parent
a75b358751
commit
cd2711942e
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Schema;
|
||||
use App\Models\Player;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class MigratePlayersTable extends Command
|
||||
{
|
||||
@ -38,12 +40,17 @@ class MigratePlayersTable extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!Schema::hasColumn('players', 'tid_steve')) {
|
||||
$this->info('No need to update.');
|
||||
return;
|
||||
}
|
||||
|
||||
$players = Player::where('tid_skin', -1)->get();
|
||||
$count = $players->count();
|
||||
|
||||
if ($count == 0) {
|
||||
$this->dropColumn();
|
||||
$this->info('No need to update.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,8 +65,18 @@ class MigratePlayersTable extends Command
|
||||
|
||||
$bar->advance();
|
||||
});
|
||||
|
||||
$this->dropColumn();
|
||||
|
||||
$bar->finish();
|
||||
|
||||
$this->info("\nCongratulations! We've updated $count rows.");
|
||||
}
|
||||
|
||||
private function dropColumn()
|
||||
{
|
||||
Schema::table('players', function (Blueprint $table) {
|
||||
$table->dropColumn(['tid_steve', 'tid_alex', 'preference']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -58,18 +58,6 @@ class Player extends Model
|
||||
return $this->belongsTo('App\Models\User', 'uid');
|
||||
}
|
||||
|
||||
public function getTidSkinAttribute($value)
|
||||
{
|
||||
if ($value == -1) {
|
||||
$this->tid_skin = $value = $this->preference == 'default'
|
||||
? $this->tid_steve
|
||||
: $this->tid_alex;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific texture of player.
|
||||
*
|
||||
|
@ -34,9 +34,6 @@ class CreateAllTables extends Migration
|
||||
$table->increments('pid');
|
||||
$table->integer('uid');
|
||||
$table->string('player_name', 50);
|
||||
$table->string('preference', 10);
|
||||
$table->integer('tid_steve')->default('0');
|
||||
$table->integer('tid_alex')->default('0');
|
||||
$table->integer('tid_cape')->default('0');
|
||||
$table->dateTime('last_modified');
|
||||
});
|
||||
|
@ -25,16 +25,8 @@ class AddVerificationToUsersTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (config('database.default') == 'sqlite') {
|
||||
// Dropping columns from a SQLite database requires `doctrine/dbal` dependency.
|
||||
// However, we won't install it because it's too hard to specify the version of
|
||||
// all the new dependencies exactly to make them support PHP ^5.5.9. Damn it.
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('verified');
|
||||
$table->dropColumn('verification_token');
|
||||
$table->dropColumn(['verified', 'verification_token']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,10 @@ class AddTidSkin extends Migration
|
||||
{
|
||||
Schema::table('players', function (Blueprint $table) {
|
||||
$table->integer('tid_skin')->default(-1);
|
||||
$table->string('preference', 10)->nullable()->change();
|
||||
|
||||
if (Schema::hasColumn('players', 'preference')) {
|
||||
$table->string('preference', 10)->nullable()->change();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -28,7 +31,10 @@ class AddTidSkin extends Migration
|
||||
{
|
||||
Schema::table('players', function (Blueprint $table) {
|
||||
$table->dropColumn('tid_skin');
|
||||
$table->string('preference', 10)->nullable(false)->change();
|
||||
|
||||
if (Schema::hasColumn('players', 'preference')) {
|
||||
$table->string('preference', 10)->nullable(false)->change();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Faker;
|
||||
use Artisan;
|
||||
use App\Models\Player;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class MigratePlayersTableTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
factory(Player::class)->create([
|
||||
'tid_skin' => -1,
|
||||
'preference' => $faker->randomElement(['default', 'slim']),
|
||||
'tid_steve' => $faker->randomDigit(),
|
||||
'tid_alex' => $faker->randomDigit(),
|
||||
]);
|
||||
}
|
||||
|
||||
Artisan::call('bs:migrate-v4:players-table');
|
||||
|
||||
Player::all()
|
||||
->each(function (Player $player) {
|
||||
if ($player->preference == 'default') {
|
||||
$this->assertEquals($player->tid_steve, $player->tid_skin);
|
||||
} else {
|
||||
$this->assertEquals($player->tid_alex, $player->tid_skin);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertEquals(0, Artisan::call('bs:migrate-v4:players-table'));
|
||||
}
|
||||
}
|
@ -29,23 +29,4 @@ class PlayerTest extends TestCase
|
||||
$player = factory(Player::class)->make();
|
||||
$this->assertNull($player->getJsonProfile(-1));
|
||||
}
|
||||
|
||||
public function testGetTidSkinAttribute()
|
||||
{
|
||||
$player = factory(Player::class)->create([
|
||||
'tid_skin' => -1,
|
||||
'preference' => 'default',
|
||||
'tid_steve' => 5,
|
||||
]);
|
||||
$this->assertEquals(5, $player->tid_skin);
|
||||
$this->assertEquals(5, Player::find($player->pid)->tid_skin);
|
||||
|
||||
$player = factory(Player::class)->create([
|
||||
'tid_skin' => -1,
|
||||
'preference' => 'slim',
|
||||
'tid_alex' => 6,
|
||||
]);
|
||||
$this->assertEquals(6, $player->tid_skin);
|
||||
$this->assertEquals(6, Player::find($player->pid)->tid_skin);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user