Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117753077
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/app/Console/ObjectDeleteCommand.php b/src/app/Console/ObjectDeleteCommand.php
index 098d2097..7a7e9026 100644
--- a/src/app/Console/ObjectDeleteCommand.php
+++ b/src/app/Console/ObjectDeleteCommand.php
@@ -1,95 +1,95 @@
<?php
namespace App\Console;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Schema;
/**
* This abstract class provides a means to treat objects in our model using CRUD.
*/
-abstract class ObjectDeleteCommand extends ObjectCommand
+abstract class ObjectDeleteCommand extends ScalpelCommand
{
public function __construct()
{
$this->description = "Delete a {$this->objectName}";
$this->signature = sprintf(
"%s%s:delete {%s}",
$this->commandPrefix ? $this->commandPrefix . ":" : "",
$this->objectName,
$this->objectName
);
$class = new $this->objectClass();
try {
foreach (Schema::getColumnListing($class->getTable()) as $column) {
if ($column == "id") {
continue;
}
$this->signature .= " {--{$column}=}";
}
} catch (\Exception $e) {
\Log::error("Could not extract options: {$e->getMessage()}");
}
$classes = class_uses_recursive($this->objectClass);
parent::__construct();
}
public function getProperties()
{
if (!empty($this->properties)) {
return $this->properties;
}
$class = new $this->objectClass();
$this->properties = [];
foreach (Schema::getColumnListing($class->getTable()) as $column) {
if ($column == "id") {
continue;
}
if (($value = $this->option($column)) !== null) {
$this->properties[$column] = $value;
}
}
return $this->properties;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$result = parent::handle();
if (!$result) {
return 1;
}
$argument = $this->argument($this->objectName);
$object = $this->getObject($this->objectClass, $argument, $this->objectTitle);
if (!$object) {
$this->error("No such {$this->objectName} {$argument}");
return 1;
}
if ($this->commandPrefix == 'scalpel') {
$this->objectClass::withoutEvents(
function () use ($object) {
$object->delete();
}
);
}
}
}
diff --git a/src/app/Console/ScalpelCommand.php b/src/app/Console/ScalpelCommand.php
new file mode 100644
index 00000000..96cdfce3
--- /dev/null
+++ b/src/app/Console/ScalpelCommand.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Console;
+
+class ScalpelCommand extends ObjectCommand
+{
+ public function handle()
+ {
+ if ($this->dangerous) {
+ $this->warn(
+ "This command is a dangerous scalpel command with potentially significant unintended consequences"
+ );
+
+ $confirmation = $this->confirm("Are you sure you understand what's about to happen?");
+
+ if (!$confirmation) {
+ $this->info("Better safe than sorry.");
+ return false;
+ }
+
+ $this->info("Vámonos!");
+ }
+
+ return true;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 5:02 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822653
Default Alt Text
(3 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline