diff options
Diffstat (limited to '')
-rw-r--r-- | include/ws_functions.inc.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 9e2040b96..8f7d7882f 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -942,6 +942,17 @@ function merge_chunks($output_filepath, $original_sum, $type) { ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath); + if (is_file($output_filepath)) + { + unlink($output_filepath); + + if (is_file($output_filepath)) + { + new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath); + exit(); + } + } + $upload_dir = PHPWG_ROOT_PATH.'upload/buffer'; $pattern = '/'.$original_sum.'-'.$type.'/'; $chunks = array(); @@ -1038,6 +1049,79 @@ function add_file($file_path, $type, $original_sum, $file_sum) ); } +function ws_images_addFile($params, &$service) +{ + // image_id + // type {thumb, file, high} + // sum + + global $conf; + if (!is_admin() || is_adviser() ) + { + return new PwgError(401, 'Access denied'); + } + + $params['image_id'] = (int)$params['image_id']; + if ($params['image_id'] <= 0) + { + return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); + } + + // + // what is the path? + // + $query = ' +SELECT + path, + md5sum + FROM '.IMAGES_TABLE.' + WHERE id = '.$params['image_id'].' +;'; + list($file_path, $original_sum) = mysql_fetch_row(pwg_query($query)); + + // TODO only files added with web API can be updated with web API + + // + // makes sure directories are there and call the merge_chunks + // + $infos = add_file($file_path, $params['type'], $original_sum, $params['sum']); + + // + // update basic metadata from file + // + $update = array(); + + if ('high' == $params['type']) + { + $update['high_filesize'] = $infos['filesize']; + $update['has_high'] = 'true'; + } + + if ('file' == $params['type']) + { + $update['filesize'] = $infos['filesize']; + $update['width'] = $infos['width']; + $update['height'] = $infos['height']; + } + + // we may have nothing to update at database level, for example with a + // thumbnail update + if (count($update) > 0) + { + $update['id'] = $params['image_id']; + + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + mass_updates( + IMAGES_TABLE, + array( + 'primary' => array('id'), + 'update' => array_diff(array_keys($update), array('id')) + ), + array($update) + ); + } +} + function ws_images_add($params, &$service) { global $conf; |