Thank you for your reply,
I chose VP Advanced User extension (and I customized its code) because it's the only one that I found full compatible with my OpenId provider
I rewrited the code of my Joomla plugin to sync the users of Joomla and CB: can you say me if now the approach is correct? I tried to fellow the code of the native syncusers() function of CB. Thank you.
// no direct access
defined( '_JEXEC' ) or die;
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
use CBLib\Language\CBTxt;
cbimport( 'cb.database' );
class PlgUserSyncusers extends JPlugin
{
public function onUserAfterSave($data, $isNew, $result, $error)
{
global $_CB_database, $_CB_Backend_Title, $ueConfig;
try {
// 0a. delete user table for bad rows
$sql = "DELETE FROM #__users WHERE id = 0";
$_CB_database->setQuery($sql);
$_CB_database->query();
// 0b. delete comprofiler table for bad rows
$sql = "DELETE FROM #__comprofiler WHERE id = 0";
$_CB_database->setQuery($sql);
$_CB_database->query();
// 1. add missing comprofiler entries, guessing naming depending on CB's name style:
switch ( $ueConfig ) {
case 2:
// firstname + lastname:
$sql = "INSERT IGNORE INTO #__comprofiler(id,user_id,lastname,firstname) "
." SELECT id,id, SUBSTRING_INDEX(name,' ',-1), "
."SUBSTRING( name, 1, length( name ) - length( SUBSTRING_INDEX( name, ' ', -1 ) ) -1 ) "
." FROM #__users";
break;
case 3:
// firstname + middlename + lastname:
$sql = "INSERT IGNORE INTO #__comprofiler(id,user_id,middlename,lastname,firstname) "
. " SELECT id,id,SUBSTRING( name, INSTR( name, ' ' ) +1,"
." length( name ) - INSTR( name, ' ' ) - length( SUBSTRING_INDEX( name, ' ', -1 ) ) -1 ),"
." SUBSTRING_INDEX(name,' ',-1),"
." IF(INSTR(name,' '),SUBSTRING_INDEX( name, ' ', 1 ),'') "
. " FROM #__users";
break;
default:
// name only:
$sql = "INSERT IGNORE INTO #__comprofiler(id,user_id) SELECT id,id FROM #__users";
break;
}
$_CB_database->setQuery($sql);
$_CB_database->query();
$sql = "UPDATE #__comprofiler SET `user_id`=`id`";
$_CB_database->setQuery($sql);
$_CB_database->query();
// 2. remove excessive comprofiler entries (e.g. if admin used mambo/joomla delete user function:
$sql = "SELECT c.id FROM #__comprofiler c LEFT JOIN #__users u ON u.id = c.id WHERE u.id IS NULL";
$_CB_database->setQuery($sql);
$users = $_CB_database->loadResultArray();
}
catch ( RuntimeException $e ) {
return;
}
}
}