Support updating a single contact

This commit is contained in:
Rich Lott / Artful Robot 2025-02-28 21:55:04 +00:00
parent 8d0a9d0926
commit 016ca2a735
2 changed files with 37 additions and 9 deletions

View file

@ -13,6 +13,15 @@ use Civi\ContactCats\Processor;
*/
class Sync extends \Civi\Api4\Generic\AbstractAction {
/**
* Contact ID
*
* Force sync for given contact only.
*
* @var int
*/
protected $contact_id;
/**
* Usually this will not act unless the time is right.
*
@ -24,7 +33,8 @@ class Sync extends \Civi\Api4\Generic\AbstractAction {
public function _run(Result $result) {
ini_set('memory_limit', '256M');
Civi::log()->debug('Begin', ['=start' => 'ContactCatSync', '=timed' => 1]);
if (!$this->force) {
if (!$this->force && !$this->contact_id) {
$nextRun = Civi::settings()->get('contactcats_next_run') ?? 0;
if (time() < $nextRun) {
// not needed yet.
@ -33,7 +43,7 @@ class Sync extends \Civi\Api4\Generic\AbstractAction {
}
}
$processor = new Processor();
$processor = new Processor($this->contact_id);
$result->exchangeArray($processor->run());
// Limit to running every 24 hours; we actually want it to be stable within one day.