fix: 🚑️ Use try catch to prevent 500 errors
This commit is contained in:
parent
af5d28e2a5
commit
371a37df7a
2 changed files with 54 additions and 3 deletions
|
@ -25,7 +25,12 @@ class TicketsController extends Controller
|
||||||
|
|
||||||
public function show($ticket_id)
|
public function show($ticket_id)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
}
|
||||||
$ticketcomments = $ticket->ticketcomments;
|
$ticketcomments = $ticket->ticketcomments;
|
||||||
$ticketcategory = $ticket->ticketcategory;
|
$ticketcategory = $ticket->ticketcategory;
|
||||||
$server = Server::where('id', $ticket->server)->first();
|
$server = Server::where('id', $ticket->server)->first();
|
||||||
|
@ -34,8 +39,14 @@ class TicketsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public function changeStatus($ticket_id)
|
public function changeStatus($ticket_id)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||||
|
} catch(Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
}
|
||||||
|
|
||||||
if($ticket->status == "Closed"){
|
if($ticket->status == "Closed"){
|
||||||
$ticket->status = "Reopened";
|
$ticket->status = "Reopened";
|
||||||
$ticket->save();
|
$ticket->save();
|
||||||
|
@ -50,7 +61,14 @@ class TicketsController extends Controller
|
||||||
|
|
||||||
public function delete($ticket_id)
|
public function delete($ticket_id)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TicketComment::where('ticket_id', $ticket->id)->delete();
|
TicketComment::where('ticket_id', $ticket->id)->delete();
|
||||||
$ticket->delete();
|
$ticket->delete();
|
||||||
|
|
||||||
|
@ -60,7 +78,14 @@ class TicketsController extends Controller
|
||||||
public function reply(Request $request)
|
public function reply(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, ['ticketcomment' => 'required']);
|
$this->validate($request, ['ticketcomment' => 'required']);
|
||||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
try {
|
||||||
|
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception $e){
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
|
||||||
|
}
|
||||||
$ticket->status = 'Answered';
|
$ticket->status = 'Answered';
|
||||||
$ticket->update();
|
$ticket->update();
|
||||||
TicketComment::create([
|
TicketComment::create([
|
||||||
|
@ -68,7 +93,12 @@ class TicketsController extends Controller
|
||||||
'user_id' => Auth::user()->id,
|
'user_id' => Auth::user()->id,
|
||||||
'ticketcomment' => $request->input('ticketcomment'),
|
'ticketcomment' => $request->input('ticketcomment'),
|
||||||
]);
|
]);
|
||||||
|
try {
|
||||||
$user = User::where('id', $ticket->user_id)->firstOrFail();
|
$user = User::where('id', $ticket->user_id)->firstOrFail();
|
||||||
|
} catch(Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('User not found on the server. Check on the admin database or try again later.'));
|
||||||
|
}
|
||||||
$newmessage = $request->input('ticketcomment');
|
$newmessage = $request->input('ticketcomment');
|
||||||
$user->notify(new ReplyNotification($ticket, $user, $newmessage));
|
$user->notify(new ReplyNotification($ticket, $user, $newmessage));
|
||||||
|
|
||||||
|
@ -145,7 +175,13 @@ class TicketsController extends Controller
|
||||||
|
|
||||||
public function blacklistAdd(Request $request)
|
public function blacklistAdd(Request $request)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$user = User::where('id', $request->user_id)->first();
|
$user = User::where('id', $request->user_id)->first();
|
||||||
|
}
|
||||||
|
catch (Exception $e){
|
||||||
|
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
|
||||||
|
|
||||||
|
}
|
||||||
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
||||||
if ($check) {
|
if ($check) {
|
||||||
$check->reason = $request->reason;
|
$check->reason = $request->reason;
|
||||||
|
|
|
@ -72,7 +72,12 @@ class TicketsController extends Controller
|
||||||
|
|
||||||
public function show($ticket_id)
|
public function show($ticket_id)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
}
|
||||||
$ticketcomments = $ticket->ticketcomments;
|
$ticketcomments = $ticket->ticketcomments;
|
||||||
$ticketcategory = $ticket->ticketcategory;
|
$ticketcategory = $ticket->ticketcategory;
|
||||||
$server = Server::where('id', $ticket->server)->first();
|
$server = Server::where('id', $ticket->server)->first();
|
||||||
|
@ -88,7 +93,12 @@ class TicketsController extends Controller
|
||||||
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
|
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
|
||||||
}
|
}
|
||||||
$this->validate($request, ['ticketcomment' => 'required']);
|
$this->validate($request, ['ticketcomment' => 'required']);
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
}
|
||||||
$ticket->status = 'Client Reply';
|
$ticket->status = 'Client Reply';
|
||||||
$ticket->update();
|
$ticket->update();
|
||||||
$ticketcomment = TicketComment::create([
|
$ticketcomment = TicketComment::create([
|
||||||
|
@ -105,8 +115,13 @@ class TicketsController extends Controller
|
||||||
return redirect()->back()->with('success', __('Your comment has been submitted'));
|
return redirect()->back()->with('success', __('Your comment has been submitted'));
|
||||||
}
|
}
|
||||||
public function changeStatus($ticket_id)
|
public function changeStatus($ticket_id)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
|
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
|
||||||
|
}
|
||||||
if($ticket->status == "Closed"){
|
if($ticket->status == "Closed"){
|
||||||
$ticket->status = "Reopened";
|
$ticket->status = "Reopened";
|
||||||
$ticket->save();
|
$ticket->save();
|
||||||
|
|
Loading…
Reference in a new issue