right, my fault. Just replaceThis code does not add people with followers but it add followers :
$entity->user_id with $entity->follow_user_id.right, my fault. Just replaceThis code does not add people with followers but it add followers :
$entity->user_id with $entity->follow_user_id.Ah now it's working with this code :right, my fault. Just replace$entity->user_idwith$entity->follow_user_id.
public static function increaseFollowersCount($entity)
{
\XF::db()->query('UPDATE xf_user SET sc_user_follow = sc_user_follow + 1 WHERE user_id = ?', $entity->follow_user_id);
}
public static function increaseFollowersCount($entity)
{
\XF::db()->query('UPDATE xf_user SET sc_user_follow = sc_user_follow - 1 WHERE user_id = ?', $entity->follow_user_id);
}
I figured why not try to do the same with the other code ! This one :right, my fault. Just replace$entity->user_idwith$entity->follow_user_id.
public static function decreaseFollowersCount($entity)
{
$finder = \XF::finder('XF:User')
->where('user_id', $entity->follow_user_id);
$user = $finder->fetchOne();
if ($user)
{
$user->fastUpdate('sc_user_follow', $finder->columnSqlName('sc_user_follow') . "- 1");
}
}
public static function increaseFollowersCount($entity)
{
$finder = \XF::finder('XF:User')
->where('user_id', $entity->follow_user_id);
$user = $finder->fetchOne();
if ($user)
{
$user->fastUpdate('sc_user_follow', $finder->columnSqlName('sc_user_follow') . "+ 1");
}
}
decreaseFollowersCount is working, not increaseFollowersCount. I'm not sure why To be secure you should exclude users who have sc_user_follow = 0:And for unfollow I use this one :
PHP:public static function increaseFollowersCount($entity) { \XF::db()->query('UPDATE xf_user SET sc_user_follow = sc_user_follow - 1 WHERE user_id = ?', $entity->follow_user_id); }
public static function decreaseFollowersCount($entity)
{
\XF::db()->query('UPDATE xf_user SET sc_user_follow = sc_user_follow - 1 WHERE user_id = ? AND sc_user_follow > 0', $entity->follow_user_id);
}
public static function decreaseFollowersCount($entity)
{
$finder = \XF::finder('XF:User')
->where('user_id', $entity->follow_user_id);
$user = $finder->fetchOne();
if ($user)
{
\XF::db()->update('xf_user', ['sc_user_follow' => 'sc_user_follow - 1'], 'user_id = ? AND sc_user_follow > 0', $user->user_id);
}
}
yeah, strange..But only thedecreaseFollowersCountis working, notincreaseFollowersCount. I'm not sure why![]()
$user->fastUpdate('sc_user_follow', $finder->columnSqlName('sc_user_follow') . "+ 1");
$user->fastUpdate('sc_user_follow', 'sc_user_follow + 1');
columnSqlName() is necessary/helpful in this case.. I'll try that tomorrow, I'll go to sleep. Thanks again !To be secure you should exclude users who have sc_user_follow = 0:
or for the other approach:PHP:public static function decreaseFollowersCount($entity) { \XF::db()->query('UPDATE xf_user SET sc_user_follow = sc_user_follow - 1 WHERE user_id = ? AND sc_user_follow > 0', $entity->follow_user_id); }
PHP:public static function decreaseFollowersCount($entity) { $finder = \XF::finder('XF:User') ->where('user_id', $entity->follow_user_id); $user = $finder->fetchOne(); if ($user) { \XF::db()->update('xf_user', ['sc_user_follow' => 'sc_user_follow - 1'], 'user_id = ? AND sc_user_follow > 0', $user->user_id); } }
yeah, strange..
What if you replace:
with:PHP:$user->fastUpdate('sc_user_follow', $finder->columnSqlName('sc_user_follow') . "+ 1");
.. not sure ifPHP:$user->fastUpdate('sc_user_follow', 'sc_user_follow + 1');columnSqlName()is necessary/helpful in this case..![]()
Hello, It doesn't change anything, really weirdWhat if you replace:
with:PHP:$user->fastUpdate('sc_user_follow', $finder->columnSqlName('sc_user_follow') . "+ 1");
.. not sure ifPHP:$user->fastUpdate('sc_user_follow', 'sc_user_follow + 1');columnSqlName()is necessary/helpful in this case..![]()
We use essential cookies to make this site work, and optional cookies to enhance your experience.