Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/rentpix.corals.io/Corals/modules/RentPix/Jobs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/rentpix.corals.io/Corals/modules/RentPix/Jobs/OfflineInspectionJob.php
<?php

namespace Corals\Modules\RentPix\Jobs;

use Carbon\Carbon;
use Corals\Modules\RentPix\Classes\Integration\RentalAPIService;
use Corals\Modules\RentPix\Constants\FailedInspectionStatus;
use Corals\Modules\RentPix\Models\FailedInspection;
use Corals\Modules\RentPix\Models\Inspection;
use Corals\Modules\RentPix\Models\Reservation;
use Corals\Modules\RentPix\Services\FailedInspectionService;
use Corals\Modules\RentPix\Traits\InspectionsTrait;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class OfflineInspectionJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, InspectionsTrait;

    protected $request;

    protected $failedInspectionCode;

    protected $user;

    /**
     * @param $request
     * @param $failedInspectionCode
     * @param $user
     */
    public function __construct($request, $failedInspectionCode, $user)
    {
        $this->request = $request;
        $this->failedInspectionCode = $failedInspectionCode;
        $this->user = $user;
    }

    public function handle(FailedInspectionService $failedInspectionService)
    {
        try {
            $reservationCode = $this->request['reservation_code'];

            $type = $this->request['type'];

            $created_at = Carbon::createFromTimestamp($this->request['timestamp'] / 1000);

            $reservation = Reservation::query()->where('code', $reservationCode)->first();

            if ($reservation) {
                $inspection = Inspection::query()
                    ->where('reservation_id', $reservation->id)
                    ->where('status', '=', 'open')
                    ->first();

                if (!$inspection) {
                    $inspection = $this->createInspection($reservation, $type, $created_at, $this->user);
                }

                $this->submit($this->request, $inspection);
            } else {
                $rentalAPIService = new RentalAPIService();

                $reservation = $rentalAPIService->getReservationDetails($reservationCode, $this->user);

                $reservationData = $reservation['data'];

                $validator = $this->validateReservationData($reservationData);

                if (!$validator->fails()) {
                    $inspection = $this->fetchCreateInspection($reservationData, $reservationCode, $type, $created_at);

                    if ($this->failedInspectionCode) {
                        $failedInspection = FailedInspection::query()->where('code',$this->failedInspectionCode)->first();
                        $failedInspectionService->update([
                            'status' => FailedInspectionStatus::FIXED->value,
                            'inspection_id' => $inspection->id,
                        ], $failedInspection);
                    }
                }
            }
        } catch (\Exception $exception) {
            report($exception);

            if (method_exists($exception, 'getResponse')) {
                $response = json_decode($exception->getResponse()->getBody()->getContents(), true);
            } else {
                $response = [
                    'status_message' => $exception->getMessage()
                ];
            }

            if ($this->failedInspectionCode) {
                $failedInspection = FailedInspection::query()->where('code',$this->failedInspectionCode)->first();
                $failedInspectionService->update([
                    'failure_message' => $response['status_message'],
                ], $failedInspection);
            } else {
                FailedInspection::query()->create([
                    'code'=> FailedInspection::getSeqCode('FI'),
                    'payload' => $this->request,
                    'failure_message' => $response['status_message'],
                    'status' => FailedInspectionStatus::PENDING->value,
                ]);
            }
        }
    }
}

Spamworldpro Mini