silence
Well-known member
Alright I've been trying to fix this all night. Every other datawriter I look at is doing this exact thing, and not receiving this error D:
It simply does not compute to me, I am checking if there is existing data, yet it's trying to overwrite a duplicate entry!
Controller:
DataWriter:
It simply does not compute to me, I am checking if there is existing data, yet it's trying to overwrite a duplicate entry!
Controller:
PHP:
if (empty($info['auth_id']))
{
$dwAccount = XenForo_DataWriter::create('Teamspeak_DataWriter_Account');
$teamspeak = $this->getHelper("Teamspeak_Helper_Query");
$index = array(
'user_id' => $user_id,
'auth_id' => $auth_id
);
if (!empty($info['user_id']))
{
$dwAccount->setExistingData($index);
}
$dwAccount->bulkSet($index);
$dwAccount->save();
if (!empty($info['user_id']))
{
$teamspeak->_updateServerGroup($user_id, $auth_id, $info['auth_id']);
}
else
{
$teamspeak->_updateServerGroup($user_id, $auth_id);
}
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildPublicLink('account/teamspeak')
);
}
PHP:
<?php
class Teamspeak_DataWriter_Account extends XenForo_DataWriter
{
/**
* Gets the fields that are defined for the table. See parent for explanation.
*
* @return array
*/
protected function _getFields()
{
return array(
'xf_teamspeak' => array(
'user_id' => array(
'type' => self::TYPE_UINT
),
'auth_id' => array(
'type' => self::TYPE_STRING, 'required' => true
),
)
);
}
/**
* Gets the actual existing data out of data that was passed in. See parent for explanation.
*
* @param mixed
*
* @see XenForo_DataWriter::_getExistingData()
*
* @return array|false
*/
protected function _getExistingData($data)
{
if (!$id = $this->_getExistingPrimaryKey($data))
{
return false;
}
return array('xf_teamspeak' => $this->_getAccountModel()->getUserID($id));
}
/**
* Gets SQL condition to update the existing record.
*
* @see XenForo_DataWriter::_getUpdateCondition()
*
* @return string
*/
protected function _getUpdateCondition($tableName)
{
return 'user_id = ' . $this->_db->quote($this->getExisting('user_id'));
}
/**
* Get the Teamspeak account model.
*
* @return Teamspeak_Model_Account
*/
protected function _getAccountModel()
{
return $this->getModelFromCache('Teamspeak_Model_Account');
}
}
?>