44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Support\Legacy\Consultations;
|
|
use App\Support\Legacy\PortalException;
|
|
use Illuminate\Console\Command;
|
|
|
|
/** Memulihkan konsultasi (x_message) yang dihapus lunak dari Portal > Konsultasi. */
|
|
class RestoreConsultationsCommand extends Command
|
|
{
|
|
protected $signature = 'siakad:pulihkan-konsultasi
|
|
{--nim= : Hanya pesan mahasiswa dengan NIM ini}
|
|
{--nip= : Hanya pesan pembimbing dengan NIP ini}
|
|
{--semua : Pulihkan semua pesan yang terhapus}';
|
|
|
|
protected $description = 'Pulihkan pesan konsultasi yang dihapus dari Portal > Konsultasi (DB untan)';
|
|
|
|
public function handle(Consultations $consultations): int
|
|
{
|
|
$nim = $this->option('nim');
|
|
$nip = $this->option('nip');
|
|
$all = (bool) $this->option('semua');
|
|
|
|
if (! $all && blank($nim) && blank($nip)) {
|
|
$this->error('Sebutkan --nim=, --nip=, atau --semua.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
try {
|
|
$count = $consultations->restore($nim, $nip, $all);
|
|
} catch (PortalException $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info($count === 0 ? 'Tidak ada pesan terhapus yang cocok.' : "{$count} pesan dipulihkan.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|