#1488585 closed Bugs (wontfix)
user_create missing functionality
| Reported by: | mikbull | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | later |
| Component: | Addressbook | Version: | 0.8-rc |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Unable to use get_address_book() in the user_create hook. When contacts or contact groups are created the new users id isn't grabbed.
Change History (5)
comment:1 Changed 10 months ago by alec
- Resolution set to wontfix
- Status changed from new to closed
comment:2 Changed 10 months ago by mikbull
Alec,
I'm not sure why I would use the create_identity hook if I want to populate the address book when a user is created on first login. As far as I can tell the addressbook has no ties to a users identity whatsoever.
The issue is as follows:
When using the 'user_create' hook
$this->add_hook('user_create', array($this, 'load_addressbook'));
function load_addressbook($args) {
$contacts = $rcmail->get_address_book("sql", true);
$record = array('email' => 'blah@blah.com');
$contact_id = $contacts->insert($record, true);
}
The contact that is created '$contact_id' isn't tied to the newly created User ID - the field has a null value. I assume the user has been created at this point as the 'user' argument contains the user_id.
---
However, when using the 'login_after' hook:
$this->add_hook('login_after', array($this, 'load_addressbook'));
function load_addressbook($args) {
$contacts = $rcmail->get_address_book("sql", true);
$record = array('email' => 'blah@blah.com');
$contact_id = $contacts->insert($record, true);
}
The contact that is created '$contact_id' is tied to User ID that just logged in.
---
This forces the developer to use the 'login_after' hook and throw in check to see if there are any existing contacts in the database before importing:
// If contacts exist they have logged in before so don't import anything: if($contacts->count()->count > 0) return true;
Just wondering why the 'insert' function when implemented in the 'create_user' hook functions differently than when used in the 'login_after' hook and the other hooks (which I haven't tested)
$contact_id = $contacts->insert($record, true);
Do you understand now?
-- Mike
comment:3 Changed 10 months ago by mikbull
- Resolution wontfix deleted
- Status changed from closed to reopened
comment:4 Changed 10 months ago by alec
- Resolution set to wontfix
- Status changed from reopened to closed
The same functionality has squirrelmail_usercopy, you can see there that in use of create_identity is nothing wrong. Of course you can also use login_after. All you need is to use user_create to set a internal flag so you wouldn't need to check if addressbook is empty. User_create hook is executed before inserting user, so ID is unknown. We can't change that.
comment:5 Changed 10 months ago by mikbull
Thanks. Didn't realize the account wasn't available in user_create

I don't understand. What do you want to achieve? If you want to insert contacts for the newly created user use create_identity hook. See squirrelmail_usercopy plugin.