Skip to content

Commit d1499de

Browse files
committed
Provisions for strict mode, fixed license deletion bug
1 parent b365ada commit d1499de

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

app/controllers/admin/LicensesController.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,20 @@ public function postEdit($licenseId = null)
188188
$license->license_name = e(Input::get('license_name'));
189189
$license->notes = e(Input::get('notes'));
190190
$license->order_number = e(Input::get('order_number'));
191-
$license->purchase_date = e(Input::get('purchase_date'));
192-
$license->purchase_cost = e(Input::get('purchase_cost'));
191+
192+
// Update the asset data
193+
if ( e(Input::get('purchase_date')) == '') {
194+
$license->purchase_date = NULL;
195+
} else {
196+
$license->purchase_date = e(Input::get('purchase_date'));
197+
}
198+
199+
if ( e(Input::get('purchase_cost')) == '') {
200+
$license->purchase_cost = NULL;
201+
} else {
202+
$license->purchase_cost = e(Input::get('purchase_cost'));
203+
}
204+
193205

194206
//Are we changing the total number of seats?
195207
if( $license->seats != e(Input::get('seats')))
@@ -205,12 +217,15 @@ public function postEdit($licenseId = null)
205217
return is_null($seat->user);
206218
});
207219

220+
208221
//If the remaining collection is as large or larger than the number of seats we want to delete
209222
if($seats->count() >= abs($difference))
210223
{
211224
for ($i=1; $i <= abs($difference); $i++) {
212225
//Delete the appropriate number of seats
213-
$seats->first()->delete();
226+
//$seats->first()->delete();
227+
$license->licenseseats->pop()->delete();
228+
echo '<li>'.$i;
214229
}
215230

216231
//Log the deletion of seats to the log
@@ -219,7 +234,9 @@ public function postEdit($licenseId = null)
219234
$logaction->asset_type = 'software';
220235
$logaction->user_id = Sentry::getUser()->id;
221236
$logaction->note = abs($difference)." seats";
237+
$logaction->checkedout_to = NULL;
222238
$log = $logaction->logaction('delete seats');
239+
223240
} else {
224241
// Redirect to the license edit page
225242
return Redirect::to("admin/licenses/$licenseId/edit")->with('error', Lang::get('admin/licenses/message.assoc_users'));
@@ -364,21 +381,34 @@ public function postCheckout($seatId)
364381

365382

366383
// Update the asset data
367-
$licenseseat->assigned_to = e(Input::get('assigned_to'));
368-
384+
if ( e(Input::get('assigned_to')) == '') {
385+
$licenseseat->assigned_to = NULL;
386+
} else {
387+
$licenseseat->assigned_to = e(Input::get('assigned_to'));
388+
}
369389

370390
// Was the asset updated?
371391
if($licenseseat->save())
372392
{
393+
373394
$logaction = new Actionlog();
374395
$logaction->asset_id = $licenseseat->license_id;
375-
$logaction->checkedout_to = $licenseseat->assigned_to;
376396
$logaction->location_id = $assigned_to->location_id;
377397
$logaction->asset_type = 'software';
378398
$logaction->user_id = Sentry::getUser()->id;
379399
$logaction->note = e(Input::get('note'));
400+
401+
402+
// Update the asset data
403+
if ( e(Input::get('assigned_to')) == '') {
404+
$logaction->checkedout_to = NULL;
405+
} else {
406+
$logaction->checkedout_to = e(Input::get('assigned_to'));
407+
}
408+
380409
$log = $logaction->logaction('checkout');
381410

411+
382412
// Redirect to the new asset page
383413
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success'));
384414
}

0 commit comments

Comments
 (0)