diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-25 18:06:34 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-28 19:24:23 +0100 |
commit | 6151a0540b94dea0bb014b26e9ac6ea84d000f05 (patch) | |
tree | c8c04e9153c162489cb2383a7e5170fecfd23322 /apps/files_sharing/lib | |
parent | b85770d636a34c7893c0f4466609b0365e7af195 (diff) | |
download | nextcloud-server-6151a0540b94dea0bb014b26e9ac6ea84d000f05.tar.gz nextcloud-server-6151a0540b94dea0bb014b26e9ac6ea84d000f05.zip |
Update the initiator of the share as well in migration
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/migration.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/migration.php b/apps/files_sharing/lib/migration.php index 4ec411d81da..90e0dead480 100644 --- a/apps/files_sharing/lib/migration.php +++ b/apps/files_sharing/lib/migration.php @@ -84,6 +84,29 @@ class Migration { } /** + * update all owner information so that all shares have an owner + * and an initiator for the upgrade from oC 8.2 to 9.0 with the new sharing + */ + public function updateInitiatorInfo() { + while (true) { + $shares = $this->getMissingInitiator(1000); + + if (empty($shares)) { + break; + } + + $owners = []; + foreach ($shares as $share) { + $owners[$share['id']] = [ + 'owner' => $share['uid_owner'], + 'initiator' => $share['uid_owner'] + ]; + } + $this->updateOwners($owners); + } + } + + /** * find the owner of a re-shared file/folder * * @param array $share @@ -147,6 +170,49 @@ class Migration { } /** + * Get $n re-shares from the database + * + * @param int $n The max number of shares to fetch + * @return array + */ + private function getMissingInitiator($n = 1000) { + $query = $this->connection->getQueryBuilder(); + $query->select(['id', 'uid_owner']) + ->from($this->table) + ->where($query->expr()->in( + 'share_type', + $query->createNamedParameter( + [ + \OCP\Share::SHARE_TYPE_USER, + \OCP\Share::SHARE_TYPE_GROUP, + \OCP\Share::SHARE_TYPE_LINK + ], + Connection::PARAM_INT_ARRAY + ) + )) + ->andWhere($query->expr()->in( + 'item_type', + $query->createNamedParameter( + ['file', 'folder'], + Connection::PARAM_STR_ARRAY + ) + )) + ->andWhere($query->expr()->isNull('uid_initiator')) + ->orderBy('id', 'asc') + ->setMaxResults($n); + $result = $query->execute(); + $shares = $result->fetchAll(); + $result->closeCursor(); + + $ordered = []; + foreach ($shares as $share) { + $ordered[(int)$share['id']] = $share; + } + + return $ordered; + } + + /** * get a specific share * * @param int $id |