diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-09-16 23:56:20 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-09-16 23:56:20 +0200 |
commit | 45b17207ccf03703d4d6c3925f5405f52579aee5 (patch) | |
tree | 7c773be19b88dfebcbde8f29b773bb46df1a44e8 | |
parent | 21afcb3e94b65164d4ec75f2d0e9ed76305687bb (diff) | |
parent | 7e2bff8545c7cbf0b63eb2b2ef2cae7dd625a245 (diff) | |
download | nextcloud-server-45b17207ccf03703d4d6c3925f5405f52579aee5.tar.gz nextcloud-server-45b17207ccf03703d4d6c3925f5405f52579aee5.zip |
Merge pull request #10745 from owncloud/fix-10708-doctrine
Use Doctrine Platform to generate SQL query for table truncation.
-rw-r--r-- | apps/user_ldap/lib/helper.php | 13 | ||||
-rw-r--r-- | apps/user_ldap/tests/helper.php | 31 |
2 files changed, 35 insertions, 9 deletions
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php index b6d7bad8727..ecda49f73fc 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 00000000000..07c24d64499 --- /dev/null +++ b/apps/user_ldap/tests/helper.php @@ -0,0 +1,31 @@ +<?php +/** +* ownCloud +* +* @author Thomas Müller +* @copyright 2014 Thomas Müller deepdiver@owncloud.com +* +*/ + +namespace OCA\user_ldap\tests; + +use OCA\user_ldap\lib\Helper; + +class Test_Helper extends \PHPUnit_Framework_TestCase { + + public function testTableTruncate() { + + $statement = \OCP\DB::prepare('INSERT INTO `*PREFIX*ldap_user_mapping` (`ldap_dn`, `owncloud_name`, `directory_uuid`) VALUES (?, ?, ?)'); + $statement->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()); + } +} |