mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 15:14:34 +00:00
Build WebDAV derivatives with validated Piwigo image sources
This commit is contained in:
@@ -6,7 +6,7 @@ if (PHP_SAPI !== 'cli')
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.5.22';
|
const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.6.0';
|
||||||
|
|
||||||
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
||||||
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
||||||
@@ -48,8 +48,6 @@ if (!function_exists('bratonien_tools_webdav_image_source_info') || !function_ex
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
echo 'WebDAV-Derivative-Builder: '.BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION."\n";
|
|
||||||
|
|
||||||
$variants = bratonien_tools_webdav_derivative_variants();
|
$variants = bratonien_tools_webdav_derivative_variants();
|
||||||
if (!$variants)
|
if (!$variants)
|
||||||
{
|
{
|
||||||
@@ -57,10 +55,11 @@ try
|
|||||||
}
|
}
|
||||||
|
|
||||||
$images = 0;
|
$images = 0;
|
||||||
$generated = 0;
|
$generated_or_ready = 0;
|
||||||
$identity = 0;
|
$identity = 0;
|
||||||
$metadata_repaired = 0;
|
$metadata_repaired = 0;
|
||||||
$errors = 0;
|
$errors = 0;
|
||||||
|
$error_lines = array();
|
||||||
|
|
||||||
$result = pwg_query('SELECT * FROM '.IMAGES_TABLE.' ORDER BY id');
|
$result = pwg_query('SELECT * FROM '.IMAGES_TABLE.' ORDER BY id');
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
@@ -74,7 +73,15 @@ try
|
|||||||
if (!$preview)
|
if (!$preview)
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
fwrite(STDERR, 'Bild #'.$image_id.": vorbereitetes WebDAV-Preview fehlt.\n");
|
$error_lines[] = 'Bild #'.$image_id.': vorbereitetes WebDAV-Preview fehlt.';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$preview_ext = strtolower(pathinfo($preview, PATHINFO_EXTENSION));
|
||||||
|
if (!in_array($preview_ext, array('jpg', 'jpeg', 'png', 'gif'), true))
|
||||||
|
{
|
||||||
|
$errors++;
|
||||||
|
$error_lines[] = 'Bild #'.$image_id.': Preview-Format '.$preview_ext.' ist nicht Piwigo-kompatibel; Precache muss neu erzeugt werden.';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +89,7 @@ try
|
|||||||
if (!is_array($size) || empty($size[0]) || empty($size[1]))
|
if (!is_array($size) || empty($size[0]) || empty($size[1]))
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
fwrite(STDERR, 'Bild #'.$image_id.": Abmessungen des WebDAV-Previews konnten nicht gelesen werden.\n");
|
$error_lines[] = 'Bild #'.$image_id.': Preview ist kein lesbares Bild: '.$preview;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,20 +120,21 @@ try
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bratonien_tools_webdav_generate_derivative($params, $src))
|
$detail = '';
|
||||||
|
if (bratonien_tools_webdav_generate_derivative($params, $src, $detail))
|
||||||
{
|
{
|
||||||
$generated++;
|
$generated_or_ready++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
fwrite(STDERR, 'Bild #'.$image_id.' '.$variant_name.": Derivat konnte nicht erzeugt werden.\n");
|
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.($detail !== '' ? $detail : 'Derivat konnte nicht erzeugt werden.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
fwrite(STDERR, 'Bild #'.$image_id.' '.$variant_name.': '.$e->getMessage()."\n");
|
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.get_class($e).': '.$e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,16 +145,30 @@ try
|
|||||||
invalidate_user_cache(true);
|
invalidate_user_cache(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo 'WebDAV-Derivate: bilder='.$images.
|
if ($errors > 0)
|
||||||
|
{
|
||||||
|
foreach (array_slice($error_lines, 0, 30) as $line)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, $line."\n");
|
||||||
|
}
|
||||||
|
if (count($error_lines) > 30)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, 'Weitere Fehler: '.(count($error_lines) - 30)."\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo 'WebDAV-Derivative-Builder: version='.BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION.
|
||||||
|
' bilder='.$images.
|
||||||
' varianten='.count($variants).
|
' varianten='.count($variants).
|
||||||
' erzeugt='.$generated.
|
' bereit='.$generated_or_ready.
|
||||||
' identisch='.$identity.
|
' identisch='.$identity.
|
||||||
' metadaten_repariert='.$metadata_repaired.
|
' metadaten_repariert='.$metadata_repaired.
|
||||||
' fehler='.$errors."\n";
|
' fehler='.$errors."\n";
|
||||||
|
|
||||||
exit($errors > 0 ? 1 : 0);
|
exit($errors > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
fwrite(STDERR, 'WebDAV-Derivate: '.$e->getMessage()."\n");
|
fwrite(STDERR, 'WebDAV-Derivate: '.get_class($e).': '.$e->getMessage()."\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user