Skip to content

Move individual to groups#448

Closed
tarunnjoshi wants to merge 1 commit intodevelopfrom
move-individual-to-groups
Closed

Move individual to groups#448
tarunnjoshi wants to merge 1 commit intodevelopfrom
move-individual-to-groups

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Nov 13, 2024

Move individual to groups

Summary by CodeRabbit

  • New Features

    • Enhanced logging for individual creation and group assignment operations, improving traceability and debugging.
    • Updated conditions in the group assignment process to reflect a shift in focus from 'Address' to 'Contribution'.
  • Bug Fixes

    • Refined checks for camp status updates to ensure correct statuses are applied based on new conditions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request introduces modifications to the CollectionCampService class, enhancing the logging of operations within several methods. Key updates include the addition of logging statements in the individualCreated and assignChapterGroupToIndividual methods, which now capture various parameters and internal states. The conditions for operation types have been refined, particularly changing from 'Address' to 'Contribution'. The methods related to camp status updates have also been adjusted to ensure correct status modifications based on new conditions, while the overall logic remains unchanged.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php - Updated individualCreated and assignChapterGroupToIndividual methods to add logging and refine conditions.
- Adjusted conditions in updateCampStatusAfterAuth and updateCampStatusOnOutcomeFilled methods for correct status updates.

Possibly related PRs

  • Collection Camp Authorisation Status #362: Updates to the updateCampStatusAfterAuth and updateCampStatusOnOutcomeFilled methods, enhancing logging and control flow related to camp status updates.
  • Fix the status feedbacks #388: Modifications to the updateCampStatusOnOutcomeFilled and updateCampStatusAfterAuth methods, closely aligning with the changes in the main PR regarding camp status management.
  • Update Email Content #411: Updates to the updateCampStatusAfterAuth method, ensuring correct camp status updates based on specific operations and conditions.

Suggested labels

status : ready for review

Suggested reviewers

  • nishant22029
  • belwalshubham

🎉 In the code where events unfold,
Logging tales of actions bold.
From 'Address' to 'Contribution' we steer,
With clearer paths and states so clear.
Camp statuses now dance in line,
Thanks to changes, all will be fine! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CollectionCampService class violates several SOLID principles:

  1. Single Responsibility Principle: The class handles logging, email sending, status management, and more
  2. Dependency Inversion Principle: Uses static methods and global state instead of dependency injection

Consider breaking this into smaller, focused services:

  1. CollectionCampLoggerService: Handle all logging
  2. CollectionCampEmailService: Handle email notifications
  3. CollectionCampStatusManager: Manage camp status transitions
  4. CollectionCampGroupManager: Handle group assignments

Use 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;
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c3f4623 and 5235f83.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1 hunks)

Comment on lines +239 to +241
error_log("op11: " . print_r($op, TRUE));
error_log("objectName11: " . print_r($objectName, TRUE));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace error_log with proper logging mechanism.

The current implementation has several issues:

  1. Using error_log for debugging is not recommended in production
  2. Using print_r can expose sensitive data in logs
  3. 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

Comment on lines +257 to +270
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Suggested change
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));

Comment on lines +280 to +286
$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...
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

  1. Remove the hardcoded contact ID
  2. 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.

Suggested change
$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...

@tarunnjoshi
Copy link
Copy Markdown
Member Author

Closing this PR as we don't need this now

@tarunnjoshi tarunnjoshi closed this Apr 1, 2025
@pokhiii pokhiii deleted the move-individual-to-groups branch April 19, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant