-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using our own deprecated method to get Shares (compat NC14)
- Loading branch information
1 parent
720746d
commit 079e9bd
Showing
4 changed files
with
241 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters