2015-10-30 15:10:08 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Jan-Philipp Litza <jplitza@users.noreply.github.com>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author phisch <git@philippschaffrath.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-10-30 15:10:08 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-10-30 15:10:08 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
namespace OC\Share20;
|
|
|
|
|
2016-11-17 16:18:47 +03:00
|
|
|
use OC\Files\Cache\Cache;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Share20\Exception\BackendError;
|
|
|
|
use OC\Share20\Exception\InvalidShare;
|
|
|
|
use OC\Share20\Exception\ProviderException;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2018-07-12 15:55:50 +03:00
|
|
|
use OCP\Defaults;
|
2016-10-31 22:19:00 +03:00
|
|
|
use OCP\Files\Folder;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\Node;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IGroupManager;
|
2018-07-12 15:55:50 +03:00
|
|
|
use OCP\IL10N;
|
2018-07-12 19:17:22 +03:00
|
|
|
use OCP\IURLGenerator;
|
2018-07-12 15:55:50 +03:00
|
|
|
use OCP\IUser;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IUserManager;
|
2018-07-12 15:55:50 +03:00
|
|
|
use OCP\Mail\IMailer;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Share\Exceptions\ShareNotFound;
|
2018-06-19 10:20:35 +03:00
|
|
|
use OCP\Share\IShare;
|
2016-01-27 14:13:53 +03:00
|
|
|
use OCP\Share\IShareProvider;
|
2015-10-30 15:10:08 +03:00
|
|
|
|
2016-01-13 15:02:23 +03:00
|
|
|
/**
|
|
|
|
* Class DefaultShareProvider
|
|
|
|
*
|
|
|
|
* @package OC\Share20
|
|
|
|
*/
|
2015-10-30 15:10:08 +03:00
|
|
|
class DefaultShareProvider implements IShareProvider {
|
|
|
|
|
2016-01-11 18:19:07 +03:00
|
|
|
// Special share type for user modified group shares
|
2020-04-10 17:54:27 +03:00
|
|
|
public const SHARE_TYPE_USERGROUP = 2;
|
2016-01-11 18:19:07 +03:00
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/** @var IDBConnection */
|
2015-10-30 15:10:08 +03:00
|
|
|
private $dbConn;
|
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/** @var IUserManager */
|
2015-10-30 15:10:08 +03:00
|
|
|
private $userManager;
|
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/** @var IGroupManager */
|
2015-10-30 15:10:08 +03:00
|
|
|
private $groupManager;
|
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/** @var IRootFolder */
|
2015-11-23 19:10:58 +03:00
|
|
|
private $rootFolder;
|
2015-10-30 15:10:08 +03:00
|
|
|
|
2018-07-12 15:55:50 +03:00
|
|
|
/** @var IMailer */
|
|
|
|
private $mailer;
|
|
|
|
|
|
|
|
/** @var Defaults */
|
|
|
|
private $defaults;
|
|
|
|
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l;
|
|
|
|
|
2018-07-12 19:17:22 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/**
|
|
|
|
* DefaultShareProvider constructor.
|
|
|
|
*
|
|
|
|
* @param IDBConnection $connection
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param IGroupManager $groupManager
|
|
|
|
* @param IRootFolder $rootFolder
|
2018-07-12 15:55:50 +03:00
|
|
|
* @param IMailer $mailer ;
|
|
|
|
* @param Defaults $defaults
|
|
|
|
* @param IL10N $l
|
2018-07-12 19:17:22 +03:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2015-11-24 11:58:37 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
IDBConnection $connection,
|
|
|
|
IUserManager $userManager,
|
|
|
|
IGroupManager $groupManager,
|
2018-07-12 15:55:50 +03:00
|
|
|
IRootFolder $rootFolder,
|
|
|
|
IMailer $mailer,
|
|
|
|
Defaults $defaults,
|
2018-07-12 19:17:22 +03:00
|
|
|
IL10N $l,
|
|
|
|
IURLGenerator $urlGenerator) {
|
2015-10-30 15:10:08 +03:00
|
|
|
$this->dbConn = $connection;
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->groupManager = $groupManager;
|
2015-11-23 19:10:58 +03:00
|
|
|
$this->rootFolder = $rootFolder;
|
2018-07-12 15:55:50 +03:00
|
|
|
$this->mailer = $mailer;
|
|
|
|
$this->defaults = $defaults;
|
|
|
|
$this->l = $l;
|
2018-07-12 19:17:22 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
2016-01-13 15:02:23 +03:00
|
|
|
/**
|
|
|
|
* Return the identifier of this provider.
|
|
|
|
*
|
|
|
|
* @return string Containing only [a-zA-Z0-9]
|
|
|
|
*/
|
|
|
|
public function identifier() {
|
|
|
|
return 'ocinternal';
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
/**
|
|
|
|
* Share a path
|
2015-12-15 11:53:16 +03:00
|
|
|
*
|
2016-01-27 14:13:53 +03:00
|
|
|
* @param \OCP\Share\IShare $share
|
|
|
|
* @return \OCP\Share\IShare The share object
|
2015-12-15 11:53:16 +03:00
|
|
|
* @throws ShareNotFound
|
|
|
|
* @throws \Exception
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-01-27 14:13:53 +03:00
|
|
|
public function create(\OCP\Share\IShare $share) {
|
2015-12-15 11:53:16 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->insert('share');
|
|
|
|
$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
|
|
|
|
|
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
//Set the UID of the user we share with
|
2016-02-02 18:57:50 +03:00
|
|
|
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
|
2019-08-21 17:15:23 +03:00
|
|
|
$qb->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING));
|
2019-10-28 21:22:05 +03:00
|
|
|
|
|
|
|
//If an expiration date is set store it
|
|
|
|
if ($share->getExpirationDate() !== null) {
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2015-12-15 11:53:16 +03:00
|
|
|
//Set the GID of the group we share with
|
2016-02-02 18:57:50 +03:00
|
|
|
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
|
2019-10-28 21:22:05 +03:00
|
|
|
|
|
|
|
//If an expiration date is set store it
|
|
|
|
if ($share->getExpirationDate() !== null) {
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
|
2018-10-16 11:31:38 +03:00
|
|
|
//set label for public link
|
|
|
|
$qb->setValue('label', $qb->createNamedParameter($share->getLabel()));
|
2015-12-15 11:53:16 +03:00
|
|
|
//Set the token of the share
|
|
|
|
$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
|
|
|
|
|
|
|
|
//If a password is set store it
|
|
|
|
if ($share->getPassword() !== null) {
|
2017-03-30 18:03:04 +03:00
|
|
|
$qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
|
2015-12-15 11:53:16 +03:00
|
|
|
}
|
|
|
|
|
2018-10-12 21:15:40 +03:00
|
|
|
$qb->setValue('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL));
|
|
|
|
|
2015-12-15 11:53:16 +03:00
|
|
|
//If an expiration date is set store it
|
|
|
|
if ($share->getExpirationDate() !== null) {
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
|
|
|
|
}
|
2016-02-11 13:55:09 +03:00
|
|
|
|
|
|
|
if (method_exists($share, 'getParent')) {
|
|
|
|
$qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
|
|
|
|
}
|
2015-12-15 11:53:16 +03:00
|
|
|
} else {
|
|
|
|
throw new \Exception('invalid share type!');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set what is shares
|
|
|
|
$qb->setValue('item_type', $qb->createParameter('itemType'));
|
2016-01-27 22:51:26 +03:00
|
|
|
if ($share->getNode() instanceof \OCP\Files\File) {
|
2015-12-15 11:53:16 +03:00
|
|
|
$qb->setParameter('itemType', 'file');
|
|
|
|
} else {
|
|
|
|
$qb->setParameter('itemType', 'folder');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the file id
|
2016-01-27 22:51:26 +03:00
|
|
|
$qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
|
|
|
|
$qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
|
2015-12-15 11:53:16 +03:00
|
|
|
|
|
|
|
// set the permissions
|
|
|
|
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
|
|
|
|
|
|
|
|
// Set who created this share
|
2016-02-02 18:57:50 +03:00
|
|
|
$qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
|
2015-12-15 11:53:16 +03:00
|
|
|
|
|
|
|
// Set who is the owner of this file/folder (and this the owner of the share)
|
2016-02-02 18:57:50 +03:00
|
|
|
$qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
|
2015-12-15 11:53:16 +03:00
|
|
|
|
|
|
|
// Set the file target
|
|
|
|
$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
|
|
|
|
|
|
|
|
// Set the time this share was created
|
|
|
|
$qb->setValue('stime', $qb->createNamedParameter(time()));
|
|
|
|
|
|
|
|
// insert the data and fetch the id of the share
|
|
|
|
$this->dbConn->beginTransaction();
|
|
|
|
$qb->execute();
|
|
|
|
$id = $this->dbConn->lastInsertId('*PREFIX*share');
|
|
|
|
|
|
|
|
// Now fetch the inserted share and create a complete share object
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
2016-01-15 23:15:25 +03:00
|
|
|
->from('share')
|
2015-12-15 11:53:16 +03:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$data = $cursor->fetch();
|
2016-11-23 14:27:06 +03:00
|
|
|
$this->dbConn->commit();
|
2015-12-15 11:53:16 +03:00
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
|
|
|
|
2017-09-11 01:56:20 +03:00
|
|
|
$mailSendValue = $share->getMailSend();
|
|
|
|
$data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue;
|
|
|
|
|
2015-12-15 11:53:16 +03:00
|
|
|
$share = $this->createShare($data);
|
|
|
|
return $share;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a share
|
|
|
|
*
|
2016-01-27 14:13:53 +03:00
|
|
|
* @param \OCP\Share\IShare $share
|
|
|
|
* @return \OCP\Share\IShare The share object
|
2018-10-16 11:31:38 +03:00
|
|
|
* @throws ShareNotFound
|
|
|
|
* @throws \OCP\Files\InvalidPathException
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-01-27 14:13:53 +03:00
|
|
|
public function update(\OCP\Share\IShare $share) {
|
2018-07-12 15:55:50 +03:00
|
|
|
$originalShare = $this->getShareById($share->getId());
|
|
|
|
|
2016-01-22 16:52:20 +03:00
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
/*
|
|
|
|
* We allow updating the recipient on user shares.
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2016-02-02 18:57:50 +03:00
|
|
|
->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
|
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2016-01-27 22:51:26 +03:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2017-03-29 17:50:23 +03:00
|
|
|
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
|
2018-07-12 15:55:50 +03:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2019-08-22 04:17:17 +03:00
|
|
|
->set('accepted', $qb->createNamedParameter($share->getStatus()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->execute();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-01-22 16:52:20 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2016-02-02 18:57:50 +03:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2016-01-27 22:51:26 +03:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2017-03-29 17:50:23 +03:00
|
|
|
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
|
2018-07-12 15:55:50 +03:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update all user defined group shares
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2018-12-04 22:55:14 +03:00
|
|
|
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
2016-02-02 18:57:50 +03:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-27 22:51:26 +03:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2017-03-29 17:50:23 +03:00
|
|
|
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
|
2018-07-12 15:55:50 +03:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now update the permissions for all children that have not set it to 0
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
|
|
|
->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
|
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
|
|
|
->execute();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
|
2016-01-22 16:52:20 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2017-03-28 16:11:07 +03:00
|
|
|
->set('password', $qb->createNamedParameter($share->getPassword()))
|
2018-10-12 21:15:40 +03:00
|
|
|
->set('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL))
|
2016-02-02 18:57:50 +03:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2016-01-27 22:51:26 +03:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2016-01-22 16:52:20 +03:00
|
|
|
->set('token', $qb->createNamedParameter($share->getToken()))
|
2016-01-26 16:29:30 +03:00
|
|
|
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
|
2018-07-12 15:55:50 +03:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2018-10-17 11:50:58 +03:00
|
|
|
->set('label', $qb->createNamedParameter($share->getLabel()))
|
2018-10-18 13:38:07 +03:00
|
|
|
->set('hide_download', $qb->createNamedParameter($share->getHideDownload() ? 1 : 0), IQueryBuilder::PARAM_INT)
|
2016-01-22 16:52:20 +03:00
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
2018-07-12 15:55:50 +03:00
|
|
|
if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
|
|
|
|
$this->propagateNote($share);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-26 16:29:30 +03:00
|
|
|
return $share;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
2019-09-04 17:50:52 +03:00
|
|
|
/**
|
|
|
|
* Accept a share.
|
|
|
|
*
|
|
|
|
* @param IShare $share
|
|
|
|
* @param string $recipient
|
|
|
|
* @return IShare The share object
|
|
|
|
* @since 9.0.0
|
|
|
|
*/
|
|
|
|
public function acceptShare(IShare $share, string $recipient): IShare {
|
|
|
|
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
$user = $this->userManager->get($recipient);
|
|
|
|
|
|
|
|
if (is_null($group)) {
|
|
|
|
throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$group->inGroup($user)) {
|
|
|
|
throw new ProviderException('Recipient not in receiving group');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to fetch user specific share
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$stmt = $qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
2019-11-18 18:11:03 +03:00
|
|
|
$stmt->closeCursor();
|
2019-09-04 17:50:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there already is a user specific group share.
|
|
|
|
* If there is update it (if required).
|
|
|
|
*/
|
|
|
|
if ($data === false) {
|
|
|
|
$id = $this->createUserSpecificGroupShare($share, $recipient);
|
|
|
|
} else {
|
|
|
|
$id = $data['id'];
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_USER) {
|
2019-09-04 17:50:52 +03:00
|
|
|
if ($share->getSharedWith() !== $recipient) {
|
|
|
|
throw new ProviderException('Recipient does not match');
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $share->getId();
|
|
|
|
} else {
|
|
|
|
throw new ProviderException('Invalid shareType');
|
|
|
|
}
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->set('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
/**
|
2015-11-10 16:14:49 +03:00
|
|
|
* Get all children of this share
|
2016-01-29 13:41:28 +03:00
|
|
|
* FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
|
2015-10-30 15:10:08 +03:00
|
|
|
*
|
2016-01-27 14:13:53 +03:00
|
|
|
* @param \OCP\Share\IShare $parent
|
2016-02-02 18:57:50 +03:00
|
|
|
* @return \OCP\Share\IShare[]
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-01-27 14:13:53 +03:00
|
|
|
public function getChildren(\OCP\Share\IShare $parent) {
|
2015-10-30 15:10:08 +03:00
|
|
|
$children = [];
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
|
|
->from('share')
|
2016-01-11 17:58:32 +03:00
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
|
2016-01-11 18:19:07 +03:00
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->in(
|
|
|
|
'share_type',
|
2016-01-29 13:41:28 +03:00
|
|
|
$qb->createNamedParameter([
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
\OCP\Share::SHARE_TYPE_LINK,
|
|
|
|
], IQueryBuilder::PARAM_INT_ARRAY)
|
2016-01-11 18:19:07 +03:00
|
|
|
)
|
|
|
|
)
|
2016-03-09 13:19:57 +03:00
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
2015-11-10 16:14:49 +03:00
|
|
|
->orderBy('id');
|
2015-10-30 15:10:08 +03:00
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2015-10-30 15:10:08 +03:00
|
|
|
$children[] = $this->createShare($data);
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
return $children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a share
|
|
|
|
*
|
2016-01-27 14:13:53 +03:00
|
|
|
* @param \OCP\Share\IShare $share
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-01-27 14:13:53 +03:00
|
|
|
public function delete(\OCP\Share\IShare $share) {
|
2015-11-02 23:06:55 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2015-10-30 15:10:08 +03:00
|
|
|
$qb->delete('share')
|
2016-01-11 17:58:32 +03:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
|
2016-01-28 22:35:46 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the share is a group share delete all possible
|
|
|
|
* user defined groups shares.
|
|
|
|
*/
|
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
|
|
|
$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
2016-01-28 22:35:46 +03:00
|
|
|
|
|
|
|
$qb->execute();
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:09 +03:00
|
|
|
/**
|
|
|
|
* Unshare a share from the recipient. If this is a group share
|
|
|
|
* this means we need a special entry in the share db.
|
|
|
|
*
|
2019-09-04 17:50:52 +03:00
|
|
|
* @param IShare $share
|
2016-02-02 18:57:50 +03:00
|
|
|
* @param string $recipient UserId of recipient
|
2016-01-21 16:31:09 +03:00
|
|
|
* @throws BackendError
|
|
|
|
* @throws ProviderException
|
|
|
|
*/
|
2019-09-04 17:50:52 +03:00
|
|
|
public function deleteFromSelf(IShare $share, $recipient) {
|
|
|
|
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-02-02 18:57:50 +03:00
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
$user = $this->userManager->get($recipient);
|
2016-01-21 16:31:09 +03:00
|
|
|
|
2017-01-19 17:02:46 +03:00
|
|
|
if (is_null($group)) {
|
|
|
|
throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
|
|
|
|
}
|
|
|
|
|
2016-02-02 18:57:50 +03:00
|
|
|
if (!$group->inGroup($user)) {
|
2016-01-21 16:31:09 +03:00
|
|
|
throw new ProviderException('Recipient not in receiving group');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to fetch user specific share
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$stmt = $qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
2016-02-02 18:57:50 +03:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
2016-01-21 16:31:09 +03:00
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2016-03-09 13:19:57 +03:00
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
2016-01-21 16:31:09 +03:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there already is a user specific group share.
|
|
|
|
* If there is update it (if required).
|
|
|
|
*/
|
|
|
|
if ($data === false) {
|
2019-09-04 17:50:52 +03:00
|
|
|
$id = $this->createUserSpecificGroupShare($share, $recipient);
|
|
|
|
$permissions = $share->getPermissions();
|
|
|
|
} else {
|
|
|
|
$permissions = $data['permissions'];
|
|
|
|
$id = $data['id'];
|
|
|
|
}
|
2016-01-21 16:31:09 +03:00
|
|
|
|
2019-09-04 17:50:52 +03:00
|
|
|
if ($permissions !== 0) {
|
2016-01-21 16:31:09 +03:00
|
|
|
// Update existing usergroup share
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->set('permissions', $qb->createNamedParameter(0))
|
2019-09-04 17:50:52 +03:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
2016-01-21 16:31:09 +03:00
|
|
|
->execute();
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_USER) {
|
2016-01-21 16:31:09 +03:00
|
|
|
if ($share->getSharedWith() !== $recipient) {
|
|
|
|
throw new ProviderException('Recipient does not match');
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can just delete user and link shares
|
|
|
|
$this->delete($share);
|
|
|
|
} else {
|
|
|
|
throw new ProviderException('Invalid shareType');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 17:50:52 +03:00
|
|
|
protected function createUserSpecificGroupShare(IShare $share, string $recipient): int {
|
|
|
|
$type = $share->getNodeType();
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->insert('share')
|
|
|
|
->values([
|
|
|
|
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
|
|
|
|
'share_with' => $qb->createNamedParameter($recipient),
|
|
|
|
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
|
|
|
|
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
|
|
|
|
'parent' => $qb->createNamedParameter($share->getId()),
|
|
|
|
'item_type' => $qb->createNamedParameter($type),
|
|
|
|
'item_source' => $qb->createNamedParameter($share->getNodeId()),
|
|
|
|
'file_source' => $qb->createNamedParameter($share->getNodeId()),
|
|
|
|
'file_target' => $qb->createNamedParameter($share->getTarget()),
|
|
|
|
'permissions' => $qb->createNamedParameter($share->getPermissions()),
|
|
|
|
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
|
|
|
|
])->execute();
|
|
|
|
|
|
|
|
return $qb->getLastInsertId();
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:20:35 +03:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*
|
|
|
|
* For now this only works for group shares
|
|
|
|
* If this gets implemented for normal shares we have to extend it
|
|
|
|
*/
|
|
|
|
public function restore(IShare $share, string $recipient): IShare {
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('permissions')
|
|
|
|
->from('share')
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))
|
|
|
|
);
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$data = $cursor->fetch();
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
$originalPermission = $data['permissions'];
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->set('permissions', $qb->createNamedParameter($originalPermission))
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent()))
|
|
|
|
)->andWhere(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
|
|
|
|
)->andWhere(
|
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))
|
|
|
|
);
|
|
|
|
|
|
|
|
$qb->execute();
|
|
|
|
|
|
|
|
return $this->getShareById($share->getId(), $recipient);
|
|
|
|
}
|
|
|
|
|
2016-01-29 12:27:39 +03:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-02-02 18:57:50 +03:00
|
|
|
public function move(\OCP\Share\IShare $share, $recipient) {
|
2016-01-29 12:27:39 +03:00
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
// Just update the target
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->set('file_target', $qb->createNamedParameter($share->getTarget()))
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
|
|
|
->execute();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-01-29 12:27:39 +03:00
|
|
|
|
|
|
|
// Check if there is a usergroup share
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$stmt = $qb->select('id')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
2016-02-02 18:57:50 +03:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
2016-01-29 12:27:39 +03:00
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2016-03-09 13:19:57 +03:00
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
2016-01-29 12:27:39 +03:00
|
|
|
->setMaxResults(1)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
|
|
|
$stmt->closeCursor();
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
// No usergroup share yet. Create one.
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->insert('share')
|
|
|
|
->values([
|
|
|
|
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
|
2016-02-02 18:57:50 +03:00
|
|
|
'share_with' => $qb->createNamedParameter($recipient),
|
|
|
|
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
|
|
|
|
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
|
2016-01-29 12:27:39 +03:00
|
|
|
'parent' => $qb->createNamedParameter($share->getId()),
|
2018-01-09 21:51:50 +03:00
|
|
|
'item_type' => $qb->createNamedParameter($share->getNodeType()),
|
|
|
|
'item_source' => $qb->createNamedParameter($share->getNodeId()),
|
|
|
|
'file_source' => $qb->createNamedParameter($share->getNodeId()),
|
2016-01-29 12:27:39 +03:00
|
|
|
'file_target' => $qb->createNamedParameter($share->getTarget()),
|
|
|
|
'permissions' => $qb->createNamedParameter($share->getPermissions()),
|
|
|
|
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
|
|
|
|
])->execute();
|
|
|
|
} else {
|
|
|
|
// Already a usergroup share. Update it.
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->update('share')
|
|
|
|
->set('file_target', $qb->createNamedParameter($share->getTarget()))
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2016-10-31 22:19:00 +03:00
|
|
|
public function getSharesInFolder($userId, Folder $node, $reshares) {
|
2016-06-18 23:04:56 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
|
|
->from('share', 's')
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
|
|
|
|
|
|
|
$qb->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
|
2016-11-01 14:15:14 +03:00
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
|
2016-06-18 23:04:56 +03:00
|
|
|
));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reshares for this user are shares where they are the owner.
|
|
|
|
*/
|
|
|
|
if ($reshares === false) {
|
|
|
|
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
|
|
|
|
} else {
|
|
|
|
$qb->andWhere(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-10 18:59:40 +03:00
|
|
|
$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
|
2016-06-18 23:04:56 +03:00
|
|
|
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
|
|
|
|
|
|
|
|
$qb->orderBy('id');
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$shares = [];
|
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
$shares[$data['fileid']][] = $this->createShare($data);
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
return $shares;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
/**
|
2016-03-11 10:51:07 +03:00
|
|
|
* @inheritdoc
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-02-02 18:57:50 +03:00
|
|
|
public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
|
2015-12-03 12:51:41 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
2016-03-09 13:19:57 +03:00
|
|
|
->from('share')
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
2015-12-03 12:51:41 +03:00
|
|
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reshares for this user are shares where they are the owner.
|
|
|
|
*/
|
|
|
|
if ($reshares === false) {
|
2016-03-07 12:40:49 +03:00
|
|
|
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
|
2015-12-03 12:51:41 +03:00
|
|
|
} else {
|
2018-11-01 18:46:38 +03:00
|
|
|
if ($node === null) {
|
2018-10-29 12:03:52 +03:00
|
|
|
$qb->andWhere(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-12-03 12:51:41 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 16:07:56 +03:00
|
|
|
if ($node !== null) {
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
2015-12-03 12:51:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($limit !== -1) {
|
|
|
|
$qb->setMaxResults($limit);
|
|
|
|
}
|
|
|
|
|
2016-01-19 16:35:16 +03:00
|
|
|
$qb->setFirstResult($offset);
|
2015-12-03 12:51:41 +03:00
|
|
|
$qb->orderBy('id');
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$shares = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2015-12-03 12:51:41 +03:00
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-29 12:07:28 +03:00
|
|
|
* @inheritdoc
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-02-02 18:57:50 +03:00
|
|
|
public function getShareById($id, $recipientId = null) {
|
2015-10-30 15:10:08 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from('share')
|
2016-01-11 18:19:07 +03:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->in(
|
|
|
|
'share_type',
|
2016-01-29 12:07:28 +03:00
|
|
|
$qb->createNamedParameter([
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
\OCP\Share::SHARE_TYPE_LINK,
|
|
|
|
], IQueryBuilder::PARAM_INT_ARRAY)
|
2016-01-11 18:19:07 +03:00
|
|
|
)
|
2016-03-09 13:19:57 +03:00
|
|
|
)
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
2016-11-17 16:18:47 +03:00
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
$cursor = $qb->execute();
|
|
|
|
$data = $cursor->fetch();
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:44:59 +03:00
|
|
|
try {
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
2015-10-30 15:10:08 +03:00
|
|
|
|
2016-01-29 12:07:28 +03:00
|
|
|
// If the recipient is set for a group share resolve to that user
|
2016-02-02 18:57:50 +03:00
|
|
|
if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-10-06 15:27:44 +03:00
|
|
|
$share = $this->resolveGroupShares([$share], $recipientId)[0];
|
2016-01-29 12:07:28 +03:00
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get shares for a given path
|
|
|
|
*
|
|
|
|
* @param \OCP\Files\Node $path
|
2016-02-02 18:57:50 +03:00
|
|
|
* @return \OCP\Share\IShare[]
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2015-12-15 11:53:16 +03:00
|
|
|
public function getSharesByPath(Node $path) {
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$cursor = $qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
|
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
|
|
|
|
)
|
2016-03-09 13:19:57 +03:00
|
|
|
)
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
|
|
|
->execute();
|
2015-12-15 11:53:16 +03:00
|
|
|
|
|
|
|
$shares = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2015-12-15 11:53:16 +03:00
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
2016-09-02 12:23:55 +03:00
|
|
|
/**
|
|
|
|
* Returns whether the given database result can be interpreted as
|
|
|
|
* a share with accessible file (not trashed, not deleted)
|
|
|
|
*/
|
|
|
|
private function isAccessibleResult($data) {
|
|
|
|
// exclude shares leading to deleted file entries
|
2020-03-26 15:49:47 +03:00
|
|
|
if ($data['fileid'] === null || $data['path'] === null) {
|
2016-09-02 12:23:55 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// exclude shares leading to trashbin on home storages
|
|
|
|
$pathSections = explode('/', $data['path'], 2);
|
|
|
|
// FIXME: would not detect rare md5'd home storage case properly
|
2017-03-28 16:11:07 +03:00
|
|
|
if ($pathSections[0] !== 'files'
|
2020-04-09 10:22:29 +03:00
|
|
|
&& in_array(explode(':', $data['storage_string_id'], 2)[0], ['home', 'object'])) {
|
2016-09-02 12:23:55 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
/**
|
2016-01-29 17:26:04 +03:00
|
|
|
* @inheritdoc
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-02-02 18:57:50 +03:00
|
|
|
public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
|
2016-01-19 15:55:51 +03:00
|
|
|
/** @var Share[] $shares */
|
2015-12-03 12:51:41 +03:00
|
|
|
$shares = [];
|
|
|
|
|
|
|
|
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
2016-01-19 15:55:51 +03:00
|
|
|
//Get shares directly with this user
|
2015-12-03 12:51:41 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2016-11-17 16:18:47 +03:00
|
|
|
$qb->select('s.*',
|
|
|
|
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
|
|
|
|
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
|
|
|
|
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
|
|
|
|
)
|
2016-09-02 12:23:55 +03:00
|
|
|
->selectAlias('st.id', 'storage_string_id')
|
|
|
|
->from('share', 's')
|
|
|
|
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
|
|
|
|
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
|
2015-12-03 12:51:41 +03:00
|
|
|
|
|
|
|
// Order by id
|
2016-09-02 12:23:55 +03:00
|
|
|
$qb->orderBy('s.id');
|
2015-12-03 12:51:41 +03:00
|
|
|
|
|
|
|
// Set limit and offset
|
|
|
|
if ($limit !== -1) {
|
|
|
|
$qb->setMaxResults($limit);
|
|
|
|
}
|
|
|
|
$qb->setFirstResult($offset);
|
|
|
|
|
2016-03-09 13:19:57 +03:00
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
2015-12-03 12:51:41 +03:00
|
|
|
|
2016-01-29 17:26:04 +03:00
|
|
|
// Filter by node if provided
|
|
|
|
if ($node !== null) {
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
|
|
|
}
|
|
|
|
|
2015-12-03 12:51:41 +03:00
|
|
|
$cursor = $qb->execute();
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2016-09-02 12:23:55 +03:00
|
|
|
if ($this->isAccessibleResult($data)) {
|
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
}
|
2015-12-03 12:51:41 +03:00
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-02-02 18:57:50 +03:00
|
|
|
$user = $this->userManager->get($userId);
|
2020-05-04 18:42:28 +03:00
|
|
|
$allGroups = $this->groupManager->getUserGroupIds($user);
|
2016-01-19 15:55:51 +03:00
|
|
|
|
2016-01-26 14:58:41 +03:00
|
|
|
/** @var Share[] $shares2 */
|
|
|
|
$shares2 = [];
|
|
|
|
|
2016-01-19 15:55:51 +03:00
|
|
|
$start = 0;
|
2020-04-10 15:19:56 +03:00
|
|
|
while (true) {
|
2016-01-19 15:55:51 +03:00
|
|
|
$groups = array_slice($allGroups, $start, 100);
|
|
|
|
$start += 100;
|
|
|
|
|
|
|
|
if ($groups === []) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2016-11-18 01:30:50 +03:00
|
|
|
$qb->select('s.*',
|
|
|
|
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
|
|
|
|
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
|
|
|
|
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
|
|
|
|
)
|
2016-09-02 12:23:55 +03:00
|
|
|
->selectAlias('st.id', 'storage_string_id')
|
|
|
|
->from('share', 's')
|
|
|
|
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
|
|
|
|
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
|
|
|
|
->orderBy('s.id')
|
2016-01-19 15:55:51 +03:00
|
|
|
->setFirstResult(0);
|
|
|
|
|
|
|
|
if ($limit !== -1) {
|
2016-01-20 16:07:56 +03:00
|
|
|
$qb->setMaxResults($limit - count($shares));
|
2016-01-19 15:55:51 +03:00
|
|
|
}
|
|
|
|
|
2016-01-29 17:26:04 +03:00
|
|
|
// Filter by node if provided
|
|
|
|
if ($node !== null) {
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:46:19 +03:00
|
|
|
|
2020-05-04 18:42:28 +03:00
|
|
|
$groups = array_filter($groups);
|
2016-01-19 15:55:51 +03:00
|
|
|
|
2016-03-09 13:19:57 +03:00
|
|
|
$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
|
|
|
|
->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
|
|
|
|
$groups,
|
|
|
|
IQueryBuilder::PARAM_STR_ARRAY
|
|
|
|
)))
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
2016-01-19 15:55:51 +03:00
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2016-01-20 16:07:56 +03:00
|
|
|
if ($offset > 0) {
|
|
|
|
$offset--;
|
|
|
|
continue;
|
|
|
|
}
|
2016-09-02 12:23:55 +03:00
|
|
|
|
|
|
|
if ($this->isAccessibleResult($data)) {
|
|
|
|
$shares2[] = $this->createShare($data);
|
|
|
|
}
|
2016-01-19 15:55:51 +03:00
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
}
|
2016-01-20 16:07:56 +03:00
|
|
|
|
|
|
|
/*
|
2020-04-09 10:22:29 +03:00
|
|
|
* Resolve all group shares to user specific shares
|
|
|
|
*/
|
2016-10-06 15:27:44 +03:00
|
|
|
$shares = $this->resolveGroupShares($shares2, $userId);
|
2015-12-03 12:51:41 +03:00
|
|
|
} else {
|
2016-01-20 16:17:25 +03:00
|
|
|
throw new BackendError('Invalid backend');
|
2015-12-03 12:51:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-14 18:44:59 +03:00
|
|
|
* Get a share by token
|
2015-10-30 15:10:08 +03:00
|
|
|
*
|
|
|
|
* @param string $token
|
2016-02-02 18:57:50 +03:00
|
|
|
* @return \OCP\Share\IShare
|
2016-01-14 18:44:59 +03:00
|
|
|
* @throws ShareNotFound
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
2016-01-14 18:44:59 +03:00
|
|
|
public function getShareByToken($token) {
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$cursor = $qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
|
|
|
|
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
|
2016-03-09 13:19:57 +03:00
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
))
|
2016-01-14 18:44:59 +03:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$data = $cursor->fetch();
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $share;
|
2015-10-30 15:10:08 +03:00
|
|
|
}
|
2016-11-17 16:18:47 +03:00
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
/**
|
|
|
|
* Create a share object from an database row
|
|
|
|
*
|
|
|
|
* @param mixed[] $data
|
2016-01-27 22:51:26 +03:00
|
|
|
* @return \OCP\Share\IShare
|
2016-01-15 23:15:25 +03:00
|
|
|
* @throws InvalidShare
|
2015-10-30 15:10:08 +03:00
|
|
|
*/
|
|
|
|
private function createShare($data) {
|
2016-05-11 21:48:27 +03:00
|
|
|
$share = new Share($this->rootFolder, $this->userManager);
|
2015-10-30 15:10:08 +03:00
|
|
|
$share->setId((int)$data['id'])
|
|
|
|
->setShareType((int)$data['share_type'])
|
2015-11-02 23:06:55 +03:00
|
|
|
->setPermissions((int)$data['permissions'])
|
2015-11-06 14:05:19 +03:00
|
|
|
->setTarget($data['file_target'])
|
2018-07-12 17:09:05 +03:00
|
|
|
->setNote($data['note'])
|
2018-10-16 11:31:38 +03:00
|
|
|
->setMailSend((bool)$data['mail_send'])
|
2019-08-21 17:15:23 +03:00
|
|
|
->setStatus((int)$data['accepted'])
|
2018-10-16 11:31:38 +03:00
|
|
|
->setLabel($data['label']);
|
2015-10-30 15:10:08 +03:00
|
|
|
|
2016-01-27 22:51:26 +03:00
|
|
|
$shareTime = new \DateTime();
|
|
|
|
$shareTime->setTimestamp((int)$data['stime']);
|
|
|
|
$share->setShareTime($shareTime);
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
2016-02-02 18:57:50 +03:00
|
|
|
$share->setSharedWith($data['share_with']);
|
2019-07-03 12:31:25 +03:00
|
|
|
$user = $this->userManager->get($data['share_with']);
|
|
|
|
if ($user !== null) {
|
|
|
|
$share->setSharedWithDisplayName($user->getDisplayName());
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-02-02 18:57:50 +03:00
|
|
|
$share->setSharedWith($data['share_with']);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
|
2017-03-28 16:11:07 +03:00
|
|
|
$share->setPassword($data['password']);
|
2018-10-12 21:15:40 +03:00
|
|
|
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
|
2015-10-30 15:10:08 +03:00
|
|
|
$share->setToken($data['token']);
|
|
|
|
}
|
|
|
|
|
2016-03-07 12:40:49 +03:00
|
|
|
$share->setSharedBy($data['uid_initiator']);
|
|
|
|
$share->setShareOwner($data['uid_owner']);
|
2015-11-23 19:10:58 +03:00
|
|
|
|
2016-02-04 14:51:23 +03:00
|
|
|
$share->setNodeId((int)$data['file_source']);
|
2016-02-04 16:28:09 +03:00
|
|
|
$share->setNodeType($data['item_type']);
|
2015-10-30 15:10:08 +03:00
|
|
|
|
|
|
|
if ($data['expiration'] !== null) {
|
|
|
|
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
|
|
|
|
$share->setExpirationDate($expiration);
|
|
|
|
}
|
|
|
|
|
2016-11-17 16:18:47 +03:00
|
|
|
if (isset($data['f_permissions'])) {
|
|
|
|
$entryData = $data;
|
|
|
|
$entryData['permissions'] = $entryData['f_permissions'];
|
2017-07-23 22:03:26 +03:00
|
|
|
$entryData['parent'] = $entryData['f_parent'];
|
2016-11-17 16:18:47 +03:00
|
|
|
$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
|
|
|
|
\OC::$server->getMimeTypeLoader()));
|
|
|
|
}
|
|
|
|
|
2016-01-13 15:02:23 +03:00
|
|
|
$share->setProviderId($this->identifier());
|
2018-10-18 13:38:07 +03:00
|
|
|
$share->setHideDownload((int)$data['hide_download'] === 1);
|
2016-01-13 15:02:23 +03:00
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2016-01-19 15:55:51 +03:00
|
|
|
/**
|
2016-10-06 15:27:44 +03:00
|
|
|
* @param Share[] $shares
|
|
|
|
* @param $userId
|
|
|
|
* @return Share[] The updates shares if no update is found for a share return the original
|
2016-01-19 15:55:51 +03:00
|
|
|
*/
|
2016-10-06 15:27:44 +03:00
|
|
|
private function resolveGroupShares($shares, $userId) {
|
|
|
|
$result = [];
|
2016-01-19 15:55:51 +03:00
|
|
|
|
2016-10-06 15:27:44 +03:00
|
|
|
$start = 0;
|
2020-04-10 15:19:56 +03:00
|
|
|
while (true) {
|
2016-10-06 15:27:44 +03:00
|
|
|
/** @var Share[] $shareSlice */
|
|
|
|
$shareSlice = array_slice($shares, $start, 100);
|
|
|
|
$start += 100;
|
|
|
|
|
|
|
|
if ($shareSlice === []) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var int[] $ids */
|
|
|
|
$ids = [];
|
|
|
|
/** @var Share[] $shareMap */
|
|
|
|
$shareMap = [];
|
|
|
|
|
|
|
|
foreach ($shareSlice as $share) {
|
|
|
|
$ids[] = (int)$share->getId();
|
|
|
|
$shareMap[$share->getId()] = $share;
|
|
|
|
}
|
2016-01-19 15:55:51 +03:00
|
|
|
|
2016-10-06 15:27:44 +03:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$query = $qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
2016-01-19 15:55:51 +03:00
|
|
|
|
2016-10-06 15:27:44 +03:00
|
|
|
$stmt = $query->execute();
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $stmt->fetch()) {
|
2016-10-06 15:27:44 +03:00
|
|
|
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
|
2019-08-21 17:15:23 +03:00
|
|
|
$shareMap[$data['parent']]->setStatus((int)$data['accepted']);
|
2016-10-06 15:27:44 +03:00
|
|
|
$shareMap[$data['parent']]->setTarget($data['file_target']);
|
2018-06-19 10:20:35 +03:00
|
|
|
$shareMap[$data['parent']]->setParent($data['parent']);
|
2016-10-06 15:27:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$stmt->closeCursor();
|
|
|
|
|
|
|
|
foreach ($shareMap as $share) {
|
|
|
|
$result[] = $share;
|
|
|
|
}
|
2016-01-19 15:55:51 +03:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:27:44 +03:00
|
|
|
return $result;
|
2016-01-19 15:55:51 +03:00
|
|
|
}
|
|
|
|
|
2016-04-04 13:28:19 +03:00
|
|
|
/**
|
|
|
|
* A user is deleted from the system
|
|
|
|
* So clean up the relevant shares.
|
|
|
|
*
|
|
|
|
* @param string $uid
|
|
|
|
* @param int $shareType
|
|
|
|
*/
|
|
|
|
public function userDeleted($uid, $shareType) {
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->delete('share');
|
|
|
|
|
|
|
|
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
/*
|
|
|
|
* Delete all user shares that are owned by this user
|
|
|
|
* or that are received by this user
|
|
|
|
*/
|
|
|
|
|
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
|
|
|
|
|
|
|
|
$qb->andWhere(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
|
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
|
|
|
|
)
|
|
|
|
);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-04-04 13:28:19 +03:00
|
|
|
/*
|
|
|
|
* Delete all group shares that are owned by this user
|
|
|
|
* Or special user group shares that are received by this user
|
|
|
|
*/
|
|
|
|
$qb->where(
|
|
|
|
$qb->expr()->andX(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
|
|
|
|
),
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$qb->orWhere(
|
|
|
|
$qb->expr()->andX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)),
|
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
|
|
|
|
)
|
|
|
|
);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
|
2016-04-04 13:28:19 +03:00
|
|
|
/*
|
|
|
|
* Delete all link shares owned by this user.
|
|
|
|
* And all link shares initiated by this user (until #22327 is in)
|
|
|
|
*/
|
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
|
|
|
|
|
|
|
|
$qb->andWhere(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
|
|
|
|
)
|
|
|
|
);
|
2020-01-28 18:00:03 +03:00
|
|
|
} else {
|
|
|
|
\OC::$server->getLogger()->logException(new \InvalidArgumentException('Default share provider tried to delete all shares for type: ' . $shareType));
|
|
|
|
return;
|
2016-04-04 13:28:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$qb->execute();
|
|
|
|
}
|
2016-04-12 10:46:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all shares received by this group. As well as any custom group
|
|
|
|
* shares for group members.
|
|
|
|
*
|
|
|
|
* @param string $gid
|
|
|
|
*/
|
|
|
|
public function groupDeleted($gid) {
|
|
|
|
/*
|
|
|
|
* First delete all custom group shares for group members
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('id')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$ids = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($row = $cursor->fetch()) {
|
2016-04-12 10:46:25 +03:00
|
|
|
$ids[] = (int)$row['id'];
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
if (!empty($ids)) {
|
|
|
|
$chunks = array_chunk($ids, 100);
|
|
|
|
foreach ($chunks as $chunk) {
|
|
|
|
$qb->delete('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
|
|
|
->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
|
|
|
|
$qb->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now delete all the group shares
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->delete('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
|
|
|
$qb->execute();
|
|
|
|
}
|
2016-04-13 16:00:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete custom group shares to this group for this user
|
|
|
|
*
|
|
|
|
* @param string $uid
|
|
|
|
* @param string $gid
|
|
|
|
*/
|
|
|
|
public function userDeletedFromGroup($uid, $gid) {
|
|
|
|
/*
|
|
|
|
* Get all group shares
|
|
|
|
*/
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
$qb->select('id')
|
|
|
|
->from('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
$ids = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($row = $cursor->fetch()) {
|
2016-04-13 16:00:12 +03:00
|
|
|
$ids[] = (int)$row['id'];
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
if (!empty($ids)) {
|
|
|
|
$chunks = array_chunk($ids, 100);
|
|
|
|
foreach ($chunks as $chunk) {
|
|
|
|
/*
|
|
|
|
* Delete all special shares wit this users for the found group shares
|
|
|
|
*/
|
|
|
|
$qb->delete('share')
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
|
|
|
|
->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
|
|
|
|
$qb->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-22 23:44:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function getAccessList($nodes, $currentAccess) {
|
|
|
|
$ids = [];
|
|
|
|
foreach ($nodes as $node) {
|
|
|
|
$ids[] = $node->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$or = $qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($currentAccess) {
|
|
|
|
$or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
|
|
|
|
}
|
|
|
|
|
2017-03-27 17:06:31 +03:00
|
|
|
$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
|
2016-12-22 23:44:21 +03:00
|
|
|
->from('share')
|
|
|
|
->where(
|
|
|
|
$or
|
|
|
|
)
|
|
|
|
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
|
|
|
|
->andWhere($qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
|
|
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
|
|
|
));
|
|
|
|
$cursor = $qb->execute();
|
|
|
|
|
|
|
|
$users = [];
|
|
|
|
$link = false;
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($row = $cursor->fetch()) {
|
2016-12-22 23:44:21 +03:00
|
|
|
$type = (int)$row['share_type'];
|
|
|
|
if ($type === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
$uid = $row['share_with'];
|
2017-03-27 17:06:31 +03:00
|
|
|
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
|
|
|
|
$users[$uid][$row['id']] = $row;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($type === \OCP\Share::SHARE_TYPE_GROUP) {
|
2016-12-22 23:44:21 +03:00
|
|
|
$gid = $row['share_with'];
|
|
|
|
$group = $this->groupManager->get($gid);
|
|
|
|
|
Fix 500 Internal Server Error on writing
In some not yet completely determined configurations, the following error could occur while writing a file:
Error: Call to a member function getUsers() on null
/var/www/nextcloud/lib/private/Share20/Manager.php - line 1277: OC\Share20\DefaultShareProvider->getAccessList(Array, true)
/var/www/nextcloud/lib/private/Share20/ShareHelper.php - line 51: OC\Share20\Manager->getAccessList(Object(OC\Files\Node\Folder), true, true)
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 616: OC\Share20\ShareHelper->getPathsForAccessList(Object(OC\Files\Node\File))
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 196: OCA\Activity\FilesHooks->getUserPathsFromPath('/path/to/file', 'user')
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 157: OCA\Activity\FilesHooks->addNotificationsForFileAction('/path/to/file', 'file_changed', 'changed_self', 'changed_by')
/var/www/nextcloud/apps/activity/lib/FilesHooksStatic.php - line 55: OCA\Activity\FilesHooks->fileUpdate('/path/to/file')
/var/www/nextcloud/lib/private/legacy/hook.php - line 106: OCA\Activity\FilesHooksStatic fileUpdate(Array)
/var/www/nextcloud/lib/private/Files/View.php - line 1245: OC_Hook emit('OC_Filesystem', 'post_update', Array)
/var/www/nextcloud/lib/private/Files/View.php - line 1173: OC\Files\View->runHooks(Array, '/path/to/file', true)
/var/www/nextcloud/lib/private/Files/View.php - line 679: OC\Files\View->basicOperation('file_put_conten...', '/path/to/file', Array, '<?xml version="...')
/var/www/nextcloud/lib/private/Files/Node/File.php - line 64: OC\Files\View->file_put_contents('/path/to/file', '<?xml version="...')
[...]
Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
2017-06-16 12:38:22 +03:00
|
|
|
if ($group === null) {
|
2016-12-22 23:44:21 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$userList = $group->getUsers();
|
|
|
|
foreach ($userList as $user) {
|
2017-03-27 17:06:31 +03:00
|
|
|
$uid = $user->getUID();
|
|
|
|
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
|
|
|
|
$users[$uid][$row['id']] = $row;
|
2016-12-22 23:44:21 +03:00
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($type === \OCP\Share::SHARE_TYPE_LINK) {
|
2016-12-22 23:44:21 +03:00
|
|
|
$link = true;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) {
|
2017-04-10 17:22:12 +03:00
|
|
|
$uid = $row['share_with'];
|
|
|
|
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
|
|
|
|
$users[$uid][$row['id']] = $row;
|
2016-12-22 23:44:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
2017-04-10 17:22:12 +03:00
|
|
|
if ($currentAccess === true) {
|
2017-04-11 13:40:36 +03:00
|
|
|
$users = array_map([$this, 'filterSharesOfUser'], $users);
|
2017-04-10 17:22:12 +03:00
|
|
|
$users = array_filter($users);
|
2017-04-11 13:40:36 +03:00
|
|
|
} else {
|
|
|
|
$users = array_keys($users);
|
2017-04-10 17:22:12 +03:00
|
|
|
}
|
2016-12-22 23:44:21 +03:00
|
|
|
|
2017-03-27 17:06:31 +03:00
|
|
|
return ['users' => $users, 'public' => $link];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For each user the path with the fewest slashes is returned
|
|
|
|
* @param array $shares
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function filterSharesOfUser(array $shares) {
|
|
|
|
// Group shares when the user has a share exception
|
|
|
|
foreach ($shares as $id => $share) {
|
|
|
|
$type = (int) $share['share_type'];
|
|
|
|
$permissions = (int) $share['permissions'];
|
|
|
|
|
|
|
|
if ($type === self::SHARE_TYPE_USERGROUP) {
|
|
|
|
unset($shares[$share['parent']]);
|
|
|
|
|
|
|
|
if ($permissions === 0) {
|
|
|
|
unset($shares[$id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$best = [];
|
|
|
|
$bestDepth = 0;
|
|
|
|
foreach ($shares as $id => $share) {
|
|
|
|
$depth = substr_count($share['file_target'], '/');
|
|
|
|
if (empty($best) || $depth < $bestDepth) {
|
|
|
|
$bestDepth = $depth;
|
|
|
|
$best = [
|
|
|
|
'node_id' => $share['file_source'],
|
|
|
|
'node_path' => $share['file_target'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $best;
|
2016-12-22 23:44:21 +03:00
|
|
|
}
|
2018-07-12 15:55:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* propagate notes to the recipients
|
|
|
|
*
|
|
|
|
* @param IShare $share
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
*/
|
|
|
|
private function propagateNote(IShare $share) {
|
|
|
|
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
$user = $this->userManager->get($share->getSharedWith());
|
|
|
|
$this->sendNote([$user], $share);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
|
2018-07-12 15:55:50 +03:00
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
$groupMembers = $group->getUsers();
|
|
|
|
$this->sendNote($groupMembers, $share);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send note by mail
|
|
|
|
*
|
|
|
|
* @param array $recipients
|
|
|
|
* @param IShare $share
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
*/
|
|
|
|
private function sendNote(array $recipients, IShare $share) {
|
|
|
|
$toList = [];
|
|
|
|
|
|
|
|
foreach ($recipients as $recipient) {
|
|
|
|
/** @var IUser $recipient */
|
|
|
|
$email = $recipient->getEMailAddress();
|
|
|
|
if ($email) {
|
|
|
|
$toList[$email] = $recipient->getDisplayName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($toList)) {
|
|
|
|
$filename = $share->getNode()->getName();
|
|
|
|
$initiator = $share->getSharedBy();
|
|
|
|
$note = $share->getNote();
|
|
|
|
|
|
|
|
$initiatorUser = $this->userManager->get($initiator);
|
|
|
|
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
|
|
|
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
|
2018-07-13 13:09:15 +03:00
|
|
|
$plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
|
|
|
|
$htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
|
2018-07-12 15:55:50 +03:00
|
|
|
$message = $this->mailer->createMessage();
|
|
|
|
|
2018-07-12 17:05:24 +03:00
|
|
|
$emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
|
2018-07-12 15:55:50 +03:00
|
|
|
|
|
|
|
$emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
|
|
|
|
$emailTemplate->addHeader();
|
2018-07-12 19:17:22 +03:00
|
|
|
$emailTemplate->addHeading($htmlHeading, $plainHeading);
|
2018-07-12 17:05:24 +03:00
|
|
|
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
|
2018-07-12 20:32:35 +03:00
|
|
|
|
|
|
|
$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
|
|
|
|
$emailTemplate->addBodyButton(
|
|
|
|
$this->l->t('Open »%s«', [$filename]),
|
|
|
|
$link
|
|
|
|
);
|
|
|
|
|
2018-07-12 15:55:50 +03:00
|
|
|
|
|
|
|
// The "From" contains the sharers name
|
|
|
|
$instanceName = $this->defaults->getName();
|
|
|
|
$senderName = $this->l->t(
|
2018-07-12 18:07:11 +03:00
|
|
|
'%1$s via %2$s',
|
2018-07-12 15:55:50 +03:00
|
|
|
[
|
|
|
|
$initiatorDisplayName,
|
|
|
|
$instanceName
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
|
|
|
if ($initiatorEmailAddress !== null) {
|
|
|
|
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
|
|
|
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
|
|
|
} else {
|
|
|
|
$emailTemplate->addFooter();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($toList) === 1) {
|
|
|
|
$message->setTo($toList);
|
|
|
|
} else {
|
|
|
|
$message->setTo([]);
|
|
|
|
$message->setBcc($toList);
|
|
|
|
}
|
|
|
|
$message->useTemplate($emailTemplate);
|
|
|
|
$this->mailer->send($message);
|
|
|
|
}
|
|
|
|
}
|
2019-10-29 18:56:06 +03:00
|
|
|
|
|
|
|
public function getAllShares(): iterable {
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from('share')
|
|
|
|
->where(
|
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_USER)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_GROUP)),
|
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_LINK))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$cursor = $qb->execute();
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($data = $cursor->fetch()) {
|
2019-10-29 18:56:06 +03:00
|
|
|
try {
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield $share;
|
|
|
|
}
|
|
|
|
$cursor->closeCursor();
|
|
|
|
}
|
2016-01-25 19:17:36 +03:00
|
|
|
}
|