mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-20 12:13:16 +00:00
Gekoppelte NC-Verbindung als Einheit loeschen
This commit is contained in:
@@ -83,11 +83,39 @@ SELECT DISTINCT i.id, i.path, i.representative_ext
|
|||||||
return array('site_id'=>$site_id, 'images'=>count($image_rows));
|
return array('site_id'=>$site_id, 'images'=>count($image_rows));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_connector_logical_delete_members(array $connection)
|
||||||
|
{
|
||||||
|
$members = array((int)$connection['id'] => $connection);
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$migration = isset($config['migration']) && is_array($config['migration']) ? $config['migration'] : array();
|
||||||
|
$role = (string)($migration['role'] ?? '');
|
||||||
|
|
||||||
|
if ($role === 'webdav-primary-candidate')
|
||||||
|
{
|
||||||
|
$legacy_id = (int)($migration['legacy_fallback_connection_id'] ?? 0);
|
||||||
|
if ($legacy_id > 0)
|
||||||
|
{
|
||||||
|
$legacy = bratonien_tools_nc_connector_connection($legacy_id, false);
|
||||||
|
if ($legacy && (string)$legacy['adapter'] === 'local') $members[$legacy_id] = $legacy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($role === 'legacy-fallback')
|
||||||
|
{
|
||||||
|
$remote_id = (int)($migration['webdav_successor_connection_id'] ?? 0);
|
||||||
|
if ($remote_id > 0)
|
||||||
|
{
|
||||||
|
$remote = bratonien_tools_nc_connector_connection($remote_id, false);
|
||||||
|
if ($remote && (string)$remote['adapter'] === 'remote') $members[$remote_id] = $remote;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $members;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a connector connection from Piwigo without depending on the web
|
* Delete one user-facing connector connection. A migration pair is one logical
|
||||||
* server being allowed to write into root-owned runtime directories.
|
* connection for the user, so its internal WebDAV and Legacy records are
|
||||||
* WebDAV-managed Piwigo records are removed before the connection itself so
|
* removed together.
|
||||||
* deleted remote content cannot remain visible or addressable in Piwigo.
|
|
||||||
*/
|
*/
|
||||||
function bratonien_tools_nc_connector_delete_safe()
|
function bratonien_tools_nc_connector_delete_safe()
|
||||||
{
|
{
|
||||||
@@ -98,38 +126,44 @@ function bratonien_tools_nc_connector_delete_safe()
|
|||||||
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$members = bratonien_tools_nc_connector_logical_delete_members($connection);
|
||||||
$cleanup = array('site_id'=>0, 'images'=>0);
|
$cleanup = array('site_id'=>0, 'images'=>0);
|
||||||
|
foreach ($members as $member)
|
||||||
|
{
|
||||||
if (
|
if (
|
||||||
(string)($connection['adapter'] ?? '') === 'remote'
|
(string)($member['adapter'] ?? '') === 'remote'
|
||||||
&& (string)($connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
&& (string)($member['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$cleanup = bratonien_tools_nc_connector_remove_webdav_piwigo_content($connection);
|
$cleanup = bratonien_tools_nc_connector_remove_webdav_piwigo_content($member);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = bratonien_tools_nc_connector_table();
|
$table = bratonien_tools_nc_connector_table();
|
||||||
pwg_query("DELETE FROM `$table` WHERE id=".$id." LIMIT 1");
|
|
||||||
|
|
||||||
$status_dir = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status';
|
$status_dir = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status';
|
||||||
$public_status = $status_dir.'/connection-'.$id.'.json';
|
foreach ($members as $member_id=>$member)
|
||||||
if (is_file($public_status))
|
|
||||||
{
|
{
|
||||||
@unlink($public_status);
|
$member_id = (int)$member_id;
|
||||||
}
|
pwg_query("DELETE FROM `$table` WHERE id=".$member_id." LIMIT 1");
|
||||||
|
|
||||||
|
$public_status = $status_dir.'/connection-'.$member_id.'.json';
|
||||||
|
if (is_file($public_status)) @unlink($public_status);
|
||||||
|
|
||||||
if (is_dir($status_dir) || @mkdir($status_dir, 0755, true))
|
if (is_dir($status_dir) || @mkdir($status_dir, 0755, true))
|
||||||
{
|
{
|
||||||
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
@file_put_contents($status_dir.'/deleted-'.$member_id, date('c')."\n", LOCK_EX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)$cleanup['site_id'] > 0)
|
if ((int)$cleanup['site_id'] > 0)
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'message'=>'Connector-Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert. Laufzeit- und Vorschaudaten werden automatisch bereinigt.',
|
'message'=>'Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'message'=>'Connector-Verbindung wurde gelöscht. Verbliebene Laufzeitdateien werden vor dem nächsten Connector-Lauf automatisch entfernt. Quelldateien blieben unverändert.',
|
'message'=>'Verbindung wurde gelöscht. Verbliebene Laufzeitdaten werden automatisch bereinigt. Quelldateien blieben unverändert.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user