You are here

function imagepicker_reallocate_image in Image Picker 6.2

Same name and namespace in other branches
  1. 7 imagepicker.admin.inc \imagepicker_reallocate_image()
1 call to imagepicker_reallocate_image()
imagepicker_admin_orphans_do in ./imagepicker.admin.inc

File

./imagepicker.admin.inc, line 1719
admin settings functions

Code

function imagepicker_reallocate_image($img_id, $old_uid, $new_uid) {
  $fstype = variable_get('imagepicker_fstype', '');
  $OK = FALSE;
  if ($fstype != 'alpha') {

    // $old_uid might not exist in users table but still have images
    $old_user_obj = new stdClass();
    $old_user_obj->uid = $old_uid;
    $img = _imagepicker_get_img($img_id, FALSE, $old_user_obj);
    if ($img) {
      $old_userdir = array(
        'uid' => $old_user_obj->uid,
      );
      $source = imagepicker_get_path(FALSE, $old_userdir);
      $source_thumbsdir = $source . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $img['img_name'];
      $source_browserdir = $source . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR . $img['img_name'];
      $source_origdir = $source . IMAGEPICKER_ORIG_DIR . DIRECTORY_SEPARATOR . $img['img_name'];
      $source = $source . $img['img_name'];
      $new_user_obj = user_load(array(
        'uid' => $new_uid,
      ));
      $new_userdir = array(
        'uid' => $new_user_obj->uid,
      );
      $dest = imagepicker_get_path(FALSE, $new_userdir);
      $dest_thumbsdir = $dest . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR;
      $dest_browserdir = $dest . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR;
      $dest_origdir = $dest . IMAGEPICKER_ORIG_DIR . DIRECTORY_SEPARATOR;
      $OK = file_move($source_thumbsdir, $dest_thumbsdir);
      $OK = file_move($source_browserdir, $dest_browserdir);
      $OK = file_move($source_origdir, $dest_origdir);
      $OK = file_move($source, $dest);
      if ($OK) {
        $OK = $source;
      }
    }
  }
  return $OK;
}