Skip to content
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

XoopsBlock::store() should return int, but it calls XoopsBlockHandler::insert() which returns bool #1105

Closed
mambax7 opened this issue Oct 2, 2021 · 4 comments · Fixed by #1183
Labels
Milestone

Comments

@mambax7
Copy link
Collaborator

mambax7 commented Oct 2, 2021

Originally store() returned int, but now, since it calls XoopsBlockHandler::insert(), it returns bool:

    /**
     * Store Block Data to Database
     *
     * @return int $id
     *
     * @deprecated
     */
    public function store()
    {
        /** @var XoopsBlockHandler $blkhandler */
        $blkhandler = xoops_getHandler('block');
        return $blkhandler->insert($this);
    }

This breaks cases like this one:

        $block = new \XoopsBlock($bid);
        $clone = $block->xoopsClone();
        //...
        $newid = $clone->store();

Should I change all these cases to something like:

        $block = new \XoopsBlock($bid);
        $clone = $block->xoopsClone();
        //...
        if ($clone->store()) {
           $newid = $clone->id();  //get the id of the cloned block
        }
@zyspec
Copy link
Contributor

zyspec commented Oct 2, 2021

We'll have to let @geekwright weigh in but in my opinion store() should be fixed to return an int. This was changed between 2.5.10 (current release) and 2.5.11 (not released yet). The store() method is deprecated in 2.5.11 (I assume you should use insert() instead) but it shouldn't break backward compatibility. The values returned by XoopsHandler::insert() and XoopsPersistableHandler::insert() methods has been inconsistent between the two for quite a while.

Having said that - the 2.5.10 version of the store() method could have returned false. So in the case where there was an error, the assignment of $newid above would have been broken anyway. So, in effect, the change brought a latent bug to light...

@mambax7
Copy link
Collaborator Author

mambax7 commented Oct 5, 2021

@zyspec, you're right that the store() method could have returned false

I found this code that deals with that in an old module Blocksadmin:

    $newid = $cblock->store();
    if (!$newid) {
        xoops_cp_header();
        $cblock->getHtmlErrors();
        xoops_cp_footer();
        exit();
    }

mambax7 added a commit to mambax7/xoopsheadline that referenced this issue Nov 26, 2021
@zyspec
Copy link
Contributor

zyspec commented Dec 8, 2021

It looks like the 'fix' in 2.5.11 XoopsBlock should be something like this:

    public function store()
    {
        /** @var XoopsBlockHandler $blkhandler */
        $blkhandler = xoops_getHandler('block');
        $bid = false;
        if (true === $blkhandler->insert($this)) {
            $bid = $this->getVar('bid');
        }
        return $bid;
    }

@mambax7
Copy link
Collaborator Author

mambax7 commented Dec 8, 2021

I think, that should work!

@zyspec zyspec added this to the 2.5.11 milestone Dec 16, 2021
@zyspec zyspec added the bug label Dec 16, 2021
geekwright added a commit to geekwright/XoopsCore25 that referenced this issue Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants