mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 10:34:30 +00:00
Compare commits
3 Commits
59792988da
...
78f34fceb9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78f34fceb9 | ||
|
|
e790bff498 | ||
|
|
a2b1d31f8c |
@@ -4,17 +4,21 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_webdav_source_index_file($state_dir)
|
||||
function bratonien_tools_webdav_source_index_file($state_dir, $connection_id=0)
|
||||
{
|
||||
$state_dir = rtrim((string)$state_dir, '/');
|
||||
if ($state_dir === '') throw new RuntimeException('Connector-State-Verzeichnis fehlt für den WebDAV-Quellenindex.');
|
||||
return $state_dir.'/webdav-cache-index.json';
|
||||
// Der Quellenindex gehoert dem Piwigo-Worker und muss deshalb in einem
|
||||
// Verzeichnis liegen, das derselbe Benutzer wie der Admin-/CLI-Worker
|
||||
// schreiben kann. Das Connector-State-Verzeichnis ist fuer den Worker nur
|
||||
// lesende Eingabe (Mapping/Priority), nicht sein eigener persistenter State.
|
||||
$connection_id = (int)$connection_id;
|
||||
if ($connection_id < 1) throw new RuntimeException('Verbindungs-ID fehlt fuer den WebDAV-Quellenindex.');
|
||||
return PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-webdav-cache-index.connection-'.$connection_id.'.json';
|
||||
}
|
||||
|
||||
function bratonien_tools_webdav_source_index_empty($connection_id)
|
||||
{
|
||||
return array(
|
||||
'schema_version'=>2,
|
||||
'schema_version'=>3,
|
||||
'connection_id'=>(int)$connection_id,
|
||||
'updated_at'=>0,
|
||||
'last_periodic_at'=>0,
|
||||
@@ -24,7 +28,7 @@ function bratonien_tools_webdav_source_index_empty($connection_id)
|
||||
|
||||
function bratonien_tools_webdav_source_index_load($state_dir, $connection_id)
|
||||
{
|
||||
$file = bratonien_tools_webdav_source_index_file($state_dir);
|
||||
$file = bratonien_tools_webdav_source_index_file($state_dir, $connection_id);
|
||||
if (!is_file($file) || !is_readable($file)) return null;
|
||||
|
||||
$raw = @file_get_contents($file);
|
||||
@@ -40,14 +44,14 @@ function bratonien_tools_webdav_source_index_load($state_dir, $connection_id)
|
||||
|
||||
function bratonien_tools_webdav_source_index_save($state_dir, $connection_id, array $index)
|
||||
{
|
||||
$file = bratonien_tools_webdav_source_index_file($state_dir);
|
||||
$file = bratonien_tools_webdav_source_index_file($state_dir, $connection_id);
|
||||
$directory = dirname($file);
|
||||
if (!is_dir($directory) && !@mkdir($directory, 0775, true) && !is_dir($directory))
|
||||
{
|
||||
throw new RuntimeException('WebDAV-Quellenindex-Verzeichnis konnte nicht angelegt werden.');
|
||||
}
|
||||
|
||||
$index['schema_version'] = 2;
|
||||
$index['schema_version'] = 3;
|
||||
$index['connection_id'] = (int)$connection_id;
|
||||
$index['updated_at'] = time();
|
||||
if (!isset($index['sources']) || !is_array($index['sources'])) $index['sources'] = array();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Bratonien Tools
|
||||
Version: 0.9.7.1.21
|
||||
Version: 0.9.7.1.22
|
||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||
Author: Bratonien
|
||||
|
||||
@@ -27,9 +27,20 @@ source "$CONFIG_FILE"
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LOCK_FILE="$STATE_DIR/webdav-sync.lock"
|
||||
WORKER_LOCK_FILE="$STATE_DIR/webdav-cache-warmup.lock"
|
||||
mkdir -p -- "$STATE_DIR"
|
||||
chgrp www-data -- "$STATE_DIR"
|
||||
chmod 0750 -- "$STATE_DIR"
|
||||
|
||||
# Das Connector-State-Verzeichnis bleibt fuer www-data bewusst nicht
|
||||
# beschreibbar. Die beiden gemeinsam verwendeten Lock-Dateien werden deshalb
|
||||
# vom privilegierten Connector explizit angelegt und gruppenschreibbar gemacht.
|
||||
# So kann der Piwigo-CLI-Worker vorhandene Locks oeffnen, ohne Schreibrechte
|
||||
# auf das gesamte Connector-State-Verzeichnis zu erhalten.
|
||||
touch -- "$LOCK_FILE" "$WORKER_LOCK_FILE"
|
||||
chgrp www-data -- "$LOCK_FILE" "$WORKER_LOCK_FILE"
|
||||
chmod 0660 -- "$LOCK_FILE" "$WORKER_LOCK_FILE"
|
||||
|
||||
exec 9>"$LOCK_FILE"
|
||||
flock -n 9 || exit 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user