freescout2ant/Jobs/ArchiveThreadsJob.php
Claude 037d93a014
Refactor: Eliminate duplicate business logic between Controller and Service
Move all business logic from AmeiseController into CrmService:
- getCrmUsers/getFSUsers: remove duplicates from controller, keep in CrmService (now return data arrays instead of HTTP responses)
- Contract transformation: extract to CrmService::getContractsWithDetails()
- Archive orchestration: extract to CrmService::archiveConversationFromRequest()
- DB queries: extract to CrmService::getArchivedContracts()
- ArchiveThreadsJob: use CrmService instead of direct sub-service instantiation

Controller now only handles HTTP request/response, delegating all logic to CrmService.

https://claude.ai/code/session_01Lbqz1JQAYAwFk6EamodxHU
2026-03-22 22:37:36 +00:00

42 lines
1.2 KiB
PHP

<?php
namespace Modules\AmeiseModule\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ArchiveThreadsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $thread;
protected $conversation;
protected $user;
public $timeout = 120;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($conversation, $thread, $user)
{
$this->conversation = $conversation;
$this->thread = $thread;
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
config('ameisemodule.ameise_log_status') && \Helper::log('Ameise Cron Log', 'Job Dispatched For Thread ID: '.$this->thread->id.' Conversation ID: '.$this->conversation->id.' User ID: '.$this->user->id.'');
$crmService = new \Modules\AmeiseModule\Services\CrmService('', $this->user->id);
$crmService->archiveConversationData($this->conversation, $this->thread, $this->user);
}
}