| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-04-15 11:34:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Nextcloud - Social Support | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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, Maxence Lange <maxence@artificial-owl.com> | 
					
						
							|  |  |  |  * @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\Social\Db; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | use DateTime; | 
					
						
							| 
									
										
										
										
											2019-04-20 14:04:35 +00:00
										 |  |  | use Exception; | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | use OCA\Social\Exceptions\FollowNotFoundException; | 
					
						
							| 
									
										
										
										
											2019-09-23 10:34:21 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\Actor\Person; | 
					
						
							| 
									
										
										
										
											2019-01-21 16:26:01 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\Object\Follow; | 
					
						
							| 
									
										
										
										
											2022-12-07 00:14:12 +00:00
										 |  |  | use OCA\Social\Tools\Traits\TArrayTools; | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | use OCP\DB\QueryBuilder\IQueryBuilder; | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class FollowsRequest | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package OCA\Social\Db | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class FollowsRequest extends FollowsRequestBuilder { | 
					
						
							| 
									
										
										
										
											2018-11-29 18:28:37 +00:00
										 |  |  | 	use TArrayTools; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Insert a new Note in the database. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param Follow $follow | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 	public function save(Follow $follow) { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsInsertSql(); | 
					
						
							|  |  |  | 		$qb->setValue('id', $qb->createNamedParameter($follow->getId())) | 
					
						
							|  |  |  | 		   ->setValue('actor_id', $qb->createNamedParameter($follow->getActorId())) | 
					
						
							| 
									
										
										
										
											2018-11-30 10:54:48 +00:00
										 |  |  | 		   ->setValue('type', $qb->createNamedParameter($follow->getType())) | 
					
						
							| 
									
										
										
										
											2018-11-21 21:58:56 +00:00
										 |  |  | 		   ->setValue('object_id', $qb->createNamedParameter($follow->getObjectId())) | 
					
						
							| 
									
										
										
										
											2019-05-17 14:33:35 +00:00
										 |  |  | 		   ->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId())) | 
					
						
							| 
									
										
										
										
											2019-09-23 10:34:21 +00:00
										 |  |  | 		   ->setValue('accepted', $qb->createNamedParameter(($follow->isAccepted()) ? '1' : '0')) | 
					
						
							| 
									
										
										
										
											2022-11-22 23:16:36 +00:00
										 |  |  | 		   ->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($follow->getActorId()))) | 
					
						
							|  |  |  | 		   ->setValue('object_id_prim', $qb->createNamedParameter($qb->prim($follow->getObjectId()))) | 
					
						
							|  |  |  | 		   ->setValue('follow_id_prim', $qb->createNamedParameter($qb->prim($follow->getFollowId()))); | 
					
						
							| 
									
										
										
										
											2019-05-17 10:19:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			$qb->setValue( | 
					
						
							|  |  |  | 				'creation', | 
					
						
							|  |  |  | 				$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} catch (Exception $e) { | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 12:11:49 +00:00
										 |  |  | 		$qb->generatePrimaryKey($follow->getId()); | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 10:34:21 +00:00
										 |  |  | 	public function generateLoopbackAccount(Person $actor) { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsInsertSql(); | 
					
						
							|  |  |  | 		$qb->setValue('id', $qb->createNamedParameter($actor->getId())) | 
					
						
							|  |  |  | 		   ->setValue('actor_id', $qb->createNamedParameter($actor->getId())) | 
					
						
							|  |  |  | 		   ->setValue('type', $qb->createNamedParameter('Loopback')) | 
					
						
							|  |  |  | 		   ->setValue('object_id', $qb->createNamedParameter($actor->getId())) | 
					
						
							|  |  |  | 		   ->setValue('follow_id', $qb->createNamedParameter($actor->getId())) | 
					
						
							|  |  |  | 		   ->setValue('accepted', $qb->createNamedParameter('1')) | 
					
						
							| 
									
										
										
										
											2022-11-22 23:16:36 +00:00
										 |  |  | 		   ->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($actor->getId()))) | 
					
						
							|  |  |  | 		   ->setValue('object_id_prim', $qb->createNamedParameter($qb->prim($actor->getId()))) | 
					
						
							|  |  |  | 		   ->setValue('follow_id_prim', $qb->createNamedParameter($qb->prim($actor->getId()))); | 
					
						
							| 
									
										
										
										
											2019-09-23 10:34:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			$qb->setValue( | 
					
						
							|  |  |  | 				'creation', | 
					
						
							|  |  |  | 				$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} catch (Exception $e) { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 12:11:49 +00:00
										 |  |  | 		$qb->generatePrimaryKey($actor->getId()); | 
					
						
							| 
									
										
										
										
											2019-09-23 10:34:21 +00:00
										 |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 10:32:52 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Follow $follow | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function accepted(Follow $follow) { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsUpdateSql(); | 
					
						
							|  |  |  | 		$qb->set('accepted', $qb->createNamedParameter('1')); | 
					
						
							|  |  |  | 		$this->limitToIdString($qb, $follow->getId()); | 
					
						
							|  |  |  | 		$this->limitToActorId($qb, $follow->getActorId()); | 
					
						
							|  |  |  | 		$this->limitToObjectId($qb, $follow->getObjectId()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getAll(): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-11-19 12:10:24 +00:00
										 |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * @param string $remoteActorId | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 	 * @throws FollowNotFoundException | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-17 14:33:35 +00:00
										 |  |  | 	public function getByPersons(string $actorId, string $remoteActorId): Follow { | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							| 
									
										
										
										
											2018-11-19 12:10:24 +00:00
										 |  |  | 		$this->limitToActorId($qb, $actorId); | 
					
						
							|  |  |  | 		$this->limitToObjectId($qb, $remoteActorId); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 18:28:37 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function countFollowers(string $actorId): int { | 
					
						
							|  |  |  | 		$qb = $this->countFollowsSelectSql(); | 
					
						
							| 
									
										
										
										
											2020-06-25 02:48:36 +00:00
										 |  |  | 		$qb->limitToObjectIdPrim($qb->prim($actorId)); | 
					
						
							| 
									
										
										
										
											2019-10-02 16:40:38 +00:00
										 |  |  | 		$qb->limitToType(Follow::TYPE); | 
					
						
							|  |  |  | 		$qb->limitToAccepted(true); | 
					
						
							| 
									
										
										
										
											2018-11-29 18:28:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-28 08:39:18 +00:00
										 |  |  | 		$cursor = $qb->executeQuery(); | 
					
						
							| 
									
										
										
										
											2018-11-29 18:28:37 +00:00
										 |  |  | 		$data = $cursor->fetch(); | 
					
						
							|  |  |  | 		$cursor->closeCursor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->getInt('count', $data, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function countFollowing(string $actorId): int { | 
					
						
							|  |  |  | 		$qb = $this->countFollowsSelectSql(); | 
					
						
							| 
									
										
										
										
											2020-06-25 02:48:36 +00:00
										 |  |  | 		$qb->limitToActorIdPrim($qb->prim($actorId)); | 
					
						
							| 
									
										
										
										
											2019-10-02 16:40:38 +00:00
										 |  |  | 		$qb->limitToType(Follow::TYPE); | 
					
						
							|  |  |  | 		$qb->limitToAccepted(true); | 
					
						
							| 
									
										
										
										
											2018-11-29 18:28:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$cursor = $qb->execute(); | 
					
						
							|  |  |  | 		$data = $cursor->fetch(); | 
					
						
							|  |  |  | 		$cursor->closeCursor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->getInt('count', $data, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function countFollows() { | 
					
						
							|  |  |  | 		$qb = $this->countFollowsSelectSql(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$cursor = $qb->execute(); | 
					
						
							|  |  |  | 		$data = $cursor->fetch(); | 
					
						
							|  |  |  | 		$cursor->closeCursor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->getInt('count', $data, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:22:09 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $followId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getByFollowId(string $followId): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		$qb->limitToFollowId($followId); | 
					
						
							|  |  |  | 		$qb->limitToAccepted(true); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:22:09 +00:00
										 |  |  | 		$this->leftJoinCacheActors($qb, 'actor_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2018-11-21 19:22:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getFollowersByActorId(string $actorId): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							| 
									
										
										
										
											2023-03-08 01:17:31 +00:00
										 |  |  | 		$this->limitToObjectId($qb, $actorId); | 
					
						
							| 
									
										
										
										
											2018-12-04 23:49:17 +00:00
										 |  |  | 		$this->limitToAccepted($qb, true); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 		$this->leftJoinCacheActors($qb, 'actor_id'); | 
					
						
							| 
									
										
										
										
											2018-12-04 08:27:56 +00:00
										 |  |  | 		$this->leftJoinDetails($qb, 'id', 'ca'); | 
					
						
							| 
									
										
										
										
											2018-12-06 14:47:12 +00:00
										 |  |  | 		$qb->orderBy('f.creation', 'desc'); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getFollowingByActorId(string $actorId): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							|  |  |  | 		$this->limitToActorId($qb, $actorId); | 
					
						
							| 
									
										
										
										
											2018-12-04 23:49:17 +00:00
										 |  |  | 		$this->limitToAccepted($qb, true); | 
					
						
							| 
									
										
										
										
											2018-12-02 20:29:55 +00:00
										 |  |  | 		$this->leftJoinCacheActors($qb, 'object_id'); | 
					
						
							| 
									
										
										
										
											2018-12-04 08:27:56 +00:00
										 |  |  | 		$this->leftJoinDetails($qb, 'id', 'ca'); | 
					
						
							| 
									
										
										
										
											2018-12-06 14:47:12 +00:00
										 |  |  | 		$qb->orderBy('f.creation', 'desc'); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:31:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 11:00:40 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $followId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getFollowersByFollowId(string $followId): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							|  |  |  | 		$this->limitToFollowId($qb, $followId); | 
					
						
							|  |  |  | 		$this->limitToAccepted($qb, true); | 
					
						
							|  |  |  | 		$this->leftJoinAccounts($qb, 'actor_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 11:55:47 +00:00
										 |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							| 
									
										
										
										
											2019-08-12 11:00:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Follow $follow | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function delete(Follow $follow) { | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 		$qb = $this->getFollowsDeleteSql(); | 
					
						
							|  |  |  | 		$this->limitToIdString($qb, $follow->getId()); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 11:48:31 +00:00
										 |  |  | 		$qb->execute(); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 12:10:24 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Follow $follow | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function deleteByPersons(Follow $follow) { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsDeleteSql(); | 
					
						
							|  |  |  | 		$this->limitToActorId($qb, $follow->getActorId()); | 
					
						
							|  |  |  | 		$this->limitToObjectId($qb, $follow->getObjectId()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 11:49:30 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function deleteRelatedId(string $actorId) { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsDeleteSql(); | 
					
						
							| 
									
										
										
										
											2022-12-07 00:14:12 +00:00
										 |  |  | 		$orX = $qb->expr()->orX(); | 
					
						
							|  |  |  | 		$orX->add($qb->exprLimitToDBField('actor_id_prim', $qb->prim($actorId))); | 
					
						
							|  |  |  | 		$orX->add($qb->exprLimitToDBField('object_id_prim', $qb->prim($actorId))); | 
					
						
							|  |  |  | 		$qb->where($orX); | 
					
						
							| 
									
										
										
										
											2019-08-21 11:49:30 +00:00
										 |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-08-22 21:49:27 +00:00
										 |  |  | 	 * @param string $id | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-22 21:49:27 +00:00
										 |  |  | 	public function deleteById(string $id) { | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 		$qb = $this->getFollowsDeleteSql(); | 
					
						
							| 
									
										
										
										
											2019-08-22 21:49:27 +00:00
										 |  |  | 		$this->limitToIdString($qb, $id); | 
					
						
							| 
									
										
										
										
											2019-08-21 12:22:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$qb->execute(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-07 00:14:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * @param Person $new | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-12-07 10:45:17 +00:00
										 |  |  | 	public function moveAccountFollowers(string $actorId, Person $new): void { | 
					
						
							| 
									
										
										
										
											2022-12-07 00:14:12 +00:00
										 |  |  | 		$qb = $this->getFollowsUpdateSql(); | 
					
						
							|  |  |  | 		$qb->set('object_id', $qb->createNamedParameter($new->getId())) | 
					
						
							|  |  |  | 		   ->set('object_id_prim', $qb->createNamedParameter($qb->prim($new->getId()))) | 
					
						
							|  |  |  | 		   ->set('follow_id', $qb->createNamedParameter($new->getFollowers())) | 
					
						
							|  |  |  | 		   ->set('follow_id_prim', $qb->createNamedParameter($qb->prim($new->getFollowers()))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->limitToObjectIdPrim($qb->prim($actorId)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->executeStatement(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * @param Person $new | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-12-07 10:45:17 +00:00
										 |  |  | 	public function moveAccountFollowing(string $actorId, Person $new): void { | 
					
						
							| 
									
										
										
										
											2022-12-07 00:14:12 +00:00
										 |  |  | 		$qb = $this->getFollowsUpdateSql(); | 
					
						
							|  |  |  | 		$qb->set('actor_id', $qb->createNamedParameter($new->getId())) | 
					
						
							|  |  |  | 		   ->set('actor_id_prim', $qb->createNamedParameter($qb->prim($new->getId()))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->limitToActorIdPrim($qb->prim($actorId)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qb->executeStatement(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-03-08 14:42:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Returns everything related to a list of actorIds. | 
					
						
							|  |  |  | 	 * Looking at actor_id_prim and object_id_prim. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param array $actorIds | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Follow[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getFollows(array $actorIds): array { | 
					
						
							|  |  |  | 		$qb = $this->getFollowsSelectSql(); | 
					
						
							|  |  |  | 		$qb->limitToType(Follow::TYPE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$prims = []; | 
					
						
							|  |  |  | 		foreach ($actorIds as $actorId) { | 
					
						
							|  |  |  | 			$prims[] = $qb->prim($actorId); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$orX = $qb->expr()->orX(); | 
					
						
							|  |  |  | 		$orX->add($qb->exprLimitInArray('actor_id_prim', $prims)); | 
					
						
							|  |  |  | 		$orX->add($qb->exprLimitInArray('object_id_prim', $prims)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->getFollowsFromRequest($qb); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-12 22:55:39 +00:00
										 |  |  | } |