function imagepicker_admin_orphans_do in Image Picker 7
Same name and namespace in other branches
- 6.2 imagepicker.admin.inc \imagepicker_admin_orphans_do()
1 call to imagepicker_admin_orphans_do()
- imagepicker_admin_orphans_form_submit in ./imagepicker.admin.inc
File
- ./imagepicker.admin.inc, line 1275
- @author Bob Hutchinson http://drupal.org/user/52366
@copyright GNU GPL
Code
function imagepicker_admin_orphans_do($orphanid, $orphans_delete = FALSE, $reallocate_to_user = '') {
$OK = FALSE;
$message = '';
$return = '';
$dir = imagepicker_get_files_directory();
$orphanids = imagepicker_check_orphans($dir);
if (in_array($orphanid, $orphanids)) {
if ($orphans_delete == 1) {
$user_obj = new stdClass();
$user_obj->uid = $orphanid;
$ct = 0;
$result = db_query('SELECT img_id FROM {imagepicker} WHERE uid=:uid', array(
':uid' => $user_obj->uid,
));
while ($row = $result
->fetchAssoc()) {
_imagepicker_image_delete($row['img_id'], $user_obj, 'admin', TRUE);
imagepicker_delete_group_image($row['img_id']);
$ct++;
}
$OK = imagepicker_delete_olduser_dirs($user_obj->uid);
if ($OK) {
$message = t('!ct Files deleted.', array(
'!ct' => $ct,
));
}
else {
$message = t('There was an error in deleting files');
}
}
elseif ($reallocate_to_user != '') {
$result = db_query("SELECT uid FROM {users} WHERE name=:s", array(
':s' => trim($reallocate_to_user),
));
if ($row = $result
->fetchAssoc()) {
$new_uid = $row['uid'];
$ct = 0;
$result2 = db_query('SELECT img_id FROM {imagepicker} WHERE uid=:uid', array(
':uid' => $orphanid,
));
while ($row2 = $result2
->fetchAssoc()) {
$newf = imagepicker_reallocate_image($row2['img_id'], $orphanid, $new_uid);
if ($newf) {
$img_name = basename($newf);
db_update('imagepicker')
->fields(array(
'uid' => $new_uid,
'img_name' => $img_name,
))
->condition('img_id', $row2['img_id'])
->execute();
$ct++;
}
}
db_update('imagepicker_user_groups')
->fields(array(
'uid' => $new_uid,
))
->condition('uid', $orphanid)
->execute();
$OK = imagepicker_delete_olduser_dirs($orphanid);
if ($OK) {
$message = t('!ct Files moved.', array(
'!ct' => $ct,
));
}
else {
$message = t('There was an error in moving files.');
}
}
}
if ($message) {
$return = array(
$message,
$OK,
);
}
}
return $return;
}