Fixes and tidies

This commit is contained in:
Rich Lott / Artful Robot 2025-02-27 18:10:48 +00:00
parent e56be4ce31
commit 69d4c6b2e8
11 changed files with 191 additions and 40 deletions

View file

@ -125,7 +125,7 @@ class Processor {
$oldCategoryId = (int) ($lastChange[0] ?? 0);
$newCategoryId = (int) ($lastChange[1] ?? 0);
$oldName = $this->categories[$oldCategoryId]['label'] ?? E::ts('(Unknown)');
$subject = "$oldName" . $this->categories[$newCategoryId];
$subject = "$oldName" . $this->categories[$newCategoryId]['label'];
// Create activity on the first contact
$a = Activity::create(FALSE)
->addValue('target_contact_id', $batch[0])
@ -139,18 +139,18 @@ class Processor {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_activity_contact (contact_id, activity_id, record_type_id)
SELECT id contact_id, $activityID activity_id, 3 record_type_id
FROM civicrm_contact_category cc
WHERE cc.category = $oldCategoryId
WHERE cc.category_definition_id = $oldCategoryId
AND cc.next_category = $newCategoryId
AND contact_id <> $batch[0]
AND cc.id <> $batch[0]
")->free();
Civi::log()->debug(count($batch) . " changes: $subject");
};
while ($changes->fetch()) {
$n++;
if ($lastChange[0] !== $changes->category || $lastChange[1] !== $changes->next_category) {
if ($lastChange[0] !== $changes->category_definition_id || $lastChange[1] !== $changes->next_category) {
$writeBatch();
$lastChange = [$changes->category, $changes->next_category];
$lastChange = [$changes->category_definition_id, $changes->next_category];
$batch = [];
}
$batch[] = $changes->id;
@ -195,7 +195,7 @@ class Processor {
// Q: is it quicker to do a WHERE NOT EXISTS? A: nope.
CRM_Core_DAO::executeQuery(<<<SQL
INSERT INTO civicrm_contact_category
SELECT id, id contact_id, NULL as category_definition_id, 0 next_category
SELECT id, NULL as category_definition_id, 0 next_category
FROM civicrm_contact
WHERE NOT EXISTS (SELECT id FROM civicrm_contact_category WHERE id = civicrm_contact.id)
SQL)->free();