48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Libraries\Radar\RadarSyncService;
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
|
|
/**
|
|
* MSOP-4 — php spark radar:sync
|
|
*/
|
|
class RadarSync extends BaseCommand
|
|
{
|
|
protected $group = 'Radar';
|
|
protected $name = 'radar:sync';
|
|
protected $description = 'Lit les mailboxes allowlist Gmail et remplit radar_threads (v0).';
|
|
|
|
public function run(array $params)
|
|
{
|
|
CLI::write('Radar sync MSOP-4…', 'yellow');
|
|
$result = (new RadarSyncService())->sync();
|
|
|
|
if (! empty($result['error']) && empty($result['mailboxes'])) {
|
|
CLI::error($result['error']);
|
|
|
|
return;
|
|
}
|
|
|
|
foreach ($result['mailboxes'] as $row) {
|
|
if (! empty($row['ok'])) {
|
|
CLI::write(sprintf(
|
|
'OK %s — fetched=%d insert=%d update=%d',
|
|
$row['mailbox'],
|
|
$row['fetched'] ?? 0,
|
|
$row['inserted'] ?? 0,
|
|
$row['updated'] ?? 0
|
|
), 'green');
|
|
} else {
|
|
CLI::error(($row['mailbox'] ?? '?') . ' — ' . ($row['error'] ?? 'erreur'));
|
|
}
|
|
}
|
|
|
|
if (! $result['ok']) {
|
|
CLI::write('Astuce DWD : ajouter le scope gmail.readonly pour le SA dans Google Admin.', 'yellow');
|
|
}
|
|
}
|
|
}
|