99namespace OCA \User_LDAP \Mapping ;
1010
1111use Doctrine \DBAL \Exception ;
12- use OCP \DB \IPreparedStatement ;
1312use OCP \DB \QueryBuilder \IQueryBuilder ;
1413use OCP \IAppConfig ;
1514use OCP \ICache ;
@@ -155,24 +154,6 @@ protected function getXbyY($fetchCol, $compareCol, $search) {
155154 }
156155 }
157156
158- /**
159- * Performs a DELETE or UPDATE query to the database.
160- *
161- * @param IPreparedStatement $statement
162- * @param array $parameters
163- * @return bool true if at least one row was modified, false otherwise
164- */
165- protected function modify (IPreparedStatement $ statement , $ parameters ) {
166- try {
167- $ result = $ statement ->execute ($ parameters );
168- $ updated = $ result ->rowCount () > 0 ;
169- $ result ->closeCursor ();
170- return $ updated ;
171- } catch (Exception $ e ) {
172- return false ;
173- }
174- }
175-
176157 /**
177158 * Gets the LDAP DN based on the provided name.
178159 */
@@ -200,13 +181,16 @@ public function getDNByName(string $name): string|false {
200181 */
201182 public function setDNbyUUID ($ fdn , $ uuid ) {
202183 $ oldDn = $ this ->getDnByUUID ($ uuid );
203- $ statement = $ this ->dbc ->prepare ('
204- UPDATE ` ' . $ this ->getTableName () . '`
205- SET `ldap_dn_hash` = ?, `ldap_dn` = ?
206- WHERE `directory_uuid` = ?
207- ' );
208-
209- $ r = $ this ->modify ($ statement , [$ this ->getDNHash ($ fdn ), $ fdn , $ uuid ]);
184+ $ qb = $ this ->dbc ->getQueryBuilder ();
185+ try {
186+ $ r = $ qb ->update ($ this ->getTableName (false ))
187+ ->set ('ldap_dn_hash ' , $ qb ->createNamedParameter ($ this ->getDNHash ($ fdn )))
188+ ->set ('ldap_dn ' , $ qb ->createNamedParameter ($ fdn ))
189+ ->where ($ qb ->expr ()->eq ('directory_uuid ' , $ qb ->createNamedParameter ($ uuid )))
190+ ->executeStatement () > 0 ;
191+ } catch (Exception $ e ) {
192+ $ r = false ;
193+ }
210194 if ($ r ) {
211195 if (is_string ($ oldDn ) && isset ($ this ->cache [$ oldDn ])) {
212196 $ userId = $ this ->cache [$ oldDn ];
@@ -232,15 +216,17 @@ public function setDNbyUUID($fdn, $uuid) {
232216 * @return bool
233217 */
234218 public function setUUIDbyDN ($ uuid , $ fdn ): bool {
235- $ statement = $ this ->dbc ->prepare ('
236- UPDATE ` ' . $ this ->getTableName () . '`
237- SET `directory_uuid` = ?
238- WHERE `ldap_dn_hash` = ?
239- ' );
240-
241219 unset($ this ->cache [$ fdn ]);
242220
243- return $ this ->modify ($ statement , [$ uuid , $ this ->getDNHash ($ fdn )]);
221+ $ qb = $ this ->dbc ->getQueryBuilder ();
222+ try {
223+ return $ qb ->update ($ this ->getTableName (false ))
224+ ->set ('directory_uuid ' , $ qb ->createNamedParameter ($ uuid ))
225+ ->where ($ qb ->expr ()->eq ('ldap_dn_hash ' , $ qb ->createNamedParameter ($ this ->getDNHash ($ fdn ))))
226+ ->executeStatement () > 0 ;
227+ } catch (Exception $ e ) {
228+ return false ;
229+ }
244230 }
245231
246232 /**
@@ -340,21 +326,22 @@ public function getListOfIdsByDn(array $fdns): array {
340326 * @return string[]
341327 */
342328 public function getNamesBySearch (string $ search , string $ prefixMatch = '' , string $ postfixMatch = '' ): array {
343- $ statement = $ this ->dbc ->prepare ('
344- SELECT `owncloud_name`
345- FROM ` ' . $ this ->getTableName () . '`
346- WHERE `owncloud_name` LIKE ?
347- ' );
348-
329+ $ qb = $ this ->dbc ->getQueryBuilder ();
349330 try {
350- $ res = $ statement ->execute ([$ prefixMatch . $ this ->dbc ->escapeLikeParameter ($ search ) . $ postfixMatch ]);
331+ $ res = $ qb ->select ('owncloud_name ' )
332+ ->from ($ this ->getTableName (false ))
333+ ->where ($ qb ->expr ()->like ('owncloud_name ' , $ qb ->createNamedParameter (
334+ $ prefixMatch . $ this ->dbc ->escapeLikeParameter ($ search ) . $ postfixMatch
335+ )))
336+ ->executeQuery ();
351337 } catch (Exception $ e ) {
352338 return [];
353339 }
354340 $ names = [];
355341 while ($ row = $ res ->fetchAssociative ()) {
356342 $ names [] = $ row ['owncloud_name ' ];
357343 }
344+ $ res ->closeCursor ();
358345 return $ names ;
359346 }
360347
@@ -450,17 +437,20 @@ public function map($fdn, $name, $uuid) {
450437 * @return bool
451438 */
452439 public function unmap ($ name ) {
453- $ statement = $ this ->dbc ->prepare ('
454- DELETE FROM ` ' . $ this ->getTableName () . '`
455- WHERE `owncloud_name` = ? ' );
456-
457440 $ dn = array_search ($ name , $ this ->cache , true );
458441 if ($ dn !== false ) {
459442 unset($ this ->cache [$ dn ]);
460443 }
461444 $ this ->localNameToDnCache ?->remove($ name );
462445
463- return $ this ->modify ($ statement , [$ name ]);
446+ $ qb = $ this ->dbc ->getQueryBuilder ();
447+ try {
448+ return $ qb ->delete ($ this ->getTableName (false ))
449+ ->where ($ qb ->expr ()->eq ('owncloud_name ' , $ qb ->createNamedParameter ($ name )))
450+ ->executeStatement () > 0 ;
451+ } catch (Exception $ e ) {
452+ return false ;
453+ }
464454 }
465455
466456 /**
0 commit comments