This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Console/Commands/FrameDelete.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2018-12-03 12:59:22 +00:00
<?php
namespace App\Console\Commands;
use App\Models\Frame;
use Illuminate\Console\Command;
class FrameDelete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'frame:delete {frame} {index}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete frames from the database.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
if (! is_numeric($this->argument('frame')))
throw new \Exception('Frame is not numeric: '.$this->argument('frame'));
if (strlen($this->argument('index')) != 1 OR ! preg_match('/^[a-z]$/',$this->argument('index')))
throw new \Exception('Subframe failed validation');
try {
$o = Frame::where('frame',$this->argument('frame'))
->where('index',$this->argument('index'))
->firstOrFail();
} catch (ModelNotFoundException $e) {
$this->error('Page not found to delete: '.$this->argument('frame').$this->argument('index'));
die(1);
}
$o->delete();
$this->info('Page deleted: '.$this->argument('frame').$this->argument('index'));
}
}