-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
21 changed files
with
439 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ | |
use App\Http\Controllers\Controller; | ||
use App\Http\Transformers\ManufacturersTransformer; | ||
use App\Http\Transformers\SelectlistTransformer; | ||
use App\Models\Actionlog; | ||
use App\Models\Manufacturer; | ||
use Illuminate\Http\Request; | ||
use App\Http\Requests\ImageUploadRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class ManufacturersController extends Controller | ||
|
@@ -159,6 +161,44 @@ public function destroy($id) | |
|
||
} | ||
|
||
/** | ||
* Restore a given Manufacturer (mark as un-deleted) | ||
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v6.3.4] | ||
* @param int $id | ||
* @return \Illuminate\Http\JsonResponse | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*/ | ||
public function restore($id) | ||
{ | ||
$this->authorize('delete', Manufacturer::class); | ||
|
||
if ($manufacturer = Manufacturer::withTrashed()->find($id)) { | ||
|
||
if ($manufacturer->deleted_at == '') { | ||
return response()->json(Helper::formatStandardApiResponse('error', trans('general.not_deleted', ['item_type' => trans('general.manufacturer')])), 200); | ||
} | ||
|
||
if ($manufacturer->restore()) { | ||
|
||
$logaction = new Actionlog(); | ||
$logaction->item_type = Manufacturer::class; | ||
$logaction->item_id = $manufacturer->id; | ||
$logaction->created_at = date('Y-m-d H:i:s'); | ||
$logaction->user_id = Auth::user()->id; | ||
$logaction->logaction('restore'); | ||
|
||
return response()->json(Helper::formatStandardApiResponse('success', trans('admin/manufacturers/message.restore.success')), 200); | ||
} | ||
|
||
// Check validation to make sure we're not restoring an item with the same unique attributes as a non-deleted one | ||
return response()->json(Helper::formatStandardApiResponse('error', trans('general.could_not_restore', ['item_type' => trans('general.manufacturer'), 'error' => $manufacturer->getErrors()->first()])), 200); | ||
} | ||
|
||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/manufacturers/message.does_not_exist'))); | ||
} | ||
|
||
/** | ||
* Gets a paginated collection for the select2 menus | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
|
||
use App\Helpers\Helper; | ||
use App\Http\Requests\ImageUploadRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\Asset; | ||
use App\Models\AssetModel; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Input; | ||
|
@@ -209,7 +212,7 @@ public function destroy($modelId) | |
$this->authorize('delete', AssetModel::class); | ||
// Check if the model exists | ||
if (is_null($model = AssetModel::find($modelId))) { | ||
return redirect()->route('models.index')->with('error', trans('admin/models/message.not_found')); | ||
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); | ||
} | ||
|
||
if ($model->assets()->count() > 0) { | ||
|
@@ -237,22 +240,42 @@ public function destroy($modelId) | |
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @param int $modelId | ||
* @param int $id | ||
* @return Redirect | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*/ | ||
public function getRestore($modelId = null) | ||
public function getRestore($id) | ||
{ | ||
$this->authorize('create', AssetModel::class); | ||
// Get user information | ||
$model = AssetModel::withTrashed()->find($modelId); | ||
|
||
if (isset($model->id)) { | ||
$model->restore(); | ||
if ($model = AssetModel::withTrashed()->find($id)) { | ||
|
||
if ($model->deleted_at == '') { | ||
return redirect()->back()->with('error', trans('general.not_deleted', ['item_type' => trans('general.asset_model')])); | ||
} | ||
|
||
return redirect()->route('models.index')->with('success', trans('admin/models/message.restore.success')); | ||
if ($model->restore()) { | ||
$logaction = new Actionlog(); | ||
$logaction->item_type = User::class; | ||
$logaction->item_id = $model->id; | ||
$logaction->created_at = date('Y-m-d H:i:s'); | ||
$logaction->user_id = Auth::user()->id; | ||
$logaction->logaction('restore'); | ||
|
||
|
||
// Redirect them to the deleted page if there are more, otherwise the section index | ||
$deleted_models = AssetModel::onlyTrashed()->count(); | ||
if ($deleted_models > 0) { | ||
return redirect()->back()->with('success', trans('admin/models/message.restore.success')); | ||
} | ||
return redirect()->route('models.index')->with('success', trans('admin/models/message.restore.success')); | ||
} | ||
|
||
// Check validation | ||
return redirect()->back()->with('error', trans('general.could_not_restore', ['item_type' => trans('general.asset_model'), 'error' => $model->getErrors()->first()])); | ||
} | ||
return redirect()->back()->with('error', trans('admin/models/message.not_found')); | ||
|
||
return redirect()->back()->with('error', trans('admin/models/message.does_not_exist')); | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.