Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)
Line range hint
1-1000: Consider breaking down the class and implementing dependency injection.The
CollectionCampServiceclass violates several SOLID principles:
- Single Responsibility Principle: The class handles logging, email sending, status management, and more
- Dependency Inversion Principle: Uses static methods and global state instead of dependency injection
Consider breaking this into smaller, focused services:
CollectionCampLoggerService: Handle all loggingCollectionCampEmailService: Handle email notificationsCollectionCampStatusManager: Manage camp status transitionsCollectionCampGroupManager: Handle group assignmentsUse dependency injection instead of static methods:
class CollectionCampService { private $logger; private $emailService; private $statusManager; public function __construct( CollectionCampLoggerService $logger, CollectionCampEmailService $emailService, CollectionCampStatusManager $statusManager ) { $this->logger = $logger; $this->emailService = $emailService; $this->statusManager = $statusManager; } }
| error_log("op11: " . print_r($op, TRUE)); | ||
| error_log("objectName11: " . print_r($objectName, TRUE)); | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Replace error_log with proper logging mechanism.
The current implementation has several issues:
- Using
error_logfor debugging is not recommended in production - Using
print_rcan expose sensitive data in logs - Hardcoded numbers in log messages (11, 222) seem arbitrary
Consider using CiviCRM's logging mechanism:
- error_log("op11: " . print_r($op, TRUE));
- error_log("objectName11: " . print_r($objectName, TRUE));
- error_log("self: " . print_r(self::$individualId, TRUE));
- error_log("objectId222: " . print_r($objectId, TRUE));
+ \Civi::log()->debug('Individual creation event', [
+ 'op' => $op,
+ 'objectName' => $objectName,
+ 'individualId' => self::$individualId,
+ 'objectId' => $objectId
+ ]);Also applies to: 246-248
| error_log("op: " . print_r($op, TRUE)); | ||
| error_log("objectName: " . print_r($objectName, TRUE)); | ||
|
|
||
| if ($op !== 'create' || $objectName !== 'Contribution') { | ||
| return FALSE; | ||
| } | ||
|
|
||
| if (self::$individualId !== $objectRef->contact_id || !$objectRef->is_primary) { | ||
| error_log("op: " . print_r($op, TRUE)); | ||
| error_log("objectName: " . print_r($objectName, TRUE)); | ||
| error_log("individualId: " . print_r(self::$individualId, TRUE)); | ||
| error_log("objectRef: " . print_r($objectRef->is_primary, TRUE)); | ||
| error_log("contact_id: " . print_r($objectRef->contact_id, TRUE)); | ||
| // error_log("objectReftarun: " . print_r($objectRef, TRUE)); | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Replace error_log statements with structured logging.
Similar to the previous method, replace debug logging with CiviCRM's logging mechanism.
- error_log("op: " . print_r($op, TRUE));
- error_log("objectName: " . print_r($objectName, TRUE));
- error_log("individualId: " . print_r(self::$individualId, TRUE));
- error_log("objectRef: " . print_r($objectRef->is_primary, TRUE));
- error_log("contact_id: " . print_r($objectRef->contact_id, TRUE));
+ \Civi::log()->debug('Chapter group assignment event', [
+ 'op' => $op,
+ 'objectName' => $objectName,
+ 'individualId' => self::$individualId,
+ 'isPrimary' => $objectRef->is_primary,
+ 'contactId' => $objectRef->contact_id
+ ]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| error_log("op: " . print_r($op, TRUE)); | |
| error_log("objectName: " . print_r($objectName, TRUE)); | |
| if ($op !== 'create' || $objectName !== 'Contribution') { | |
| return FALSE; | |
| } | |
| if (self::$individualId !== $objectRef->contact_id || !$objectRef->is_primary) { | |
| error_log("op: " . print_r($op, TRUE)); | |
| error_log("objectName: " . print_r($objectName, TRUE)); | |
| error_log("individualId: " . print_r(self::$individualId, TRUE)); | |
| error_log("objectRef: " . print_r($objectRef->is_primary, TRUE)); | |
| error_log("contact_id: " . print_r($objectRef->contact_id, TRUE)); | |
| // error_log("objectReftarun: " . print_r($objectRef, TRUE)); | |
| \Civi::log()->debug('Chapter group assignment event', [ | |
| 'op' => $op, | |
| 'objectName' => $objectName, | |
| 'individualId' => self::$individualId, | |
| 'isPrimary' => $objectRef->is_primary, | |
| 'contactId' => $objectRef->contact_id | |
| ]); | |
| if ($op !== 'create' || $objectName !== 'Contribution') { | |
| return FALSE; | |
| } | |
| // error_log("objectReftarun: " . print_r($objectRef, TRUE)); |
| $addresses = \Civi\Api4\Address::get(TRUE) | ||
| ->addSelect('state_province_id') | ||
| ->addWhere('contact_id', '=', 15837) | ||
| ->execute()->first(); | ||
|
|
||
| $stateIdNew = $addresses['state_province_id']; | ||
| error_log("stateIdNew: " . print_r($stateIdNew, TRUE)); // Getting state id from here... |
There was a problem hiding this comment.
Remove hardcoded contact ID and extract address lookup logic.
The method contains a hardcoded contact ID (15837) and mixes address lookup with group assignment logic.
- Remove the hardcoded contact ID
- Extract the address lookup into a separate method:
+ private static function getContactAddress($contactId) {
+ return \Civi\Api4\Address::get(TRUE)
+ ->addSelect('state_province_id')
+ ->addWhere('contact_id', '=', $contactId)
+ ->execute()->first();
+ }
- $addresses = \Civi\Api4\Address::get(TRUE)
- ->addSelect('state_province_id')
- ->addWhere('contact_id', '=', 15837)
- ->execute()->first();
+ $addresses = self::getContactAddress($contactId);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $addresses = \Civi\Api4\Address::get(TRUE) | |
| ->addSelect('state_province_id') | |
| ->addWhere('contact_id', '=', 15837) | |
| ->execute()->first(); | |
| $stateIdNew = $addresses['state_province_id']; | |
| error_log("stateIdNew: " . print_r($stateIdNew, TRUE)); // Getting state id from here... | |
| private static function getContactAddress($contactId) { | |
| return \Civi\Api4\Address::get(TRUE) | |
| ->addSelect('state_province_id') | |
| ->addWhere('contact_id', '=', $contactId) | |
| ->execute()->first(); | |
| } | |
| $addresses = self::getContactAddress($contactId); | |
| $stateIdNew = $addresses['state_province_id']; | |
| error_log("stateIdNew: " . print_r($stateIdNew, TRUE)); // Getting state id from here... |
|
Closing this PR as we don't need this now |
Move individual to groups
Summary by CodeRabbit
New Features
Bug Fixes