Incorrect integer value

Cupara

Well-known member
Error Info
Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Incorrect integer value: '' for column 'xfpoints_currency' at row 1 - library/Zend/Db/Statement/Mysqli.php:214
Generated By: Unknown Account, 2 minutes ago
Stack Trace

#2 /library/xfPoints/Model/Currency.php(270): Zend_Db_Adapter_Abstract->query('????UPDATE xf_u...', Array)
#3 /library/xfPoints/DataWriter/User.php(38): xfPoints_Model_Currency::updateUserPoints(40, false)
#4 /library/XenForo/DataWriter.php(1385): xfPoints_DataWriter_User->_postSave()

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.
 
Make sure $pointsEarned is an integer and that it is within the allowed range for that field in the database.
 
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.
 
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));
	}
 
Ok I have put intval within the $addPoints if condition to check if the echo comes back right or not.
 
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.
 
Back
Top Bottom