Hi Klas,
As I use and external tools to manage users
subscription and so on. This tools create directly the user into Joomla
table. Nevertheless when the user is registered, it is better to used
Seblod, so SEBLOD table must be updated before. For that I have added
following trigger to Joomla table:
DELIMITER //
CREATE TRIGGER `xxxxx_user_create_t` AFTER INSERT ON `xxxxx_users`
FOR EACH ROW BEGIN
INSERT INTO xxxxx_cck_core (cck, pk, pkb, storage_location, author_id,
parent_id, store_id, date_time) VALUES ('user', NEW.id, 0,
'joomla_user', NEW.id,0,0,NOW());
INSERT INTO xxxxx_cck_store_item_users (id, cck) VALUES (NEW.id, 'user');
INSERT INTO xxxxx_cck_store_form_user (id, ..... ) VALUES (NEW.id,
...... ); /*Only if you use a Seblod form with additionnal fields*/
END
//
DELIMITER ;
DELIMITER //
CREATE TRIGGER `xxxxxx_user_delete_t` BEFORE DELETE ON `xxxxx_users`
FOR EACH ROW BEGIN
DELETE FROM xxxxx_cck_core where pk=OLD.id;
DELETE FROM xxxxx_cck_store_item_users where id=OLD.id;
DELETE FROM xxxxx_cck_store_form_user where id=OLD.id; /*Only if you use a Seblod form with additionnal fields*/
END
//
DELIMITER ;
Note than DELIMITER and // are used only to execute this script with PHPMyAdmin.
IMPORTANT:
This solution work only if user is created by Joomla or external tools.
If user must be created also manually with a Seblod Form, two entry are
created into xxxxx_cck_core (One from trigger, second by Seblod). To
prevent this behaviour, the following code must be added into Seblod
User Creation Form with AfterStore:
<?php
//Dans le cas d'une création de user depuis une Form Seblod, détruire le doublon inséré par le trigger et Seblod
defined( '_JEXEC' ) or die;
if (config['isNew'] == 1){
// Uniquement si nouveau user
$db = JFactory::getDbo(); // Get a db connection.
$pk_user = $config['pk']; // Id user
// Vérifie si le trigger a créé un doublon (Cas d'un User créé depuis une form Seblod)
// Uniquement sur table #__cck_core, car pk n'est pas unique
$db->SetQuery("SELECT count(*) FROM `#__cck_core` WHERE pk = " . $pk_user);
$result = $db->loadResult();
if ($result>1){
// la première ligne est celle insérée par le trigger --> a détruire
$db->SetQuery("SELECT MIN(id) from `#__cck_core` WHERE pk = " . $pk_user);
$id = $db->loadResult();
$db->SetQuery("DELETE FROM `#__cck_core` WHERE id = " . $id);
$db->execute();
}
}
?>
Into the context of my WebSite, this solution work fine.
Hope can help.