XF 2.2 Updating a value in a db table

Anatoliy

Well-known member
I added a custom column av-aw-processed into xf-user table. I want to be able to 'mark' users by updating the field (overwrite with the current timestamp).

Is there some built in xF way to do it, like fetching with a finder? Or I should run a usual SQL query like

PHP:
public function actionProcessed(ParameterBag $params)
    {
        $userId = $params->user_id;
        $time = time();

        $db = $this->app->db();
        $db->query("
        UPDATE xf_user SET av-aw-processed=$time WHERE id=$userId
        ")->execute();
    }

Thanks in advance.
 
Yeh, $db->query() works, finder should work too, although it seems pointless to grab a record from the database just to update it.


PHP:
$user = \XF::finder('XF:User')->where('user_id', $userId)->fetchOne();
if($user)
{
    $user->av-aw-processed = $time; // untested, I think you might have an issue with the presence of "-" in the column name
    $user->save();
}
 
Last edited:
Yeh, $db->query() works, finder should work too, although it seems pointless to grab a record from the database just to update it.
no, not fetching one to update. sorry for my english. )
I mean maybe there is something like 'updater' (like finder) in xenForo. something like
PHP:
$user = \XF::updater('XF:User')
  ->where('user_id', $userId)
  ->update('av-aw-processed', $someData);
$user->save();
)))
 
Last edited:
Top Bottom