| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Circles - Bring cloud-users closer together. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * later. See the COPYING file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Maxence Lange <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @copyright 2021 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | namespace OCA\Circles\Db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use daita\MySmallPhpTools\Traits\TStringTools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use OCA\Circles\Exceptions\RequestBuilderException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use OCA\Circles\IFederatedUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use OCA\Circles\Model\Mount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * Class GSSharesRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * @package OCA\Circles\Db | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | class MountRequest extends MountRequestBuilder { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	use TStringTools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * @param Mount $mount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 55 |  | View Code Duplication | 	public function save(Mount $mount): void { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		// TODO: fix hash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$hash = $this->token(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$qb = $this->getMountInsertSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$qb->setValue('circle_id', $qb->createNamedParameter($mount->getCircleId())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		   ->setValue('mount_id', $qb->createNamedParameter($mount->getMountId())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		   ->setValue('single_id', $qb->createNamedParameter($mount->getOwner()->getSingleId())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		   ->setValue('token', $qb->createNamedParameter($mount->getToken())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		   ->setValue('parent', $qb->createNamedParameter($mount->getParent())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		   ->setValue('mountpoint', $qb->createNamedParameter($mount->getMountPoint())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		   ->setValue('mountpoint_hash', $qb->createNamedParameter($hash)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * @param string $token | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | 	public function delete(string $token): void { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 		$qb = $this->getMountDeleteSql(); | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 		$qb->limitToToken($token); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 		$qb->execute(); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * @param IFederatedUser $federatedUser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * @return Mount[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * @throws RequestBuilderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	public function getForUser(IFederatedUser $federatedUser): array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$qb = $this->getMountSelectSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$qb->setOptions([CoreQueryBuilder::MOUNT], ['getData' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$qb->leftJoinMember(CoreQueryBuilder::MOUNT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$qb->leftJoinMountpoint(CoreQueryBuilder::MOUNT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		$qb->limitToInitiator(CoreQueryBuilder::MOUNT, $federatedUser, 'circle_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		return $this->getItemsFromRequest($qb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | //		FederatedUser $federatedUser, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | //		int $nodeId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | //		int $offset, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | //		int $limit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | //		bool $getData = false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | //	): array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | //			$qb = $this->getShareSelectSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | //			$qb->setOptions([CoreRequestBuilder::SHARE], ['getData' => $getData]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | //			if ($getData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | //				$qb->leftJoinCircle(CoreRequestBuilder::SHARE, null, 'share_with'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | //			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | //			$qb->limitToInitiator(CoreRequestBuilder::SHARE, $federatedUser, 'share_with'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | //			$qb->leftJoinFileCache(CoreRequestBuilder::SHARE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | //			$qb->limitToDBFieldEmpty('parent', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | //			$qb->leftJoinShareChild(CoreRequestBuilder::SHARE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | //			if ($nodeId > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | //				$qb->limitToFileSource($nodeId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | //			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | //			$qb->chunk($offset, $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | //			return $this->getItemsFromRequest($qb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | //			$this->joinMembership($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | //		$this->leftJoinMountPoint($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | //		$shares = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | //		$cursor = $qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | //		while ($data = $cursor->fetch()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | //			$shares[] = $this->parseGSSharesSelectSql($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | //		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | //		$cursor->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | //		return $shares; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | //	 * @param string $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | //	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | //	 * @return Mount[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | //	public function getForUser(string $userId): array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | //		$qb = $this->getMountSelectSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | //		$this-> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | //		$this->joinMembership($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | //		$this->leftJoinMountPoint($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | //		$shares = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | //		$cursor = $qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | //		while ($data = $cursor->fetch()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | //			$shares[] = $this->parseGSSharesSelectSql($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | //		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | //		$cursor->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | //		return $shares; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | //	 * @param DeprecatedMember $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | //	public function removeGSSharesFromMember(DeprecatedMember $member) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | //		$qb = $this->getMountDeleteSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | //		$this->limitToCircleId($qb, $member->getCircleId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | //		$this->limitToInstance($qb, $member->getInstance()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | //		$this->limitToOwner($qb, $member->getUserId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | //		$qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | //	 * @param IQueryBuilder $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | //	 * @param string $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | //	private function joinMembership(IQueryBuilder $qb, string $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | //		$qb->from(DeprecatedRequestBuilder::TABLE_MEMBERS, 'm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | //		$expr = $qb->expr(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | //		$andX = $expr->andX(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | //		$andX->add($expr->eq('m.user_id', $qb->createNamedParameter($userId))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | //		$andX->add($expr->eq('m.instance', $qb->createNamedParameter(''))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | //		$andX->add($expr->gt('m.level', $qb->createNamedParameter(0))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | //		$andX->add($expr->eq('m.user_type', $qb->createNamedParameter(DeprecatedMember::TYPE_USER))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | //		$andX->add($expr->eq('m.circle_id', 'gsh.circle_id')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | //		$qb->andWhere($andX); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | //	private function leftJoinMountPoint(IQueryBuilder $qb, string $userId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | //		$expr = $qb->expr(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | //		$pf = '' . $this->default_select_alias . '.'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | //		$on = $expr->andX(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | //		$on->add($expr->eq('mp.user_id', $qb->createNamedParameter($userId))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | //		$on->add($expr->eq('mp.share_id', $pf . 'id')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | //		/** @noinspection PhpMethodParametersCountMismatchInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | //		$qb->selectAlias('mp.mountPoint', 'gsshares_mountpoint') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | //		   ->leftJoin($this->default_select_alias, DeprecatedRequestBuilder::TABLE_GSSHARES_MOUNTPOINT, 'mp', $on); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | //	 * @param string $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | //	 * @param string $target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | //	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | //	 * @return GSShareMountpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | //	 * @throws ShareNotFound | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | //	public function getShareMountPointByPath(string $userId, string $target): GSShareMountpoint { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | //		$qb = $this->getMountMountpointSelectSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | //		$targetHash = md5($target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | //		$this->limitToUserId($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | //		$this->limitToMountpointHash($qb, $targetHash); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | //		$shares = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | //		$cursor = $qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | //		$data = $cursor->fetch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | //		if ($data === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | //			throw new ShareNotFound(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | //		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | //		return $this->parseGSSharesMountpointSelectSql($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | //	 * @param int $gsShareId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | //	 * @param string $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | //	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | //	 * @return GSShareMountpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | //	 * @throws ShareNotFound | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | //	public function getShareMountPointById(int $gsShareId, string $userId): GSShareMountpoint { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | //		$qb = $this->getMountMountpointSelectSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | //		$this->limitToShareId($qb, $gsShareId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | //		$this->limitToUserId($qb, $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | //		$shares = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | //		$cursor = $qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | //		$data = $cursor->fetch(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | //		if ($data === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | //			throw new ShareNotFound(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | //		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | //		return $this->parseGSSharesMountpointSelectSql($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | //	 * @param GSShareMountpoint $mountpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | //	public function generateShareMountPoint(GSShareMountpoint $mountpoint) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | //		$qb = $this->getMountMountpointInsertSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | //		$hash = ($mountpoint->getMountPoint() === '-') ? '' : md5($mountpoint->getMountPoint()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | //		$qb->setValue('user_id', $qb->createNamedParameter($mountpoint->getUserId())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | //		   ->setValue('share_id', $qb->createNamedParameter($mountpoint->getShareId())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | //		   ->setValue('mountpoint', $qb->createNamedParameter($mountpoint->getMountPoint())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | //		   ->setValue('mountpoint_hash', $qb->createNamedParameter($hash)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | //		$qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | //	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | //	 * @param GSShareMountpoint $mountpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | //	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | //	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | //	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | //	public function updateShareMountPoint(GSShareMountpoint $mountpoint) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | //		$qb = $this->getMountMountpointUpdateSql(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | //		$hash = ($mountpoint->getMountPoint() === '-') ? '' : md5($mountpoint->getMountPoint()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | //		$qb->set('mountpoint', $qb->createNamedParameter($mountpoint->getMountPoint())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | //		   ->set('mountpoint_hash', $qb->createNamedParameter($hash)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | //		$this->limitToShareId($qb, $mountpoint->getShareId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | //		$this->limitToUserId($qb, $mountpoint->getUserId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | //		$nb = $qb->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | //		return ($nb === 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | //	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 294 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 295 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.