MCPcopy Create free account
hub / github.com/error311/FileRise / renameTree

Method renameTree

src/FileRise/Support/ACL.php:284–310  ·  view source on GitHub ↗

Re-key explicit ACL entries for an entire subtree: old/... → new/... */

(string $oldFolder, string $newFolder)

Source from the content-addressed store, hash-verified

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

Callers 1

renameFolderMethod · 0.80

Calls 3

normalizeFolderMethod · 0.95
loadFreshMethod · 0.95
saveMethod · 0.95

Tested by

no test coverage detected