feature 2548 multisize - implement delete_element_derivatives

git-svn-id: http://piwigo.org/svn/trunk@12917 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2012-01-17 21:02:16 +00:00
parent 89933672f2
commit c6265c515d
3 changed files with 61 additions and 61 deletions

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery | // | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
@ -175,16 +175,12 @@ function delete_element_files($ids)
return 0; return 0;
} }
include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
$new_ids = array(); $new_ids = array();
$query = ' $query = '
SELECT SELECT
id, id,
path, path,
tn_ext,
has_high,
representative_ext representative_ext
FROM '.IMAGES_TABLE.' FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $ids).') WHERE id IN ('.implode(',', $ids).')
@ -196,7 +192,7 @@ SELECT
{ {
continue; continue;
} }
$files = array(); $files = array();
$files[] = get_element_path($row); $files[] = get_element_path($row);
@ -215,9 +211,10 @@ SELECT
break; break;
} }
} }
if ($ok) if ($ok)
{ {
delete_element_derivatives($row);
$new_ids[] += $row['id']; $new_ids[] += $row['id'];
} }
else else
@ -388,7 +385,7 @@ DELETE FROM '.USERS_TABLE.'
function delete_orphan_tags() function delete_orphan_tags()
{ {
$orphan_tags = get_orphan_tags(); $orphan_tags = get_orphan_tags();
if (count($orphan_tags) > 0) if (count($orphan_tags) > 0)
{ {
$orphan_tag_ids = array(); $orphan_tag_ids = array();
@ -412,7 +409,7 @@ DELETE
function get_orphan_tags() function get_orphan_tags()
{ {
$orphan_tags = array(); $orphan_tags = array();
$query = ' $query = '
SELECT SELECT
id, id,
@ -1389,14 +1386,14 @@ function delete_tags($tag_ids)
{ {
return false; return false;
} }
$query = ' $query = '
DELETE DELETE
FROM '.IMAGE_TAG_TABLE.' FROM '.IMAGE_TAG_TABLE.'
WHERE tag_id IN ('.implode(',', $tag_ids).') WHERE tag_id IN ('.implode(',', $tag_ids).')
;'; ;';
pwg_query($query); pwg_query($query);
$query = ' $query = '
DELETE DELETE
FROM '.TAGS_TABLE.' FROM '.TAGS_TABLE.'
@ -2038,7 +2035,7 @@ function get_active_menu($menu_page)
function get_taglist($query, $only_user_language=true) function get_taglist($query, $only_user_language=true)
{ {
$result = pwg_query($query); $result = pwg_query($query);
$taglist = array(); $taglist = array();
while ($row = pwg_db_fetch_assoc($result)) while ($row = pwg_db_fetch_assoc($result))
{ {
@ -2057,7 +2054,7 @@ function get_taglist($query, $only_user_language=true)
$row['name'] = preg_replace('#\[lang=(.*?)\](.*?)\[/lang\]#is', null, $row['name']); $row['name'] = preg_replace('#\[lang=(.*?)\](.*?)\[/lang\]#is', null, $row['name']);
} }
if (strlen($row['name']) > 0) if (strlen($row['name']) > 0)
{ {
array_push( array_push(
@ -2069,7 +2066,7 @@ function get_taglist($query, $only_user_language=true)
); );
} }
} }
$cmp = create_function('$a,$b', 'return strcasecmp($a["name"], $b["name"]);'); $cmp = create_function('$a,$b', 'return strcasecmp($a["name"], $b["name"]);');
usort($taglist, $cmp); usort($taglist, $cmp);
@ -2136,7 +2133,7 @@ function add_permission_on_category($category_ids, $user_ids)
{ {
return; return;
} }
// make sure categories are private and select uppercats or subcats // make sure categories are private and select uppercats or subcats
$cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids($category_ids)).",".implode(',', get_uppercat_ids($category_ids)) : implode(',', get_uppercat_ids($category_ids)); $cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids($category_ids)).",".implode(',', get_uppercat_ids($category_ids)) : implode(',', get_uppercat_ids($category_ids));
$query = ' $query = '
@ -2152,14 +2149,14 @@ SELECT
{ {
return; return;
} }
// We must not reinsert already existing lines in user_access table // We must not reinsert already existing lines in user_access table
$granteds = array(); $granteds = array();
foreach ($private_cats as $cat_id) foreach ($private_cats as $cat_id)
{ {
$granteds[$cat_id] = array(); $granteds[$cat_id] = array();
} }
$query = ' $query = '
SELECT SELECT
user_id, user_id,
@ -2175,11 +2172,11 @@ SELECT
} }
$inserts = array(); $inserts = array();
foreach ($private_cats as $cat_id) foreach ($private_cats as $cat_id)
{ {
$grant_to_users = array_diff($user_ids, $granteds[$cat_id]); $grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
foreach ($grant_to_users as $user_id) foreach ($grant_to_users as $user_id)
{ {
array_push( array_push(
@ -2207,7 +2204,7 @@ function get_admins($include_webmaster=true)
{ {
$status_list[] = 'webmaster'; $status_list[] = 'webmaster';
} }
$query = ' $query = '
SELECT SELECT
user_id user_id
@ -2245,7 +2242,7 @@ function clear_derivative_cache($types='all')
{ {
$pattern .= derivative_to_url($types[0]); $pattern .= derivative_to_url($types[0]);
} }
$pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#'; $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#';
if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR)) if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
{ {
@ -2294,7 +2291,7 @@ function clear_derivative_cache_rec($path, $pattern)
} }
} }
closedir($contents); closedir($contents);
if ($rmdir) if ($rmdir)
{ {
if ($rm_index) if ($rm_index)
@ -2308,16 +2305,22 @@ function clear_derivative_cache_rec($path, $pattern)
} }
} }
function delete_element_derivatives($ids) function delete_element_derivatives($infos)
{ {
// todo $path = $infos['path'];
if (!is_array($ids)) if (!empty($infos['representative_ext']))
{ {
$ids = array($ids); $path = original_to_representative( $path, $infos['representative_ext']);
}
if (substr_compare($path, '../', 0, 3)==0)
{
$path = substr($path, 3);
}
$dot = strpos($path, '.');
$path = substr_replace($path, '-*', $dot, 0);
foreach( glob(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$path) as $file)
{
@unlink($file);
} }
// for now I do a massive clear, to be removed once the function is
// properly implemented
clear_derivative_cache();
} }
?> ?>

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery | // | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
@ -36,7 +36,7 @@ function get_upload_form_config()
'default' => false, 'default' => false,
'can_be_null' => false, 'can_be_null' => false,
), ),
'original_resize_maxwidth' => array( 'original_resize_maxwidth' => array(
'default' => 2000, 'default' => 2000,
'min' => 500, 'min' => 500,
@ -45,7 +45,7 @@ function get_upload_form_config()
'can_be_null' => false, 'can_be_null' => false,
'error_message' => l10n('The original maximum width must be a number between %d and %d'), 'error_message' => l10n('The original maximum width must be a number between %d and %d'),
), ),
'original_resize_maxheight' => array( 'original_resize_maxheight' => array(
'default' => 2000, 'default' => 2000,
'min' => 300, 'min' => 300,
@ -54,7 +54,7 @@ function get_upload_form_config()
'can_be_null' => false, 'can_be_null' => false,
'error_message' => l10n('The original maximum height must be a number between %d and %d'), 'error_message' => l10n('The original maximum height must be a number between %d and %d'),
), ),
'original_resize_quality' => array( 'original_resize_quality' => array(
'default' => 95, 'default' => 95,
'min' => 50, 'min' => 50,
@ -112,7 +112,7 @@ function save_upload_form_config($data, &$errors=array())
$min = $upload_form_config[$field]['min']; $min = $upload_form_config[$field]['min'];
$max = $upload_form_config[$field]['max']; $max = $upload_form_config[$field]['max'];
$pattern = $upload_form_config[$field]['pattern']; $pattern = $upload_form_config[$field]['pattern'];
if (preg_match($pattern, $value) and $value >= $min and $value <= $max) if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
{ {
$updates[] = array( $updates[] = array(
@ -157,10 +157,10 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
// 2) keep/resize original // 2) keep/resize original
// //
// 3) register in database // 3) register in database
// TODO // TODO
// * check md5sum (already exists?) // * check md5sum (already exists?)
global $conf, $user; global $conf, $user;
if (isset($original_md5sum)) if (isset($original_md5sum))
@ -171,9 +171,9 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
{ {
$md5sum = md5_file($source_filepath); $md5sum = md5_file($source_filepath);
} }
$file_path = null; $file_path = null;
if (isset($image_id)) if (isset($image_id))
{ {
// this photo already exists, we update it // this photo already exists, we update it
@ -188,7 +188,7 @@ SELECT
{ {
$file_path = $row['path']; $file_path = $row['path'];
} }
if (!isset($file_path)) if (!isset($file_path))
{ {
die('['.__FUNCTION__.'] this photo does not exist in the database'); die('['.__FUNCTION__.'] this photo does not exist in the database');
@ -200,11 +200,11 @@ SELECT
else else
{ {
// this photo is new // this photo is new
// current date // current date
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
// upload directory hierarchy // upload directory hierarchy
$upload_dir = sprintf( $upload_dir = sprintf(
PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s', PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s',
@ -250,11 +250,11 @@ SELECT
if ($conf['original_resize']) if ($conf['original_resize'])
{ {
$need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
if ($need_resize) if ($need_resize)
{ {
$img = new pwg_image($file_path); $img = new pwg_image($file_path);
$img->pwg_resize( $img->pwg_resize(
$file_path, $file_path,
$conf['original_resize_maxwidth'], $conf['original_resize_maxwidth'],
@ -263,14 +263,14 @@ SELECT
$conf['upload_form_automatic_rotation'], $conf['upload_form_automatic_rotation'],
false false
); );
$img->destroy(); $img->destroy();
} }
} }
} }
$file_infos = pwg_image_infos($file_path); $file_infos = pwg_image_infos($file_path);
if (isset($image_id)) if (isset($image_id))
{ {
$update = array( $update = array(
@ -281,7 +281,7 @@ SELECT
'md5sum' => $md5sum, 'md5sum' => $md5sum,
'added_by' => $user['id'], 'added_by' => $user['id'],
); );
if (isset($level)) if (isset($level))
{ {
$update['level'] = $level; $update['level'] = $level;
@ -292,8 +292,6 @@ SELECT
$update, $update,
array('id' => $image_id) array('id' => $image_id)
); );
delete_element_derivatives($image_id);
} }
else else
{ {
@ -308,14 +306,14 @@ SELECT
'md5sum' => $md5sum, 'md5sum' => $md5sum,
'added_by' => $user['id'], 'added_by' => $user['id'],
); );
if (isset($level)) if (isset($level))
{ {
$insert['level'] = $level; $insert['level'] = $level;
} }
single_insert(IMAGES_TABLE, $insert); single_insert(IMAGES_TABLE, $insert);
$image_id = pwg_db_insert_id(IMAGES_TABLE); $image_id = pwg_db_insert_id(IMAGES_TABLE);
} }
@ -326,7 +324,7 @@ SELECT
$categories $categories
); );
} }
// update metadata from the uploaded file (exif/iptc) // update metadata from the uploaded file (exif/iptc)
if ($conf['use_exif'] and !function_exists('read_exif_data')) if ($conf['use_exif'] and !function_exists('read_exif_data'))
{ {
@ -374,7 +372,7 @@ function need_resize($image_filepath, $max_width, $max_height)
// rotation must be applied to the resized photo, then we should test // rotation must be applied to the resized photo, then we should test
// invert width and height. // invert width and height.
list($width, $height) = getimagesize($image_filepath); list($width, $height) = getimagesize($image_filepath);
if ($width > $max_width or $height > $max_height) if ($width > $max_width or $height > $max_height)
{ {
return true; return true;
@ -387,7 +385,7 @@ function pwg_image_infos($path)
{ {
list($width, $height) = getimagesize($path); list($width, $height) = getimagesize($path);
$filesize = floor(filesize($path)/1024); $filesize = floor(filesize($path)/1024);
return array( return array(
'width' => $width, 'width' => $width,
'height' => $height, 'height' => $height,
@ -433,7 +431,7 @@ function get_ini_size($ini_key, $in_bytes=true)
{ {
$size = convert_shorthand_notation_to_bytes($size); $size = convert_shorthand_notation_to_bytes($size);
} }
return $size; return $size;
} }
@ -441,7 +439,7 @@ function convert_shorthand_notation_to_bytes($value)
{ {
$suffix = substr($value, -1); $suffix = substr($value, -1);
$multiply_by = null; $multiply_by = null;
if ('K' == $suffix) if ('K' == $suffix)
{ {
$multiply_by = 1024; $multiply_by = 1024;
@ -454,7 +452,7 @@ function convert_shorthand_notation_to_bytes($value)
{ {
$multiply_by = 1024*1024*1024; $multiply_by = 1024*1024*1024;
} }
if (isset($multiply_by)) if (isset($multiply_by))
{ {
$value = substr($value, 0, -1); $value = substr($value, 0, -1);
@ -499,7 +497,7 @@ function ready_for_upload_message()
if (!is_writable($conf['upload_dir'])) if (!is_writable($conf['upload_dir']))
{ {
@chmod($conf['upload_dir'], 0777); @chmod($conf['upload_dir'], 0777);
if (!is_writable($conf['upload_dir'])) if (!is_writable($conf['upload_dir']))
{ {
return sprintf( return sprintf(

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery | // | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
@ -458,11 +458,10 @@ SELECT date_available,
if ($max_elements>0) if ($max_elements>0)
{ // get some thumbnails ... { // get some thumbnails ...
$query = ' $query = '
SELECT DISTINCT id, path, name, representative_ext, file SELECT DISTINCT i.*
FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id
'.$where_sql.' '.$where_sql.'
AND date_available=\''.$dates[$i]['date_available'].'\' AND date_available=\''.$dates[$i]['date_available'].'\'
AND tn_ext IS NOT NULL
ORDER BY '.DB_RANDOM_FUNCTION.'() ORDER BY '.DB_RANDOM_FUNCTION.'()
LIMIT '.$max_elements.' LIMIT '.$max_elements.'
;'; ;';