Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120827340
RemoveSkuCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
RemoveSkuCommand.php
View Options
<?php
namespace
App\Console\Commands\User
;
use
App\Console\Command
;
use
App\Sku
;
use
Illuminate\Support\Facades\DB
;
class
RemoveSkuCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'user:remove-sku {user} {sku} {--qty=}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Remove a SKU from the user'
;
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$user
=
$this
->
getUser
(
$this
->
argument
(
'user'
));
if
(!
$user
)
{
$this
->
error
(
"User not found."
);
return
1
;
}
$sku
=
$this
->
getObject
(
Sku
::
class
,
$this
->
argument
(
'sku'
),
'title'
);
if
(!
$sku
)
{
$this
->
error
(
"Unable to find the SKU {$this->argument('sku')}."
);
return
1
;
}
$quantity
=
((
int
)
$this
->
option
(
'qty'
))
?:
1
;
if
(
$user
->
entitlements
()->
where
(
'sku_id'
,
$sku
->
id
)->
count
()
<
$quantity
)
{
$this
->
error
(
"There aren't that many entitlements."
);
return
1
;
}
// removeSku() can charge the user wallet, let's use database transaction
DB
::
beginTransaction
();
$user
->
removeSku
(
$sku
,
$quantity
);
DB
::
commit
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Apr 24, 11:10 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18740316
Default Alt Text
RemoveSkuCommand.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline