1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Incorrect integer value

Discussion in 'XenForo Development Discussions' started by Mythotical, Mar 21, 2013.

  1. Mythotical

    Mythotical Well-Known Member

    xfPoints_Model_Currency Line 270:
    Code:
    		$db = XenForo_Application::get('db');
    
    		return $db->query("
    			UPDATE xf_user
    			SET xfpoints_currency = ?
    			WHERE user_id = ?
    		", array($pointsEarned, $userId));
    xfPoints_Datawriter_User Line 38:
    Code:
    class xfPoints_DataWriter_User extends XFCP_xfPoints_DataWriter_User
    {
    
    	/**
    	 * Post-save handling.
    	 */
    	protected function _postSave()
    	{
    		parent::_postSave();
    		$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
    		$addPoints = false;
    		if ($this->get('user_state') == 'valid')
    		{
    			if ($this->isInsert())
    			{
    				$addPoints = true;
    			}
    			else if ($this->isChanged('user_state'))
    			{
    				$previousState = $this->getExisting('user_state');
    				if ($previousState == 'moderated' || $previousState == 'email_confirm')
    				{
    					$addPoints = true;
    				}
    			}
    		}
    
    		if ($addPoints)
    		{
    			$pointsEarned = $this->getModelFromCache('xfPoints_Model_Currency')->assignUserPoints($this->get('user_id'), 'register');
    			$pointsModel->updateUserPoints($this->get('user_id'), $pointsEarned);
    		}
    	}
    }
    I figured it was an issue with checking user_state but I'm not sure now.
     
  2. Mythotical

    Mythotical Well-Known Member

    The mod that is using the same method is Social Connect (Facebook) by Chris Deeming.
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Make sure $pointsEarned is an integer and that it is within the allowed range for that field in the database.
     
  4. Mythotical

    Mythotical Well-Known Member

    It is passed from xfPoints_Model_Currency and that is always an integer whether it comes out to be 0 or not. I have it set in the DB to a max of 10 so it is well within range.
     
  5. Mythotical

    Mythotical Well-Known Member

    Here is the data that is used for determining $pointsEarned:
    Code:
    	public function assignUserPoints($userId, $type)
    	{
    		$db = XenForo_Application::get('db');
    		$options = XenForo_Application::get('options');
    
    		switch ($type)
    		{
    			case 'post':
    			{
    				$numPoints = $options->xfpoints_currency_posts;
    				break;
    			}
    			case 'thread':
    			{
    				$numPoints = $options->xfpoints_currency_thread;
    				break;
    			}
    			case 'poll':
    			{
    				$numPoints = $options->xfpoints_currency_poll;
    				break;
    			}
    			case 'attachment':
    			{
    				$numPoints = $options->xfpoints_currency_upload;
    				break;
    			}
    			case 'register':
    			{
    				$numPoints = $options->xfpoints_currency_register;
    				break;
    			}
    			case 'donation':
    			{
    				$numPoints = $options->xfpoints_currency_donation;
    				break;
    			}
    			case 'refer':
    			{
    				$numPoints = $options->xfpoints_currency_refer;
    				break;
    			}
    			case 'upgrade':
    			{
    				$numPoints = $options->xfpoints_currency_upgrade;
    				break;
    			}
    			case 'birthday':
    			{
    				$numPoints = $options->xfpoints_currency_birthday;
    				break;
    			}
    			case 'activity':
    			{
    				$numPoints = $options->xfpoints_currency_activity;
    				break;
    			}
    			case 'size':
    			{
    				$numPoints = $options->xfpoints_currency_size;
    				break;
    			}
    			case 'avatar':
    			{
    				$numPoints = $options->xfpoints_currency_avatar;
    				break;
    			}
    			case 'friend':
    			{
    				$numPoints = $options->xfpoints_currency_friend;
    				break;
    			}
    			case 'download':
    			{
    				$numPoints = $options->xfpoints_currency_download;
    				break;
    			}
    			case 'like':
    			{
    				$numPoints = $options->xfpoints_like;
    				break;
    			}
    			case 'unlike':
    			{
    				$numPoints = $options->xfpoints_unlike;
    				break;
    			}
    			case 'attachment_downloaded':
    				if (!empty($extraData)) {
    					$extension = strtolower($extraData);
    					$list = explode("\n", $options->xfpoints_attachment_download);
    					foreach ($list as $line) {
    						$parts = explode("=", $line);
    						if (count($parts) == 2) {
    							$extensions = explode(',', str_replace(' ', '', strtolower($parts[0])));
    							$point = intval($parts[1]);
    							if (count($extensions) == 1 AND $extensions[0] == '*') {
    								// match all rule
    								return $point;
    							} else if (in_array($extension, $extensions)) {
    								return $point;
    							}
    						}
    					}
    				}
    				return 0;
    				break;
    			default: // unknown type
    			{
    				return false;
    			}
    		}
    
    
    		// for a new insert
    		$pointsEarned = $numPoints;
    
    		$userPoints = $this->getUserPoints($userId);
    
    		if (!empty($userPoints)) // update
    		{
    			if ($type == 'register')
    			{
    				$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    			}
    		}
    
    		if ($type == 'attachment')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'download')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'attachment_downloaded')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'donation')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'like')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'unlike')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] - $numPoints;
    		}
    
    		if ($type == 'upgrade')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'downgrade')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] - $options->xfpoints_currency_upgrade;
    		}
    
    		if ($type == 'friend')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		if ($type == 'unfriend')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] - $options->xfpoints_currency_friend;
    		}
    		if ($type == 'post')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $options->xfpoints_currency_posts;
    		}
    		if ($type == 'thread')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $options->xfpoints_currency_thread;
    		}
    		if ($type == 'upgrade')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    		if ($type == 'avatar')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    		if ($type == 'poll')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    		if ($type == 'birthday')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    		if ($type == 'activity')
    		{
    			$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
    		}
    
    		return $pointsEarned ? $pointsEarned : false;
    	}
    	public static function updateUserPoints($userId, $pointsEarned)
    	{
    
    		$db = XenForo_Application::get('db');
    
    		return $db->query("
    			UPDATE xf_user
    			SET xfpoints_currency = ?
    			WHERE user_id = ?
    		", array($pointsEarned, $userId));
    	}
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  7. Mythotical

    Mythotical Well-Known Member

    Ok I have put intval within the $addPoints if condition to check if the echo comes back right or not.
     
  8. Mythotical

    Mythotical Well-Known Member

    Ok it returns 10 which is the amount that is being inserted.
     
  9. Mythotical

    Mythotical Well-Known Member

    I think I forgot to include a check to make sure the setting was not 0 then proceed if greater than 0. Testing it out now.
     

Share This Page