diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php index b6d7bad872..ecda49f73f 100644 --- a/apps/user_ldap/lib/helper.php +++ b/apps/user_ldap/lib/helper.php @@ -159,14 +159,9 @@ class Helper { return false; } - $dbtype = \OCP\Config::getSystemValue('dbtype'); - if(strpos($dbtype, 'sqlite') !== false || $dbtype === 'oci') { - $query = \OCP\DB::prepare('DELETE FROM '.$table); - } else { - $query = \OCP\DB::prepare('TRUNCATE '.$table); - } - - + $connection = \OC_DB::getConnection(); + $sql = $connection->getDatabasePlatform()->getTruncateTableSQL($table); + $query = \OCP\DB::prepare($sql); $res = $query->execute(); if(\OCP\DB::isError($res)) { @@ -177,7 +172,7 @@ class Helper { } /** - * extractsthe domain from a given URL + * extracts the domain from a given URL * @param string $url the URL * @return string|false domain as string on success, false otherwise */ diff --git a/apps/user_ldap/tests/helper.php b/apps/user_ldap/tests/helper.php new file mode 100644 index 0000000000..07c24d6449 --- /dev/null +++ b/apps/user_ldap/tests/helper.php @@ -0,0 +1,31 @@ +execute(array('db01', 'oc1', '000-0000-0000')); + $statement->execute(array('db02', 'oc2', '000-0000-0001')); + + $statement = \OCP\DB::prepare('SELECT count(*) FROM `*PREFIX*ldap_user_mapping`'); + $result = $statement->execute(); + $this->assertEquals(2, $result->fetchOne()); + + Helper::clearMapping('user'); + + $result = $statement->execute(); + $this->assertEquals(0, $result->fetchOne()); + } +}