update code for clone#175
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds support for properly cloning objects by resetting the primary key and marking the new object as new, and updates all call sites to the clone helper to pass the field id explicitly. Sequence diagram for updated clone flow with primary key resetsequenceDiagram
participant AdminPages
participant CreateXoopsCode as CreateXoopsCode
participant CreatePhpCode as CreatePhpCode
participant CreateFile as CreateFile
AdminPages->>CreateXoopsCode: getXcCommonPagesClone(tableName, fieldId, ccFieldId, t, language)
CreateXoopsCode->>CreatePhpCode: getPhpCodeCommentLine
CreateXoopsCode->>CreateXoopsCode: getXcHandlerGet
CreateXoopsCode->>CreateXoopsCode: getXcEqualsOperator
CreateXoopsCode->>CreateFile: getSimpleString($tableNameObj->setNew();)
CreateXoopsCode->>CreateXoopsCode: getXcSetVarObj(tableName, fieldId, 0)
CreateXoopsCode->>CreateXoopsCode: getXcGetForm
CreateXoopsCode->>CreateXoopsCode: getXcXoopsTplAssign
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR updates clone-page code generation to handle field initialization. The ChangesClone Page Generation Updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the getXcCommonPagesClone method to accept a new $fieldId parameter, updating its usages in UserPages.php and AdminPages.php. Feedback suggests optimizing the code by using direct string interpolation instead of instantiating the CreateFile class, and using the indentation parameter $t instead of hardcoded tabs to ensure consistent formatting.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| $cf = Modulebuilder\Files\CreateFile::getInstance(); | ||
|
|
||
| $ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t"); | ||
| $ret .= $xc->getXcHandlerGet($tableName, $ccFieldId . 'Source', 'ObjSource', $tableName . 'Handler', false, $t); | ||
| $tablenameObj = $pc->getPhpCodeIsobject($tableName . 'ObjSource'); | ||
| $redirectError = $xc->getXcRedirectHeader($tableName, '', '3', "{$language}INVALID_PARAM", true, $t . "\t"); | ||
| $ret .= $pc->getPhpCodeConditions('!' . $tablenameObj, '', '', $redirectError, false, $t); | ||
| $ret .= $xc->getXcEqualsOperator('$' . $tableName . 'Obj', '$' . $tableName . 'ObjSource->xoopsClone()', null, $t); | ||
| $ret .= $cf->getSimpleString('$' . $tableName . 'Obj->setNew();', "\t\t"); | ||
| $ret .= $this->getXcSetVarObj($tableName, $fieldId, 0, "\t\t"); |
There was a problem hiding this comment.
Instantiating the heavy CreateFile class just to call getSimpleString() (which simply appends a newline) is highly inefficient. Instead, we can use direct string interpolation. Additionally, the indentation parameter $t should be used instead of hardcoding "\t\t" to ensure consistent code generation.
$ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t");
$ret .= $xc->getXcHandlerGet($tableName, $ccFieldId . 'Source', 'ObjSource', $tableName . 'Handler', false, $t);
$tablenameObj = $pc->getPhpCodeIsobject($tableName . 'ObjSource');
$redirectError = $xc->getXcRedirectHeader($tableName, '', '3', "{$language}INVALID_PARAM", true, $t . "\t");
$ret .= $pc->getPhpCodeConditions('!' . $tablenameObj, '', '', $redirectError, false, $t);
$ret .= $xc->getXcEqualsOperator('$' . $tableName . 'Obj', '$' . $tableName . 'ObjSource->xoopsClone()', null, $t);
$ret .= "{$t}\${$tableName}Obj->setNew();\n";
$ret .= $this->getXcSetVarObj($tableName, $fieldId, 0, $t);
Summary by Sourcery
Update clone page generation to correctly reset identifiers when cloning objects.
Bug Fixes:
Enhancements:
Summary by CodeRabbit