235 lines
No EOL
6 KiB
PHP
235 lines
No EOL
6 KiB
PHP
<?php
|
|
|
|
use App\Models\Admin;
|
|
use App\Models\Card;
|
|
use App\Models\Raid;
|
|
use App\Models\Character;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Console Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This file is where you may define all of your Closure based console
|
|
| commands. Each Closure is bound to a command instance allowing a
|
|
| simple approach to interacting with each command's IO methods.
|
|
|
|
|
*/
|
|
|
|
// Characters
|
|
// --------------------------
|
|
|
|
Artisan::command('character:add {name}', function ($name) {
|
|
|
|
Character::create([
|
|
'name' => Str::ucfirst($name),
|
|
]);
|
|
|
|
$this->info("Created character");
|
|
})->purpose('Add a character');
|
|
|
|
Artisan::command('character:edit {id} {name}', function ($id, $name) {
|
|
|
|
$character = Character::find($id);
|
|
if (!$character) {
|
|
$this->warn("Could not find character.");
|
|
return;
|
|
}
|
|
|
|
$character->name = Str::ucfirst($name);
|
|
$character->save();
|
|
|
|
$this->info("Updated character");
|
|
})->purpose('Edit a character');
|
|
|
|
Artisan::command('character:list {--trashed}', function ($trashed) {
|
|
$cols = ['id', 'name' ];
|
|
if ($trashed) {
|
|
$cols[] = 'deleted_at';
|
|
$q = Character::onlyTrashed();
|
|
} else {
|
|
$q = Character::query();
|
|
}
|
|
$this->table($cols, $q->select($cols)->get());
|
|
})->purpose('list characters');
|
|
|
|
Artisan::command('character:delete {id}', function ($id) {
|
|
$char = Character::find($id);
|
|
|
|
if ($char) {
|
|
$char->delete();
|
|
$this->info(sprintf("Character #%s deleted", $id));
|
|
} else {
|
|
$this->warn(sprintf("Could not find character with id %s", $id));
|
|
}
|
|
})->purpose('Delete a character');
|
|
|
|
// Raids
|
|
// --------------------------
|
|
|
|
Artisan::command('raid:add {name}', function ($name) {
|
|
|
|
Raid::create([
|
|
'name' => $name,
|
|
]);
|
|
|
|
$this->info("Created raid");
|
|
})->purpose('Add a raid');
|
|
|
|
Artisan::command('raid:edit {id} {name}', function ($id, $name) {
|
|
|
|
$raid = Raid::find($id);
|
|
if (!$raid ) {
|
|
$this->warn("Could not find raid.");
|
|
return;
|
|
}
|
|
|
|
$raid->name = $name;
|
|
$raid->save();
|
|
|
|
$this->info("Updated raid");
|
|
})->purpose('Edit a raid');
|
|
|
|
Artisan::command('raid:list {--trashed}', function ($trashed) {
|
|
$cols = ['id', 'name' ];
|
|
if ($trashed) {
|
|
$cols[] = 'deleted_at';
|
|
$q = Raid::onlyTrashed();
|
|
} else {
|
|
$q = Raid::query();
|
|
}
|
|
$this->table($cols, $q->select($cols)->get());
|
|
})->purpose('list raids');
|
|
|
|
Artisan::command('raid:delete {id}', function ($id) {
|
|
$raid = Raid::find($id);
|
|
|
|
if ($raid) {
|
|
$raid->delete();
|
|
$this->info(sprintf("Raid #%s deleted", $id));
|
|
} else {
|
|
$this->warn(sprintf("Could not find raid with id %s", $id));
|
|
}
|
|
})->purpose('Delete a raid');
|
|
|
|
|
|
// Cards
|
|
// --------------------------
|
|
|
|
Artisan::command('card:add {body} {--column=} {--value=}', function ($body, $column=null, $value=null) {
|
|
|
|
$data = [ 'body' => $body ];
|
|
|
|
if ($value && !in_array($column, ['character_id', 'raid_id', 'class', 'role'])) {
|
|
$this->warn(sprintf("Invalid column '%s'", $column));
|
|
return;
|
|
}
|
|
|
|
if ($value && $column) {
|
|
$data[$column] = $value;
|
|
}
|
|
|
|
Card::create($data);
|
|
$this->info("Created card");
|
|
})->purpose('Create a new card');
|
|
|
|
Artisan::command('card:edit {id} {--body=} {--column=} {--value=}', function ($id, $body=null, $column=null, $value=null) {
|
|
|
|
$card = Card::find($id);
|
|
|
|
if (!$card) {
|
|
$this->warn("Could not find card.");
|
|
return;
|
|
}
|
|
|
|
if ($body) {
|
|
$card->body = $body;
|
|
}
|
|
|
|
if ($value && in_array($column, ['character_id', 'raid_id', 'class', 'role'])) {
|
|
$card->character_id = null;
|
|
$card->raid_id = null;
|
|
$card->class = null;
|
|
$card->role = null;
|
|
$card->{$column} = $value;
|
|
}
|
|
|
|
$card->save();
|
|
|
|
$this->info("Updated card");
|
|
})->purpose('Update a card');
|
|
|
|
Artisan::command('card:list {--trashed}', function ($trashed) {
|
|
$cols = ['id', 'character_id', 'raid_id', 'role', 'class', 'body' ];
|
|
$q = Card::query();
|
|
if ($trashed) {
|
|
$cols[] = 'deleted_at';
|
|
$q->onlyTrashed();
|
|
}
|
|
$data = $q->select($cols)->get()->makeHidden('subject');
|
|
$this->table($cols, $data);
|
|
})->purpose('list cards');
|
|
|
|
Artisan::command('card:delete {id}', function ($id) {
|
|
$record = Card::find($id);
|
|
if ($record) {
|
|
$record->delete();
|
|
$this->info(sprintf("Card #%s deleted", $id));
|
|
} else {
|
|
$this->warn(sprintf("Could not find card with id %s", $id));
|
|
}
|
|
})->purpose('Delete a card');
|
|
|
|
// Admin
|
|
// --------------------------
|
|
|
|
Artisan::command('admin:add {username} {password}', function ($username, $password) {
|
|
|
|
Admin::create([
|
|
'username' => $username,
|
|
'password' => Hash::make($password)
|
|
]);
|
|
|
|
$this->info("Created admin user");
|
|
})->purpose('Add a admin user');
|
|
|
|
Artisan::command('admin:edit {id} {--username=} {--password=}', function ($id, $username=null, $password=null) {
|
|
|
|
$admin = Admin::find($id);
|
|
if (!$admin) {
|
|
$this->warn("Could not find admin.");
|
|
return;
|
|
}
|
|
|
|
if ($username) {
|
|
$admin->username = $username;
|
|
}
|
|
if ($password) {
|
|
$admin->password = Hash::make($password);
|
|
}
|
|
|
|
$admin->save();
|
|
|
|
$this->info("Updated admin user");
|
|
})->purpose('Edit a admin user');
|
|
|
|
Artisan::command('admin:delete {id}', function ($id) {
|
|
$record = Admin::find($id);
|
|
if ($record) {
|
|
$record->delete();
|
|
$this->info(sprintf("Admin #%s deleted", $id));
|
|
} else {
|
|
$this->warn(sprintf("Could not find admin with id %s", $id));
|
|
}
|
|
})->purpose('Delete a admin user');
|
|
|
|
Artisan::command('admin:list', function () {
|
|
$cols = ['id', 'username', 'password', 'created_at', 'updated_at' ];
|
|
$q = Admin::query();
|
|
$data = $q->select($cols)->get()->makeVisible('password');
|
|
$this->table($cols, $data);
|
|
})->purpose('list admin users'); |