Compare commits

..
Author SHA1 Message Date
Terranom674 699c1494cc Disable automatic workflow triggers; manual runs only 2026-10-19 20:28:38 +02:00
5 changed files with 42 additions and 80 deletions

No files matched your search

+1 -9
View File
@@ -117,10 +117,7 @@ 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);
@@ -139,15 +136,10 @@ 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 angefordert.'); return array('started'=>true, 'message'=>'NC-Abgleich wurde gestartet.');
} }
function bratonien_tools_nc_scheduler_tick() function bratonien_tools_nc_scheduler_tick()
+6 -25
View File
@@ -67,9 +67,7 @@ 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']);
$scheduler_state = (string)($scheduler['state'] ?? ''); $running = (string)($scheduler['state'] ?? '') === 'running';
$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);
@@ -83,23 +81,10 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
$next_label = 'Beim nächsten Piwigo-Aufruf'; $next_label = 'Beim nächsten Piwigo-Aufruf';
} }
$scheduler_timestamp = (int)($scheduler['timestamp'] ?? 0); if ((int)$last['timestamp'] <= 0 && !empty($scheduler['finished_at']))
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'] = $scheduler_state; $last['state'] = (string)($scheduler['state'] ?? '');
$last['message'] = (string)($scheduler['message'] ?? ''); $last['message'] = (string)($scheduler['message'] ?? '');
if ((string)$last['state'] === 'error') if ((string)$last['state'] === 'error')
{ {
@@ -109,17 +94,13 @@ 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 || $queued, 'service_active'=>$running,
'current_run_timestamp'=>$queued ? (int)($scheduler['queued_at'] ?? 0) : $started, 'current_run_timestamp'=>$started,
'current_run_label'=>$current_label, 'current_run_label'=>$running ? ($started > 0 ? 'Läuft seit '.date('d.m.Y H:i:s', $started) : 'Läuft gerade') : 'Kein Lauf aktiv',
'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'],
+29 -13
View File
@@ -56,6 +56,7 @@ 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.'\')
@@ -121,9 +122,10 @@ 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)
{ {
// Bestehende Piwigo-Alben gehoeren nicht automatisch dem Connector. $ids = query2array('SELECT id FROM '.CATEGORIES_TABLE.' WHERE site_id='.(int)$site_id.' AND dir IS NOT NULL', null, 'id');
// Ohne eindeutige Connector-Eigentumsmarkierung darf hier nichts geloescht werden. if (!$ids) return 0;
return 0; delete_categories(array_map('intval', $ids));
return count($ids);
} }
function bratonien_tools_ws_nc_sync_productive($params, &$service) function bratonien_tools_ws_nc_sync_productive($params, &$service)
@@ -167,6 +169,8 @@ 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)
@@ -195,10 +199,20 @@ 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);
// Nicht-destruktiver Schutz: Bestehende Piwigo-Bilder werden niemals allein $to_delete = array();
// deshalb geloescht, weil sie im aktuellen WebDAV-Scan nicht vorkommen. foreach ($db_elements as $id=>$path)
// Das Entfernen ist erst wieder zulaessig, wenn Connector-Eigentum eindeutig {
// und verbindungsbezogen gespeichert wird. if (!array_key_exists($path, $fs)) $to_delete[] = (int)$id;
}
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();
@@ -218,9 +232,13 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
if (isset($db_by_path[$path])) if (isset($db_by_path[$path]))
{ {
// Altbestand niemals umhaengen. Vorhandene Bild-Album-Zuordnungen bleiben $id = (int)$db_by_path[$path];
// exakt bestehen; der Connector darf nur neue Datensaetze ergaenzen. $all_ids[] = $id;
$all_ids[] = (int)$db_by_path[$path]; pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id='.$id);
if ($category_id !== null)
{
single_insert(IMAGE_CATEGORY_TABLE, array('image_id'=>$id, 'category_id'=>$category_id));
}
continue; continue;
} }
@@ -258,10 +276,8 @@ 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 ($new_ids as $id) foreach ($all_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;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: Bratonien Tools Plugin Name: Bratonien Tools
Version: 0.9.7.2 Version: 0.9.7.1
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
+5 -32
View File
@@ -93,37 +93,7 @@ function bratonien_tools_resolve_album_rule($category_id, array $categories, arr
$by_id[(int)$category['id']] = $category; $by_id[(int)$category['id']] = $category;
} }
$category_id = (int)$category_id; $current = (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]))
@@ -146,7 +116,10 @@ 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);
} }
$profile_id = $defaults['public_profile'] ?? null; $root = $by_id[(int)$category_id] ?? 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');