Lack of interest Return expired upgrade from UserUpgrade repo expireActiveUpgrade

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

Sim

Well-known member
In \XF\Repository\UserUpgrade::expireActiveUpgrade it would be super useful if the expired upgrade which was created/saved was returned by the function so that we can do something with it in our class extensions.

Basically, just add return $expired; to the end of the function.
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Changing the expected return value of a method can be a bit dicey because existing code extending that method probably aren't returning anything from their extensions. Ultimately it can lead to somewhere down the chain, the return value being totally lost. So, at best, it'll be a 2.1 thing but even then it will still break stuff but it's at the least slightly more acceptable in a second point release.

There's a workaround however, which I think should work:
PHP:
public function expireActiveUpgrade(\XF\Entity\UserUpgradeActive $active, \XF\Entity\UserUpgradeExpired $expired = null)
{
    if ($expired === null)
    {
        $expired = $this->em->create('XF:UserUpgradeExpired');
    }

    parent::actionExpireActiveUpgrade($active, $expired);

    // you can now do stuff with $expired
}
It's a slightly unusual pattern seeing as we usually do parent calls at the start or end of an extended method, but this should be valid. The method either receives an existing expired entity, in which case you can freely use that, or null. If it's null you can feed it your own expired entity, and work with that after the parent call has done its thing.
 
Thanks @Chris D - I was concerned that the passed in UserUpgradeExpired was supposed to have meaning at this point, but having traced through the code I see that it's either a newly created entity or null, so your code should work for me.
 
Back
Top Bottom