| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @copyright Copyright (c) 2017, Matias De lellis <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @author Branko Kokanovic <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | namespace OCA\FaceRecognition\Db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OC\DB\QueryBuilder\Literal; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCP\IDBConnection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\IUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use OCP\AppFramework\Db\QBMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use OCP\AppFramework\Db\DoesNotExistException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use OCP\DB\QueryBuilder\IQueryBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class PersonMapper extends QBMapper { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 4 |  | 	public function __construct(IDBConnection $db) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 4 |  | 		parent::__construct($db, 'face_recognition_persons', '\OCA\FaceRecognition\Db\Person'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 4 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	public function find(string $userId, int $personId): Person { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$qb->select('id', 'name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			->from('face_recognition_persons', 'p') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			->where($qb->expr()->eq('id', $qb->createNamedParameter($personId))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($userId))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$person = $this->findEntity($qb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		return $person; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	public function findAll (string $userId): array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$qb->select('id', 'name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			->from('face_recognition_persons', 'p') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$person = $this->findEntities($qb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		return $person; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * Returns count of persons (clusters) found for a given user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * @param string $userId ID of the user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @param bool $onlyInvalid True if client wants count of invalid persons only, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 *  false if client want count of all persons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @return int Count of persons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	public function countPersons(string $userId, bool $onlyInvalid=false): int { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$qb = $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			->select($qb->createFunction('COUNT(' . $qb->getColumnName('id') . ')')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			->from($this->getTableName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			->where($qb->expr()->eq('user', $qb->createParameter('user'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		if ($onlyInvalid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			$qb = $qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 				->andWhere($qb->expr()->eq('is_valid', $qb->createParameter('is_valid'))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 				->setParameter('is_valid', false, IQueryBuilder::PARAM_BOOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$query = $qb->setParameter('user', $userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$resultStatement = $query->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$data = $resultStatement->fetch(\PDO::FETCH_NUM); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$resultStatement->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		return (int)$data[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * Based on a given fileId, takes all person that belong to that image | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 * and return an array with that. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	 * @param string $userId ID of the user that clusters belong to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * @param int $fileId ID of file image for which to searh persons. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 * @return array of persons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	public function findFromFile(string $userId, int $fileId): array { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$qb->select('p.id', 'name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$qb->from("face_recognition_persons", "p") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			->innerJoin('p', 'face_recognition_faces' ,'f', $qb->expr()->eq('p.id', 'f.person')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			->innerJoin('p', 'face_recognition_images' ,'i', $qb->expr()->eq('i.id', 'f.image')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 			->where($qb->expr()->eq('p.user', $qb->createNamedParameter($userId))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 			->andWhere($qb->expr()->eq('i.file', $qb->createNamedParameter($fileId))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$persons = $this->findEntities($qb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		return $persons; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * Based on a given image, takes all faces that belong to that image | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 * and invalidates all person that those faces belongs to. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * @param int $imageId ID of image for which to invalidate persons for | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	public function invalidatePersons(int $imageId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		$sub = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$sub->select(new Literal('1')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		$sub->from("face_recognition_images", "i") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			->innerJoin('i', 'face_recognition_faces' ,'f', $sub->expr()->eq('i.id', 'f.image')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			->where($sub->expr()->eq('p.id', 'f.person')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			->andWhere($sub->expr()->eq('i.id', $sub->createParameter('image_id'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$qb->update($this->getTableName(), 'p') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			->set("is_valid", $qb->createParameter('is_valid')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			->where('EXISTS (' . $sub->getSQL() . ')') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			->setParameter('image_id', $imageId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			->setParameter('is_valid', false, IQueryBuilder::PARAM_BOOL) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * Updates one face with $faceId to database to person ID $personId. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	 * @param int $faceId ID of the face | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	 * @param int|null $personId ID of the person | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	private function updateFace(int $faceId, $personId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		$qb->update('face_recognition_faces') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			->set("person", $qb->createNamedParameter($personId)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			->where($qb->expr()->eq('id', $qb->createNamedParameter($faceId))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 			->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	 * Based on current clusters and new clusters, do database reconciliation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	 * It tries to do that in minumal number of SQL queries. Operation is atomic. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	 * Clusters are array, where keys are ID of persons, and values are indexed arrays | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	 * with values that are ID of the faces for those persons. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	 * @param string $userId ID of the user that clusters belong to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * @param array $currentClusters Current clusters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * @param array $newClusters New clusters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	public function mergeClusterToDatabase(string $userId, $currentClusters, $newClusters) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		$this->db->beginTransaction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		$currentDateTime = new \DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 			// Delete clusters that do not exist anymore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 			foreach($currentClusters as $oldPerson => $oldFaces) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 				if (array_key_exists($oldPerson, $newClusters)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 					continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 				// OK, we bumped into cluster that existed and now it does not exist. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 				// We need to remove all references to it and to delete it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 				foreach ($oldFaces as $oldFace) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 					$this->updateFace($oldFace, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 				// todo: this is not very cool. What if user had associated linked user to this. And all lost? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 				$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 				// todo: for extra safety, we should probably add here additional condition, where (user=$userId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 				$qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 					->delete($this->getTableName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 					->where($qb->expr()->eq('id', $qb->createNamedParameter($oldPerson))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 					->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 			// Modify existing clusters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			foreach($newClusters as $newPerson=>$newFaces) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 				if (!array_key_exists($newPerson, $currentClusters)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 					// This cluster didn't exist, there is nothing to modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 					// It will be processed during cluster adding operation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 					continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 				$oldFaces = $currentClusters[$newPerson]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 				if ($newFaces === $oldFaces) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 					continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 				// OK, set of faces do differ. Now, we could potentially go into finer grain details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 				// and add/remove each individual face, but this seems too detailed. Enough is to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 				// reset all existing faces to null and to add new faces to new person. That should | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 				// take care of both faces that are removed from cluster, as well as for newly added | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 				// faces to this cluster. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 				// First remove all old faces from any cluster (reset them to null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 				foreach ($oldFaces as $oldFace) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 					// Reset face to null only if it wasn't moved to other cluster! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 					// (if face is just moved to other cluster, do not reset to null, as some other | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 					// pass for some other cluster will eventually update it to proper cluster) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 					if ($this->isFaceInClusters($oldFace, $newClusters) === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 						$this->updateFace($oldFace, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 				// Then set all new faces to belong to this cluster | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 				foreach ($newFaces as $newFace) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 					$this->updateFace($newFace, $newPerson); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 			// Add new clusters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 			foreach($newClusters as $newPerson=>$newFaces) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 				if (array_key_exists($newPerson, $currentClusters)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 					// This cluster already existed, nothing to add | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 					// It was already processed during modify cluster operation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 					continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 				// Create new cluster and add all faces to it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 				$qb = $this->db->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 				$qb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 					->insert($this->getTableName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 					->values([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 						'user' => $qb->createNamedParameter($userId), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 						'name' => $qb->createNamedParameter(sprintf("New person %d", $newPerson)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 						'is_valid' => $qb->createNamedParameter(true), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 						'last_generation_time' => $qb->createNamedParameter($currentDateTime, IQueryBuilder::PARAM_DATE), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 						'linked_user' => $qb->createNamedParameter(null)]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 					->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 				$insertedPersonId = $this->db->lastInsertId($this->getTableName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 				foreach ($newFaces as $newFace) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 					$this->updateFace($newFace, $insertedPersonId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 			$this->db->commit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 		} catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			$this->db->rollBack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 			throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 	 * Checks if face with a given ID is in any cluster. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 	 * @param int $faceId ID of the face to check | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 	 * @param array $cluster All clusters to check into | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 	 * @return bool True if face is found in any cluster, false otherwise. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 259 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 260 |  |  | 	private function isFaceInClusters(int $faceId, array $clusters): bool { | 
            
                                                                        
                            
            
                                    
            
            
                | 261 |  |  | 		foreach ($clusters as $_=>$faces) { | 
            
                                                                        
                            
            
                                    
            
            
                | 262 |  |  | 			if (in_array($faceId, $faces)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 263 |  |  | 				return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 264 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 265 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 266 |  |  | 		return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 268 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 269 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths