Plugin 1:
This will delete users from the gallery table when you delete them from the VB Admin Panel.
1. new hook (Plugin System: Add New Plugin)
2. Hook Location: userdata_delete
3. Call it "Delete Gallery User' or something similar
4. The code:
Code:
require_once('/absolute/path/to/gallery2/embed.php');
$ret = GalleryEmbed::init();
if ($ret) {
// echo $ret->getAsHtml();
}
$uid = $this->existing['userid'];
$ret2 = GalleryEmbed::deleteUser($uid);
if ($ret2) {
// echo "ret2".$ret2->getAsHtml() ;
}
You can uncomment the echos to see what is happening if badness occurs. Now whenever you delete a user from VB, you'll delete that user from Gallery, as well as the entry in the gallery ExternalIdMap database table.
Plugin 2:
This plugin will:
a. Update a VB user's information in the gallery2 database when they modify their User CP.
b. If a user has not been created already in the gallery2 database, a new user will be created.
c. Also note the use of custom user fields in the code, to allow for full names in the gallery information area.
Installation is similar to my previous post:
1. new hook (Plugin System: Add New Plugin)
2. location: userdata_postsave
3. call it "Update Gallery User" or something
4. The code follows:
Code:
require_once('/absolute/path/to/gallery2/embed.php'');
$ret = GalleryEmbed::init();
if ($ret) {
// echo $ret->getAsHtml();
}
// Set fullname based upon custom fields
$fullname=$this->existing['field13'] ." ". $this->existing['field14'];
// Set the array for updating
$args['fullname'] = $fullname ;
$args['username'] = $this->existing['username'];
$args['hashedpassword'] = $this->existing['password'];
$args['hashmethod'] = 'md5';
$args['email'] = $this->existing['email'];
$args['language'] = $this->existing['lang_code'];
$args['creationtimestamp'] = $this->existing['joindate'];
$args['groupid'] = $this->existing['usergroupid'];
// Get the userid
$uid = $this->existing['userid'];
$ret = GalleryEmbed::isExternalIdMapped($uid,$args);
//Now if no user exists, we'll create one
//If user exists, we'll update existing user
if ($ret && ($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
$ret2 = GalleryEmbed::createUser($uid,$args);
}else {
$ret2 = GalleryEmbed::updateUser($uid,$args);
}
if ($ret2) {
// echo "ret2: ". $ret2->getAsHtml() ;
}