-
Notifications
You must be signed in to change notification settings - Fork 1
Collection camp code bug #1594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tarunnjoshi
wants to merge
1
commit into
dev
Choose a base branch
from
collection-camp-code-bug
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Collection camp code bug #1594
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,21 +97,21 @@ public static function generateCollectionSourceCode(string $op, string $objectNa | |
| if (!$statusDetails) { | ||
| return; | ||
| } | ||
| error_log('Institution CC code generation working'); | ||
| \Civi::log()->debug('generateCollectionSourceCode code is running'); | ||
|
|
||
| $newStatus = $statusDetails['newStatus']; | ||
| $currentStatus = $statusDetails['currentStatus']; | ||
|
|
||
| if ($currentStatus !== $newStatus) { | ||
| if ($newStatus === 'authorized') { | ||
| $subtypeId = $objectRef['subtype'] ?? NULL; | ||
| error_log('subtype:' . print_r($subtypeId, TRUE)); | ||
| \Civi::log()->debug('[CodeGen] subtypeId', ['subtypeId' => $subtypeId]); | ||
| if (!$subtypeId) { | ||
| return; | ||
| } | ||
|
|
||
| $sourceId = $objectRef['id'] ?? NULL; | ||
| error_log('sourceId:' . print_r($sourceId, TRUE)); | ||
| \Civi::log()->debug('[CodeGen] sourceId', ['sourceId' => $sourceId]); | ||
| if (!$sourceId) { | ||
| return; | ||
| } | ||
|
|
@@ -121,52 +121,47 @@ public static function generateCollectionSourceCode(string $op, string $objectNa | |
| ->execute()->single(); | ||
|
|
||
| $collectionSourceCreatedDate = $collectionSource['created_date'] ?? NULL; | ||
| error_log('collectionSourceCreatedDate:' . print_r($collectionSourceCreatedDate, TRUE)); | ||
| \Civi::log()->debug('[CodeGen] createdDate', ['createdDate' => $collectionSourceCreatedDate]); | ||
|
|
||
| $sourceTitle = $collectionSource['title'] ?? NULL; | ||
|
|
||
| $year = date('Y', strtotime($collectionSourceCreatedDate)); | ||
|
|
||
| $stateId = self::getStateIdForSourceType($objectRef, $subtypeId, $sourceTitle); | ||
| error_log('stateId:' . print_r($stateId, TRUE)); | ||
| \Civi::log()->debug('[CodeGen] stateId', ['stateId' => $stateId]); | ||
|
|
||
| if (!$stateId) { | ||
| \Civi::log()->debug('[CodeGen] Aborting: stateId missing', ['sourceId' => $sourceId]); | ||
| return; | ||
| } | ||
|
|
||
| $stateProvince = StateProvince::get(FALSE) | ||
| ->addWhere('id', '=', $stateId) | ||
| ->execute()->single(); | ||
| error_log('stateProvince:' . print_r($stateProvince, TRUE)); | ||
|
|
||
| if (empty($stateProvince)) { | ||
| \Civi::log()->debug('[CodeGen] Aborting: stateProvince not found', ['stateId' => $stateId]); | ||
| return; | ||
| } | ||
|
|
||
| $stateAbbreviation = $stateProvince['abbreviation'] ?? NULL; | ||
| if (!$stateAbbreviation) { | ||
| \Civi::log()->debug('[CodeGen] Aborting: stateAbbreviation missing', ['stateId' => $stateId]); | ||
| return; | ||
| } | ||
|
|
||
| // Fetch the Goonj-specific state code. | ||
| $config = self::getConfig(); | ||
| $stateCode = $config['state_codes'][$stateAbbreviation] ?? 'UNKNOWN'; | ||
| // Get the current event title. | ||
| $currentTitle = $sourceTitle ?? 'Collection Camp'; | ||
| $sourceTypeName = self::getSourceTypeName($subtypeId); | ||
| $sourceTypeTitle = str_replace('_', ' ', $sourceTypeName); | ||
| $eventCode = $config['event_codes'][$sourceTypeTitle] ?? 'UNKNOWN'; | ||
| \Civi::log()->debug('[CodeGen] eventCode', ['sourceTypeName' => $sourceTypeName, 'sourceTypeTitle' => $sourceTypeTitle, 'eventCode' => $eventCode]); | ||
|
|
||
| // Fetch the event code. | ||
| $eventCode = $config['event_codes'][$currentTitle] ?? 'UNKNOWN'; | ||
|
|
||
| // Modify the title to include the year, state code, event code, and camp Id. | ||
| $newTitle = $year . '/' . $stateCode . '/' . $eventCode . '/' . $sourceId; | ||
| error_log('newTitle:' . print_r($newTitle, TRUE)); | ||
| \Civi::log()->info('[CodeGen] newTitle', ['newTitle' => $newTitle]); | ||
| $objectRef['title'] = $newTitle; | ||
|
|
||
| // Save the updated title back to the Collection Camp entity. | ||
| EckEntity::update('Collection_Camp') | ||
| ->addWhere('id', '=', $sourceId) | ||
| ->addValue('title', $newTitle) | ||
| ->execute(); | ||
| \Civi::log()->info('[CodeGen] Camp code generated', ['sourceId' => $sourceId, 'newTitle' => $newTitle]); | ||
|
Comment on lines
160
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generated title is not persisted in an after-write hook. Line 162 only mutates Suggested persistence fix $newTitle = $year . '/' . $stateCode . '/' . $eventCode . '/' . $sourceId;
\Civi::log()->info('[CodeGen] newTitle', ['newTitle' => $newTitle]);
$objectRef['title'] = $newTitle;
+ if (($sourceTitle ?? NULL) !== $newTitle) {
+ EckEntity::update('Collection_Camp', FALSE)
+ ->addValue('title', $newTitle)
+ ->addWhere('id', '=', $sourceId)
+ ->execute();
+ }
\Civi::log()->info('[CodeGen] Camp code generated', ['sourceId' => $sourceId, 'newTitle' => $newTitle]);🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid silently generating event codes with
UNKNOWN.If subtype-to-event mapping fails, the code still proceeds and produces a title with
UNKNOWN, which can corrupt identifier semantics downstream. Abort generation when mapping is missing.Suggested hardening
🤖 Prompt for AI Agents