JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr{ gilour

File "ExportLinkGroupsCsv.php"

Full Path: /home/markqprx/iniasli.pro/app-20260222054640/Jobs/ExportLinkGroupsCsv.php
File size: 1.71 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Jobs;

use App\Models\LinkGroup;
use App\Models\User;
use Common\Csv\BaseCsvExportJob;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;

class ExportLinkGroupsCsv extends BaseCsvExportJob
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(
        protected int $requesterId,
        protected ?User $forUser = null,
    ) {
    }

    public function cacheName(): string
    {
        $cacheName = 'link-groups';
        if ($this->forUser) {
            $cacheName .= ".{$this->forUser->id}";
        }
        return $cacheName;
    }

    protected function notificationName(): string
    {
        return 'link-groups';
    }

    protected function generateLines()
    {
        $selectCols = [
            'id',
            'name',
            'hash',
            'active',
            'rotator',
            'description',
            'created_at',
            'updated_at',
        ];

        $builder = $this->forUser
            ? $this->forUser->linkGroups()
            : app(LinkGroup::class);

        $builder
            ->select($selectCols)
            ->with('domain')
            ->chunkById(100, function (Collection $chunk) {
                $chunk->each(function (LinkGroup $link) {
                    $data = $link->toArray();
                    unset(
                        $data['short_url'],
                        $data['has_password'],
                        $data['model_type'],
                    );
                    $this->writeLineToCsv($data);
                });
            });
    }
}