Compare commits

..

12 Commits

Author SHA1 Message Date
Terranom674
ba0b5af417 Release 0.9.7.4 2026-08-19 21:12:39 +02:00
Terranom674
315af9641c Build only gallery derivative from WebDAV preview 2026-08-19 21:12:24 +02:00
Terranom674
77ae007a28 Merge pull request #25 from Terranom674/fix/0973-webdav-root-altimports
0.9.7.3: Altimporte aus WebDAV-Stammverzeichnis reparieren
2026-08-19 21:02:13 +02:00
Terranom674
e5be2b3043 Release 0.9.7.3 2026-08-19 21:01:26 +02:00
Terranom674
3fe9527537 Fix root WebDAV alt-import derivative detection 2026-08-19 21:01:00 +02:00
Terranom674
fb1f12d608 0.9.7.2: sichtbarer Abgleich und sicherer WebDAV-Import
0.9.7.2: sichtbarer Abgleich und sicherer WebDAV-Import
2026-08-19 20:53:28 +02:00
Terranom674
017cbdbd3b 0.9.7.2: private Alben nicht von öffentlichen Regeln erben lassen 2026-08-19 20:52:16 +02:00
Terranom674
9aaa1a47b3 0.9.7.2: WebDAV-Sync nicht-destruktiv machen 2026-08-19 20:51:23 +02:00
Terranom674
fc3d855e5e 0.9.7.2: Version anheben 2026-08-19 20:49:18 +02:00
Terranom674
4847d2ff11 0.9.7.2: aktuellen Schedulerstatus in Statuskarte spiegeln 2026-08-19 20:48:48 +02:00
Terranom674
0b405e9efb 0.9.7.2: Abgleich sofort als angefordert markieren 2026-08-19 20:48:25 +02:00
Terranom674
2c302b356d Merge pull request #23 from Terranom674/fix/0971-webdav-public-ip
0.9.7.1: WebDAV über öffentliche Ziel-IP
2026-08-19 20:43:19 +02:00
7 changed files with 136 additions and 79 deletions

View File

@@ -117,7 +117,10 @@ function bratonien_tools_nc_scheduler_spawn($force = false)
$state['enabled'] = true; $state['enabled'] = true;
$state['mode'] = 'piwigo-native'; $state['mode'] = 'piwigo-native';
$state['state'] = 'queued';
$state['message'] = 'NC-Abgleich wurde angefordert.';
$state['queued_at'] = $now; $state['queued_at'] = $now;
$state['timestamp'] = $now;
$state['next_due'] = $now + bratonien_tools_nc_scheduler_interval(); $state['next_due'] = $now + bratonien_tools_nc_scheduler_interval();
bratonien_tools_nc_scheduler_write_state($state); bratonien_tools_nc_scheduler_write_state($state);
@@ -136,10 +139,15 @@ function bratonien_tools_nc_scheduler_spawn($force = false)
if ($exit !== 0) if ($exit !== 0)
{ {
$state = bratonien_tools_nc_scheduler_read_state();
$state['state'] = 'error';
$state['message'] = 'Der native NC-Abgleich konnte nicht gestartet werden.';
$state['timestamp'] = time();
bratonien_tools_nc_scheduler_write_state($state);
throw new RuntimeException('Der native NC-Abgleich konnte nicht gestartet werden.'); throw new RuntimeException('Der native NC-Abgleich konnte nicht gestartet werden.');
} }
return array('started'=>true, 'message'=>'NC-Abgleich wurde gestartet.'); return array('started'=>true, 'message'=>'NC-Abgleich wurde angefordert.');
} }
function bratonien_tools_nc_scheduler_tick() function bratonien_tools_nc_scheduler_tick()

View File

@@ -67,7 +67,9 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
{ {
$scheduler = bratonien_tools_nc_scheduler_read_state(); $scheduler = bratonien_tools_nc_scheduler_read_state();
$enabled = !isset($scheduler['enabled']) || !empty($scheduler['enabled']); $enabled = !isset($scheduler['enabled']) || !empty($scheduler['enabled']);
$running = (string)($scheduler['state'] ?? '') === 'running'; $scheduler_state = (string)($scheduler['state'] ?? '');
$running = $scheduler_state === 'running';
$queued = $scheduler_state === 'queued';
$started = (int)($scheduler['started_at'] ?? 0); $started = (int)($scheduler['started_at'] ?? 0);
$next = (int)($scheduler['next_due'] ?? 0); $next = (int)($scheduler['next_due'] ?? 0);
$last = bratonien_tools_nc_connector_last_status($connections); $last = bratonien_tools_nc_connector_last_status($connections);
@@ -81,10 +83,23 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
$next_label = 'Beim nächsten Piwigo-Aufruf'; $next_label = 'Beim nächsten Piwigo-Aufruf';
} }
if ((int)$last['timestamp'] <= 0 && !empty($scheduler['finished_at'])) $scheduler_timestamp = (int)($scheduler['timestamp'] ?? 0);
if ($scheduler_timestamp > (int)$last['timestamp'])
{
$last['timestamp'] = $scheduler_timestamp;
$last['state'] = $scheduler_state;
$last['message'] = (string)($scheduler['message'] ?? '');
if ($scheduler_state === 'error')
{
$detail = trim((string)($scheduler['stderr'] ?? ''));
if ($detail === '') $detail = trim((string)($scheduler['stdout'] ?? ''));
$last['error_detail'] = $detail;
}
}
elseif ((int)$last['timestamp'] <= 0 && !empty($scheduler['finished_at']))
{ {
$last['timestamp'] = (int)$scheduler['finished_at']; $last['timestamp'] = (int)$scheduler['finished_at'];
$last['state'] = (string)($scheduler['state'] ?? ''); $last['state'] = $scheduler_state;
$last['message'] = (string)($scheduler['message'] ?? ''); $last['message'] = (string)($scheduler['message'] ?? '');
if ((string)$last['state'] === 'error') if ((string)$last['state'] === 'error')
{ {
@@ -94,13 +109,17 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
} }
} }
$current_label = 'Kein Lauf aktiv';
if ($queued) $current_label = 'Abgleich angefordert';
if ($running) $current_label = $started > 0 ? 'Läuft seit '.date('d.m.Y H:i:s', $started) : 'Läuft gerade';
return array( return array(
'timer_name'=>'Piwigo nativer NC-Scheduler', 'timer_name'=>'Piwigo nativer NC-Scheduler',
'timer_active'=>$enabled, 'timer_active'=>$enabled,
'timer_enabled'=>$enabled, 'timer_enabled'=>$enabled,
'service_active'=>$running, 'service_active'=>$running || $queued,
'current_run_timestamp'=>$started, 'current_run_timestamp'=>$queued ? (int)($scheduler['queued_at'] ?? 0) : $started,
'current_run_label'=>$running ? ($started > 0 ? 'Läuft seit '.date('d.m.Y H:i:s', $started) : 'Läuft gerade') : 'Kein Lauf aktiv', 'current_run_label'=>$current_label,
'last_run_timestamp'=>(int)$last['timestamp'], 'last_run_timestamp'=>(int)$last['timestamp'],
'last_run_label'=>(int)$last['timestamp'] > 0 ? date('d.m.Y H:i:s', (int)$last['timestamp']) : 'Nicht verfügbar', 'last_run_label'=>(int)$last['timestamp'] > 0 ? date('d.m.Y H:i:s', (int)$last['timestamp']) : 'Nicht verfügbar',
'last_run_state'=>(string)$last['state'], 'last_run_state'=>(string)$last['state'],

View File

@@ -56,7 +56,6 @@ function bratonien_tools_nc_find_album($parent_id, $dir, $name, $excluded_site_i
SELECT id, dir, name SELECT id, dir, name
FROM '.CATEGORIES_TABLE.' FROM '.CATEGORIES_TABLE.'
WHERE '.$where_parent.' WHERE '.$where_parent.'
AND (site_id IS NULL OR site_id <> '.(int)$excluded_site_id.')
AND ( AND (
dir = \''.$dir_sql.'\' dir = \''.$dir_sql.'\'
OR LOWER(name) = LOWER(\''.$name_sql.'\') OR LOWER(name) = LOWER(\''.$name_sql.'\')
@@ -122,10 +121,9 @@ function bratonien_tools_nc_managed_images($basedir)
function bratonien_tools_nc_remove_storage_categories($site_id) function bratonien_tools_nc_remove_storage_categories($site_id)
{ {
$ids = query2array('SELECT id FROM '.CATEGORIES_TABLE.' WHERE site_id='.(int)$site_id.' AND dir IS NOT NULL', null, 'id'); // Bestehende Piwigo-Alben gehoeren nicht automatisch dem Connector.
if (!$ids) return 0; // Ohne eindeutige Connector-Eigentumsmarkierung darf hier nichts geloescht werden.
delete_categories(array_map('intval', $ids)); return 0;
return count($ids);
} }
function bratonien_tools_ws_nc_sync_productive($params, &$service) function bratonien_tools_ws_nc_sync_productive($params, &$service)
@@ -169,8 +167,6 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
try try
{ {
$counts['removed_duplicate_categories'] = bratonien_tools_nc_remove_storage_categories($site_id);
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW()')); list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW()'));
$fs_dirs = $site_reader->get_full_directories($basedir); $fs_dirs = $site_reader->get_full_directories($basedir);
usort($fs_dirs, function($a, $b) usort($fs_dirs, function($a, $b)
@@ -199,20 +195,10 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
$db_elements = bratonien_tools_nc_managed_images($basedir); $db_elements = bratonien_tools_nc_managed_images($basedir);
$db_by_path = array_flip($db_elements); $db_by_path = array_flip($db_elements);
$to_delete = array(); // Nicht-destruktiver Schutz: Bestehende Piwigo-Bilder werden niemals allein
foreach ($db_elements as $id=>$path) // deshalb geloescht, weil sie im aktuellen WebDAV-Scan nicht vorkommen.
{ // Das Entfernen ist erst wieder zulaessig, wenn Connector-Eigentum eindeutig
if (!array_key_exists($path, $fs)) $to_delete[] = (int)$id; // und verbindungsbezogen gespeichert wird.
}
if ($to_delete)
{
delete_elements($to_delete, false);
$counts['del_elements'] = count($to_delete);
foreach ($to_delete as $id)
{
if (isset($db_elements[$id])) unset($db_by_path[$db_elements[$id]], $db_elements[$id]);
}
}
$next_element_id = pwg_db_nextval('id', IMAGES_TABLE); $next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
$image_inserts = array(); $image_inserts = array();
@@ -232,13 +218,9 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
if (isset($db_by_path[$path])) if (isset($db_by_path[$path]))
{ {
$id = (int)$db_by_path[$path]; // Altbestand niemals umhaengen. Vorhandene Bild-Album-Zuordnungen bleiben
$all_ids[] = $id; // exakt bestehen; der Connector darf nur neue Datensaetze ergaenzen.
pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id='.$id); $all_ids[] = (int)$db_by_path[$path];
if ($category_id !== null)
{
single_insert(IMAGE_CATEGORY_TABLE, array('image_id'=>$id, 'category_id'=>$category_id));
}
continue; continue;
} }
@@ -276,8 +258,10 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
$counts['new_elements'] = count($new_ids); $counts['new_elements'] = count($new_ids);
} }
// Bestehende Bilder werden nicht durch den Connector aktualisiert. Nur neu
// angelegte Connector-Bilder erhalten die aus der Quelle ermittelten Attribute.
$updates = array(); $updates = array();
foreach ($all_ids as $id) foreach ($new_ids as $id)
{ {
$path_result = pwg_query('SELECT path FROM '.IMAGES_TABLE.' WHERE id='.(int)$id.' LIMIT 1'); $path_result = pwg_query('SELECT path FROM '.IMAGES_TABLE.' WHERE id='.(int)$id.' LIMIT 1');
if (!pwg_db_num_rows($path_result)) continue; if (!pwg_db_num_rows($path_result)) continue;

View File

@@ -49,18 +49,21 @@ function bratonien_tools_webdav_image_source_info($image_id)
} }
$root_path = ''; $root_path = '';
$root_found = false;
$roots = isset($config['roots']) && is_array($config['roots']) ? $config['roots'] : array(); $roots = isset($config['roots']) && is_array($config['roots']) ? $config['roots'] : array();
foreach ($roots as $root) foreach ($roots as $root)
{ {
if ((int)($root['fileid'] ?? 0) === $root_fileid) if ((int)($root['fileid'] ?? 0) === $root_fileid)
{ {
$root_path = trim((string)($root['webdav_path'] ?? ''), '/'); $root_path = trim((string)($root['webdav_path'] ?? ''), '/');
$root_found = true;
break; break;
} }
} }
if ($root_path === '') return $cache[$image_id] = null; if (!$root_found) return $cache[$image_id] = null;
$webdav_path = $root_path.'/'.$relative_path; $root_is_base = $root_path === '';
$webdav_path = $root_is_base ? $relative_path : $root_path.'/'.$relative_path;
$content_type = ''; $content_type = '';
$size = 0; $size = 0;
$etag = ''; $etag = '';
@@ -90,6 +93,7 @@ function bratonien_tools_webdav_image_source_info($image_id)
'image_id'=>$image_id, 'image_id'=>$image_id,
'connection_id'=>$connection_id, 'connection_id'=>$connection_id,
'webdav_path'=>$webdav_path, 'webdav_path'=>$webdav_path,
'root_is_base'=>$root_is_base,
'content_type'=>$content_type, 'content_type'=>$content_type,
'size'=>$size, 'size'=>$size,
'etag'=>$etag, 'etag'=>$etag,
@@ -415,18 +419,21 @@ function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image,
$info = bratonien_tools_webdav_image_source_info((int)$src_image->id); $info = bratonien_tools_webdav_image_source_info((int)$src_image->id);
if (!$info) return $url; if (!$info) return $url;
try if (empty($info['root_is_base']))
{ {
$derivative = new DerivativeImage($params, $src_image); try
if (!$derivative->same_as_source())
{ {
$path = $derivative->get_path(); $derivative = new DerivativeImage($params, $src_image);
if ($path !== '' && is_file($path) && is_readable($path)) return $url; if (!$derivative->same_as_source())
{
$path = $derivative->get_path();
if ($path !== '' && is_file($path) && is_readable($path)) return $url;
}
}
catch (Throwable $e)
{
error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
} }
}
catch (Throwable $e)
{
error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
} }
$preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true); $preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true);

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: Bratonien Tools Plugin Name: Bratonien Tools
Version: 0.9.7.1 Version: 0.9.7.4
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation. Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
Author: Bratonien Author: Bratonien

View File

@@ -6,7 +6,7 @@ if (PHP_SAPI !== 'cli')
exit(1); exit(1);
} }
const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.6.1'; const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.7.4';
$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,12 +48,27 @@ if (!function_exists('bratonien_tools_webdav_image_source_info') || !function_ex
try try
{ {
$variants = bratonien_tools_webdav_derivative_variants(); $standard_gallery = ImageStdParams::get_by_type(IMG_THUMB);
if (!$variants) if (!$standard_gallery || !isset($standard_gallery->sizing->ideal_size))
{ {
throw new RuntimeException('Keine Piwigo-Derivate konfiguriert.'); throw new RuntimeException('Piwigo-Galeriederivat ist nicht konfiguriert.');
} }
// Only the gallery thumbnail is prebuilt. Keep the Piwigo target type/path,
// but never crop to the 1x1 placeholder geometry. The real Nextcloud
// preview dimensions determine the aspect ratio.
$gallery_params = clone $standard_gallery;
$gallery_params->sizing = new SizingParams(
array(
(int)$standard_gallery->sizing->ideal_size[0],
(int)$standard_gallery->sizing->ideal_size[1],
),
0,
null
);
$gallery_params->type = IMG_THUMB;
$gallery_params->use_watermark = false;
$images = 0; $images = 0;
$generated_or_ready = 0; $generated_or_ready = 0;
$identity = 0; $identity = 0;
@@ -109,34 +124,31 @@ try
} }
$src = new SrcImage($row); $src = new SrcImage($row);
foreach ($variants as $variant_name => $params) try
{ {
try $probe = new DerivativeImage($gallery_params, $src);
if ($probe->same_as_source())
{ {
$probe = new DerivativeImage($params, $src); $identity++;
if ($probe->same_as_source()) continue;
{
$identity++;
continue;
}
$detail = '';
if (bratonien_tools_webdav_generate_derivative($params, $src, $detail))
{
$generated_or_ready++;
}
else
{
$errors++;
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.($detail !== '' ? $detail : 'Derivat konnte nicht erzeugt werden.');
}
} }
catch (Throwable $e)
$detail = '';
if (bratonien_tools_webdav_generate_derivative($gallery_params, $src, $detail))
{
$generated_or_ready++;
}
else
{ {
$errors++; $errors++;
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.get_class($e).': '.$e->getMessage(); $error_lines[] = 'Bild #'.$image_id.' Galerie: '.($detail !== '' ? $detail : 'Galeriederivat konnte nicht erzeugt werden.');
} }
} }
catch (Throwable $e)
{
$errors++;
$error_lines[] = 'Bild #'.$image_id.' Galerie: '.get_class($e).': '.$e->getMessage();
}
} }
if ($metadata_repaired > 0) if ($metadata_repaired > 0)
@@ -159,7 +171,7 @@ try
echo 'WebDAV-Derivative-Builder: version='.BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION. echo 'WebDAV-Derivative-Builder: version='.BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION.
' bilder='.$images. ' bilder='.$images.
' varianten='.count($variants). ' varianten=1'.
' bereit='.$generated_or_ready. ' bereit='.$generated_or_ready.
' identisch='.$identity. ' identisch='.$identity.
' metadaten_repariert='.$metadata_repaired. ' metadaten_repariert='.$metadata_repaired.

View File

@@ -93,7 +93,37 @@ function bratonien_tools_resolve_album_rule($category_id, array $categories, arr
$by_id[(int)$category['id']] = $category; $by_id[(int)$category['id']] = $category;
} }
$current = (int)$category_id; $category_id = (int)$category_id;
$root = $by_id[$category_id] ?? null;
$is_private = $root && isset($root['status']) && $root['status'] === 'private';
// Privat ist eine Vererbungsgrenze. Eine direkt auf diesem privaten Album
// gesetzte Regel bleibt moeglich, aber Regeln oeffentlicher Eltern duerfen
// nicht in ein privates Album hineinvererbt werden.
if ($is_private)
{
if (isset($rules[$category_id]))
{
$rule = $rules[$category_id];
if ($rule['mode'] === 'disabled')
{
return array('mode'=>'disabled','profile_id'=>null,'source'=>'album');
}
if ($rule['mode'] === 'profile')
{
return array('mode'=>'profile','profile_id'=>(int)$rule['profile_id'],'source'=>'album');
}
}
$profile_id = $defaults['private_profile'] ?? null;
if (empty($profile_id))
{
return array('mode'=>'disabled','profile_id'=>null,'source'=>'global');
}
return array('mode'=>'profile','profile_id'=>(int)$profile_id,'source'=>'global');
}
$current = $category_id;
$visited = array(); $visited = array();
while ($current > 0 && isset($by_id[$current]) && !isset($visited[$current])) while ($current > 0 && isset($by_id[$current]) && !isset($visited[$current]))
@@ -116,10 +146,7 @@ function bratonien_tools_resolve_album_rule($category_id, array $categories, arr
$current = (int)($by_id[$current]['id_uppercat'] ?? 0); $current = (int)($by_id[$current]['id_uppercat'] ?? 0);
} }
$root = $by_id[(int)$category_id] ?? null; $profile_id = $defaults['public_profile'] ?? null;
$is_private = $root && isset($root['status']) && $root['status'] === 'private';
$profile_id = $is_private ? ($defaults['private_profile'] ?? null) : ($defaults['public_profile'] ?? null);
if (empty($profile_id)) if (empty($profile_id))
{ {
return array('mode'=>'disabled','profile_id'=>null,'source'=>'global'); return array('mode'=>'disabled','profile_id'=>null,'source'=>'global');