XF 2.1 How to move an entity to another table

Matt C.

Well-known member
So in matchmaking add-on, I want to move matches that are older than 1 day to the archived match entity. I want to set up a cron job that runs once a day that searched for each match that is older than 24 hours, and then moves it to the archived match entity.

This is what I have right now:
Code:
public function moveOldMatches()
{
    /** @var \AH\Matchmaking\Finder\Match $matchFinder */
    $matchFinder = $this->finder('AH\Matchmaking:Match');
    $matches = $matchFinder
                ->where('match_date', '>=', time() - 86400)->fetch();

    foreach($matches as $match)
    {

    }
}

The part I'm confused about is how to actually move the entity to another entity, if that makes sense. Thank you.
 
Why do they need to be in a separate table rather than just a boolean that marks it as being archived? You can't really "move" things between tables, so you'd need to get all of the values and reinsert them into the new table and delete from current table. You would also need to duplicate the columns exactly in the two tables. Probably easier and cleaner to just have either a state with the value of archived or an archived boolean column
 
You're right Jake.

I'm using this code to display all matches in the default list that aren't archived.

Code:
$matchFinder
    ->useDefaultOrder()
    ->where('archived', '=', 'true');

Funny thing, using true gets all the ones that aren't archived, and using false gets the ones that are.
 
As for the code to archive matches, this should work right?

Code:
public function archiveOldMatches()
{
    /** @var \AH\Matchmaking\Finder\Match $matchFinder */
    $matchFinder = $this->finder('AH\Matchmaking:Match');
    $matches = $matchFinder
                ->where('match_date', '>=', time() - 86400)->fetch();

    foreach($matches as $match)
    {
        $match->archived = true;
    }
}
 
My code isn't working for me.

PHP:
public function archiveOldMatches()
{
    /** @var \AH\Matchmaking\Finder\Match $matchFinder */
    $matchFinder = $this->finder('AH\Matchmaking:Match');
    $matches = $matchFinder
                ->where('match_date', '>=', time() + 86400)->fetch();

    foreach($matches as $match)
    {
        $match->archived = true;
        $match->save();
    }
}

Maybe @DragonByte Tech can help? Thank you.
 
Back
Top Bottom