HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/quadcode-jobs/app/Models/DataRequest.php
<?php


namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

/**
 * @property int $id
 * @property string $email
 * @property int $type
 * @property string $token
 * @property string $updated_at
 * @property string $path
 */
class DataRequest extends Model
{

    protected $table = 'data_requests';

    public $timestamps = false;

    const TYPE_REQUEST = 1;
    const TYPE_REMOVE = 2;
    const TYPE_NO_DATA = 3;

    protected $fillable = [
        'email',
        'type',
        'token',
        'path',
        'updated_at',
    ];

    public static function createRequest(string $email, int $type = self::TYPE_REMOVE, ?string $path = null): self
    {
        $dataRequest = new self();
        $dataRequest->email = strtolower($email);
        $dataRequest->type = $type;
        $dataRequest->token = Str::random(32);
        $dataRequest->updated_at = Carbon::now();
        if (isset($path)) {
            $dataRequest->path = $path;
        }
        $dataRequest->save();

        return $dataRequest;
    }

    public function clear(): void
    {
        if (!empty($this->path)) {
            File::delete($this->path);
        }

        $this->delete();
    }

    public static function isLimitReached(string $email, int $type): bool
    {
        return self::whereRaw('LOWER(email) = \'' . strtolower($email) . '\'')
                ->where('type', $type)
                ->where('updated_at', '>', date('Y-m-d H:i:s', strtotime('-1 hour')))
                ->count() > 1;
    }

}