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/Console/Commands/Lever.php
<?php

namespace App\Console\Commands;

use App\Repositories\CategoryRepository;
use App\Repositories\LocationRepository;
use App\Repositories\VacancyRepository;
use Exception;
use Illuminate\Console\Command;
use Lever\Api\Client;
use Symfony\Component\Console\Command\Command as CommandAlias;

class Lever extends Command
{

    protected $signature = 'lever:update';

    protected $description = 'Update vacancies';

    const LIMIT = 50;

    private function mapVacancy($posting): array
    {
        return [
            'external_id' => $posting['id'],
            'title' => $posting['text'],
            'state' => $posting['state'],
            'commitment' => $posting['categories']['commitment'],
            'workplace_type' => $posting['workplaceType'],
            'department' => $posting['categories']['department'],
            'team' => $posting['categories']['team'],
            'location' => $posting['categories']['location'],
            'locations' => $posting['categories']['allLocations'],
            'country' => $posting['country'] ?? '',
            'url' => $posting['urls']['show'] ?? null,
        ];
    }

    public function handle(): int
    {
        $this->info($this->description);
        $token = env('LEVER_TOKEN');
        if (empty($token)) {
            $this->error('LEVER_TOKEN need to set');

            return CommandAlias::FAILURE;
        }

        try {
            $leverClient = new Client(['authToken' => $token]);

            $result = $leverClient->get('/postings', ['limit' => self::LIMIT]);
            $postings = $result['data'];
            while ($result['hasNext']) {
                $result = $leverClient->get('/postings', ['limit' => self::LIMIT, 'offset' => $result['next']]);
                $postings = array_merge($postings, $result['data']);
            }

            $this->line('Found vacancies: ' . count($postings));
            foreach ($postings as $posting) {
                VacancyRepository::sync($this->mapVacancy($posting));
            }

            CategoryRepository::updateVacanciesCount();
            LocationRepository::updateVacanciesCount();
        } catch (Exception $exception) {
            $this->error($exception->getMessage());

            return CommandAlias::FAILURE;
        }

        return CommandAlias::SUCCESS;
    }

}