Re-key explicit ACL entries for an entire subtree: old/... → new/... */
(string $oldFolder, string $newFolder)
| 282 | |
| 283 | /** Re-key explicit ACL entries for an entire subtree: old/... → new/... */ |
| 284 | public static function renameTree(string $oldFolder, string $newFolder): void |
| 285 | { |
| 286 | $old = self::normalizeFolder($oldFolder); |
| 287 | $new = self::normalizeFolder($newFolder); |
| 288 | if ($old === '' || $old === 'root') { |
| 289 | return; // nothing to re-key for root |
| 290 | } |
| 291 | |
| 292 | $acl = self::$cache ?? self::loadFresh(); |
| 293 | if (!isset($acl['folders']) || !is_array($acl['folders'])) { |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | $rebased = []; |
| 298 | foreach ($acl['folders'] as $k => $rec) { |
| 299 | if ($k === $old || strpos($k, $old . '/') === 0) { |
| 300 | $suffix = substr($k, strlen($old)); |
| 301 | $suffix = ltrim((string)$suffix, '/'); |
| 302 | $newKey = $new . ($suffix !== '' ? '/' . $suffix : ''); |
| 303 | $rebased[$newKey] = $rec; |
| 304 | } else { |
| 305 | $rebased[$k] = $rec; |
| 306 | } |
| 307 | } |
| 308 | $acl['folders'] = $rebased; |
| 309 | self::save($acl); |
| 310 | } |
| 311 | |
| 312 | /** Remove explicit ACL entries for a folder subtree. */ |
| 313 | public static function deleteTree(string $folder): array |
no test coverage detected