Save drupal user id when creating new Chamilo user - refs BT#9083

1.10.x
Imanol Losada 11 years ago
parent ab65166912
commit 3c893775f6
  1. 13
      main/inc/lib/hook/HookCreateUser.php
  2. 20
      main/inc/lib/usermanager.lib.php
  3. 9
      plugin/createdrupaluser/src/HookCreateDrupalUser.php

@ -17,18 +17,21 @@ class HookCreateUser extends HookEvent implements HookCreateUserEventInterface
/**
* Update all the observers
* @param int $type
* @param int $type
*
* @return int
* @return array User ids
*/
public function notifyCreateUser($type)
{
/** @var \HookCreateUserObserverInterface $observer */
$this->eventData['type'] = $type;
$userIds = array();
foreach ($this->observers as $observer) {
$observer->hookCreateUser($this);
$userId = $observer->hookCreateUser($this);
if ($userId !== false) {
$userIds[] = $userId;
}
}
return 1;
return $userIds;
}
}

@ -276,6 +276,18 @@ class UserManager
return api_set_failure('error inserting in Database');
}
if (!empty($hook)) {
$hook->setEventData(array(
'return' => $return,
'originalPassword' => $original_password
));
$userIds = $hook->notifyCreateUser(HOOK_EVENT_TYPE_POST);
foreach ($userIds as $userId) {
$key = key($userId);
$extra[$key] = $userId[$key];
}
}
if (is_array($extra) && count($extra) > 0) {
$res = true;
foreach ($extra as $fname => $fvalue) {
@ -283,14 +295,6 @@ class UserManager
}
}
self::update_extra_field_value($return, 'already_logged_in', 'false');
if (!empty($hook)) {
$hook->setEventData(array(
'return' => $return,
'originalPassword' => $original_password
));
$hook->notifyCreateUser(HOOK_EVENT_TYPE_POST);
}
return $return;
}

@ -22,7 +22,8 @@ class HookCreateDrupalUser extends HookObserver implements HookCreateUserObserve
/**
* Create a Drupal user when the Chamilo user is registered
* @param HookCreateUserEventInterface $hook The hook
* @param HookCreateUserEventInterface $hook The hook
* @return array|bool Drupal created user id
*/
public function hookCreateUser(HookCreateUserEventInterface $hook)
{
@ -54,7 +55,11 @@ class HookCreateDrupalUser extends HookObserver implements HookCreateUserObserve
);
$client = new SoapClient(null, $options);
$client->addUser($fields, $extraFields);
$drupalUserId = $client->addUser($fields, $extraFields);
if ($drupalUserId !== false) {
$drupalUserId = array('drupal_user_id' => $drupalUserId);
}
return $drupalUserId;
}
}

Loading…
Cancel
Save