Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120836944
ObjectUpdateCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
ObjectUpdateCommand.php
View Options
<?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
ObjectUpdateCommand
extends
ObjectCommand
{
public
function
__construct
()
{
$this
->
description
=
"Update a {$this->objectName}"
;
$this
->
signature
=
sprintf
(
"%s%s:update {%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
);
if
(
in_array
(
SoftDeletes
::
class
,
$classes
))
{
$this
->
signature
.=
" {--with-deleted : Include deleted {$this->objectName}s}"
;
}
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
()
{
$argument
=
$this
->
argument
(
$this
->
objectName
);
$object
=
$this
->
getObject
(
$this
->
objectClass
,
$argument
,
$this
->
objectTitle
);
if
(!
$object
)
{
$this
->
error
(
"No such {$this->objectName} {$argument}"
);
return
1
;
}
foreach
(
$this
->
getProperties
()
as
$property
=>
$value
)
{
if
(
$property
==
"deleted_at"
&&
$value
==
"null"
)
{
$value
=
null
;
}
$object
->{
$property
}
=
$value
;
}
$object
->
timestamps
=
false
;
if
(
$this
->
commandPrefix
==
'scalpel'
)
{
$this
->
objectClass
::
withoutEvents
(
function
()
use
(
$object
)
{
$object
->
save
();
}
);
}
else
{
$object
->
save
();
}
$this
->
cacheRefresh
(
$object
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Apr 24, 1:38 PM (1 h, 14 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18750141
Default Alt Text
ObjectUpdateCommand.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline