Skip to content

Commit

Permalink
Using our own deprecated method to get Shares (compat NC14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Feb 12, 2018
1 parent 720746d commit 079e9bd
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 19 deletions.
89 changes: 89 additions & 0 deletions lib/Db/CoreRequestBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Files_FullTextSearch - Index the content of your files
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_FullTextSearch\Db;


use Doctrine\DBAL\Query\QueryBuilder;
use OCA\FullTextSearch\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

class CoreRequestBuilder {

const TABLE_SHARES = 'share';

/** @var IDBConnection */
protected $dbConnection;

/** @var MiscService */
protected $miscService;

/** @var string */
protected $defaultSelectAlias;


/**
* CoreRequestBuilder constructor.
*
* @param IDBConnection $connection
* @param MiscService $miscService
*/
public function __construct(
IDBConnection $connection, MiscService $miscService
) {
$this->dbConnection = $connection;
$this->miscService = $miscService;
}


/**
* Limit the request to the Id
*
* @param IQueryBuilder $qb
* @param $fileSource
*/
protected function limitToFileSource(IQueryBuilder &$qb, $fileSource) {
$this->limitToDBField($qb, 'file_source', $fileSource);
}


/**
* @param IQueryBuilder $qb
* @param string $field
* @param string|integer $value
*/
private function limitToDBField(IQueryBuilder &$qb, $field, $value) {
$expr = $qb->expr();
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
$qb->andWhere($expr->eq($pf . $field, $qb->createNamedParameter($value)));
}


}



61 changes: 61 additions & 0 deletions lib/Db/SharesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Files_FullTextSearch - Index the content of your files
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_FullTextSearch\Db;


use OCP\Files\Node;

class SharesRequest extends SharesRequestBuilder {


/**
* @param Node $file
*
* @deprecated
* @return array
*/
public function getFromFile(Node $file) {

$shares = [];
try {
$qb = $this->getSharesSelectSql();

$this->limitToFileSource($qb, $file->getId());

$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$shares[] = $this->parseSharesSelectSql($data);
}
$cursor->closeCursor();
} catch (\Exception $e) {
/** issue while doing some DB request */
}

return $shares;
}

}
62 changes: 62 additions & 0 deletions lib/Db/SharesRequestBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Files_FullTextSearch - Index the content of your files
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_FullTextSearch\Db;


use OCP\DB\QueryBuilder\IQueryBuilder;

class SharesRequestBuilder extends CoreRequestBuilder {


/**
* Base of the Sql Select request for Shares
*
* @return IQueryBuilder
*/
protected function getSharesSelectSql() {
$qb = $this->dbConnection->getQueryBuilder();

/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select('s.*')
->from(self::TABLE_SHARES, 's');

$this->defaultSelectAlias = 's';

return $qb;
}


/**
* @param array $data
*
* @return array
*/
protected function parseSharesSelectSql($data) {
return $data;
}

}
48 changes: 29 additions & 19 deletions lib/Service/FilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

use Exception;
use OC\Share\Constants;
use OC\Share\Share;
use OCA\Files_FullTextSearch\Db\SharesRequest;
use OCA\Files_FullTextSearch\Exceptions\FileIsNotIndexableException;
use OCA\Files_FullTextSearch\Model\FilesDocument;
use OCA\Files_FullTextSearch\Provider\FilesProvider;
Expand Down Expand Up @@ -71,6 +71,9 @@ class FilesService {
/** @var IManager */
private $shareManager;

/** @var SharesRequest */
private $sharesRequest;

/** @var ConfigService */
private $configService;

Expand All @@ -87,6 +90,7 @@ class FilesService {
* @param IRootFolder $rootFolder
* @param IUserManager $userManager
* @param IManager $shareManager
* @param SharesRequest $sharesRequest
* @param ConfigService $configService
* @param ExternalFilesService $externalFilesService
* @param MiscService $miscService
Expand All @@ -95,13 +99,14 @@ class FilesService {
*/
public function __construct(
IRootFolder $rootFolder, IUserManager $userManager, IManager $shareManager,
ConfigService $configService, ExternalFilesService $externalFilesService,
MiscService $miscService
SharesRequest $sharesRequest, ConfigService $configService,
ExternalFilesService $externalFilesService, MiscService $miscService
) {
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
$this->shareManager = $shareManager;

$this->sharesRequest = $sharesRequest;
$this->configService = $configService;
$this->externalFilesService = $externalFilesService;
$this->miscService = $miscService;
Expand Down Expand Up @@ -313,13 +318,16 @@ public function setDocumentLink(IndexDocument $document) {
$dir = substr($path, 0, -strlen($document->getInfo('filename')));
$filename = $document->getInfo('filename');

$document->setLink(\OC::$server->getURLGenerator()->linkToRoute(
'files.view.index',
[
'dir' => $dir,
'scrollto' => $filename,
]
));
$document->setLink(
\OC::$server->getURLGenerator()
->linkToRoute(
'files.view.index',
[
'dir' => $dir,
'scrollto' => $filename,
]
)
);
}


Expand Down Expand Up @@ -351,7 +359,8 @@ public function setDocumentMore(IndexDocument $document) {
}

// TODO: better way to do this : we remove the '/userid/files/'
$path = MiscService::noEndSlash(substr($file->getPath(), 7 + strlen($access->getViewerId())));
$path =
MiscService::noEndSlash(substr($file->getPath(), 7 + strlen($access->getViewerId())));

$more = [
'webdav' => $this->getWebdavId($document->getId()),
Expand Down Expand Up @@ -383,7 +392,9 @@ public function generateDocuments($documents) {
continue;
}

$document->setPath($this->getPathFromViewerId($document->getId(), $document->getViewerId()));
$document->setPath(
$this->getPathFromViewerId($document->getId(), $document->getViewerId())
);

try {
$this->updateDocumentFromFilesDocument($document);
Expand Down Expand Up @@ -486,8 +497,8 @@ private function updateDocumentFromFile(FilesDocument $document, Node $file) {
* @throws NotPermittedException
*/
private function generateDocumentFromIndex(Index $index) {

$file = $this->getFileFromId($index->getOwnerId(), $index->getDocumentId());

if ($file === null) {
$index->setStatus(Index::INDEX_REMOVE);
$document = new FilesDocument($index->getProviderId(), $index->getDocumentId());
Expand Down Expand Up @@ -684,8 +695,6 @@ private function extractContentFromFileOffice(FilesDocument $document, File $fil
* @param Node $file
*
* @return DocumentAccess
* @throws InvalidPathException
* @throws NotFoundException
*/
private function getDocumentAccessFromFile(Node $file) {

Expand All @@ -694,7 +703,7 @@ private function getDocumentAccessFromFile(Node $file) {
->getUID()
);

list($users, $groups, $circles, $links) = $this->getSharesFromFileId($file->getId());
list($users, $groups, $circles, $links) = $this->getSharesFromFileId($file);
$access->setUsers($users);
$access->setGroups($groups);
$access->setCircles($circles);
Expand Down Expand Up @@ -756,16 +765,17 @@ private function getAllSharesFromFile(Node $file) {


/**
* @param $fileId
* @param Node $file
*
* @return array
*/
private function getSharesFromFileId($fileId) {
private function getSharesFromFileId(Node $file) {

$users = $groups = $circles = $links = [];
$shares = Share::getAllSharesForFileId($fileId);
$shares = $this->sharesRequest->getFromFile($file);

foreach ($shares as $share) {

if ($share['parent'] !== null) {
continue;
}
Expand Down

0 comments on commit 079e9bd

Please sign in to comment.