Skip to content

update code for clone#175

Open
ggoffy wants to merge 1 commit into
XoopsModules25x:masterfrom
ggoffy:master
Open

update code for clone#175
ggoffy wants to merge 1 commit into
XoopsModules25x:masterfrom
ggoffy:master

Conversation

@ggoffy
Copy link
Copy Markdown
Collaborator

@ggoffy ggoffy commented Jun 5, 2026

Summary by Sourcery

Update clone page generation to correctly reset identifiers when cloning objects.

Bug Fixes:

  • Ensure cloned objects are marked as new and have their identifier fields reset during clone page generation.

Enhancements:

  • Extend common clone page helper to accept both primary field ID and clone-control field ID and propagate this to user and admin pages.

Summary by CodeRabbit

  • Refactor
    • Improved clone operation handling to ensure proper object initialization and field management across user and admin sections.
    • Enhanced consistency in how cloned objects are created and configured throughout the application.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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 reset

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Extend common clone page generator to accept the field id and reset primary key on cloned objects.
  • Add $fieldId parameter to getXcCommonPagesClone and thread it through the implementation.
  • Instantiate CreateFile helper within getXcCommonPagesClone.
  • After xoopsClone(), explicitly mark the cloned object as new with setNew().
  • Reset the id field on the cloned object using getXcSetVarObj so the primary key is cleared for inserts.
class/Files/CreateXoopsCode.php
Update user and admin clone page generators to pass the new field id argument into the common clone helper.
  • Adjust getUserPagesClone to call getXcCommonPagesClone with $fieldId before $ccFieldId.
  • Adjust getAdminPagesClone to call getXcCommonPagesClone with $fieldId before $ccFieldId.
class/Files/User/UserPages.php
class/Files/admin/AdminPages.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22ca9c83-962b-446a-91d3-287b078b3135

📥 Commits

Reviewing files that changed from the base of the PR and between b172eca and f46c753.

📒 Files selected for processing (3)
  • class/Files/CreateXoopsCode.php
  • class/Files/User/UserPages.php
  • class/Files/admin/AdminPages.php

📝 Walkthrough

Walkthrough

The PR updates clone-page code generation to handle field initialization. The getXcCommonPagesClone() method in CreateXoopsCode.php accepts a new $fieldId parameter and generates extended clone logic including object initialization and field assignment. Both UserPages and AdminPages are updated to pass this parameter when invoking the method.

Changes

Clone Page Generation Updates

Layer / File(s) Summary
Clone page method signature and code generation extension
class/Files/CreateXoopsCode.php, class/Files/User/UserPages.php, class/Files/admin/AdminPages.php
getXcCommonPagesClone() accepts a new $fieldId parameter and generates additional clone-handling code including CreateFile initialization, setNew() call, and field assignment via getXcSetVarObj(). Both UserPages and AdminPages are updated to provide this parameter in their calls.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A clone is born anew, with field in place,
The code flows swift through generation's embrace,
Three files in sync, one parameter shared,
A rabbit's delight—the clone is prepared!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'update code for clone' is vague and generic, lacking specific details about what aspect of clone functionality was modified or why. Provide a more descriptive title that specifies the nature of the changes, such as 'Add fieldId parameter to clone code generation' or 'Update clone method signatures across UserPages and AdminPages'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +1813 to +1822
$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");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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