Ignore:
Timestamp:
Nov 23, 2009, 12:59:14 AM (14 years ago)
Author:
plg
Message:

merge r4345 from branch 2.0 to trunk

feature 1051: ability to add/update a file for an existing photo. For example,
you can add the "high" later. Another example is to update the "web resized"
file (new dimensions is a common example). It also works for thumbnails.
Updating an existing file has no impact on the logical level (list of tags,
list of categories, title, description and so on).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r4347 r4348  
    943943  ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath);
    944944
     945  if (is_file($output_filepath))
     946  {
     947    unlink($output_filepath);
     948   
     949    if (is_file($output_filepath))
     950    {
     951      new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath);
     952      exit();
     953    }
     954  }
     955 
    945956  $upload_dir = PHPWG_ROOT_PATH.'upload/buffer';
    946957  $pattern = '/'.$original_sum.'-'.$type.'/';
     
    10371048    'filesize' => $filesize,
    10381049    );
     1050}
     1051
     1052function ws_images_addFile($params, &$service)
     1053{
     1054  // image_id
     1055  // type {thumb, file, high}
     1056  // sum
     1057
     1058  global $conf;
     1059  if (!is_admin() || is_adviser() )
     1060  {
     1061    return new PwgError(401, 'Access denied');
     1062  }
     1063
     1064  $params['image_id'] = (int)$params['image_id'];
     1065  if ($params['image_id'] <= 0)
     1066  {
     1067    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
     1068  }
     1069
     1070  //
     1071  // what is the path?
     1072  //
     1073  $query = '
     1074SELECT
     1075    path,
     1076    md5sum
     1077  FROM '.IMAGES_TABLE.'
     1078  WHERE id = '.$params['image_id'].'
     1079;';
     1080  list($file_path, $original_sum) = mysql_fetch_row(pwg_query($query));
     1081
     1082  // TODO only files added with web API can be updated with web API
     1083
     1084  //
     1085  // makes sure directories are there and call the merge_chunks
     1086  //
     1087  $infos = add_file($file_path, $params['type'], $original_sum, $params['sum']);
     1088
     1089  //
     1090  // update basic metadata from file
     1091  //
     1092  $update = array();
     1093 
     1094  if ('high' == $params['type'])
     1095  {
     1096    $update['high_filesize'] = $infos['filesize'];
     1097    $update['has_high'] = 'true';
     1098  }
     1099
     1100  if ('file' == $params['type'])
     1101  {
     1102    $update['filesize'] = $infos['filesize'];
     1103    $update['width'] = $infos['width'];
     1104    $update['height'] = $infos['height'];
     1105  }
     1106
     1107  // we may have nothing to update at database level, for example with a
     1108  // thumbnail update
     1109  if (count($update) > 0)
     1110  {
     1111    $update['id'] = $params['image_id'];
     1112   
     1113    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1114    mass_updates(
     1115      IMAGES_TABLE,
     1116      array(
     1117        'primary' => array('id'),
     1118        'update'  => array_diff(array_keys($update), array('id'))
     1119        ),
     1120      array($update)
     1121      );
     1122  }
    10391123}
    10401124
Note: See TracChangeset for help on using the changeset viewer.