aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-11-22 23:38:57 +0000
committerplegall <plg@piwigo.org>2009-11-22 23:38:57 +0000
commitd7f0f0f9b2146ed18df7a83f5d529f5afc9e4aad (patch)
tree4a2d5987ce543d678b1e2598c6cb0255d47055db /include
parent6768482bcf5ba73a1fd429a1584134c2b213044d (diff)
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). git-svn-id: http://piwigo.org/svn/branches/2.0@4345 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/ws_functions.inc.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index a01322547..323c6c689 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;