Compare commits

..

10 Commits

Author SHA1 Message Date
Terranom674
8510d9faad 0.9.7.25: Piwigo-Core-Synchronisation wiederherstellen 2026-08-20 09:12:01 +02:00
Terranom674
f21f19bd30 Merge pull request #46 from Terranom674/fix/09724-native-ajaxload-placeholder
0.9.7.24: Piwigo-Nachladen für WebDAV-Platzhalter reparieren
2026-08-20 09:02:33 +02:00
Terranom674
29990aee4f 0.9.7.24: Version anheben 2026-08-20 09:00:53 +02:00
Terranom674
9c551c8dfc 0.9.7.24: Piwigo ajaxload fuer WebDAV-Platzhalter bedienen 2026-08-20 09:00:36 +02:00
Terranom674
e5bc260622 Merge pull request #45 from Terranom674/fix/09723-visible-run-status
0.9.7.23: Abgleich sichtbar ausführen und Fehlerdetails anzeigen
2026-08-20 08:34:32 +02:00
Terranom674
5b883706c7 0.9.7.23: Version anheben 2026-08-20 08:33:27 +02:00
Terranom674
66f463422e 0.9.7.23: Konkrete Shadow-Tree-Fehler in Diagnose übernehmen 2026-08-20 08:32:51 +02:00
Terranom674
df9e9e6424 0.9.7.23: Verbindungsbezogenen Live-Status bereitstellen 2026-08-20 08:32:23 +02:00
Terranom674
26b602783f 0.9.7.23: Abgleich sichtbar und ohne Seitenreload ausführen 2026-08-20 08:32:04 +02:00
Terranom674
ae1b47c4c4 Merge pull request #44 from Terranom674/fix/09722-placeholder-dimension-fallback
0.9.7.22: Originalmaße robust aus Nextcloud übernehmen
2026-08-20 08:24:54 +02:00
6 changed files with 344 additions and 440 deletions

View File

@@ -18,7 +18,7 @@ function bratonien_tools_register_nc_productive_ws_methods($arr)
'info' => 'Piwigo storage site to synchronize. Default: 1.', 'info' => 'Piwigo storage site to synchronize. Default: 1.',
), ),
), ),
'Runs the approved direct Bratonien filesystem synchronization for the NC Connector.', 'Runs the approved Piwigo filesystem synchronization for the Bratonien NC Connector.',
null, null,
array( array(
'admin_only' => true, 'admin_only' => true,
@@ -27,17 +27,9 @@ function bratonien_tools_register_nc_productive_ws_methods($arr)
); );
} }
function bratonien_tools_nc_productive_error(&$errors, $path, $type)
{
$errors[] = array(
'path' => (string)$path,
'type' => (string)$type,
);
}
function bratonien_tools_ws_nc_sync_productive($params, &$service) function bratonien_tools_ws_nc_sync_productive($params, &$service)
{ {
global $conf, $user; global $conf, $user, $template, $page;
$piwigo_version = defined('PHPWG_VERSION') ? (string)PHPWG_VERSION : ''; $piwigo_version = defined('PHPWG_VERSION') ? (string)PHPWG_VERSION : '';
if ($piwigo_version !== '16.4.0') if ($piwigo_version !== '16.4.0')
@@ -59,385 +51,92 @@ function bratonien_tools_ws_nc_sync_productive($params, &$service)
return new PwgError(400, 'Invalid site_id.'); return new PwgError(400, 'Invalid site_id.');
} }
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); $saved_get = $_GET;
include_once(PHPWG_ROOT_PATH.'admin/site_reader_local.php'); $saved_post = $_POST;
$saved_request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null;
$query = 'SELECT galleries_url FROM '.SITES_TABLE.' WHERE id = '.$site_id.' LIMIT 1'; $saved_default_status = isset($conf['newcat_default_status']) ? $conf['newcat_default_status'] : null;
$result = pwg_query($query); $saved_template_dirs = null;
if (!pwg_db_num_rows($result)) $output = '';
{ $counts = array();
return new PwgError(404, 'Piwigo site does not exist.');
}
list($site_url) = pwg_db_fetch_row($result);
if (url_is_remote($site_url))
{
return new PwgError(400, 'Remote Piwigo sites are not supported by this synchronization method.');
}
$site_reader = new LocalSiteReader($site_url);
if (!$site_reader->open())
{
return new PwgError(500, 'Piwigo could not open the configured local site.');
}
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW()'));
$errors = array();
$counts = array(
'new_categories' => 0,
'del_categories' => 0,
'new_elements' => 0,
'del_elements' => 0,
'upd_elements' => 0,
'new_formats' => 0,
'del_formats' => 0,
'metadata_candidates' => 0,
'metadata_updated' => 0,
);
try try
{ {
$query = 'SELECT id, id_uppercat, uppercats, global_rank, status, visible FROM '.CATEGORIES_TABLE.' WHERE dir IS NOT NULL AND site_id = '.$site_id; if (!defined('IN_ADMIN'))
$db_categories = hash_from_query($query, 'id');
$db_fulldirs = get_fulldirs(array_keys($db_categories));
$basedir = preg_replace('#/*$#', '', $site_url);
$db_fulldirs = array_flip($db_fulldirs);
$fs_fulldirs = $site_reader->get_full_directories($basedir);
$next_rank = array('NULL'=>1);
$result = pwg_query('SELECT id FROM '.CATEGORIES_TABLE);
while ($row = pwg_db_fetch_assoc($result))
{ {
$next_rank[$row['id']] = 1; define('IN_ADMIN', true);
}
$result = pwg_query('SELECT id_uppercat, MAX(`rank`)+1 AS next_rank FROM '.CATEGORIES_TABLE.' GROUP BY id_uppercat');
while ($row = pwg_db_fetch_assoc($result))
{
$key = empty($row['id_uppercat']) ? 'NULL' : $row['id_uppercat'];
$next_rank[$key] = (int)$row['next_rank'];
} }
$next_id = pwg_db_nextval('id', CATEGORIES_TABLE); if (is_object($template) && isset($template->smarty) && method_exists($template, 'set_template_dir'))
$category_inserts = array();
foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
{ {
$dir = basename($fulldir); $saved_template_dirs = $template->smarty->getTemplateDir();
if (!preg_match($conf['sync_chars_regex'], $dir)) $template->set_template_dir(PHPWG_ROOT_PATH.'admin/themes/default/template');
{
bratonien_tools_nc_productive_error($errors, $fulldir, 'PWG-UPDATE-1');
continue;
}
$insert = array(
'id' => $next_id++,
'dir' => $dir,
'name' => str_replace('_', ' ', $dir),
'site_id' => $site_id,
'commentable' => boolean_to_string($conf['newcat_default_commentable']),
'status' => 'private',
'visible' => boolean_to_string($conf['newcat_default_visible']),
);
$parent_path = dirname($fulldir);
if (isset($db_fulldirs[$parent_path]))
{
$parent = $db_fulldirs[$parent_path];
$insert['id_uppercat'] = $parent;
$insert['uppercats'] = $db_categories[$parent]['uppercats'].','.$insert['id'];
$insert['rank'] = $next_rank[$parent]++;
$insert['global_rank'] = $db_categories[$parent]['global_rank'].'.'.$insert['rank'];
if ((string)$db_categories[$parent]['visible'] === 'false')
{
$insert['visible'] = 'false';
}
}
else
{
$insert['uppercats'] = (string)$insert['id'];
$insert['rank'] = $next_rank['NULL']++;
$insert['global_rank'] = (string)$insert['rank'];
}
$category_inserts[] = $insert;
$db_categories[$insert['id']] = array(
'id' => $insert['id'],
'id_uppercat' => $insert['id_uppercat'] ?? null,
'uppercats' => $insert['uppercats'],
'global_rank' => $insert['global_rank'],
'status' => 'private',
'visible' => $insert['visible'],
);
$db_fulldirs[$fulldir] = $insert['id'];
$next_rank[$insert['id']] = 1;
} }
if ($category_inserts) $conf['newcat_default_status'] = 'private';
{ $_SERVER['REQUEST_METHOD'] = 'POST';
mass_inserts( $_GET = array(
CATEGORIES_TABLE, 'page' => 'site_update',
array('id','dir','name','site_id','id_uppercat','uppercats','commentable','visible','status','rank','global_rank'), 'site' => $site_id,
$category_inserts );
); $_POST = array(
$category_ids = array_map(function ($row) { return (int)$row['id']; }, $category_inserts); 'sync' => 'files',
pwg_activity('album', $category_ids, 'add', array('sync'=>true)); 'display_info' => 1,
add_permission_on_category($category_ids, get_admins()); 'privacy_level' => 0,
$counts['new_categories'] = count($category_ids); 'sync_meta' => 1,
} 'simulate' => 0,
'subcats-included' => 1,
'bratonien_connector' => 1,
'submit' => 1,
);
$to_delete_categories = array(); ob_start();
foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir) include(PHPWG_ROOT_PATH.'admin/site_update.php');
{ $output = (string)ob_get_clean();
$to_delete_categories[] = (int)$db_fulldirs[$fulldir];
unset($db_fulldirs[$fulldir]);
}
if ($to_delete_categories)
{
delete_categories($to_delete_categories);
$counts['del_categories'] = count($to_delete_categories);
}
$fs = $site_reader->get_elements($basedir);
$cat_ids = array_diff(array_keys($db_categories), $to_delete_categories);
$db_elements = array();
if ($cat_ids)
{
$query = 'SELECT id, path FROM '.IMAGES_TABLE.' WHERE storage_category_id IN ('.implode(',', array_map('intval', $cat_ids)).')';
$db_elements = simple_hash_from_query($query, 'id', 'path');
}
$next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
$image_inserts = array();
$image_links = array();
$format_inserts = array();
$new_image_ids = array();
foreach (array_diff(array_keys($fs), $db_elements) as $path)
{
$dirname = dirname($path);
if (!isset($db_fulldirs[$dirname]))
{
continue;
}
$filename = basename($path);
if (!preg_match($conf['sync_chars_regex'], $filename))
{
bratonien_tools_nc_productive_error($errors, $path, 'PWG-UPDATE-1');
continue;
}
$id = $next_element_id++;
$image_inserts[] = array(
'id' => $id,
'file' => $filename,
'name' => get_name_from_file($filename),
'date_available' => $dbnow,
'path' => $path,
'representative_ext' => $fs[$path]['representative_ext'],
'storage_category_id' => $db_fulldirs[$dirname],
'added_by' => (int)$user['id'],
);
$image_links[] = array('image_id'=>$id, 'category_id'=>$db_fulldirs[$dirname]);
$new_image_ids[] = $id;
if (!empty($conf['enable_formats']) && !empty($fs[$path]['formats']))
{
foreach ($fs[$path]['formats'] as $ext => $filesize)
{
$format_inserts[] = array('image_id'=>$id, 'ext'=>$ext, 'filesize'=>$filesize);
}
}
}
if ($image_inserts)
{
mass_inserts(IMAGES_TABLE, array_keys($image_inserts[0]), $image_inserts);
mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($image_links[0]), $image_links);
pwg_activity('photo', $new_image_ids, 'add', array('sync'=>true));
$counts['new_elements'] = count($image_inserts);
}
if ($format_inserts)
{
mass_inserts(IMAGE_FORMAT_TABLE, array_keys($format_inserts[0]), $format_inserts);
$counts['new_formats'] += count($format_inserts);
}
if (!empty($conf['enable_formats']) && $db_elements)
{
$db_elements_flip = array_flip($db_elements);
$existing_ids = array();
foreach (array_intersect_key($fs, $db_elements_flip) as $path => $unused)
{
$existing_ids[] = (int)$db_elements_flip[$path];
}
if ($existing_ids)
{
$db_formats = array();
$result = pwg_query('SELECT * FROM '.IMAGE_FORMAT_TABLE.' WHERE image_id IN ('.implode(',', $existing_ids).')');
while ($row = pwg_db_fetch_assoc($result))
{
$db_formats[$row['image_id']][$row['ext']] = $row['format_id'];
}
$formats_to_delete = array();
$formats_to_insert = array();
foreach ($existing_ids as $image_id)
{
$path = $db_elements[$image_id];
$known = $db_formats[$image_id] ?? array();
$present = $fs[$path]['formats'] ?? array();
foreach (array_diff_key($known, $present) as $format_id)
{
$formats_to_delete[] = (int)$format_id;
}
foreach (array_diff_key($present, $known) as $ext => $filesize)
{
$formats_to_insert[] = array('image_id'=>$image_id, 'ext'=>$ext, 'filesize'=>$filesize);
}
}
if ($formats_to_delete)
{
pwg_query('DELETE FROM '.IMAGE_FORMAT_TABLE.' WHERE format_id IN ('.implode(',', $formats_to_delete).')');
$counts['del_formats'] = count($formats_to_delete);
}
if ($formats_to_insert)
{
mass_inserts(IMAGE_FORMAT_TABLE, array_keys($formats_to_insert[0]), $formats_to_insert);
$counts['new_formats'] += count($formats_to_insert);
}
}
}
$to_delete_elements = array();
foreach (array_diff($db_elements, array_keys($fs)) as $path)
{
$id = array_search($path, $db_elements, true);
if ($id !== false)
{
$to_delete_elements[] = (int)$id;
}
}
if ($to_delete_elements)
{
delete_elements($to_delete_elements);
$counts['del_elements'] = count($to_delete_elements);
}
update_category('all');
update_global_rank();
$files = get_filelist('', $site_id, true, false);
$updates = array();
foreach ($files as $id => $file)
{
$data = $site_reader->get_element_update_attributes($file['path']);
if (!is_array($data))
{
continue;
}
$data['id'] = $id;
$updates[] = $data;
}
if ($updates)
{
mass_updates(
IMAGES_TABLE,
array('primary'=>array('id'), 'update'=>$site_reader->get_update_attributes()),
$updates
);
}
$counts['upd_elements'] = count($updates);
$metadata_files = get_filelist('', $site_id, true, true);
$counts['metadata_candidates'] = count($metadata_files);
$metadata_updates = array();
$tags_of = array();
foreach ($metadata_files as $id => $element_infos)
{
$data = $site_reader->get_element_metadata($element_infos);
if (!is_array($data))
{
bratonien_tools_nc_productive_error($errors, $element_infos['path'], 'PWG-ERROR-NO-FS');
continue;
}
$data['date_metadata_update'] = $dbnow;
$data['id'] = $id;
$metadata_updates[] = $data;
foreach (array('keywords','tags') as $key)
{
if (!isset($data[$key]))
{
continue;
}
$tags_of[$id] = $tags_of[$id] ?? array();
foreach (explode(',', $data[$key]) as $tag_name)
{
$tags_of[$id][] = tag_id_from_tag_name($tag_name);
}
}
}
if ($metadata_updates)
{
mass_updates(
IMAGES_TABLE,
array(
'primary'=>array('id'),
'update'=>array_unique(array_merge(
array_diff($site_reader->get_metadata_attributes(), array('keywords','tags')),
array('date_metadata_update')
)),
),
$metadata_updates,
MASS_UPDATES_SKIP_EMPTY
);
}
if ($tags_of)
{
set_tags_of($tags_of);
}
$counts['metadata_updated'] = count($metadata_updates);
// Mirror Piwigo 16.4.0 Maintenance -> "Update albums informations".
// This repairs the derived album hierarchy and counters that the direct
// API sync otherwise bypasses when no admin maintenance page is invoked.
images_integrity();
categories_integrity();
update_uppercats();
update_category('all');
update_global_rank();
invalidate_user_cache(true);
// Mirror Piwigo 16.4.0 Maintenance -> "Update photos information".
// This finalizes physical paths, ratings and derived photo information.
images_integrity();
update_path();
include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
update_rating_score();
invalidate_user_cache();
} }
catch (Throwable $e) catch (Throwable $e)
{ {
return new PwgError(500, 'Bratonien direct synchronization failed: '.$e->getMessage()); if (ob_get_level() > 0)
{
ob_end_clean();
}
return new PwgError(500, 'Piwigo core synchronization failed: '.$e->getMessage());
}
finally
{
$_GET = $saved_get;
$_POST = $saved_post;
if ($saved_template_dirs !== null && is_object($template) && isset($template->smarty))
{
$template->smarty->setTemplateDir($saved_template_dirs);
}
if ($saved_default_status === null)
{
unset($conf['newcat_default_status']);
}
else
{
$conf['newcat_default_status'] = $saved_default_status;
}
if ($saved_request_method === null)
{
unset($_SERVER['REQUEST_METHOD']);
}
else
{
$_SERVER['REQUEST_METHOD'] = $saved_request_method;
}
} }
return array( return array(
'mode' => 'productive', 'mode' => 'productive',
'engine' => 'bratonien-direct',
'approved_piwigo_version' => '16.4.0', 'approved_piwigo_version' => '16.4.0',
'piwigo_version' => $piwigo_version, 'piwigo_version' => $piwigo_version,
'site_id' => $site_id, 'site_id' => $site_id,
'site_url' => $site_url, 'counts' => is_array($counts) ? $counts : array(),
'counts' => $counts,
'errors' => $errors,
'error_count' => count($errors),
'database_writes' => true, 'database_writes' => true,
'core_output_bytes' => strlen($output),
'username' => isset($user['username']) ? (string)$user['username'] : '', 'username' => isset($user['username']) ? (string)$user['username'] : '',
'status' => isset($user['status']) ? (string)$user['status'] : '', 'status' => isset($user['status']) ? (string)$user['status'] : '',
); );

View File

@@ -1,6 +1,134 @@
(function () { (function () {
'use strict'; 'use strict';
var statusEndpoint = 'plugins/bratonien_tools/nc-connector-status.php';
function ensureLiveStatus(detail, actions) {
var node = detail.querySelector('[data-nc-run-live]');
if (node) return node;
node = document.createElement('div');
node.setAttribute('data-nc-run-live', '1');
node.className = 'bratonien-base-note';
node.style.marginTop = '.6rem';
node.hidden = true;
actions.parentNode.insertBefore(node, actions.nextSibling);
return node;
}
function renderLiveStatus(node, data) {
var state = String(data && data.state || '');
var message = String(data && data.message || '');
var detail = String(data && data.error_detail || '');
node.hidden = false;
node.innerHTML = '';
var strong = document.createElement('strong');
if (state === 'queued') strong.textContent = 'Angefordert: ';
else if (state === 'running') strong.textContent = 'Läuft: ';
else if (state === 'ok' || state === 'success') strong.textContent = 'Erfolgreich: ';
else if (state === 'error') strong.textContent = 'Fehler: ';
else strong.textContent = 'Status: ';
node.appendChild(strong);
node.appendChild(document.createTextNode(message || state || 'Status wird ermittelt …'));
if (detail) {
var details = document.createElement('details');
details.style.marginTop = '.35rem';
var summary = document.createElement('summary');
summary.textContent = 'Technische Laufzeitdetails';
var pre = document.createElement('pre');
pre.style.whiteSpace = 'pre-wrap';
pre.style.wordBreak = 'break-word';
pre.textContent = detail;
details.appendChild(summary);
details.appendChild(pre);
node.appendChild(details);
}
}
function pollConnection(connectionId, node, button) {
var attempts = 0;
var maxAttempts = 180;
var timer = null;
function stop() {
if (timer) window.clearInterval(timer);
timer = null;
if (button) {
button.disabled = false;
button.textContent = 'Jetzt abgleichen';
}
}
function poll() {
attempts += 1;
fetch(statusEndpoint + '?connection_id=' + encodeURIComponent(connectionId) + '&_=' + Date.now(), {
credentials: 'same-origin',
cache: 'no-store',
headers: {'Accept': 'application/json'}
})
.then(function (response) {
if (!response.ok) throw new Error('HTTP ' + response.status);
return response.json();
})
.then(function (data) {
renderLiveStatus(node, data);
var state = String(data && data.state || '');
if (state === 'ok' || state === 'success' || state === 'error' || attempts >= maxAttempts) stop();
})
.catch(function (error) {
if (attempts >= maxAttempts) {
renderLiveStatus(node, {state: 'error', message: 'Status konnte nicht gelesen werden.', error_detail: error.message});
stop();
}
});
}
poll();
timer = window.setInterval(poll, 1000);
}
function bindRunNow(form, detail, liveNode) {
if (form.dataset.ncRunBound === '1') return;
form.dataset.ncRunBound = '1';
form.addEventListener('submit', function (event) {
event.preventDefault();
detail.open = true;
var button = form.querySelector('button[value="nc_connector_run_now"]');
var connectionInput = form.querySelector('input[name="connection_id"]');
if (!connectionInput) return;
if (button) {
button.disabled = true;
button.textContent = 'Abgleich wird gestartet …';
}
renderLiveStatus(liveNode, {state: 'queued', message: 'Abgleich wird angefordert …'});
fetch(form.action || window.location.href, {
method: 'POST',
credentials: 'same-origin',
cache: 'no-store',
body: new FormData(form)
})
.then(function (response) {
if (!response.ok) throw new Error('HTTP ' + response.status);
renderLiveStatus(liveNode, {state: 'queued', message: 'Abgleich wurde angefordert.'});
pollConnection(connectionInput.value, liveNode, button);
})
.catch(function (error) {
renderLiveStatus(liveNode, {state: 'error', message: 'Abgleich konnte nicht angefordert werden.', error_detail: error.message});
if (button) {
button.disabled = false;
button.textContent = 'Jetzt abgleichen';
}
});
});
}
function restoreRunNowButtons() { function restoreRunNowButtons() {
var section = document.getElementById('nc-connector'); var section = document.getElementById('nc-connector');
if (!section) return; if (!section) return;
@@ -18,36 +146,42 @@
var details = connectionCard.querySelectorAll(':scope > details'); var details = connectionCard.querySelectorAll(':scope > details');
details.forEach(function (detail) { details.forEach(function (detail) {
var actions = detail.querySelector('.bratonien-actions'); var actions = detail.querySelector('.bratonien-actions');
if (!actions || actions.querySelector('[value="nc_connector_run_now"]')) return; if (!actions) return;
var connectionInput = detail.querySelector('input[name="connection_id"]'); var connectionInput = detail.querySelector('input[name="connection_id"]');
var tokenInput = detail.querySelector('input[name="pwg_token"]'); var tokenInput = detail.querySelector('input[name="pwg_token"]');
if (!connectionInput || !tokenInput) return; if (!connectionInput || !tokenInput) return;
var form = document.createElement('form'); var form = actions.querySelector('form[data-nc-run-now]');
form.method = 'post'; if (!form) {
form = document.createElement('form');
form.method = 'post';
form.setAttribute('data-nc-run-now', '1');
var token = document.createElement('input'); var token = document.createElement('input');
token.type = 'hidden'; token.type = 'hidden';
token.name = 'pwg_token'; token.name = 'pwg_token';
token.value = tokenInput.value; token.value = tokenInput.value;
form.appendChild(token); form.appendChild(token);
var connection = document.createElement('input'); var connection = document.createElement('input');
connection.type = 'hidden'; connection.type = 'hidden';
connection.name = 'connection_id'; connection.name = 'connection_id';
connection.value = connectionInput.value; connection.value = connectionInput.value;
form.appendChild(connection); form.appendChild(connection);
var button = document.createElement('button'); var button = document.createElement('button');
button.className = 'buttonLike'; button.className = 'buttonLike';
button.type = 'submit'; button.type = 'submit';
button.name = 'bratonien_tool'; button.name = 'bratonien_tool';
button.value = 'nc_connector_run_now'; button.value = 'nc_connector_run_now';
button.textContent = 'Jetzt abgleichen'; button.textContent = 'Jetzt abgleichen';
form.appendChild(button); form.appendChild(button);
actions.insertBefore(form, actions.firstChild); actions.insertBefore(form, actions.firstChild);
}
bindRunNow(form, detail, ensureLiveStatus(detail, actions));
}); });
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: Bratonien Tools Plugin Name: Bratonien Tools
Version: 0.9.7.22 Version: 0.9.7.24
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

@@ -24,6 +24,7 @@ if (!function_exists('is_admin') || !is_admin())
exit; exit;
} }
$requested_connection_id = isset($_GET['connection_id']) ? max(0, (int)$_GET['connection_id']) : 0;
$dir = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status'; $dir = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status';
$latest = array( $latest = array(
'state'=>'idle', 'state'=>'idle',
@@ -41,11 +42,16 @@ $latest = array(
'route_timestamp'=>0, 'route_timestamp'=>0,
'route_time_label'=>'Nicht verfügbar', 'route_time_label'=>'Nicht verfügbar',
'route_detail'=>'', 'route_detail'=>'',
'connection_id'=>$requested_connection_id,
); );
if (is_dir($dir)) if (is_dir($dir))
{ {
foreach (glob($dir.'/connection-*.json') ?: array() as $file) $files = $requested_connection_id > 0
? array($dir.'/connection-'.$requested_connection_id.'.json')
: (glob($dir.'/connection-*.json') ?: array());
foreach ($files as $file)
{ {
if (!is_readable($file)) if (!is_readable($file))
{ {
@@ -63,60 +69,58 @@ if (is_dir($dir))
} }
} }
$route_file = $dir.'/route-status.json'; if ($requested_connection_id === 0)
if (is_readable($route_file))
{ {
$route = json_decode((string)@file_get_contents($route_file), true); $route_file = $dir.'/route-status.json';
if (is_array($route)) if (is_readable($route_file))
{ {
$route_name = (string)($route['route'] ?? ''); $route = json_decode((string)@file_get_contents($route_file), true);
$route_timestamp = (int)($route['timestamp'] ?? 0); if (is_array($route))
$route_label = (string)($route['label'] ?? ''); {
$route_name = (string)($route['route'] ?? '');
$route_timestamp = (int)($route['timestamp'] ?? 0);
$route_label = (string)($route['label'] ?? '');
if ($route_name === 'webdav') if ($route_name === 'webdav')
{ {
$route_label = 'WEBDAV PRIMÄR'; $route_label = 'WEBDAV PRIMÄR';
} }
elseif ($route_name === 'legacy_fallback') elseif ($route_name === 'legacy_fallback')
{ {
$route_label = 'LEGACY-FALLBACK AKTIV'; $route_label = 'LEGACY-FALLBACK AKTIV';
} }
elseif ($route_name === 'failed') elseif ($route_name === 'failed')
{ {
$route_label = 'FEHLER - KEIN ERFOLGREICHER DATENWEG'; $route_label = 'FEHLER - KEIN ERFOLGREICHER DATENWEG';
} }
elseif ($route_label === '') elseif ($route_label === '')
{ {
$route_label = 'UNBEKANNTER DATENWEG'; $route_label = 'UNBEKANNTER DATENWEG';
} }
$route_detail = trim((string)($route['detail'] ?? '')); $route_detail = trim((string)($route['detail'] ?? ''));
$latest['route'] = $route_name; $latest['route'] = $route_name;
$latest['route_label'] = $route_label; $latest['route_label'] = $route_label;
$latest['route_timestamp'] = $route_timestamp; $latest['route_timestamp'] = $route_timestamp;
$latest['route_time_label'] = $route_timestamp > 0 ? date('d.m.Y H:i:s', $route_timestamp) : 'Nicht verfügbar'; $latest['route_time_label'] = $route_timestamp > 0 ? date('d.m.Y H:i:s', $route_timestamp) : 'Nicht verfügbar';
$latest['route_detail'] = $route_detail; $latest['route_detail'] = $route_detail;
$base_message = trim((string)($latest['message'] ?? '')); $base_message = trim((string)($latest['message'] ?? ''));
$message_parts = array($route_label); $message_parts = array($route_label);
if ($route_name !== 'webdav' && $route_detail !== '') if ($route_name !== 'webdav' && $route_detail !== '')
{ {
$message_parts[] = $route_detail; $message_parts[] = $route_detail;
}
if ($base_message !== '')
{
$message_parts[] = $base_message;
}
$latest['message'] = implode(' · ', $message_parts);
} }
if ($base_message !== '')
{
$message_parts[] = $base_message;
}
$latest['message'] = implode(' · ', $message_parts);
} }
} }
} }
if ((int)$latest['timestamp'] > 0)
{
$latest['last_run_label'] = date('d.m.Y H:i:s', (int)$latest['timestamp']);
}
$system_file = BRATONIEN_TOOLS_PATH.'include/nc_connector_system.inc.php'; $system_file = BRATONIEN_TOOLS_PATH.'include/nc_connector_system.inc.php';
if (is_readable($system_file)) if (is_readable($system_file))
{ {
@@ -129,4 +133,27 @@ if (is_readable($system_file))
} }
} }
$scheduler_file = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-scheduler/state.json';
if ($requested_connection_id > 0 && is_readable($scheduler_file))
{
$scheduler = json_decode((string)@file_get_contents($scheduler_file), true);
if (
is_array($scheduler)
&& (int)($scheduler['connection_id'] ?? 0) === $requested_connection_id
&& in_array((string)($scheduler['state'] ?? ''), array('queued','running'), true)
&& (int)($scheduler['timestamp'] ?? 0) >= (int)($latest['timestamp'] ?? 0)
)
{
$latest['state'] = (string)$scheduler['state'];
$latest['message'] = (string)($scheduler['message'] ?? 'NC-Abgleich läuft.');
$latest['timestamp'] = (int)($scheduler['timestamp'] ?? time());
$latest['error_detail'] = '';
}
}
if ((int)$latest['timestamp'] > 0)
{
$latest['last_run_label'] = date('d.m.Y H:i:s', (int)$latest['timestamp']);
}
echo json_encode($latest, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); echo json_encode($latest, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

View File

@@ -78,7 +78,9 @@ done < "$WEBDAV_ROOTS_FILE"
WEBDAV_CONNECT_IP="$(php "$SCRIPT_DIR/lib/resolve-nextcloud-target.php" "$WEBDAV_BASE_URL")" WEBDAV_CONNECT_IP="$(php "$SCRIPT_DIR/lib/resolve-nextcloud-target.php" "$WEBDAV_BASE_URL")"
[[ -n "$WEBDAV_CONNECT_IP" ]] || { write_status error "Nextcloud-Zieladresse konnte nicht ermittelt werden"; exit 1; } [[ -n "$WEBDAV_CONNECT_IP" ]] || { write_status error "Nextcloud-Zieladresse konnte nicht ermittelt werden"; exit 1; }
python3 "$SCRIPT_DIR/lib/build_webdav_placeholder_source.py" \ PLACEHOLDER_OUTPUT=""
PLACEHOLDER_EXIT=0
if PLACEHOLDER_OUTPUT="$(python3 "$SCRIPT_DIR/lib/build_webdav_placeholder_source.py" \
--base-url "$WEBDAV_BASE_URL" \ --base-url "$WEBDAV_BASE_URL" \
--connect-ip "$WEBDAV_CONNECT_IP" \ --connect-ip "$WEBDAV_CONNECT_IP" \
--user "$WEBDAV_USER" \ --user "$WEBDAV_USER" \
@@ -86,12 +88,42 @@ python3 "$SCRIPT_DIR/lib/build_webdav_placeholder_source.py" \
"${ROOT_ARGS[@]}" \ "${ROOT_ARGS[@]}" \
--source-dir "$WEBDAV_SOURCE_DIR" \ --source-dir "$WEBDAV_SOURCE_DIR" \
--manifest "$MANIFEST" \ --manifest "$MANIFEST" \
--mapping "$WEBDAV_MAPPING_FILE" --mapping "$WEBDAV_MAPPING_FILE" 2>&1)"; then
PLACEHOLDER_EXIT=0
else
PLACEHOLDER_EXIT=$?
fi
[[ -z "$PLACEHOLDER_OUTPUT" ]] || printf '%s\n' "$PLACEHOLDER_OUTPUT"
if [[ "$PLACEHOLDER_EXIT" -ne 0 ]]; then
DETAIL="Exit-Code: $PLACEHOLDER_EXIT"
if [[ -n "$PLACEHOLDER_OUTPUT" ]]; then
DETAIL+="; Ausgabe: $(printf '%s\n' "$PLACEHOLDER_OUTPUT" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
fi
trap - ERR
write_status error "WebDAV-Shadow-Tree fehlgeschlagen" "$DETAIL"
exit "$PLACEHOLDER_EXIT"
fi
python3 "$SCRIPT_DIR/lib/shadow_tree.py" \ SHADOW_OUTPUT=""
SHADOW_EXIT=0
if SHADOW_OUTPUT="$(python3 "$SCRIPT_DIR/lib/shadow_tree.py" \
--manifest "$MANIFEST" \ --manifest "$MANIFEST" \
--destination "$GALLERY_ROOT" \ --destination "$GALLERY_ROOT" \
--state "$SHADOW_MAP_FILE" --state "$SHADOW_MAP_FILE" 2>&1)"; then
SHADOW_EXIT=0
else
SHADOW_EXIT=$?
fi
[[ -z "$SHADOW_OUTPUT" ]] || printf '%s\n' "$SHADOW_OUTPUT"
if [[ "$SHADOW_EXIT" -ne 0 ]]; then
DETAIL="Exit-Code: $SHADOW_EXIT"
if [[ -n "$SHADOW_OUTPUT" ]]; then
DETAIL+="; Ausgabe: $(printf '%s\n' "$SHADOW_OUTPUT" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
fi
trap - ERR
write_status error "WebDAV-Shadow-Tree fehlgeschlagen" "$DETAIL"
exit "$SHADOW_EXIT"
fi
trap - ERR trap - ERR

View File

@@ -52,6 +52,18 @@ if (!pwg_db_num_rows($access_result)) bratonien_tools_webdav_image_abort(403, 'K
$source = bratonien_tools_webdav_image_source_info($image_id); $source = bratonien_tools_webdav_image_source_info($image_id);
if (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.'); if (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.');
if (!empty($_GET['ajaxload']))
{
$preview = !empty($_GET['preview']);
$final_url = bratonien_tools_webdav_image_url($image_id, $preview);
if (!$final_url) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Bild-URL verfügbar.');
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store, max-age=0');
echo json_encode(array('url'=>$final_url), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
if (!empty($_GET['preview'])) if (!empty($_GET['preview']))
{ {
$preview = bratonien_tools_webdav_preview_path($source); $preview = bratonien_tools_webdav_preview_path($source);
@@ -121,7 +133,7 @@ $options = array(
CURLOPT_USERPWD => $user.':'.$password, CURLOPT_USERPWD => $user.':'.$password,
CURLOPT_RETURNTRANSFER => false, CURLOPT_RETURNTRANSFER => false,
CURLOPT_FAILONERROR => false, CURLOPT_FAILONERROR => false,
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.16', CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.24',
CURLOPT_HEADERFUNCTION => function($ch, $line) CURLOPT_HEADERFUNCTION => function($ch, $line)
{ {
$length = strlen($line); $length = strlen($line);