mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 19:54:31 +00:00
Merge pull request #52 from Terranom674/fix/0963-clean-webdav-orphans
0.9.6.3: verwaiste WebDAV-Bilder einmalig bereinigen
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.6.2
|
Version: 0.9.6.3
|
||||||
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
|
||||||
|
|||||||
101
runtime/repair-webdav-orphans.php
Normal file
101
runtime/repair-webdav-orphans.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
if (PHP_SAPI !== 'cli')
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "CLI only\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginRoot = dirname(__DIR__);
|
||||||
|
$piwigoRoot = dirname($pluginRoot, 2);
|
||||||
|
define('PHPWG_ROOT_PATH', rtrim($piwigoRoot, '/').'/');
|
||||||
|
|
||||||
|
$_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/repair-webdav-orphans.php';
|
||||||
|
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
|
||||||
|
$_SERVER['QUERY_STRING'] = '';
|
||||||
|
$_SERVER['HTTPS'] = 'off';
|
||||||
|
|
||||||
|
require_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||||
|
require_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
$stateRoot = '/var/lib/bratonien-tools/nc-connector';
|
||||||
|
$marker = $stateRoot.'/.webdav-orphan-repair-0963.done';
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (is_file($marker))
|
||||||
|
{
|
||||||
|
echo "NC WebDAV Altlasten-Reparatur: bereits abgeschlossen.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_dir($stateRoot) && !mkdir($stateRoot, 0750, true))
|
||||||
|
{
|
||||||
|
throw new RuntimeException('State-Verzeichnis konnte nicht angelegt werden: '.$stateRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
$relativePrefix = './_data/bratonien-tools/nc-webdav-gallery/connection-';
|
||||||
|
$absolutePrefix = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-webdav-gallery/connection-';
|
||||||
|
$relativeLength = strlen($relativePrefix);
|
||||||
|
$absoluteLength = strlen($absolutePrefix);
|
||||||
|
|
||||||
|
$query = "SELECT id,path FROM ".IMAGES_TABLE.
|
||||||
|
" WHERE LEFT(path,".$relativeLength.")='".pwg_db_real_escape_string($relativePrefix)."'".
|
||||||
|
" OR LEFT(path,".$absoluteLength.")='".pwg_db_real_escape_string($absolutePrefix)."'";
|
||||||
|
$result = pwg_query($query);
|
||||||
|
|
||||||
|
$staleIds = array();
|
||||||
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
$id = (int)$row['id'];
|
||||||
|
$storedPath = (string)$row['path'];
|
||||||
|
if ($id < 1 || $storedPath === '') continue;
|
||||||
|
|
||||||
|
if (strpos($storedPath, $relativePrefix) === 0)
|
||||||
|
{
|
||||||
|
$filesystemPath = rtrim(PHPWG_ROOT_PATH, '/').'/'.ltrim(substr($storedPath, 2), '/');
|
||||||
|
}
|
||||||
|
elseif (strpos($storedPath, $absolutePrefix) === 0)
|
||||||
|
{
|
||||||
|
$filesystemPath = $storedPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_file($filesystemPath))
|
||||||
|
{
|
||||||
|
$staleIds[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$staleIds = array_values(array_unique(array_map('intval', $staleIds)));
|
||||||
|
if ($staleIds)
|
||||||
|
{
|
||||||
|
delete_elements($staleIds, false);
|
||||||
|
invalidate_user_cache(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = date('c').' removed='.count($staleIds)."\n";
|
||||||
|
if (file_put_contents($marker, $payload, LOCK_EX) === false)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Abschlussmarker konnte nicht geschrieben werden: '.$marker);
|
||||||
|
}
|
||||||
|
@chmod($marker, 0640);
|
||||||
|
|
||||||
|
echo 'NC WebDAV Altlasten-Reparatur: entfernte verwaiste Bilder='.count($staleIds)."\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
catch (Throwable $e)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, 'NC WebDAV Altlasten-Reparatur: '.$e->getMessage()."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
@@ -10,6 +10,11 @@ if ! php "$SCRIPT_DIR/reconcile-webdav.php"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! php "$SCRIPT_DIR/repair-webdav-orphans.php"; then
|
||||||
|
echo "NC Connector: verwaiste WebDAV-Bilddatensaetze konnten nicht repariert werden." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if ! php "$SCRIPT_DIR/cleanup-webdav-piwigo.php"; then
|
if ! php "$SCRIPT_DIR/cleanup-webdav-piwigo.php"; then
|
||||||
echo "NC Connector: Piwigo-Inhalte geloeschter WebDAV-Verbindungen konnten nicht bereinigt werden." >&2
|
echo "NC Connector: Piwigo-Inhalte geloeschter WebDAV-Verbindungen konnten nicht bereinigt werden." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user