inmateaid
12-01-2012, 12:25 PM
I have spent the last 2 days trying to integrate vB 4.2 into CI 2.1.2...
Everything seems fine, but the datamanager outputs an SQL error page when saving a new user (outside of vB).
My index.php...
<?php
// vBulletin
define('REGISTERED_USERGROUP', 2); // typical default for registered users
define('PERMANENT_COOKIE', false); // false=session cookies (recommended)
define('THIS_SCRIPT', __FILE__);
define('VB_AREA', 'External');
$dir = getcwd();
chdir('forum/');
require_once('./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout
chdir($dir);
My library...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Forum2 {
private $dmuser;
public function __construct()
{
global $vbulletin;
$this->dmuser =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
}
public function register($data = array(), $login = FALSE)
{
global $vbulletin;
foreach ($data as $key => $value) {
if (!is_array($value)) {
$this->dmuser->set($key, $value);
}
}
if (isset($data['options']) && is_array($data['options'])) {
foreach ($data['options'] as $key => $value) {
$this->dmuser->set_bitfield('options', $key, $value);
}
}
$this->dmuser->pre_save();
//print_r($this->dm);
if (count($this->dmuser->errors) > 0) {
return implode('<li>', $this->dmuser->errors);
}
return $this->dm->save();
}
}
My controller...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sandbox extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function vb_test()
{
$this->load->library('forum2');
$this->forum2->register(array(
'username' => 'testing5',
'email' => 'test@test5.com',
'password' => 'password5'
));
}
}
Loading mydomain.com/sandbox/vb_test generates the vB sql error page and I receive the following email...
Database error in vBulletin 4.2.0:
Invalid SQL:
INSERT INTO usertextfield
(userid)
VALUES
(29);
MySQL Error : Duplicate entry '29' for key 1
I am at a loss. Why is the datamanager is trying to insert the "usertextfield" record twice? The records for user, userfield, and usertextfield are all added to the database. I simply can't figure out why the sql error is coming through using the datamanager. I've rewritten this library a few times already to make sure it was an issue with me providing incorrect data to the manager, but nothing gets around this problem.
Please help :(
Notes: We have a custom cms in place that already has users. Any new registrations will be processed on the main site, and our script adds the forum user to the vB database using the datamanager. Registration and login are handled externally. Login/logout works fine so I did not include those methods in the code above.
Everything seems fine, but the datamanager outputs an SQL error page when saving a new user (outside of vB).
My index.php...
<?php
// vBulletin
define('REGISTERED_USERGROUP', 2); // typical default for registered users
define('PERMANENT_COOKIE', false); // false=session cookies (recommended)
define('THIS_SCRIPT', __FILE__);
define('VB_AREA', 'External');
$dir = getcwd();
chdir('forum/');
require_once('./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout
chdir($dir);
My library...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Forum2 {
private $dmuser;
public function __construct()
{
global $vbulletin;
$this->dmuser =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
}
public function register($data = array(), $login = FALSE)
{
global $vbulletin;
foreach ($data as $key => $value) {
if (!is_array($value)) {
$this->dmuser->set($key, $value);
}
}
if (isset($data['options']) && is_array($data['options'])) {
foreach ($data['options'] as $key => $value) {
$this->dmuser->set_bitfield('options', $key, $value);
}
}
$this->dmuser->pre_save();
//print_r($this->dm);
if (count($this->dmuser->errors) > 0) {
return implode('<li>', $this->dmuser->errors);
}
return $this->dm->save();
}
}
My controller...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sandbox extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function vb_test()
{
$this->load->library('forum2');
$this->forum2->register(array(
'username' => 'testing5',
'email' => 'test@test5.com',
'password' => 'password5'
));
}
}
Loading mydomain.com/sandbox/vb_test generates the vB sql error page and I receive the following email...
Database error in vBulletin 4.2.0:
Invalid SQL:
INSERT INTO usertextfield
(userid)
VALUES
(29);
MySQL Error : Duplicate entry '29' for key 1
I am at a loss. Why is the datamanager is trying to insert the "usertextfield" record twice? The records for user, userfield, and usertextfield are all added to the database. I simply can't figure out why the sql error is coming through using the datamanager. I've rewritten this library a few times already to make sure it was an issue with me providing incorrect data to the manager, but nothing gets around this problem.
Please help :(
Notes: We have a custom cms in place that already has users. Any new registrations will be processed on the main site, and our script adds the forum user to the vB database using the datamanager. Registration and login are handled externally. Login/logout works fine so I did not include those methods in the code above.