mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 23:24:36 +00:00
Compare commits
71 Commits
fix/0973-w
...
fix/09717-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c772010137 | ||
|
|
d075d05708 | ||
|
|
a4fb7421f0 | ||
|
|
9da08b5d8e | ||
|
|
f28365b0ca | ||
|
|
fb6c1a03d2 | ||
|
|
98d0471683 | ||
|
|
63eba888f8 | ||
|
|
748b0e986d | ||
|
|
c1281ad077 | ||
|
|
bc0593642c | ||
|
|
9052076fd7 | ||
|
|
5772a59b55 | ||
|
|
84762154d6 | ||
|
|
1580c235a8 | ||
|
|
4aac5ca4a2 | ||
|
|
ab1f20beef | ||
|
|
f94a001006 | ||
|
|
3f64895f8e | ||
|
|
48f1eacce7 | ||
|
|
7c8c7ab98a | ||
|
|
ade38ff2d1 | ||
|
|
6a013fe875 | ||
|
|
c71112d94e | ||
|
|
7d97e1b515 | ||
|
|
47afbc7f43 | ||
|
|
706639a57e | ||
|
|
c7b14add33 | ||
|
|
f9e87df305 | ||
|
|
6ba5eb4d7f | ||
|
|
85369fa15e | ||
|
|
981ba6c18b | ||
|
|
77e20af977 | ||
|
|
e187c517da | ||
|
|
28e34d6c73 | ||
|
|
b8852310bd | ||
|
|
ae96fc2e3e | ||
|
|
ebf4fc7e74 | ||
|
|
d798b82ec7 | ||
|
|
9e282af1b4 | ||
|
|
d7628d1dac | ||
|
|
7e9c3ae05f | ||
|
|
b64e46a549 | ||
|
|
779ba80dfe | ||
|
|
ebbc183f87 | ||
|
|
f3b5002f4d | ||
|
|
6c393bbcfc | ||
|
|
829381676d | ||
|
|
6382cee491 | ||
|
|
69c3932e9b | ||
|
|
747a76c066 | ||
|
|
5024757136 | ||
|
|
5125d2e247 | ||
|
|
6607c4aefe | ||
|
|
32f2ceaaec | ||
|
|
5a5669d976 | ||
|
|
e4ab277cfc | ||
|
|
9e07cd8042 | ||
|
|
588f1fc100 | ||
|
|
a23fc81190 | ||
|
|
ff5af83e65 | ||
|
|
c61d8e32cc | ||
|
|
38c4955f70 | ||
|
|
5c217288a8 | ||
|
|
17c79ce8ab | ||
|
|
7746d26c9f | ||
|
|
d05ab28549 | ||
|
|
55b5be56b6 | ||
|
|
ba0b5af417 | ||
|
|
315af9641c | ||
|
|
77ae007a28 |
1
.ci-trigger-0977
Normal file
1
.ci-trigger-0977
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0.9.7.7
|
||||||
@@ -28,18 +28,34 @@ function bratonien_tools_nc_connector_webdav_site_id(array $connection)
|
|||||||
return (int)$row['id'];
|
return (int)$row['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_connector_gallery_db_prefix(array $connection)
|
||||||
|
{
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$gallery_root = rtrim((string)($config['parallel_gallery_root'] ?? ''), '/');
|
||||||
|
$piwigo_root = rtrim(PHPWG_ROOT_PATH, '/');
|
||||||
|
if ($gallery_root === '' || strpos($gallery_root, $piwigo_root.'/') !== 0) return '';
|
||||||
|
|
||||||
|
$relative = ltrim(substr($gallery_root, strlen($piwigo_root)), '/');
|
||||||
|
return $relative === '' ? '' : './'.rtrim($relative, '/').'/';
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connection)
|
function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connection)
|
||||||
{
|
{
|
||||||
$site_id = bratonien_tools_nc_connector_webdav_site_id($connection);
|
|
||||||
if ($site_id < 1) return array('site_id'=>0, 'images'=>0);
|
|
||||||
|
|
||||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
$site_id = bratonien_tools_nc_connector_webdav_site_id($connection);
|
||||||
|
$db_prefix = bratonien_tools_nc_connector_gallery_db_prefix($connection);
|
||||||
|
if ($db_prefix === '') return array('site_id'=>$site_id, 'images'=>0);
|
||||||
|
|
||||||
|
$escaped = pwg_db_real_escape_string(addcslashes($db_prefix, '_%\\'));
|
||||||
$image_rows = array();
|
$image_rows = array();
|
||||||
$query = '\nSELECT DISTINCT i.id, i.path, i.representative_ext\n FROM '.IMAGES_TABLE.' AS i\n LEFT JOIN '.CATEGORIES_TABLE.' AS sc ON sc.id = i.storage_category_id\n LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id\n LEFT JOIN '.CATEGORIES_TABLE.' AS vc ON vc.id = ic.category_id\n WHERE sc.site_id = '.$site_id.' OR vc.site_id = '.$site_id.'\n;';
|
$result = pwg_query(
|
||||||
$result = pwg_query($query);
|
"SELECT id, path, representative_ext FROM ".IMAGES_TABLE.
|
||||||
|
" WHERE path LIKE '".$escaped."%' ESCAPE '\\\\'"
|
||||||
|
);
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
|
if (strpos((string)$row['path'], $db_prefix) !== 0) continue;
|
||||||
$row['id'] = (int)$row['id'];
|
$row['id'] = (int)$row['id'];
|
||||||
$image_rows[$row['id']] = $row;
|
$image_rows[$row['id']] = $row;
|
||||||
}
|
}
|
||||||
@@ -56,20 +72,14 @@ function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_site($site_id);
|
|
||||||
|
|
||||||
if ($image_rows)
|
if ($image_rows)
|
||||||
{
|
{
|
||||||
$ids = array_keys($image_rows);
|
delete_elements(array_map('intval', array_keys($image_rows)), false);
|
||||||
$remaining = query2array(
|
|
||||||
'SELECT id FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', array_map('intval', $ids)).')',
|
|
||||||
null,
|
|
||||||
'id'
|
|
||||||
);
|
|
||||||
if ($remaining)
|
|
||||||
{
|
|
||||||
delete_elements(array_map('intval', $remaining), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($site_id > 0)
|
||||||
|
{
|
||||||
|
delete_site($site_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate_user_cache(true);
|
invalidate_user_cache(true);
|
||||||
@@ -110,14 +120,7 @@ function bratonien_tools_nc_connector_delete_safe()
|
|||||||
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)$cleanup['site_id'] > 0)
|
|
||||||
{
|
|
||||||
return array(
|
return array(
|
||||||
'message'=>'Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
'message'=>'Verbindung wurde gelöscht. '.(int)$cleanup['images'].' eindeutig zu dieser Verbindung gehörende Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'message'=>'Verbindung wurde gelöscht. Verbliebene Laufzeitdaten werden automatisch bereinigt. Quelldateien blieben unverändert.',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ function bratonien_tools_nc_scheduler_paths()
|
|||||||
'trigger_lock'=>$base.'/nc-connector-scheduler/trigger.lock',
|
'trigger_lock'=>$base.'/nc-connector-scheduler/trigger.lock',
|
||||||
'worker_lock'=>$base.'/nc-connector-scheduler/worker.lock',
|
'worker_lock'=>$base.'/nc-connector-scheduler/worker.lock',
|
||||||
'log'=>$base.'/nc-connector-scheduler/last-worker.log',
|
'log'=>$base.'/nc-connector-scheduler/last-worker.log',
|
||||||
|
'status_root'=>$base.'/nc-connector-status',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,31 @@ function bratonien_tools_nc_scheduler_write_state(array $state)
|
|||||||
return @rename($tmp, $paths['state']);
|
return @rename($tmp, $paths['state']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_scheduler_write_connection_status($connection_id, $state, $message)
|
||||||
|
{
|
||||||
|
$connection_id = (int)$connection_id;
|
||||||
|
if ($connection_id < 1) return false;
|
||||||
|
$paths = bratonien_tools_nc_scheduler_paths();
|
||||||
|
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
||||||
|
$target = $paths['status_root'].'/connection-'.$connection_id.'.json';
|
||||||
|
$existing = array();
|
||||||
|
if (is_readable($target))
|
||||||
|
{
|
||||||
|
$decoded = json_decode((string)@file_get_contents($target), true);
|
||||||
|
if (is_array($decoded)) $existing = $decoded;
|
||||||
|
}
|
||||||
|
$existing['state'] = (string)$state;
|
||||||
|
$existing['message'] = (string)$message;
|
||||||
|
$existing['timestamp'] = time();
|
||||||
|
$existing['connection_id'] = $connection_id;
|
||||||
|
$json = json_encode($existing, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||||
|
if (!is_string($json)) return false;
|
||||||
|
$tmp = $target.'.tmp';
|
||||||
|
if (@file_put_contents($tmp, $json."\n", LOCK_EX) === false) return false;
|
||||||
|
@chmod($tmp, 0644);
|
||||||
|
return @rename($tmp, $target);
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_scheduler_install()
|
function bratonien_tools_nc_scheduler_install()
|
||||||
{
|
{
|
||||||
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
||||||
@@ -82,8 +108,9 @@ function bratonien_tools_nc_scheduler_php_binary()
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_scheduler_spawn($force = false)
|
function bratonien_tools_nc_scheduler_spawn($force = false, $connection_id = 0)
|
||||||
{
|
{
|
||||||
|
$connection_id = max(0, (int)$connection_id);
|
||||||
$paths = bratonien_tools_nc_scheduler_paths();
|
$paths = bratonien_tools_nc_scheduler_paths();
|
||||||
if (!bratonien_tools_nc_scheduler_ensure_dirs())
|
if (!bratonien_tools_nc_scheduler_ensure_dirs())
|
||||||
{
|
{
|
||||||
@@ -118,14 +145,20 @@ 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['state'] = 'queued';
|
||||||
$state['message'] = 'NC-Abgleich wurde angefordert.';
|
$state['message'] = $connection_id > 0 ? 'NC-Abgleich für Verbindung #'.$connection_id.' wurde angefordert.' : 'NC-Abgleich für alle Verbindungen wurde angefordert.';
|
||||||
$state['queued_at'] = $now;
|
$state['queued_at'] = $now;
|
||||||
$state['timestamp'] = $now;
|
$state['timestamp'] = $now;
|
||||||
|
$state['connection_id'] = $connection_id;
|
||||||
$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);
|
||||||
|
if ($connection_id > 0)
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_scheduler_write_connection_status($connection_id, 'queued', 'Abgleich wurde angefordert.');
|
||||||
|
}
|
||||||
|
|
||||||
$runner = BRATONIEN_TOOLS_PATH.'runtime/native-runner.php';
|
$runner = BRATONIEN_TOOLS_PATH.'runtime/native-runner.php';
|
||||||
$command = escapeshellarg($php).' '.escapeshellarg($runner).' >> '.escapeshellarg($paths['log']).' 2>&1 &';
|
$runner_args = $connection_id > 0 ? ' --connection-id='.escapeshellarg((string)$connection_id) : '';
|
||||||
|
$command = escapeshellarg($php).' '.escapeshellarg($runner).$runner_args.' >> '.escapeshellarg($paths['log']).' 2>&1 &';
|
||||||
$spec = array(
|
$spec = array(
|
||||||
0=>array('file','/dev/null','r'),
|
0=>array('file','/dev/null','r'),
|
||||||
1=>array('file','/dev/null','a'),
|
1=>array('file','/dev/null','a'),
|
||||||
@@ -144,10 +177,14 @@ function bratonien_tools_nc_scheduler_spawn($force = false)
|
|||||||
$state['message'] = 'Der native NC-Abgleich konnte nicht gestartet werden.';
|
$state['message'] = 'Der native NC-Abgleich konnte nicht gestartet werden.';
|
||||||
$state['timestamp'] = time();
|
$state['timestamp'] = time();
|
||||||
bratonien_tools_nc_scheduler_write_state($state);
|
bratonien_tools_nc_scheduler_write_state($state);
|
||||||
|
if ($connection_id > 0)
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_scheduler_write_connection_status($connection_id, 'error', 'Abgleich konnte nicht gestartet werden.');
|
||||||
|
}
|
||||||
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'=>$connection_id > 0 ? 'Abgleich für Verbindung #'.$connection_id.' wurde angefordert.' : 'Abgleich für alle Verbindungen wurde angefordert.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_scheduler_tick()
|
function bratonien_tools_nc_scheduler_tick()
|
||||||
@@ -159,7 +196,7 @@ function bratonien_tools_nc_scheduler_tick()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bratonien_tools_nc_scheduler_spawn(false);
|
bratonien_tools_nc_scheduler_spawn(false, 0);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
|||||||
115
include/nc_legacy_reset.inc.php
Normal file
115
include/nc_legacy_reset.inc.php
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('PHPWG_ROOT_PATH'))
|
||||||
|
{
|
||||||
|
die('Hacking attempt!');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_legacy_remove_tree($path, $allowed_root)
|
||||||
|
{
|
||||||
|
$path = rtrim(str_replace('\\', '/', (string)$path), '/');
|
||||||
|
$allowed_root = rtrim(str_replace('\\', '/', (string)$allowed_root), '/');
|
||||||
|
if ($path === '' || $allowed_root === '' || $path === $allowed_root || strpos($path, $allowed_root.'/') !== 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!file_exists($path) && !is_link($path)) return 0;
|
||||||
|
|
||||||
|
if (is_link($path) || is_file($path))
|
||||||
|
{
|
||||||
|
return @unlink($path) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$removed = 0;
|
||||||
|
$items = @scandir($path);
|
||||||
|
if (is_array($items))
|
||||||
|
{
|
||||||
|
foreach ($items as $item)
|
||||||
|
{
|
||||||
|
if ($item === '.' || $item === '..') continue;
|
||||||
|
$removed += bratonien_tools_nc_legacy_remove_tree($path.'/'.$item, $allowed_root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (@rmdir($path)) $removed++;
|
||||||
|
return $removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_legacy_remove_state_files($state_root)
|
||||||
|
{
|
||||||
|
$removed = 0;
|
||||||
|
foreach (glob(rtrim($state_root, '/').'/connection-*') ?: array() as $connection_dir)
|
||||||
|
{
|
||||||
|
if (!is_dir($connection_dir)) continue;
|
||||||
|
foreach (array('webdav-map.json', 'webdav-manifest.tsv', 'webdav-shadow-map.json') as $name)
|
||||||
|
{
|
||||||
|
$path = $connection_dir.'/'.$name;
|
||||||
|
if (is_file($path) && @unlink($path)) $removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_reset_legacy_imports()
|
||||||
|
{
|
||||||
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
$ids = array();
|
||||||
|
$result = pwg_query(
|
||||||
|
"SELECT id FROM ".IMAGES_TABLE.
|
||||||
|
" WHERE path LIKE '%nc-webdav-source/connection-%'"
|
||||||
|
);
|
||||||
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
$ids[] = (int)$row['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ids)
|
||||||
|
{
|
||||||
|
delete_elements($ids, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data_root = rtrim(PHPWG_ROOT_PATH, '/').'/_data';
|
||||||
|
$tool_root = $data_root.'/bratonien-tools';
|
||||||
|
$removed_files = 0;
|
||||||
|
foreach (array(
|
||||||
|
$tool_root.'/nc-webdav-source',
|
||||||
|
$tool_root.'/nc-webdav-preview',
|
||||||
|
$tool_root.'/nc-webdav-gallery',
|
||||||
|
) as $generated_root)
|
||||||
|
{
|
||||||
|
$removed_files += bratonien_tools_nc_legacy_remove_tree($generated_root, $data_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined('PWG_DERIVATIVE_DIR'))
|
||||||
|
{
|
||||||
|
$derivative_root = rtrim(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR, '/');
|
||||||
|
foreach (array(
|
||||||
|
$derivative_root.'/_data/bratonien-tools/nc-webdav-source',
|
||||||
|
$derivative_root.'/_data/bratonien-tools/nc-webdav-gallery',
|
||||||
|
) as $generated_derivative_root)
|
||||||
|
{
|
||||||
|
$removed_files += bratonien_tools_nc_legacy_remove_tree($generated_derivative_root, $derivative_root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$removed_state_files = bratonien_tools_nc_legacy_remove_state_files($tool_root.'/nc-connector-state');
|
||||||
|
|
||||||
|
if ($ids)
|
||||||
|
{
|
||||||
|
update_category('all');
|
||||||
|
invalidate_user_cache(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'timestamp'=>time(),
|
||||||
|
'removed_image_records'=>count($ids),
|
||||||
|
'removed_generated_entries'=>$removed_files,
|
||||||
|
'removed_state_files'=>$removed_state_files,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (function_exists('conf_update_param'))
|
||||||
|
{
|
||||||
|
conf_update_param('bratonien_nc_legacy_reset_0977', json_encode($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
@@ -47,8 +47,17 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_system.inc.php');
|
|||||||
|
|
||||||
function bratonien_tools_nc_connector_run_now()
|
function bratonien_tools_nc_connector_run_now()
|
||||||
{
|
{
|
||||||
$result = bratonien_tools_nc_scheduler_spawn(true);
|
$connection_id = isset($_POST['connection_id']) ? max(0, (int)$_POST['connection_id']) : 0;
|
||||||
return array('message'=>(string)($result['message'] ?? 'NC-Abgleich wurde gestartet.'));
|
if ($connection_id > 0)
|
||||||
|
{
|
||||||
|
$connection = bratonien_tools_nc_connector_connection($connection_id, false);
|
||||||
|
if (!$connection)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Die ausgewählte Verbindung existiert nicht.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = bratonien_tools_nc_scheduler_spawn(true, $connection_id);
|
||||||
|
return array('message'=>(string)($result['message'] ?? ($connection_id > 0 ? 'Abgleich wurde gestartet.' : 'Abgleich für alle Verbindungen wurde gestartet.')));
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_get_tools()
|
function bratonien_tools_get_tools()
|
||||||
|
|||||||
@@ -8,12 +8,22 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_base.inc.php');
|
|||||||
|
|
||||||
function bratonien_tools_watermark_engine_enabled()
|
function bratonien_tools_watermark_engine_enabled()
|
||||||
{
|
{
|
||||||
|
static $initialized = false;
|
||||||
|
static $enabled = false;
|
||||||
|
|
||||||
|
if ($initialized)
|
||||||
|
{
|
||||||
|
return $enabled;
|
||||||
|
}
|
||||||
|
|
||||||
$config = bratonien_tools_get_watermark_engine_config();
|
$config = bratonien_tools_get_watermark_engine_config();
|
||||||
$enabled = !empty($config['enabled']);
|
$enabled = !empty($config['enabled']);
|
||||||
|
$initialized = true;
|
||||||
|
|
||||||
// Piwigo recalculates use_watermark for custom derivatives from the native
|
// Piwigo recalculates use_watermark for custom derivatives from the native
|
||||||
// watermark file itself. Therefore an active Bratonien engine must keep the
|
// watermark file itself. Therefore an active Bratonien engine must keep the
|
||||||
// native watermark file empty, not only the stored use_watermark flags false.
|
// native watermark file empty, not only the stored use_watermark flags false.
|
||||||
|
// This initialization is required only once per PHP request.
|
||||||
if ($enabled)
|
if ($enabled)
|
||||||
{
|
{
|
||||||
bratonien_tools_disable_piwigo_watermarks();
|
bratonien_tools_disable_piwigo_watermarks();
|
||||||
|
|||||||
@@ -27,6 +27,72 @@ function bratonien_tools_runtime_category_id()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_watermark_album_cover_category($src_image, $category_id=null)
|
||||||
|
{
|
||||||
|
static $map = null;
|
||||||
|
|
||||||
|
if ($map === null)
|
||||||
|
{
|
||||||
|
$map = new SplObjectStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_object($src_image))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($category_id !== null)
|
||||||
|
{
|
||||||
|
$category_id = (int)$category_id;
|
||||||
|
if ($category_id > 0)
|
||||||
|
{
|
||||||
|
$map[$src_image] = $category_id;
|
||||||
|
}
|
||||||
|
return $category_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map->contains($src_image) ? (int)$map[$src_image] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_watermark_prepare_album_overview($thumbnails)
|
||||||
|
{
|
||||||
|
if (!is_array($thumbnails))
|
||||||
|
{
|
||||||
|
return $thumbnails;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($thumbnails as &$thumbnail)
|
||||||
|
{
|
||||||
|
$category_id = (int)($thumbnail['id'] ?? $thumbnail['ID'] ?? 0);
|
||||||
|
if ($category_id < 1 || empty($thumbnail['representative']['src_image']) || !is_object($thumbnail['representative']['src_image']))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ein Repraesentantenbild kann fuer mehrere Alben verwendet werden. Piwigo
|
||||||
|
// reicht in der Albumuebersicht aber nur das SrcImage an get_derivative_url
|
||||||
|
// weiter. Deshalb bekommt jedes Album-Cover eine eigene SrcImage-Instanz,
|
||||||
|
// damit seine konkrete Albumregel erhalten bleibt.
|
||||||
|
$src_image = clone $thumbnail['representative']['src_image'];
|
||||||
|
$thumbnail['representative']['src_image'] = $src_image;
|
||||||
|
bratonien_tools_watermark_album_cover_category($src_image, $category_id);
|
||||||
|
}
|
||||||
|
unset($thumbnail);
|
||||||
|
|
||||||
|
return $thumbnails;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_runtime_derivative_category_id($src_image)
|
||||||
|
{
|
||||||
|
$category_id = bratonien_tools_runtime_category_id();
|
||||||
|
if ($category_id > 0)
|
||||||
|
{
|
||||||
|
return $category_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bratonien_tools_watermark_album_cover_category($src_image);
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_runtime_effective_rule($category_id)
|
function bratonien_tools_runtime_effective_rule($category_id)
|
||||||
{
|
{
|
||||||
static $categories = null;
|
static $categories = null;
|
||||||
@@ -230,7 +296,7 @@ function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_u
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rule = bratonien_tools_runtime_effective_rule(bratonien_tools_runtime_category_id());
|
$rule = bratonien_tools_runtime_effective_rule(bratonien_tools_runtime_derivative_category_id($src_image));
|
||||||
if ($rule['mode'] !== 'profile' || empty($rule['profile_id']))
|
if ($rule['mode'] !== 'profile' || empty($rule['profile_id']))
|
||||||
{
|
{
|
||||||
return $url;
|
return $url;
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
function bratonien_tools_webdav_image_source_info($image_id)
|
function bratonien_tools_webdav_image_source_info($image_id)
|
||||||
{
|
{
|
||||||
static $cache = array();
|
static $cache = array();
|
||||||
|
static $connection_cache = array();
|
||||||
|
static $mapping_cache = array();
|
||||||
|
|
||||||
$image_id = (int)$image_id;
|
$image_id = (int)$image_id;
|
||||||
if ($image_id < 1) return null;
|
if ($image_id < 1) return null;
|
||||||
if (array_key_exists($image_id, $cache)) return $cache[$image_id];
|
if (array_key_exists($image_id, $cache)) return $cache[$image_id];
|
||||||
@@ -20,12 +23,12 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$absolute = $path;
|
$absolute = $path;
|
||||||
if (strpos($absolute, '/') !== 0)
|
if (strpos($absolute, '/') !== 0)
|
||||||
{
|
{
|
||||||
$absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\./#', '', $absolute), '/');
|
$absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\\./#', '', $absolute), '/');
|
||||||
}
|
}
|
||||||
$resolved = realpath($absolute);
|
$resolved = realpath($absolute);
|
||||||
if ($resolved === false) return $cache[$image_id] = null;
|
if ($resolved === false) return $cache[$image_id] = null;
|
||||||
|
|
||||||
$normalized = str_replace('\\', '/', $resolved);
|
$normalized = str_replace('\\\\', '/', $resolved);
|
||||||
if (!preg_match('#/nc-webdav-source/connection-([0-9]+)/root-([0-9]+)/(.*)$#', $normalized, $match))
|
if (!preg_match('#/nc-webdav-source/connection-([0-9]+)/root-([0-9]+)/(.*)$#', $normalized, $match))
|
||||||
{
|
{
|
||||||
return $cache[$image_id] = null;
|
return $cache[$image_id] = null;
|
||||||
@@ -36,13 +39,25 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$relative_path = trim((string)$match[3], '/');
|
$relative_path = trim((string)$match[3], '/');
|
||||||
if ($relative_path === '') return $cache[$image_id] = null;
|
if ($relative_path === '') return $cache[$image_id] = null;
|
||||||
|
|
||||||
|
if (!array_key_exists($connection_id, $connection_cache))
|
||||||
|
{
|
||||||
$table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE')
|
$table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE')
|
||||||
? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE
|
? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE
|
||||||
: $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections';
|
: $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections';
|
||||||
$connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
$connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
||||||
if (!pwg_db_num_rows($connection_result)) return $cache[$image_id] = null;
|
if (!pwg_db_num_rows($connection_result))
|
||||||
|
{
|
||||||
|
$connection_cache[$connection_id] = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$connection_row = pwg_db_fetch_assoc($connection_result);
|
$connection_row = pwg_db_fetch_assoc($connection_result);
|
||||||
$config = json_decode((string)$connection_row['config_json'], true);
|
$decoded = json_decode((string)$connection_row['config_json'], true);
|
||||||
|
$connection_cache[$connection_id] = is_array($decoded) ? $decoded : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = $connection_cache[$connection_id];
|
||||||
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
||||||
{
|
{
|
||||||
return $cache[$image_id] = null;
|
return $cache[$image_id] = null;
|
||||||
@@ -68,6 +83,9 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$size = 0;
|
$size = 0;
|
||||||
$etag = '';
|
$etag = '';
|
||||||
|
|
||||||
|
if (!array_key_exists($connection_id, $mapping_cache))
|
||||||
|
{
|
||||||
|
$mapping_cache[$connection_id] = array();
|
||||||
$state_dir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
$state_dir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
||||||
if ($state_dir !== '')
|
if ($state_dir !== '')
|
||||||
{
|
{
|
||||||
@@ -77,7 +95,13 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
||||||
if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files']))
|
if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files']))
|
||||||
{
|
{
|
||||||
$entry = $mapping['files'][$resolved] ?? $mapping['files'][$normalized] ?? null;
|
$mapping_cache[$connection_id] = $mapping['files'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry = $mapping_cache[$connection_id][$resolved] ?? $mapping_cache[$connection_id][$normalized] ?? null;
|
||||||
if (is_array($entry) && (string)($entry['kind'] ?? '') === 'file')
|
if (is_array($entry) && (string)($entry['kind'] ?? '') === 'file')
|
||||||
{
|
{
|
||||||
$webdav_path = trim((string)($entry['webdav_path'] ?? $webdav_path), '/');
|
$webdav_path = trim((string)($entry['webdav_path'] ?? $webdav_path), '/');
|
||||||
@@ -85,9 +109,6 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$size = (int)($entry['size'] ?? 0);
|
$size = (int)($entry['size'] ?? 0);
|
||||||
$etag = (string)($entry['etag'] ?? '');
|
$etag = (string)($entry['etag'] ?? '');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cache[$image_id] = array(
|
return $cache[$image_id] = array(
|
||||||
'image_id'=>$image_id,
|
'image_id'=>$image_id,
|
||||||
@@ -416,11 +437,17 @@ function bratonien_tools_filter_webdav_src_url($url, $src_image)
|
|||||||
function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image, $rel_url)
|
function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image, $rel_url)
|
||||||
{
|
{
|
||||||
if (!is_object($src_image) || empty($src_image->id)) return $url;
|
if (!is_object($src_image) || empty($src_image->id)) return $url;
|
||||||
$info = bratonien_tools_webdav_image_source_info((int)$src_image->id);
|
|
||||||
if (!$info) return $url;
|
|
||||||
|
|
||||||
if (empty($info['root_is_base']))
|
// Hotpath: Bei einem bereits vorbereiteten WebDAV-Derivat keinerlei
|
||||||
|
// Connection-DB oder Mapping-Datei mehr anfassen. Der reale Quellpfad
|
||||||
|
// reicht aus, um Connector-Bilder sicher zu erkennen.
|
||||||
|
$source_path = $src_image->get_path();
|
||||||
|
$resolved_source = $source_path !== '' ? realpath($source_path) : false;
|
||||||
|
if ($resolved_source === false || !preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/#', str_replace('\\\\', '/', $resolved_source)))
|
||||||
{
|
{
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$derivative = new DerivativeImage($params, $src_image);
|
$derivative = new DerivativeImage($params, $src_image);
|
||||||
@@ -434,7 +461,6 @@ function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image,
|
|||||||
{
|
{
|
||||||
error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
|
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);
|
||||||
return $preview_url ?: $url;
|
return $preview_url ?: $url;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.3
|
Version: 0.9.7.17
|
||||||
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
|
||||||
@@ -27,16 +27,16 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/nc_productive_ws.inc.php');
|
|||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
||||||
|
|
||||||
add_event_handler('get_admin_plugin_menu_links', 'bratonien_tools_admin_menu');
|
add_event_handler('get_admin_plugin_menu_links', 'bratonien_tools_admin_menu');
|
||||||
|
add_event_handler('loc_end_index_category_thumbnails', 'bratonien_tools_watermark_prepare_album_overview');
|
||||||
add_event_handler('get_derivative_url', 'bratonien_tools_filter_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
|
add_event_handler('get_derivative_url', 'bratonien_tools_filter_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
|
||||||
add_event_handler('get_src_image_url', 'bratonien_tools_filter_webdav_src_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 2);
|
add_event_handler('get_src_image_url', 'bratonien_tools_filter_webdav_src_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 2);
|
||||||
add_event_handler('get_derivative_url', 'bratonien_tools_filter_webdav_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 4);
|
|
||||||
add_event_handler('loc_end_element_set_global', 'bratonien_tools_batch_titles_register_action');
|
add_event_handler('loc_end_element_set_global', 'bratonien_tools_batch_titles_register_action');
|
||||||
add_event_handler('element_set_global_action', 'bratonien_tools_batch_titles_apply', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
|
add_event_handler('element_set_global_action', 'bratonien_tools_batch_titles_apply', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
|
||||||
|
add_event_handler('init', 'bratonien_tools_watermark_cache_upgrade', EVENT_HANDLER_PRIORITY_NEUTRAL - 40);
|
||||||
add_event_handler('init', 'bratonien_tools_prepare_connector_private_import', EVENT_HANDLER_PRIORITY_NEUTRAL - 30);
|
add_event_handler('init', 'bratonien_tools_prepare_connector_private_import', EVENT_HANDLER_PRIORITY_NEUTRAL - 30);
|
||||||
add_event_handler('init', 'bratonien_tools_prepare_private_album_permissions', EVENT_HANDLER_PRIORITY_NEUTRAL - 20);
|
add_event_handler('init', 'bratonien_tools_prepare_private_album_permissions', EVENT_HANDLER_PRIORITY_NEUTRAL - 20);
|
||||||
add_event_handler('init', 'bratonien_tools_preserve_private_album_access', EVENT_HANDLER_PRIORITY_NEUTRAL - 10);
|
add_event_handler('init', 'bratonien_tools_preserve_private_album_access', EVENT_HANDLER_PRIORITY_NEUTRAL - 10);
|
||||||
add_event_handler('init', 'bratonien_tools_album_shares_init');
|
add_event_handler('init', 'bratonien_tools_album_shares_init');
|
||||||
add_event_handler('init', 'bratonien_tools_nc_scheduler_tick', EVENT_HANDLER_PRIORITY_NEUTRAL + 100);
|
|
||||||
add_event_handler('delete_categories', 'bratonien_tools_album_shares_on_delete_categories');
|
add_event_handler('delete_categories', 'bratonien_tools_album_shares_on_delete_categories');
|
||||||
add_event_handler('ws_add_methods', 'bratonien_tools_register_ws_methods');
|
add_event_handler('ws_add_methods', 'bratonien_tools_register_ws_methods');
|
||||||
add_event_handler('ws_add_methods', 'bratonien_tools_register_nc_orphan_ws_methods');
|
add_event_handler('ws_add_methods', 'bratonien_tools_register_nc_orphan_ws_methods');
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ require_once(dirname(__FILE__) . '/include/database.class.php');
|
|||||||
require_once(dirname(__FILE__) . '/tools/watermark_profiles.inc.php');
|
require_once(dirname(__FILE__) . '/tools/watermark_profiles.inc.php');
|
||||||
require_once(dirname(__FILE__) . '/include/dependencies.inc.php');
|
require_once(dirname(__FILE__) . '/include/dependencies.inc.php');
|
||||||
require_once(dirname(__FILE__) . '/include/nc_connector_scheduler.inc.php');
|
require_once(dirname(__FILE__) . '/include/nc_connector_scheduler.inc.php');
|
||||||
|
require_once(dirname(__FILE__) . '/include/nc_legacy_reset.inc.php');
|
||||||
|
|
||||||
class bratonien_tools_maintain extends PluginMaintain
|
class bratonien_tools_maintain extends PluginMaintain
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,18 @@ class bratonien_tools_maintain extends PluginMaintain
|
|||||||
public function update($old_version, $new_version, &$errors = array())
|
public function update($old_version, $new_version, &$errors = array())
|
||||||
{
|
{
|
||||||
$this->prepare($errors);
|
$this->prepare($errors);
|
||||||
|
|
||||||
|
if (version_compare((string)$old_version, '0.9.7.7', '<') && version_compare((string)$new_version, '0.9.7.7', '>='))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_reset_legacy_imports();
|
||||||
|
}
|
||||||
|
catch (Throwable $e)
|
||||||
|
{
|
||||||
|
$errors[] = 'Connector-Altbestand konnte nicht vollständig bereinigt werden: '.$e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
umask 0002
|
||||||
|
|
||||||
CONFIG_FILE="${PIWIGO_CONFIG:-}"
|
CONFIG_FILE="${PIWIGO_CONFIG:-}"
|
||||||
[[ -n "$CONFIG_FILE" && -r "$CONFIG_FILE" ]] || { echo "WebDAV-Konfiguration fehlt: ${CONFIG_FILE:-<leer>}" >&2; exit 1; }
|
[[ -n "$CONFIG_FILE" && -r "$CONFIG_FILE" ]] || { echo "WebDAV-Konfiguration fehlt: ${CONFIG_FILE:-<leer>}" >&2; exit 1; }
|
||||||
@@ -22,6 +23,47 @@ exec 9>"$LOCK_FILE"
|
|||||||
flock -n 9 || exit 0
|
flock -n 9 || exit 0
|
||||||
|
|
||||||
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
||||||
|
SOURCE_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-gallery/connection-$CONNECTION_ID"
|
||||||
|
DERIVATIVE_CACHE="$PIWIGO_ROOT/_data/i/_data/bratonien-tools/nc-webdav-gallery/connection-$CONNECTION_ID"
|
||||||
|
PIWIGO_DATA="$PIWIGO_ROOT/_data"
|
||||||
|
|
||||||
|
normalize_connector_cache_permissions() {
|
||||||
|
[[ -d "$PIWIGO_DATA" ]] || return 0
|
||||||
|
|
||||||
|
local data_uid data_gid current_uid path
|
||||||
|
data_uid="$(stat -c '%u' "$PIWIGO_DATA")"
|
||||||
|
data_gid="$(stat -c '%g' "$PIWIGO_DATA")"
|
||||||
|
current_uid="$(id -u)"
|
||||||
|
|
||||||
|
for path in "$SOURCE_CACHE" "$PREVIEW_CACHE" "$DERIVATIVE_CACHE"; do
|
||||||
|
[[ -e "$path" ]] || continue
|
||||||
|
|
||||||
|
if [[ "$current_uid" -eq 0 ]]; then
|
||||||
|
chown -R "$data_uid:$data_gid" -- "$path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! find "$path" -type d -exec chmod 2775 {} + 2>/dev/null; then
|
||||||
|
echo "Hinweis: Verzeichnisrechte konnten ohne Root-Rechte nicht vollständig repariert werden: $path" >&2
|
||||||
|
fi
|
||||||
|
if ! find "$path" -type f -exec chmod 0664 {} + 2>/dev/null; then
|
||||||
|
echo "Hinweis: Dateirechte konnten ohne Root-Rechte nicht vollständig repariert werden: $path" >&2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Altbestände aus früheren root/systemd-Läufen werden repariert, sobald dieser
|
||||||
|
# Lauf mit ausreichenden Rechten ausgeführt wird. Bei normalen Webserver-Läufen
|
||||||
|
# werden zumindest alle eigenen Dateien gruppenschreibbar gehalten.
|
||||||
|
normalize_connector_cache_permissions
|
||||||
|
|
||||||
|
# Dieser Medienlauf wird erst nach einem erfolgreichen WebDAV-Aufbau und einer
|
||||||
|
# erfolgreichen Piwigo-Synchronisierung gestartet. Deshalb darf erst hier aus
|
||||||
|
# "lokale Connector-Datei fehlt" auf eine in Nextcloud entfernte Freigabe/Datei
|
||||||
|
# geschlossen werden. Bei einer nicht erreichbaren Verbindung wird dieser Block
|
||||||
|
# niemals ausgeführt und der vorhandene Piwigo-Bestand bleibt unverändert.
|
||||||
|
php "$SCRIPT_DIR/cleanup-missing-webdav-images.php" \
|
||||||
|
--piwigo-root="$PIWIGO_ROOT" \
|
||||||
|
--connection-id="$CONNECTION_ID"
|
||||||
|
|
||||||
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
||||||
--mapping="$WEBDAV_MAPPING_FILE" \
|
--mapping="$WEBDAV_MAPPING_FILE" \
|
||||||
@@ -33,3 +75,5 @@ php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
|||||||
php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
||||||
--piwigo-root="$PIWIGO_ROOT" \
|
--piwigo-root="$PIWIGO_ROOT" \
|
||||||
--connection-id="$CONNECTION_ID"
|
--connection-id="$CONNECTION_ID"
|
||||||
|
|
||||||
|
normalize_connector_cache_permissions
|
||||||
|
|||||||
124
runtime/cleanup-missing-webdav-images.php
Normal file
124
runtime/cleanup-missing-webdav-images.php
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
if (PHP_SAPI !== 'cli')
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "CLI only\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
||||||
|
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
||||||
|
$connection_id = (int)($options['connection-id'] ?? 0);
|
||||||
|
if ($piwigo_root === '' || $connection_id < 1)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Parameter --piwigo-root und --connection-id werden benoetigt.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db_config = $piwigo_root.'/local/config/database.inc.php';
|
||||||
|
if (!is_readable($db_config))
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist nicht lesbar.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = array();
|
||||||
|
$prefixeTable = 'piwigo_';
|
||||||
|
require $db_config;
|
||||||
|
foreach (array('db_host','db_user','db_password','db_base') as $key)
|
||||||
|
{
|
||||||
|
if (!isset($conf[$key]))
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist unvollstaendig: $key\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = new mysqli($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_base']);
|
||||||
|
if ($db->connect_errno)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbank ist nicht erreichbar: ".$db->connect_error."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$db->set_charset('utf8mb4');
|
||||||
|
|
||||||
|
$table = $prefixeTable.'bratonien_tools_nc_connections';
|
||||||
|
$result = $db->query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
||||||
|
if (!$result || !$result->num_rows)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Connector-Verbindung #$connection_id wurde nicht gefunden.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$config = json_decode((string)$result->fetch_assoc()['config_json'], true);
|
||||||
|
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
||||||
|
{
|
||||||
|
echo "Keine WebDAV-Bereinigung erforderlich.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$gallery_root = rtrim((string)($config['parallel_gallery_root'] ?? ''), '/');
|
||||||
|
if ($gallery_root === '' || strpos($gallery_root, $piwigo_root.'/') !== 0)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Verbindungseigene Gallery-Root ist ungueltig.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$relative = ltrim(substr($gallery_root, strlen($piwigo_root)), '/');
|
||||||
|
$db_prefix = './'.rtrim($relative, '/').'/';
|
||||||
|
$escaped_prefix = $db->real_escape_string(addcslashes($db_prefix, "_%\\"));
|
||||||
|
$images_table = $prefixeTable.'images';
|
||||||
|
$query = "SELECT id, path FROM `{$images_table}` WHERE path LIKE '{$escaped_prefix}%' ESCAPE '\\\\'";
|
||||||
|
$rows = $db->query($query);
|
||||||
|
if (!$rows)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Connector-Bilder konnten nicht gelesen werden: ".$db->error."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$missing_ids = array();
|
||||||
|
while ($row = $rows->fetch_assoc())
|
||||||
|
{
|
||||||
|
$path = (string)$row['path'];
|
||||||
|
if (strpos($path, $db_prefix) !== 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$absolute = $piwigo_root.'/'.ltrim(preg_replace('#^\\./#', '', $path), '/');
|
||||||
|
if (!is_file($absolute))
|
||||||
|
{
|
||||||
|
$missing_ids[] = (int)$row['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$db->close();
|
||||||
|
|
||||||
|
if (!$missing_ids)
|
||||||
|
{
|
||||||
|
echo "WebDAV-Bereinigung: keine fehlenden Piwigo-Bilder.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erst jetzt Piwigo bootstrappen. Dieser Prozess wird nur nach einem erfolgreich
|
||||||
|
// abgeschlossenen WebDAV-Abruf gestartet. Eine nicht erreichbare Verbindung kann
|
||||||
|
// daher niemals ueber diesen Pfad Bilder loeschen.
|
||||||
|
define('PHPWG_ROOT_PATH', $piwigo_root.'/');
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
||||||
|
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||||
|
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||||
|
$_SERVER['SERVER_PORT'] = '80';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
$_SERVER['SCRIPT_NAME'] = '/plugins/bratonien_tools/runtime/cleanup-missing-webdav-images.php';
|
||||||
|
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
|
||||||
|
$_SERVER['QUERY_STRING'] = '';
|
||||||
|
$_SERVER['HTTPS'] = 'off';
|
||||||
|
|
||||||
|
require_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||||
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
delete_elements($missing_ids, false);
|
||||||
|
update_category('all');
|
||||||
|
invalidate_user_cache(true);
|
||||||
|
|
||||||
|
echo 'WebDAV-Bereinigung: '.count($missing_ids)." nicht mehr freigegebene/ vorhandene Bilder aus Piwigo entfernt.\n";
|
||||||
@@ -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.8';
|
||||||
|
|
||||||
$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'] ?? ''), '/');
|
||||||
@@ -46,20 +46,84 @@ if (!function_exists('bratonien_tools_webdav_image_source_info') || !function_ex
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_modus_config()
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$modus = $conf['modus_theme'] ?? array();
|
||||||
|
if (is_string($modus) && $modus !== '')
|
||||||
|
{
|
||||||
|
$decoded = @unserialize($modus);
|
||||||
|
if (is_array($decoded)) $modus = $decoded;
|
||||||
|
}
|
||||||
|
if (!is_array($modus)) $modus = array();
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
array(
|
||||||
|
'index_photo_deriv'=>'2small',
|
||||||
|
'index_photo_deriv_hdpi'=>'xsmall',
|
||||||
|
),
|
||||||
|
$modus
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_gallery_base_params()
|
||||||
|
{
|
||||||
|
$modus = bratonien_tools_webdav_modus_config();
|
||||||
|
$type = trim((string)($modus['index_photo_deriv'] ?? '2small'));
|
||||||
|
$params = $type !== '' ? @ImageStdParams::get_by_type($type) : null;
|
||||||
|
if ($params) return $params;
|
||||||
|
|
||||||
|
$params = ImageStdParams::get_by_type(IMG_THUMB);
|
||||||
|
if (!$params)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Piwigo-Galeriederivat ist nicht konfiguriert.');
|
||||||
|
}
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_modus_gallery_params(SrcImage $src, $base_params)
|
||||||
|
{
|
||||||
|
$row_height = (int)$base_params->max_height();
|
||||||
|
$candidates = array($base_params);
|
||||||
|
|
||||||
|
foreach (ImageStdParams::get_defined_type_map() as $params)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
$params->max_height() > $row_height
|
||||||
|
&& $params->sizing->max_crop == $base_params->sizing->max_crop
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$candidates[] = $params;
|
||||||
|
if (count($candidates) === 3) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$selected = $base_params;
|
||||||
|
foreach ($candidates as $params)
|
||||||
|
{
|
||||||
|
$selected = $params;
|
||||||
|
$probe = new DerivativeImage($params, $src);
|
||||||
|
$size = $probe->get_size();
|
||||||
|
if ((int)$size[1] >= $row_height - 2) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $selected;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$variants = bratonien_tools_webdav_derivative_variants();
|
$gallery_base_params = bratonien_tools_webdav_gallery_base_params();
|
||||||
if (!$variants)
|
$gallery_base_type = (string)$gallery_base_params->type;
|
||||||
{
|
|
||||||
throw new RuntimeException('Keine Piwigo-Derivate konfiguriert.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$images = 0;
|
$images = 0;
|
||||||
$generated_or_ready = 0;
|
$generated_or_ready = 0;
|
||||||
$identity = 0;
|
$identity = 0;
|
||||||
$metadata_repaired = 0;
|
$metadata_repaired = 0;
|
||||||
|
$legacy_derivatives_rebuilt = 0;
|
||||||
$errors = 0;
|
$errors = 0;
|
||||||
$error_lines = array();
|
$error_lines = array();
|
||||||
|
$variant_counts = 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))
|
||||||
@@ -109,33 +173,58 @@ try
|
|||||||
}
|
}
|
||||||
|
|
||||||
$src = new SrcImage($row);
|
$src = new SrcImage($row);
|
||||||
foreach ($variants as $variant_name => $params)
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$probe = new DerivativeImage($params, $src);
|
$gallery_params = bratonien_tools_webdav_modus_gallery_params($src, $gallery_base_params);
|
||||||
|
$variant = (string)$gallery_params->type;
|
||||||
|
if ($variant === '') $variant = 'custom';
|
||||||
|
$variant_counts[$variant] = ($variant_counts[$variant] ?? 0) + 1;
|
||||||
|
|
||||||
|
$probe = new DerivativeImage($gallery_params, $src);
|
||||||
if ($probe->same_as_source())
|
if ($probe->same_as_source())
|
||||||
{
|
{
|
||||||
$identity++;
|
$identity++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$target = $probe->get_path();
|
||||||
|
if ($target !== '' && is_file($target) && is_readable($target))
|
||||||
|
{
|
||||||
|
$expected_size = $gallery_params->compute_final_size(array($preview_width, $preview_height));
|
||||||
|
$existing_size = @getimagesize($target);
|
||||||
|
if (
|
||||||
|
is_array($expected_size)
|
||||||
|
&& isset($expected_size[0], $expected_size[1])
|
||||||
|
&& is_array($existing_size)
|
||||||
|
&& isset($existing_size[0], $existing_size[1])
|
||||||
|
&& ((int)$existing_size[0] !== (int)$expected_size[0] || (int)$existing_size[1] !== (int)$expected_size[1])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!@unlink($target))
|
||||||
|
{
|
||||||
|
$errors++;
|
||||||
|
$error_lines[] = 'Bild #'.$image_id.' Galerie: falsches Alt-Derivat konnte nicht entfernt werden: '.$target;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$legacy_derivatives_rebuilt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$detail = '';
|
$detail = '';
|
||||||
if (bratonien_tools_webdav_generate_derivative($params, $src, $detail))
|
if (bratonien_tools_webdav_generate_derivative($gallery_params, $src, $detail))
|
||||||
{
|
{
|
||||||
$generated_or_ready++;
|
$generated_or_ready++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.($detail !== '' ? $detail : 'Derivat konnte nicht erzeugt werden.');
|
$error_lines[] = 'Bild #'.$image_id.' Galerie: '.($detail !== '' ? $detail : 'Galeriederivat konnte nicht erzeugt werden.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
$error_lines[] = 'Bild #'.$image_id.' '.$variant_name.': '.get_class($e).': '.$e->getMessage();
|
$error_lines[] = 'Bild #'.$image_id.' Galerie: '.get_class($e).': '.$e->getMessage();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,12 +246,22 @@ try
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($variant_counts);
|
||||||
|
$variant_parts = array();
|
||||||
|
foreach ($variant_counts as $type=>$count)
|
||||||
|
{
|
||||||
|
$variant_parts[] = $type.':'.$count;
|
||||||
|
}
|
||||||
|
|
||||||
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_pro_bild=1'.
|
||||||
|
' modus_basis='.$gallery_base_type.
|
||||||
|
' modus_varianten='.implode(',', $variant_parts).
|
||||||
' bereit='.$generated_or_ready.
|
' bereit='.$generated_or_ready.
|
||||||
' identisch='.$identity.
|
' identisch='.$identity.
|
||||||
' metadaten_repariert='.$metadata_repaired.
|
' metadaten_repariert='.$metadata_repaired.
|
||||||
|
' alt_derivate_neu='.$legacy_derivatives_rebuilt.
|
||||||
' fehler='.$errors."\n";
|
' fehler='.$errors."\n";
|
||||||
|
|
||||||
exit($errors > 0 ? 1 : 0);
|
exit($errors > 0 ? 1 : 0);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ function fetch_remote_blob($url, $user, $password)
|
|||||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||||
CURLOPT_USERPWD => $user.':'.$password,
|
CURLOPT_USERPWD => $user.':'.$password,
|
||||||
CURLOPT_FAILONERROR => false,
|
CURLOPT_FAILONERROR => false,
|
||||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.7.1',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.7.16',
|
||||||
);
|
);
|
||||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
@@ -52,12 +52,11 @@ function fetch_remote_blob($url, $user, $password)
|
|||||||
|
|
||||||
function preview_extension_for_entry(array $entry)
|
function preview_extension_for_entry(array $entry)
|
||||||
{
|
{
|
||||||
$content_type = strtolower(trim((string)($entry['content_type'] ?? '')));
|
|
||||||
$path = strtolower((string)($entry['webdav_path'] ?? ''));
|
$path = strtolower((string)($entry['webdav_path'] ?? ''));
|
||||||
if ($content_type === 'image/png' || preg_match('/\.png$/', $path))
|
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||||
{
|
if ($extension === 'png') return 'png';
|
||||||
return 'png';
|
if ($extension === 'gif') return 'gif';
|
||||||
}
|
if ($extension === 'webp') return 'webp';
|
||||||
return 'jpg';
|
return 'jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ function preview_target_for_entry($cache_dir, $key, array $entry)
|
|||||||
|
|
||||||
function remove_other_preview_format($cache_dir, $key, $keep_target)
|
function remove_other_preview_format($cache_dir, $key, $keep_target)
|
||||||
{
|
{
|
||||||
foreach (array('jpg', 'png', 'webp') as $ext)
|
foreach (array('jpg', 'png', 'gif', 'webp') as $ext)
|
||||||
{
|
{
|
||||||
$candidate = $cache_dir.'/'.$key.'.'.$ext;
|
$candidate = $cache_dir.'/'.$key.'.'.$ext;
|
||||||
if ($candidate !== $keep_target && is_file($candidate)) @unlink($candidate);
|
if ($candidate !== $keep_target && is_file($candidate)) @unlink($candidate);
|
||||||
@@ -90,13 +89,19 @@ function write_preview_imagick($blob, $target, $extension)
|
|||||||
{
|
{
|
||||||
$image->setImageFormat('png');
|
$image->setImageFormat('png');
|
||||||
}
|
}
|
||||||
|
elseif ($extension === 'gif')
|
||||||
|
{
|
||||||
|
$image->setImageFormat('gif');
|
||||||
|
}
|
||||||
|
elseif ($extension === 'webp')
|
||||||
|
{
|
||||||
|
$image->setImageFormat('webp');
|
||||||
|
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$image->setImageBackgroundColor('white');
|
$image->setImageBackgroundColor('white');
|
||||||
if (method_exists($image, 'mergeImageLayers'))
|
if (method_exists($image, 'mergeImageLayers')) $image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
||||||
{
|
|
||||||
$image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
|
||||||
}
|
|
||||||
$image->setImageFormat('jpeg');
|
$image->setImageFormat('jpeg');
|
||||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||||
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
@@ -131,7 +136,7 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ($extension === 'png')
|
if (in_array($extension, array('png', 'gif', 'webp'), true))
|
||||||
{
|
{
|
||||||
imagealphablending($preview, false);
|
imagealphablending($preview, false);
|
||||||
imagesavealpha($preview, true);
|
imagesavealpha($preview, true);
|
||||||
@@ -149,10 +154,12 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
fail_preview('GD konnte das Preview nicht skalieren.');
|
fail_preview('GD konnte das Preview nicht skalieren.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$written = $extension === 'png'
|
if ($extension === 'png') $written = imagepng($preview, $target, 6);
|
||||||
? imagepng($preview, $target, 6)
|
elseif ($extension === 'gif') $written = function_exists('imagegif') ? imagegif($preview, $target) : false;
|
||||||
: imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
elseif ($extension === 'webp') $written = function_exists('imagewebp') ? imagewebp($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY) : false;
|
||||||
if (!$written) fail_preview('GD konnte das Preview nicht schreiben.');
|
else $written = imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
|
|
||||||
|
if (!$written) fail_preview('GD konnte das Preview im Format '.$extension.' nicht schreiben.');
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -168,7 +175,7 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
function write_preview($blob, $target, $extension)
|
function write_preview($blob, $target, $extension)
|
||||||
{
|
{
|
||||||
$dir = dirname($target);
|
$dir = dirname($target);
|
||||||
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
||||||
|
|
||||||
if (class_exists('Imagick'))
|
if (class_exists('Imagick'))
|
||||||
{
|
{
|
||||||
@@ -190,7 +197,48 @@ function write_preview($blob, $target, $extension)
|
|||||||
@unlink($target);
|
@unlink($target);
|
||||||
fail_preview('Das erzeugte Preview ist ungültig.');
|
fail_preview('Das erzeugte Preview ist ungültig.');
|
||||||
}
|
}
|
||||||
@chmod($target, 0644);
|
@chmod($target, 0664);
|
||||||
|
}
|
||||||
|
|
||||||
|
function local_source_is_hydrated($source_path, $preview)
|
||||||
|
{
|
||||||
|
if (!is_file($source_path) || !is_readable($source_path)) return false;
|
||||||
|
$source_size = @getimagesize($source_path);
|
||||||
|
$preview_size = @getimagesize($preview);
|
||||||
|
if (!is_array($source_size) || !is_array($preview_size)) return false;
|
||||||
|
if ((int)$source_size[0] !== (int)$preview_size[0] || (int)$source_size[1] !== (int)$preview_size[1]) return false;
|
||||||
|
$source_bytes = @filesize($source_path);
|
||||||
|
$preview_bytes = @filesize($preview);
|
||||||
|
return $source_bytes !== false && $preview_bytes !== false && (int)$source_bytes === (int)$preview_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hydrate_local_source($source_path, $preview)
|
||||||
|
{
|
||||||
|
$normalized = str_replace('\\', '/', (string)$source_path);
|
||||||
|
if (!preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/#', $normalized))
|
||||||
|
{
|
||||||
|
fail_preview('Unsicherer lokaler Connector-Quellpfad: '.$source_path);
|
||||||
|
}
|
||||||
|
if (!is_file($preview) || !is_readable($preview)) fail_preview('Preview für lokale Quelle fehlt: '.$preview);
|
||||||
|
if (local_source_is_hydrated($source_path, $preview)) return false;
|
||||||
|
|
||||||
|
$dir = dirname($source_path);
|
||||||
|
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Lokales Connector-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||||
|
|
||||||
|
$tmp = $source_path.'.bratonien-next-'.getmypid();
|
||||||
|
if (!@copy($preview, $tmp)) fail_preview('Preview konnte nicht in lokale Piwigo-Quelle kopiert werden: '.$source_path);
|
||||||
|
@chmod($tmp, 0664);
|
||||||
|
$mtime = @filemtime($preview);
|
||||||
|
if ($mtime) @touch($tmp, $mtime);
|
||||||
|
if (!@rename($tmp, $source_path))
|
||||||
|
{
|
||||||
|
@unlink($tmp);
|
||||||
|
fail_preview('Lokale Piwigo-Quelle konnte nicht ersetzt werden: '.$source_path);
|
||||||
|
}
|
||||||
|
clearstatcache(true, $source_path);
|
||||||
|
$size = @getimagesize($source_path);
|
||||||
|
if (!is_array($size) || empty($size[0]) || empty($size[1])) fail_preview('Lokale Piwigo-Quelle ist nach dem Ersetzen ungültig: '.$source_path);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -212,8 +260,8 @@ try
|
|||||||
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
||||||
if (!is_array($mapping) || !isset($mapping['files']) || !is_array($mapping['files'])) fail_preview('WebDAV-Mapping ist ungültig.');
|
if (!is_array($mapping) || !isset($mapping['files']) || !is_array($mapping['files'])) fail_preview('WebDAV-Mapping ist ungültig.');
|
||||||
|
|
||||||
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0755, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0775, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
||||||
@chmod($cache_dir, 0755);
|
@chmod($cache_dir, 2775);
|
||||||
|
|
||||||
$state_file = $cache_dir.'/state.json';
|
$state_file = $cache_dir.'/state.json';
|
||||||
$old_state = array();
|
$old_state = array();
|
||||||
@@ -226,9 +274,10 @@ try
|
|||||||
$new_state = array();
|
$new_state = array();
|
||||||
$generated = 0;
|
$generated = 0;
|
||||||
$cached = 0;
|
$cached = 0;
|
||||||
|
$hydrated = 0;
|
||||||
$errors = 0;
|
$errors = 0;
|
||||||
|
|
||||||
foreach ($mapping['files'] as $entry)
|
foreach ($mapping['files'] as $local_path=>$entry)
|
||||||
{
|
{
|
||||||
if (!is_array($entry) || (string)($entry['kind'] ?? '') !== 'file') continue;
|
if (!is_array($entry) || (string)($entry['kind'] ?? '') !== 'file') continue;
|
||||||
$webdav_path = trim((string)($entry['webdav_path'] ?? ''), '/');
|
$webdav_path = trim((string)($entry['webdav_path'] ?? ''), '/');
|
||||||
@@ -245,20 +294,16 @@ try
|
|||||||
'version' => BRATONIEN_WEBDAV_PREVIEW_VERSION,
|
'version' => BRATONIEN_WEBDAV_PREVIEW_VERSION,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$old = $old_state[$key] ?? null;
|
$old = $old_state[$key] ?? null;
|
||||||
if (
|
$valid_cached = is_file($target)
|
||||||
is_file($target)
|
|
||||||
&& is_array($old)
|
&& is_array($old)
|
||||||
&& (string)($old['etag'] ?? '') === $etag
|
&& (string)($old['etag'] ?? '') === $etag
|
||||||
&& (string)($old['format'] ?? '') === $extension
|
&& (string)($old['format'] ?? '') === $extension
|
||||||
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION
|
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION;
|
||||||
)
|
|
||||||
{
|
|
||||||
$cached++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
if (!$valid_cached)
|
||||||
{
|
{
|
||||||
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
||||||
$blob = fetch_remote_blob($url, $user, $password);
|
$blob = fetch_remote_blob($url, $user, $password);
|
||||||
@@ -266,6 +311,13 @@ try
|
|||||||
remove_other_preview_format($cache_dir, $key, $target);
|
remove_other_preview_format($cache_dir, $key, $target);
|
||||||
$generated++;
|
$generated++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$cached++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hydrate_local_source((string)$local_path, $target)) $hydrated++;
|
||||||
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
@@ -277,14 +329,14 @@ try
|
|||||||
{
|
{
|
||||||
if (!is_file($file) || basename($file) === 'state.json') continue;
|
if (!is_file($file) || basename($file) === 'state.json') continue;
|
||||||
$name = basename($file);
|
$name = basename($file);
|
||||||
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|webp)$/', $name, $m)) continue;
|
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|gif|webp)$/', $name, $m)) continue;
|
||||||
if (!isset($new_state[$m[1]])) @unlink($file);
|
if (!isset($new_state[$m[1]])) @unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($state_file, json_encode($new_state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n", LOCK_EX);
|
file_put_contents($state_file, json_encode($new_state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n", LOCK_EX);
|
||||||
@chmod($state_file, 0644);
|
@chmod($state_file, 0664);
|
||||||
|
|
||||||
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' fehler='.$errors."\n";
|
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' lokale_quellen='.$hydrated.' fehler='.$errors."\n";
|
||||||
exit($errors > 0 ? 1 : 0);
|
exit($errors > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ if (PHP_SAPI !== 'cli')
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$options = getopt('', array('connection-id::'));
|
||||||
|
$connectionId = isset($options['connection-id']) ? (int)$options['connection-id'] : 0;
|
||||||
|
|
||||||
$pluginRoot = dirname(__DIR__);
|
$pluginRoot = dirname(__DIR__);
|
||||||
$piwigoRoot = dirname($pluginRoot, 2);
|
$piwigoRoot = dirname($pluginRoot, 2);
|
||||||
$base = rtrim($piwigoRoot, '/').'/_data/bratonien-tools';
|
$base = rtrim($piwigoRoot, '/').'/_data/bratonien-tools';
|
||||||
@@ -44,9 +47,10 @@ $state = native_scheduler_state($stateFile);
|
|||||||
$state['enabled'] = true;
|
$state['enabled'] = true;
|
||||||
$state['mode'] = 'piwigo-native';
|
$state['mode'] = 'piwigo-native';
|
||||||
$state['state'] = 'running';
|
$state['state'] = 'running';
|
||||||
$state['message'] = 'NC-Abgleich läuft.';
|
$state['message'] = $connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' läuft.' : 'NC-Abgleich läuft.';
|
||||||
$state['started_at'] = time();
|
$state['started_at'] = time();
|
||||||
$state['timestamp'] = time();
|
$state['timestamp'] = time();
|
||||||
|
$state['connection_id'] = $connectionId;
|
||||||
native_scheduler_write($stateFile, $state);
|
native_scheduler_write($stateFile, $state);
|
||||||
|
|
||||||
$env = $_ENV;
|
$env = $_ENV;
|
||||||
@@ -55,6 +59,7 @@ $env['BRATONIEN_NC_NATIVE'] = '1';
|
|||||||
$env['BRATONIEN_NC_PIWIGO_ROOT'] = $piwigoRoot;
|
$env['BRATONIEN_NC_PIWIGO_ROOT'] = $piwigoRoot;
|
||||||
$env['BRATONIEN_NC_CONFIG_DIR'] = $runtimeDir;
|
$env['BRATONIEN_NC_CONFIG_DIR'] = $runtimeDir;
|
||||||
$env['BRATONIEN_NC_STATE_ROOT'] = $stateRoot;
|
$env['BRATONIEN_NC_STATE_ROOT'] = $stateRoot;
|
||||||
|
$env['BRATONIEN_NC_CONNECTION_ID'] = (string)$connectionId;
|
||||||
$env['LC_ALL'] = 'C';
|
$env['LC_ALL'] = 'C';
|
||||||
$env['LANG'] = 'C';
|
$env['LANG'] = 'C';
|
||||||
|
|
||||||
@@ -86,10 +91,13 @@ $state = native_scheduler_state($stateFile);
|
|||||||
$state['enabled'] = true;
|
$state['enabled'] = true;
|
||||||
$state['mode'] = 'piwigo-native';
|
$state['mode'] = 'piwigo-native';
|
||||||
$state['state'] = $exit === 0 ? 'success' : 'error';
|
$state['state'] = $exit === 0 ? 'success' : 'error';
|
||||||
$state['message'] = $exit === 0 ? 'NC-Abgleich erfolgreich abgeschlossen.' : 'NC-Abgleich fehlgeschlagen.';
|
$state['message'] = $exit === 0
|
||||||
|
? ($connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' erfolgreich abgeschlossen.' : 'NC-Abgleich erfolgreich abgeschlossen.')
|
||||||
|
: ($connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' fehlgeschlagen.' : 'NC-Abgleich fehlgeschlagen.');
|
||||||
$state['timestamp'] = time();
|
$state['timestamp'] = time();
|
||||||
$state['finished_at'] = time();
|
$state['finished_at'] = time();
|
||||||
$state['exit_code'] = $exit;
|
$state['exit_code'] = $exit;
|
||||||
|
$state['connection_id'] = $connectionId;
|
||||||
$state['stdout'] = trim($stdout);
|
$state['stdout'] = trim($stdout);
|
||||||
$state['stderr'] = trim($stderr);
|
$state['stderr'] = trim($stderr);
|
||||||
if (empty($state['next_due']) || (int)$state['next_due'] < time())
|
if (empty($state['next_due']) || (int)$state['next_due'] < time())
|
||||||
|
|||||||
36
runtime/repair-webdav-cache-permissions.sh
Normal file
36
runtime/repair-webdav-cache-permissions.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
PIWIGO_ROOT="${1:-/var/www/piwigo}"
|
||||||
|
PIWIGO_ROOT="${PIWIGO_ROOT%/}"
|
||||||
|
DATA_DIR="$PIWIGO_ROOT/_data"
|
||||||
|
|
||||||
|
[[ -d "$DATA_DIR" ]] || { echo "Piwigo-_data wurde nicht gefunden: $DATA_DIR" >&2; exit 1; }
|
||||||
|
[[ "$(id -u)" -eq 0 ]] || { echo "Die Reparatur muss als root ausgeführt werden." >&2; exit 1; }
|
||||||
|
|
||||||
|
DATA_UID="$(stat -c '%u' "$DATA_DIR")"
|
||||||
|
DATA_GID="$(stat -c '%g' "$DATA_DIR")"
|
||||||
|
|
||||||
|
PATHS=(
|
||||||
|
"$DATA_DIR/bratonien-tools/nc-webdav-gallery"
|
||||||
|
"$DATA_DIR/bratonien-tools/nc-webdav-preview"
|
||||||
|
"$DATA_DIR/i/_data/bratonien-tools/nc-webdav-gallery"
|
||||||
|
"$DATA_DIR/i/bratonien-watermark"
|
||||||
|
)
|
||||||
|
|
||||||
|
found=0
|
||||||
|
for path in "${PATHS[@]}"; do
|
||||||
|
[[ -e "$path" ]] || continue
|
||||||
|
found=1
|
||||||
|
echo "Repariere: $path"
|
||||||
|
chown -R "$DATA_UID:$DATA_GID" -- "$path"
|
||||||
|
find "$path" -type d -exec chmod 2775 {} +
|
||||||
|
find "$path" -type f -exec chmod 0664 {} +
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$found" -eq 0 ]]; then
|
||||||
|
echo "Keine Bratonien-Cache-Verzeichnisse gefunden."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Bratonien-Cache-Rechte wurden an $DATA_DIR angeglichen (UID $DATA_UID, GID $DATA_GID)."
|
||||||
@@ -5,6 +5,7 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
PIWIGO_ROOT_DEFAULT="${BRATONIEN_NC_PIWIGO_ROOT:-$(cd -- "$SCRIPT_DIR/../../.." && pwd)}"
|
PIWIGO_ROOT_DEFAULT="${BRATONIEN_NC_PIWIGO_ROOT:-$(cd -- "$SCRIPT_DIR/../../.." && pwd)}"
|
||||||
CONFIG_DIR="${BRATONIEN_NC_CONFIG_DIR:-/etc/bratonien-tools/nc-connector}"
|
CONFIG_DIR="${BRATONIEN_NC_CONFIG_DIR:-/etc/bratonien-tools/nc-connector}"
|
||||||
NATIVE_MODE="${BRATONIEN_NC_NATIVE:-0}"
|
NATIVE_MODE="${BRATONIEN_NC_NATIVE:-0}"
|
||||||
|
TARGET_CONNECTION_ID="${BRATONIEN_NC_CONNECTION_ID:-0}"
|
||||||
GLOBAL_LOCK_DIR="${PIWIGO_ROOT_DEFAULT%/}/_data/bratonien-tools/nc-connector-scheduler"
|
GLOBAL_LOCK_DIR="${PIWIGO_ROOT_DEFAULT%/}/_data/bratonien-tools/nc-connector-scheduler"
|
||||||
GLOBAL_LOCK_FILE="$GLOBAL_LOCK_DIR/worker.lock"
|
GLOBAL_LOCK_FILE="$GLOBAL_LOCK_DIR/worker.lock"
|
||||||
mkdir -p -- "$GLOBAL_LOCK_DIR"
|
mkdir -p -- "$GLOBAL_LOCK_DIR"
|
||||||
@@ -15,6 +16,11 @@ if ! flock -n 8; then
|
|||||||
fi
|
fi
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
|
if [[ ! "$TARGET_CONNECTION_ID" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "NC Connector: ungültige Ziel-Verbindungs-ID: $TARGET_CONNECTION_ID" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
read_config_value() {
|
read_config_value() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
local file="$2"
|
local file="$2"
|
||||||
@@ -69,6 +75,10 @@ fi
|
|||||||
route_piwigo_root=""
|
route_piwigo_root=""
|
||||||
for candidate in "${webdav_configs[@]}" "${configs[@]}"; do
|
for candidate in "${webdav_configs[@]}" "${configs[@]}"; do
|
||||||
[[ -f "$candidate" ]] || continue
|
[[ -f "$candidate" ]] || continue
|
||||||
|
candidate_id="$(read_config_value CONNECTION_ID "$candidate")"
|
||||||
|
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$candidate_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
route_piwigo_root="$(read_config_value PIWIGO_ROOT "$candidate")"
|
route_piwigo_root="$(read_config_value PIWIGO_ROOT "$candidate")"
|
||||||
[[ -n "$route_piwigo_root" ]] && break
|
[[ -n "$route_piwigo_root" ]] && break
|
||||||
done
|
done
|
||||||
@@ -79,6 +89,7 @@ failure_count=0
|
|||||||
webdav_count=0
|
webdav_count=0
|
||||||
local_count=0
|
local_count=0
|
||||||
summary_parts=()
|
summary_parts=()
|
||||||
|
matched_count=0
|
||||||
|
|
||||||
for config in "${webdav_configs[@]}"; do
|
for config in "${webdav_configs[@]}"; do
|
||||||
[[ -f "$config" ]] || continue
|
[[ -f "$config" ]] || continue
|
||||||
@@ -90,7 +101,11 @@ for config in "${webdav_configs[@]}"; do
|
|||||||
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$connection_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
matched_count=$((matched_count + 1))
|
||||||
webdav_count=$((webdav_count + 1))
|
webdav_count=$((webdav_count + 1))
|
||||||
echo "NC Connector WebDAV #$connection_id: $name"
|
echo "NC Connector WebDAV #$connection_id: $name"
|
||||||
output=""
|
output=""
|
||||||
@@ -119,7 +134,11 @@ if [[ "$NATIVE_MODE" != "1" ]]; then
|
|||||||
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$connection_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
matched_count=$((matched_count + 1))
|
||||||
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
||||||
[[ -n "$piwigo_root" ]] || piwigo_root="$PIWIGO_ROOT_DEFAULT"
|
[[ -n "$piwigo_root" ]] || piwigo_root="$PIWIGO_ROOT_DEFAULT"
|
||||||
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
||||||
@@ -145,6 +164,12 @@ if [[ "$NATIVE_MODE" != "1" ]]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$matched_count" -eq 0 ]]; then
|
||||||
|
write_route_status "failed" "FEHLER - Verbindung #$TARGET_CONNECTION_ID" "Keine Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." "0"
|
||||||
|
echo "NC Connector: keine Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
||||||
[[ -n "$summary_detail" ]] || summary_detail="Keine Verbindung wurde ausgefuehrt."
|
[[ -n "$summary_detail" ]] || summary_detail="Keine Verbindung wurde ausgefuehrt."
|
||||||
|
|
||||||
@@ -160,10 +185,10 @@ if [[ "$failure_count" -eq 0 ]]; then
|
|||||||
label="Local"
|
label="Local"
|
||||||
fi
|
fi
|
||||||
write_route_status "$route" "$label" "$summary_detail" "1"
|
write_route_status "$route" "$label" "$summary_detail" "1"
|
||||||
echo "NC Connector: alle Verbindungen wurden erfolgreich verarbeitet."
|
echo "NC Connector: angeforderte Verbindung wurde erfolgreich verarbeitet."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
write_route_status "failed" "FEHLER - mindestens eine Verbindung" "$summary_detail" "0"
|
write_route_status "failed" "FEHLER - angeforderte Verbindung" "$summary_detail" "0"
|
||||||
echo "NC Connector: mindestens eine Verbindung ist fehlgeschlagen." >&2
|
echo "NC Connector: die angeforderte Verbindung ist fehlgeschlagen." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function bratonien_tools_save_album_rule()
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Albumregel gespeichert.');
|
return array('message'=>'Albumregel gespeichert.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +98,6 @@ function bratonien_tools_resolve_album_rule($category_id, array $categories, arr
|
|||||||
$root = $by_id[$category_id] ?? null;
|
$root = $by_id[$category_id] ?? null;
|
||||||
$is_private = $root && isset($root['status']) && $root['status'] === 'private';
|
$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 ($is_private)
|
||||||
{
|
{
|
||||||
if (isset($rules[$category_id]))
|
if (isset($rules[$category_id]))
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ function bratonien_tools_save_watermark_profile()
|
|||||||
mass_inserts($table, array_keys($data), array($data));
|
mass_inserts($table, array_keys($data), array($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Wasserzeichenprofil gespeichert.');
|
return array('message'=>'Wasserzeichenprofil gespeichert.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +159,7 @@ function bratonien_tools_delete_watermark_profile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
pwg_query('DELETE FROM '.bratonien_tools_table('watermark_profiles').' WHERE id='.$id);
|
pwg_query('DELETE FROM '.bratonien_tools_table('watermark_profiles').' WHERE id='.$id);
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Wasserzeichenprofil geloescht.');
|
return array('message'=>'Wasserzeichenprofil geloescht.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +176,7 @@ function bratonien_tools_duplicate_watermark_profile()
|
|||||||
$profile['name'] .= ' (Kopie)';
|
$profile['name'] .= ' (Kopie)';
|
||||||
$profile['created'] = date('Y-m-d H:i:s');
|
$profile['created'] = date('Y-m-d H:i:s');
|
||||||
mass_inserts(bratonien_tools_table('watermark_profiles'), array_keys($profile), array($profile));
|
mass_inserts(bratonien_tools_table('watermark_profiles'), array_keys($profile), array($profile));
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
|
|
||||||
return array('message'=>'Wasserzeichenprofil dupliziert.');
|
return array('message'=>'Wasserzeichenprofil dupliziert.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,59 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
die('Hacking attempt!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_watermark_cache_dir()
|
||||||
|
{
|
||||||
|
return PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.'bratonien-watermark';
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_remove_tree($path)
|
||||||
|
{
|
||||||
|
$path = rtrim((string)$path, DIRECTORY_SEPARATOR);
|
||||||
|
if ($path === '' || !file_exists($path)) return;
|
||||||
|
|
||||||
|
if (is_file($path) || is_link($path))
|
||||||
|
{
|
||||||
|
@unlink($path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (scandir($path) ?: array() as $entry)
|
||||||
|
{
|
||||||
|
if ($entry === '.' || $entry === '..') continue;
|
||||||
|
bratonien_tools_remove_tree($path.DIRECTORY_SEPARATOR.$entry);
|
||||||
|
}
|
||||||
|
@rmdir($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_clear_watermark_cache()
|
||||||
|
{
|
||||||
|
$dir = bratonien_tools_watermark_cache_dir();
|
||||||
|
$derivative_root = realpath(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR);
|
||||||
|
$parent = realpath(dirname($dir));
|
||||||
|
|
||||||
|
if ($derivative_root === false || $parent === false || $parent !== $derivative_root)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Wasserzeichen-Cachepfad ist ungueltig.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($dir))
|
||||||
|
{
|
||||||
|
bratonien_tools_remove_tree($dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_watermark_cache_upgrade()
|
||||||
|
{
|
||||||
|
$version = '0.9.7.13';
|
||||||
|
if ((string)conf_get_param('bratonien_watermark_cache_version', '') === $version)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
|
conf_update_param('bratonien_watermark_cache_version', $version);
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_get_watermark_defaults()
|
function bratonien_tools_get_watermark_defaults()
|
||||||
{
|
{
|
||||||
$defaults = conf_get_param('bratonien_watermark_defaults', null);
|
$defaults = conf_get_param('bratonien_watermark_defaults', null);
|
||||||
@@ -40,6 +93,7 @@ function bratonien_tools_save_watermark_defaults()
|
|||||||
);
|
);
|
||||||
|
|
||||||
conf_update_param('bratonien_watermark_defaults', json_encode($config));
|
conf_update_param('bratonien_watermark_defaults', json_encode($config));
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
|
|
||||||
return array('message'=>'Globale Wasserzeichenregeln gespeichert.');
|
return array('message'=>'Globale Wasserzeichenregeln gespeichert.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,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.1',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.16',
|
||||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||||
{
|
{
|
||||||
$length = strlen($line);
|
$length = strlen($line);
|
||||||
|
|||||||
Reference in New Issue
Block a user