Added checkin action on delete for checked out assets

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2024-10-01 14:29:02 +01:00
parent cfc04a1d12
commit 5823197e6f
3 changed files with 19 additions and 5 deletions
@@ -428,7 +428,7 @@ class AssetsController extends Controller
* @param int $assetId
* @since [v1.0]
*/
public function destroy($assetId) : RedirectResponse
public function destroy(Request $request, $assetId) : RedirectResponse
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
@@ -438,9 +438,17 @@ class AssetsController extends Controller
$this->authorize('delete', $asset);
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
if ($asset->assignedTo) {
$target = $asset->assignedTo;
$checkin_at = date('Y-m-d H:i:s');
$originalValues = $asset->getRawOriginal();
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on delete', $checkin_at, $originalValues));
DB::table('assets')
->where('id', $asset->id)
->update(['assigned_to' => null]);
}
if ($asset->image) {
try {