From 0fdd8f87cbfddef35aa54a8cc6f7b0febb7fe635 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 28 Apr 2020 14:16:09 -0600 Subject: [PATCH] Api: Fix out of memory error when deleting users and filesystem is large Fixed by not deleting the files, just changing owner --- api/src/Vfs/Hooks.php | 10 ++-------- api/src/Vfs/Sqlfs/StreamWrapper.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/api/src/Vfs/Hooks.php b/api/src/Vfs/Hooks.php index b885e23189..99f115d60a 100644 --- a/api/src/Vfs/Hooks.php +++ b/api/src/Vfs/Hooks.php @@ -97,8 +97,6 @@ class Hooks } Api\Vfs::rename('/home/'.$data['account_lid'],$new_dir); - // make the new owner the owner of the dir and it's content - Api\Vfs::find($new_dir, array(), 'EGroupware\Api\Vfs::chown', $data['new_owner']); } elseif(!empty($data['account_lid']) && $data['account_lid'] != '/') { @@ -110,12 +108,8 @@ class Hooks throw new Api\Exception\AssertionFailed(__METHOD__.'('.array2string($data).') account_lid NOT set!'); } - // Other files in home - Api\Vfs::find( - '/home', - array('user' => $data['account_lid']), - $data['new_owner'] ? 'EGroupware\Api\Vfs::chown' : 'EGroupware\Api\Vfs::remove', $data['new_owner'] - ); + // Change owner of all files + Api\Vfs\Sqlfs\StreamWrapper::chownAll($data['account_id'], $data['new_owner'] ? $data['new_owner'] : 0); Api\Vfs::$is_root = false; } diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index a9ae163b10..fc3f2f946f 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -961,6 +961,21 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface )); } + /** + * chown but for all files a user owns + * + * @param $old_uid + * @param $new_uid + */ + public static function chownAll($old_uid, $new_uid) + { + $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_uid=:old_uid'); + return $stmt->execute(array( + 'fs_uid' => (int) $new_uid, + 'old_uid' => $old_uid, + )); + } + /** * Chgrp command, not yet a stream-wrapper function, but necessary *