Removed debugging
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
60e0e899bc
commit
b87879f8e7
1 changed files with 27 additions and 39 deletions
|
@ -112,7 +112,8 @@ class BulkAssetsController extends Controller
|
||||||
public function update(Request $request)
|
public function update(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('update', Asset::class);
|
$this->authorize('update', Asset::class);
|
||||||
$error_bag = [];
|
$has_errors = 0;
|
||||||
|
$error_array = array();
|
||||||
|
|
||||||
// Get the back url from the session and then destroy the session
|
// Get the back url from the session and then destroy the session
|
||||||
$bulk_back_url = route('hardware.index');
|
$bulk_back_url = route('hardware.index');
|
||||||
|
@ -120,11 +121,9 @@ class BulkAssetsController extends Controller
|
||||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||||
}
|
}
|
||||||
|
|
||||||
\Log::debug(print_r($request->all(), true));
|
|
||||||
|
|
||||||
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
||||||
|
|
||||||
if(Session::exists('ids')) {
|
if (Session::exists('ids')) {
|
||||||
$assets = Session::get('ids');
|
$assets = Session::get('ids');
|
||||||
} elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
} elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
||||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||||
|
@ -157,7 +156,6 @@ class BulkAssetsController extends Controller
|
||||||
) {
|
) {
|
||||||
foreach ($assets as $assetId) {
|
foreach ($assets as $assetId) {
|
||||||
|
|
||||||
\Log::debug('Asset ID is: '.$assetId);
|
|
||||||
$this->update_array = [];
|
$this->update_array = [];
|
||||||
|
|
||||||
$this->conditionallyAddItem('purchase_date')
|
$this->conditionallyAddItem('purchase_date')
|
||||||
|
@ -221,14 +219,13 @@ class BulkAssetsController extends Controller
|
||||||
$changed[$key]['new'] = $this->update_array[$key];
|
$changed[$key]['new'] = $this->update_array[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\Log::debug('$this->update_array:');
|
// \Log::debug('$this->update_array:');
|
||||||
\Log::debug(print_r($this->update_array, true));
|
// \Log::debug(print_r($this->update_array, true));
|
||||||
|
//
|
||||||
\Log::debug('$changed');
|
// \Log::debug('$changed');
|
||||||
\Log::debug(print_r($changed, true));
|
// \Log::debug(print_r($changed, true));
|
||||||
|
|
||||||
if ($custom_fields_present) {
|
if ($custom_fields_present) {
|
||||||
\Log::debug('Custom fields are present');
|
|
||||||
|
|
||||||
$model = $asset->model()->first();
|
$model = $asset->model()->first();
|
||||||
// Make sure this model is valid
|
// Make sure this model is valid
|
||||||
|
@ -236,18 +233,15 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
if ($assetCustomFields && $assetCustomFields->fields) {
|
if ($assetCustomFields && $assetCustomFields->fields) {
|
||||||
|
|
||||||
\Log::debug('There are custom fields on '.$assetCustomFields->name);
|
|
||||||
|
|
||||||
foreach ($assetCustomFields->fields as $field) {
|
foreach ($assetCustomFields->fields as $field) {
|
||||||
|
|
||||||
if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) {
|
if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) {
|
||||||
\Log::debug('The custom field is encrypted!');
|
|
||||||
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
|
||||||
|
|
||||||
// Check if the decrypted existing value is different than one we just submitted
|
// Check if the decrypted existing value is different than one we just submitted
|
||||||
// and if not, pull it out of the object
|
// and if not, pull it out of the object
|
||||||
if ($decrypted_old != $this->update_array[$field->db_column]) {
|
if ($decrypted_old != $this->update_array[$field->db_column]) {
|
||||||
\Log::debug('The decrypted existing value is different than the one submitted');
|
|
||||||
$asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]);
|
$asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]);
|
||||||
} else {
|
} else {
|
||||||
\Log::debug('The decrypted existing value is the same as the one submitted - unset it');
|
\Log::debug('The decrypted existing value is the same as the one submitted - unset it');
|
||||||
|
@ -258,7 +252,6 @@ class BulkAssetsController extends Controller
|
||||||
// These fields aren't encrypted, just carry on as usual
|
// These fields aren't encrypted, just carry on as usual
|
||||||
} else {
|
} else {
|
||||||
if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) {
|
if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) {
|
||||||
\Log::debug('The custom field value is different than the original one');
|
|
||||||
$asset->{$field->db_column} = $this->update_array[$field->db_column];
|
$asset->{$field->db_column} = $this->update_array[$field->db_column];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,41 +262,37 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
// Check if it passes validation, and then try to save
|
// Check if it passes validation, and then try to save
|
||||||
$has_errors = 0;
|
if ($asset->update($this->update_array)) {
|
||||||
$error_array = array();
|
$logAction = new Actionlog();
|
||||||
|
$logAction->item_type = Asset::class;
|
||||||
if ($asset->isValid()) {
|
$logAction->item_id = $assetId;
|
||||||
if ($asset->update($this->update_array)) {
|
$logAction->created_at = date("Y-m-d H:i:s");
|
||||||
$logAction = new Actionlog();
|
$logAction->user_id = Auth::id();
|
||||||
$logAction->item_type = Asset::class;
|
$logAction->log_meta = json_encode($changed);
|
||||||
$logAction->item_id = $assetId;
|
$logAction->logaction('update');
|
||||||
$logAction->created_at = date("Y-m-d H:i:s");
|
|
||||||
$logAction->user_id = Auth::id();
|
|
||||||
$logAction->log_meta = json_encode($changed);
|
|
||||||
$logAction->logaction('update');
|
|
||||||
}
|
|
||||||
|
|
||||||
\Log::debug('New asset info:');
|
|
||||||
\Log::debug('Model name: '.$asset->model->name);
|
|
||||||
\Log::debug('Asset ID '.$asset->id.' with custom fields bulk edited successfully');
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$has_errors++;
|
|
||||||
|
\Log::debug('Error bag:');
|
||||||
\Log::debug(print_r($asset->getErrors(), true));
|
\Log::debug(print_r($asset->getErrors(), true));
|
||||||
// Build the error array
|
// Build the error array
|
||||||
foreach ($asset->getErrors()->toArray() as $key => $message) {
|
foreach ($asset->getErrors()->toArray() as $key => $message) {
|
||||||
for ($x = 0; $x < count($message); $x++) {
|
for ($x = 0; $x < count($message); $x++) {
|
||||||
$error_array[][] = trans('general.asset').' '.$asset->id.': '.$message[$x];
|
$error_array[$key][] = trans('general.asset') . ' ' . $asset->id . ': ' . $message[$x];
|
||||||
|
$has_errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} // end if saved
|
||||||
|
|
||||||
} // end asset foreach
|
} // end asset foreach
|
||||||
|
|
||||||
|
\Log::debug($has_errors.' errors');
|
||||||
if ($has_errors > 0) {
|
if ($has_errors > 0) {
|
||||||
\Log::debug('Ooops!');
|
\Log::debug('Error array:');
|
||||||
dd($error_array);
|
\Log::debug(print_r($error_array, true));
|
||||||
return redirect($bulk_back_url)->with('bulk_errors', array_unique($error_array));
|
//dd($error_array);
|
||||||
|
return redirect($bulk_back_url)->with('bulk_asset_errors', $error_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
|
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
|
||||||
|
@ -327,7 +316,6 @@ class BulkAssetsController extends Controller
|
||||||
{
|
{
|
||||||
if (request()->filled($field)) {
|
if (request()->filled($field)) {
|
||||||
$this->update_array[$field] = request()->input($field);
|
$this->update_array[$field] = request()->input($field);
|
||||||
\Log::debug('Conditionally adding '.$field);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
Loading…
Add table
Reference in a new issue