35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Whmcs;
|
|
|
|
use App\Integrations\Whmcs\Support\CustomerIdResolver;
|
|
use App\Integrations\Whmcs\Support\SyncReport;
|
|
use App\Integrations\Whmcs\Writers\LeadWriter;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SyncContactsCommand extends Command
|
|
{
|
|
protected $signature = 'whmcs:sync-contacts';
|
|
|
|
protected $description = 'Import WHMCS contacts (tblcontacts) into the Lead module, merging duplicate emails';
|
|
|
|
public function handle(CustomerIdResolver $customers, LeadWriter $writer): int
|
|
{
|
|
$contacts = DB::connection('whmcs')->table('tblcontacts')->orderBy('id');
|
|
$bar = $this->output->createProgressBar($contacts->count());
|
|
|
|
foreach ($contacts->cursor() as $contact) {
|
|
$writer->write($contact, $customers->resolve((int) $contact->userid));
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
$this->newLine();
|
|
$this->info('Đã nhập liên hệ vào khách tiềm năng (leads).');
|
|
app(SyncReport::class)->finish($this);
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|