mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
feature #379 multiple format, step 3: add/remove
* during sync, Piwigo will detect new/removed formats for an existing photo * multiple formats features is disabled by default
This commit is contained in:
@@ -101,12 +101,12 @@ function get_elements($path)
|
||||
$representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
|
||||
}
|
||||
|
||||
$formats = $this->get_formats($path, $filename_wo_ext);
|
||||
|
||||
$fs[ $path.'/'.$node ] = array(
|
||||
'representative_ext' => $representative_ext,
|
||||
'formats' => $formats,
|
||||
);
|
||||
$fs[ $path.'/'.$node ] = array('representative_ext' => $representative_ext);
|
||||
|
||||
if ($conf['enable_formats'])
|
||||
{
|
||||
$fs[ $path.'/'.$node ]['formats'] = $this->get_formats($path, $filename_wo_ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (is_dir($path.'/'.$node)
|
||||
@@ -201,13 +201,7 @@ function get_formats($path, $filename_wo_ext)
|
||||
|
||||
if (is_file($test))
|
||||
{
|
||||
// $formats[] = array(
|
||||
// 'ext' => $ext,
|
||||
// 'filesize' => floor(filesize($file) / 1024),
|
||||
// );
|
||||
|
||||
// we return a "/" splitted string instead of an array with 2 keys, to reduce memory usage
|
||||
$formats[] = $ext.'/'.floor(filesize($test) / 1024);
|
||||
$formats[$ext] = floor(filesize($test) / 1024);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -537,62 +537,145 @@ SELECT id, path
|
||||
'info' => l10n('added')
|
||||
);
|
||||
|
||||
foreach ($fs[$path]['formats'] as $format)
|
||||
if ($conf['enable_formats'])
|
||||
{
|
||||
list($ext, $filesize) = explode('/', $format);
|
||||
foreach ($fs[$path]['formats'] as $ext => $filesize)
|
||||
{
|
||||
$insert_formats[] = array(
|
||||
'image_id' => $insert['id'],
|
||||
'ext' => $ext,
|
||||
'filesize' => $filesize,
|
||||
);
|
||||
|
||||
$insert_formats[] = array(
|
||||
'image_id' => $insert['id'],
|
||||
'ext' => $ext,
|
||||
'filesize' => $filesize,
|
||||
);
|
||||
|
||||
$infos[] = array(
|
||||
'path' => $insert['path'],
|
||||
'info' => l10n('format %s added', $ext)
|
||||
);
|
||||
$infos[] = array(
|
||||
'path' => $insert['path'],
|
||||
'info' => l10n('format %s added', $ext)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$caddiables[] = $insert['id'];
|
||||
}
|
||||
|
||||
if (count($inserts) > 0)
|
||||
// search new/removed formats on photos already registered in database
|
||||
if ($conf['enable_formats'])
|
||||
{
|
||||
if (!$simulate)
|
||||
$db_elements_flip = array_flip($db_elements);
|
||||
|
||||
$existing_ids = array();
|
||||
|
||||
foreach (array_intersect_key($fs, $db_elements_flip) as $path => $existing)
|
||||
{
|
||||
$existing_ids[] = $db_elements_flip[$path];
|
||||
}
|
||||
|
||||
$logger->debug('existing_ids', 'sync', $existing_ids);
|
||||
|
||||
if (count($existing_ids) > 0)
|
||||
{
|
||||
$db_formats = array();
|
||||
|
||||
// find formats for existing photos
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM '.IMAGE_FORMAT_TABLE.'
|
||||
WHERE image_id IN ('.implode(',', $existing_ids).')
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
if (!isset($db_formats[$row['image_id']]))
|
||||
{
|
||||
$db_formats[$row['image_id']] = array();
|
||||
}
|
||||
|
||||
$db_formats[$row['image_id']][$row['ext']] = $row['format_id'];
|
||||
}
|
||||
|
||||
$formats_to_delete = array();
|
||||
|
||||
foreach ($db_formats as $image_id => $formats)
|
||||
{
|
||||
$image_formats_to_delete = array_diff_key($formats, $fs[ $db_elements[$image_id] ]['formats']);
|
||||
$logger->debug('image_formats_to_delete', 'sync', $image_formats_to_delete);
|
||||
foreach ($image_formats_to_delete as $ext => $format_id)
|
||||
{
|
||||
$formats_to_delete[] = $format_id;
|
||||
|
||||
$infos[] = array(
|
||||
'path' => $db_elements[$image_id],
|
||||
'info' => l10n('format %s removed', $ext)
|
||||
);
|
||||
}
|
||||
|
||||
$image_formats_to_insert = array_diff_key($fs[ $db_elements[$image_id] ]['formats'], $formats);
|
||||
$logger->debug('image_formats_to_insert', 'sync', $image_formats_to_insert);
|
||||
foreach ($image_formats_to_insert as $ext => $filesize)
|
||||
{
|
||||
$insert_formats[] = array(
|
||||
'image_id' => $image_id,
|
||||
'ext' => $ext,
|
||||
'filesize' => $filesize,
|
||||
);
|
||||
|
||||
$infos[] = array(
|
||||
'path' => $db_elements[$image_id],
|
||||
'info' => l10n('format %s added', $ext)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$simulate)
|
||||
{
|
||||
// inserts all new elements
|
||||
if (count($inserts) > 0)
|
||||
{
|
||||
// inserts all new elements
|
||||
mass_inserts(
|
||||
IMAGES_TABLE,
|
||||
array_keys($inserts[0]),
|
||||
$inserts
|
||||
);
|
||||
|
||||
|
||||
// inserts all links between new elements and their storage category
|
||||
mass_inserts(
|
||||
IMAGE_CATEGORY_TABLE,
|
||||
array_keys($insert_links[0]),
|
||||
$insert_links
|
||||
);
|
||||
|
||||
// inserts all formats
|
||||
if (count($insert_formats) > 0)
|
||||
{
|
||||
mass_inserts(
|
||||
IMAGE_FORMAT_TABLE,
|
||||
array_keys($insert_formats[0]),
|
||||
$insert_formats
|
||||
);
|
||||
}
|
||||
|
||||
// add new photos to caddie
|
||||
if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
|
||||
{
|
||||
fill_caddie($caddiables);
|
||||
}
|
||||
}
|
||||
$counts['new_elements'] = count($inserts);
|
||||
|
||||
// inserts all formats
|
||||
if (count($insert_formats) > 0)
|
||||
{
|
||||
mass_inserts(
|
||||
IMAGE_FORMAT_TABLE,
|
||||
array_keys($insert_formats[0]),
|
||||
$insert_formats
|
||||
);
|
||||
}
|
||||
|
||||
if (count($formats_to_delete) > 0)
|
||||
{
|
||||
$query = '
|
||||
DELETE
|
||||
FROM '.IMAGE_FORMAT_TABLE.'
|
||||
WHERE format_id IN ('.implode(',', $formats_to_delete).')
|
||||
;';
|
||||
pwg_query($query);
|
||||
}
|
||||
|
||||
// add new photos to caddie
|
||||
if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
|
||||
{
|
||||
fill_caddie($caddiables);
|
||||
}
|
||||
}
|
||||
|
||||
$counts['new_elements'] = count($inserts);
|
||||
|
||||
// delete elements that are in database but not in the filesystem
|
||||
$to_delete_elements = array();
|
||||
foreach (array_diff($db_elements, array_keys($fs)) as $path)
|
||||
|
||||
@@ -63,6 +63,9 @@ $conf['file_ext'] = array_merge(
|
||||
array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf')
|
||||
);
|
||||
|
||||
// enable_formats: should Piwigo search for multiple formats?
|
||||
$conf['enable_formats'] = false;
|
||||
|
||||
// format_ext : file extensions for formats, ie additional versions of a
|
||||
// photo (or nay other file). Formats are in sub-directory pwg_format.
|
||||
$conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai');
|
||||
|
||||
Reference in New Issue
Block a user