diff options
author | Björn Schießle <schiessle@owncloud.com> | 2013-07-02 13:54:31 +0200 |
---|---|---|
committer | Björn Schießle <schiessle@owncloud.com> | 2013-07-02 13:54:31 +0200 |
commit | 3fc5b34247cc30809ca525b96e73f1448e5b2e9b (patch) | |
tree | e92a0b479329a3f386452396b595a38cac61e4b4 | |
parent | 38ed00398f4df27967ae771c54a6a8f6bed07dbd (diff) | |
parent | 29dd7eda2de629024548ddef419f1d6991ae07a6 (diff) | |
download | nextcloud-server-3fc5b34247cc30809ca525b96e73f1448e5b2e9b.tar.gz nextcloud-server-3fc5b34247cc30809ca525b96e73f1448e5b2e9b.zip |
Merge branch 'master' into encryption_check_php_version
Conflicts:
apps/files_encryption/files/error.php
-rw-r--r-- | apps/files/ajax/upload.php | 70 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 2 | ||||
-rw-r--r-- | apps/files_encryption/files/error.php | 2 | ||||
-rw-r--r-- | lib/db.php | 190 | ||||
-rwxr-xr-x | lib/request.php | 22 | ||||
-rw-r--r-- | settings/js/apps.js | 11 | ||||
-rw-r--r-- | settings/templates/apps.php | 2 | ||||
-rw-r--r-- | tests/data/db_structure2.xml | 3 | ||||
-rw-r--r-- | tests/lib/dbschema.php | 80 |
9 files changed, 189 insertions, 193 deletions
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 12db682c1e2..8433716dec1 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -8,40 +8,40 @@ OCP\JSON::setContentTypeHeader('text/plain'); // If no token is sent along, rely on login only $l = OC_L10N::get('files'); -if (!$_POST['dirToken']) { - // The standard case, files are uploaded through logged in users :) - OCP\JSON::checkLoggedIn(); - $dir = isset($_POST['dir']) ? $_POST['dir'] : ""; - if (!$dir || empty($dir) || $dir === false) { - OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); - die(); - } +if (empty($_POST['dirToken'])) { + // The standard case, files are uploaded through logged in users :) + OCP\JSON::checkLoggedIn(); + $dir = isset($_POST['dir']) ? $_POST['dir'] : ""; + if (!$dir || empty($dir) || $dir === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); + die(); + } } else { - $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); - - if ($linkItem === false) { - OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Invalid Token'))))); - die(); - } - - if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { - OCP\JSON::checkLoggedIn(); - } else { - - // The token defines the target directory (security reasons) - $dir = sprintf( - "/%s/%s", - $linkItem['file_target'], - isset($_POST['subdir']) ? $_POST['subdir'] : '' - ); - - if (!$dir || empty($dir) || $dir === false) { - OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); - die(); - } - // Setup FS with owner - OC_Util::setupFS($linkItem['uid_owner']); - } + $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); + + if ($linkItem === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Invalid Token'))))); + die(); + } + + if (!($linkItem['permissions'] & OCP\PERMISSION_CREATE)) { + OCP\JSON::checkLoggedIn(); + } else { + + // The token defines the target directory (security reasons) + $dir = sprintf( + "/%s/%s", + $linkItem['file_target'], + isset($_POST['subdir']) ? $_POST['subdir'] : '' + ); + + if (!$dir || empty($dir) || $dir === false) { + OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Unable to set upload directory.'))))); + die(); + } + // Setup FS with owner + OC_Util::setupFS($linkItem['uid_owner']); + } } @@ -61,7 +61,7 @@ foreach ($_FILES['files']['error'] as $error) { $errors = array( UPLOAD_ERR_OK => $l->t('There is no error, the file uploaded with success'), UPLOAD_ERR_INI_SIZE => $l->t('The uploaded file exceeds the upload_max_filesize directive in php.ini: ') - . ini_get('upload_max_filesize'), + . ini_get('upload_max_filesize'), UPLOAD_ERR_FORM_SIZE => $l->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), UPLOAD_ERR_PARTIAL => $l->t('The uploaded file was only partially uploaded'), UPLOAD_ERR_NO_FILE => $l->t('No file was uploaded'), @@ -107,7 +107,7 @@ if (strpos($dir, '..') === false) { 'size' => $meta['size'], 'id' => $meta['fileid'], 'name' => basename($target), - 'originalname'=>$files['name'][$i], + 'originalname' => $files['name'][$i], 'uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize ); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index c15fc21abf4..cf3ce2e5089 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -467,7 +467,7 @@ $(document).ready(function(){ } var date=new Date(); var param = {}; - if ($('#publicUploadRequestToken')) { + if ($('#publicUploadRequestToken').length) { param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + uniqueName; } // create new file context diff --git a/apps/files_encryption/files/error.php b/apps/files_encryption/files/error.php index 85128fa4aea..f93c67d920a 100644 --- a/apps/files_encryption/files/error.php +++ b/apps/files_encryption/files/error.php @@ -4,7 +4,7 @@ if (!isset($_)) { //also provide standalone error page $l = OC_L10N::get('files_encryption'); - $errorMsg = $l->t('Your private key is not valid! Maybe your password was changed from outside. You can update your private key password in your personal settings to regain access to your files.'); + $errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.'); if(isset($_GET['p']) && $_GET['p'] === '1') { header('HTTP/1.0 404 ' . $errorMsg); diff --git a/lib/db.php b/lib/db.php index 4d6788f2bda..a93b9eccbdf 100644 --- a/lib/db.php +++ b/lib/db.php @@ -180,28 +180,18 @@ class OC_DB { $dsn = 'oci:dbname=//' . $host . '/' . $name; } break; - case 'mssql': + case 'mssql': if ($port) { $dsn='sqlsrv:Server='.$host.','.$port.';Database='.$name; } else { $dsn='sqlsrv:Server='.$host.';Database='.$name; } - break; + break; default: return false; } - try{ - self::$PDO=new PDO($dsn, $user, $pass, $opts); - }catch(PDOException $e) { - OC_Log::write('core', $e->getMessage(), OC_Log::FATAL); - OC_User::setUserId(null); - - // send http status 503 - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); - OC_Template::printErrorPage('Failed to connect to database'); - die(); - } + self::$PDO=new PDO($dsn, $user, $pass, $opts); + // We always, really always want associative arrays self::$PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -299,19 +289,8 @@ class OC_DB { // Try to establish connection self::$MDB2 = MDB2::factory( $dsn, $options ); - - // Die if we could not connect - if( PEAR::isError( self::$MDB2 )) { - OC_Log::write('core', self::$MDB2->getUserInfo(), OC_Log::FATAL); - OC_Log::write('core', self::$MDB2->getMessage(), OC_Log::FATAL); - OC_User::setUserId(null); - - // send http status 503 - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); - OC_Template::printErrorPage('Failed to connect to database'); - die(); - } + + self::raiseExceptionOnError( self::$MDB2 ); // We always, really always want associative arrays self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC); @@ -803,9 +782,9 @@ class OC_DB { $query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query ); $query = str_replace( 'LENGTH(', 'LEN(', $query ); $query = str_replace( 'SUBSTR(', 'SUBSTRING(', $query ); - - $query = self::fixLimitClauseForMSSQL($query); - } + + $query = self::fixLimitClauseForMSSQL($query); + } // replace table name prefix $query = str_replace( '*PREFIX*', $prefix, $query ); @@ -813,60 +792,60 @@ class OC_DB { return $query; } - private static function fixLimitClauseForMSSQL($query) { - $limitLocation = stripos ($query, "LIMIT"); - - if ( $limitLocation === false ) { - return $query; - } - - // total == 0 means all results - not zero results - // - // First number is either total or offset, locate it by first space - // - $offset = substr ($query, $limitLocation + 5); - $offset = substr ($offset, 0, stripos ($offset, ' ')); - $offset = trim ($offset); - - // check for another parameter - if (stripos ($offset, ',') === false) { - // no more parameters - $offset = 0; - $total = intval ($offset); - } else { - // found another parameter - $offset = intval ($offset); - - $total = substr ($query, $limitLocation + 5); - $total = substr ($total, stripos ($total, ',')); - - $total = substr ($total, 0, stripos ($total, ' ')); - $total = intval ($total); - } - - $query = trim (substr ($query, 0, $limitLocation)); - - if ($offset == 0 && $total !== 0) { - if (strpos($query, "SELECT") === false) { - $query = "TOP {$total} " . $query; - } else { - $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query); - } - } else if ($offset > 0) { - $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query); - $query = 'SELECT * - FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3 - FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3'; - - if ($total > 0) { - $query .= ' WHERE line3 BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $total); - } else { - $query .= ' WHERE line3 > ' . $offset; - } - } - return $query; - } - + private static function fixLimitClauseForMSSQL($query) { + $limitLocation = stripos ($query, "LIMIT"); + + if ( $limitLocation === false ) { + return $query; + } + + // total == 0 means all results - not zero results + // + // First number is either total or offset, locate it by first space + // + $offset = substr ($query, $limitLocation + 5); + $offset = substr ($offset, 0, stripos ($offset, ' ')); + $offset = trim ($offset); + + // check for another parameter + if (stripos ($offset, ',') === false) { + // no more parameters + $offset = 0; + $total = intval ($offset); + } else { + // found another parameter + $offset = intval ($offset); + + $total = substr ($query, $limitLocation + 5); + $total = substr ($total, stripos ($total, ',')); + + $total = substr ($total, 0, stripos ($total, ' ')); + $total = intval ($total); + } + + $query = trim (substr ($query, 0, $limitLocation)); + + if ($offset == 0 && $total !== 0) { + if (strpos($query, "SELECT") === false) { + $query = "TOP {$total} " . $query; + } else { + $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query); + } + } else if ($offset > 0) { + $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query); + $query = 'SELECT * + FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3 + FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3'; + + if ($total > 0) { + $query .= ' WHERE line3 BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $total); + } else { + $query .= ' WHERE line3 > ' . $offset; + } + } + return $query; + } + /** * @brief drop a table * @param string $tableName the table to drop @@ -962,18 +941,21 @@ class OC_DB { * @return bool */ public static function isError($result) { - if(self::$backend==self::BACKEND_PDO and $result === false) { + //MDB2 returns an MDB2_Error object + if (class_exists('PEAR') === true && PEAR::isError($result)) { return true; - }elseif(self::$backend==self::BACKEND_MDB2 and PEAR::isError($result)) { + } + //PDO returns false on error (and throws an exception) + if (self::$backend===self::BACKEND_PDO and $result === false) { return true; - }else{ - return false; } + + return false; } /** * check if a result is an error and throws an exception, works with MDB2 and PDOException * @param mixed $result - * @param string message + * @param string $message * @return void * @throws DatabaseException */ @@ -989,12 +971,15 @@ class OC_DB { } public static function getErrorCode($error) { - if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) { - $code = $error->getCode(); - } elseif ( self::$backend==self::BACKEND_PDO and self::$PDO ) { - $code = self::$PDO->errorCode(); + if ( class_exists('PEAR') === true && PEAR::isError($error) ) { + /** @var $error PEAR_Error */ + return $error->getCode(); + } + if ( self::$backend==self::BACKEND_PDO and self::$PDO ) { + return self::$PDO->errorCode(); } - return $code; + + return -1; } /** * returns the error code and message as a string for logging @@ -1003,23 +988,24 @@ class OC_DB { * @return string */ public static function getErrorMessage($error) { - if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) { + if ( class_exists('PEAR') === true && PEAR::isError($error) ) { $msg = $error->getCode() . ': ' . $error->getMessage(); $msg .= ' (' . $error->getDebugInfo() . ')'; - } elseif (self::$backend==self::BACKEND_PDO and self::$PDO) { + + return $msg; + } + if (self::$backend==self::BACKEND_PDO and self::$PDO) { $msg = self::$PDO->errorCode() . ': '; $errorInfo = self::$PDO->errorInfo(); if (is_array($errorInfo)) { $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; $msg .= 'Driver Code = '.$errorInfo[1] . ', '; $msg .= 'Driver Message = '.$errorInfo[2]; - }else{ - $msg = ''; } - }else{ - $msg = ''; + return $msg; } - return $msg; + + return ''; } /** @@ -1172,7 +1158,7 @@ class PDOStatementWrapper{ die ($entry); } } - + /** * provide numRows */ diff --git a/lib/request.php b/lib/request.php index 4d8380eb9ac..df33217f95d 100755 --- a/lib/request.php +++ b/lib/request.php @@ -9,7 +9,7 @@ class OC_Request { /** * @brief Check overwrite condition - * @returns true/false + * @returns bool */ private static function isOverwriteCondition($type = '') { $regex = '/' . OC_Config::getValue('overwritecondaddr', '') . '/'; @@ -19,7 +19,7 @@ class OC_Request { /** * @brief Returns the server host - * @returns the server host + * @returns string the server host * * Returns the server host, even if the website uses one or more * reverse proxies @@ -40,7 +40,13 @@ class OC_Request { } } else{ - $host = $_SERVER['HTTP_HOST']; + if (isset($_SERVER['HTTP_HOST'])) { + return $_SERVER['HTTP_HOST']; + } + if (isset($_SERVER['SERVER_NAME'])) { + return $_SERVER['SERVER_NAME']; + } + return 'localhost'; } return $host; } @@ -48,7 +54,7 @@ class OC_Request { /** * @brief Returns the server protocol - * @returns the server protocol + * @returns string the server protocol * * Returns the server protocol. It respects reverse proxy servers and load balancers */ @@ -70,7 +76,7 @@ class OC_Request { /** * @brief Returns the request uri - * @returns the request uri + * @returns string the request uri * * Returns the request uri, even if the website uses one or more * reverse proxies @@ -85,7 +91,7 @@ class OC_Request { /** * @brief Returns the script name - * @returns the script name + * @returns string the script name * * Returns the script name, even if the website uses one or more * reverse proxies @@ -139,7 +145,7 @@ class OC_Request { /** * @brief Check if this is a no-cache request - * @returns true for no-cache + * @returns boolean true for no-cache */ static public function isNoCache() { if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) { @@ -150,7 +156,7 @@ class OC_Request { /** * @brief Check if the requestor understands gzip - * @returns true for gzip encoding supported + * @returns boolean true for gzip encoding supported */ static public function acceptGZip() { if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { diff --git a/settings/js/apps.js b/settings/js/apps.js index 9c1604cfcd9..1ee3372f893 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -20,6 +20,11 @@ OC.Settings.Apps = OC.Settings.Apps || { page.find('span.score').html(app.score); page.find('p.description').text(app.description); page.find('img.preview').attr('src', app.preview); + if (app.preview && app.preview.length) { + page.find('img.preview').show(); + } else { + page.find('img.preview').hide(); + } page.find('small.externalapp').attr('style', 'visibility:visible'); page.find('span.author').text(app.author); page.find('span.licence').text(app.licence); @@ -142,12 +147,16 @@ OC.Settings.Apps = OC.Settings.Apps || { li.attr('data-id', entry.id); var img= $('<img class="icon"/>').attr({ src: entry.icon}); var a=$('<a></a>').attr('href', entry.href); - var filename=$('<span></span>') + var filename=$('<span></span>'); filename.text(entry.name); a.prepend(filename); a.prepend(img); li.append(a); container.append(li); + if (!SVGSupport() && entry.icon.match(/\.svg$/i)) { + $(img).addClass('svg'); + replaceSVG(); + } } } } diff --git a/settings/templates/apps.php b/settings/templates/apps.php index 0903b9bd5c4..d60fd82f917 100644 --- a/settings/templates/apps.php +++ b/settings/templates/apps.php @@ -34,7 +34,7 @@ class="version"></span><small class="externalapp" style="visibility:hidden;"></small></h3> <span class="score"></span> <p class="description"></p> - <img src="" class="preview" /> + <img src="" class="preview hidden" /> <p class="appslink hidden"><a href="#" target="_blank"><?php p($l->t('See application page at apps.owncloud.com'));?></a></p> <p class="license hidden"><?php diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index fc6fe0bba7d..6f12f81f477 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -49,8 +49,9 @@ <field> <name>description</name> - <type>clob</type> + <type>text</type> <notnull>false</notnull> + <length>1024</length> </field> <field> diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 59f203993ef..c2e55eabf4b 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -7,9 +7,8 @@ */ class Test_DBSchema extends PHPUnit_Framework_TestCase { - protected static $schema_file = 'static://test_db_scheme'; - protected static $schema_file2 = 'static://test_db_scheme2'; - protected $test_prefix; + protected $schema_file = 'static://test_db_scheme'; + protected $schema_file2 = 'static://test_db_scheme2'; protected $table1; protected $table2; @@ -20,19 +19,20 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { $r = '_'.OC_Util::generate_random_bytes('4').'_'; $content = file_get_contents( $dbfile ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); - file_put_contents( self::$schema_file, $content ); + file_put_contents( $this->schema_file, $content ); $content = file_get_contents( $dbfile2 ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); - file_put_contents( self::$schema_file2, $content ); + file_put_contents( $this->schema_file2, $content ); - $this->test_prefix = $r; - $this->table1 = $this->test_prefix.'cntcts_addrsbks'; - $this->table2 = $this->test_prefix.'cntcts_cards'; + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + + $this->table1 = $prefix.$r.'cntcts_addrsbks'; + $this->table2 = $prefix.$r.'cntcts_cards'; } public function tearDown() { - unlink(self::$schema_file); - unlink(self::$schema_file2); + unlink($this->schema_file); + unlink($this->schema_file2); } // everything in one test, they depend on each other @@ -47,13 +47,13 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaCreating() { - OC_DB::createDbFromStructure(self::$schema_file); + OC_DB::createDbFromStructure($this->schema_file); $this->assertTableExist($this->table1); $this->assertTableExist($this->table2); } public function doTestSchemaChanging() { - OC_DB::updateDbFromStructure(self::$schema_file2); + OC_DB::updateDbFromStructure($this->schema_file2); $this->assertTableExist($this->table2); } @@ -66,67 +66,61 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaRemoving() { - OC_DB::removeDBStructure(self::$schema_file); + OC_DB::removeDBStructure($this->schema_file); $this->assertTableNotExist($this->table1); $this->assertTableNotExist($this->table2); } public function tableExist($table) { - $table = '*PREFIX*' . $table; switch (OC_Config::getValue( 'dbtype', 'sqlite' )) { case 'sqlite': case 'sqlite3': $sql = "SELECT name FROM sqlite_master " - . "WHERE type = 'table' AND name != 'sqlite_sequence' " - . "AND name != 'geometry_columns' AND name != 'spatial_ref_sys' " - . "UNION ALL SELECT name FROM sqlite_temp_master " - . "WHERE type = 'table' AND name = '".$table."'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + . "WHERE type = 'table' AND name = ? " + . "UNION ALL SELECT name FROM sqlite_temp_master " + . "WHERE type = 'table' AND name = ?"; + $result = \OC_DB::executeAudited($sql, array($table, $table)); break; case 'mysql': - $sql = 'SHOW TABLES LIKE "'.$table.'"'; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SHOW TABLES LIKE ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; case 'pgsql': - $sql = "SELECT tablename AS table_name, schemaname AS schema_name " - . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " - . "AND schemaname != 'information_schema' " - . "AND tablename = '".$table."'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SELECT tablename AS table_name, schemaname AS schema_name ' + . 'FROM pg_tables WHERE schemaname NOT LIKE \'pg_%\' ' + . 'AND schemaname != \'information_schema\' ' + . 'AND tablename = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; case 'oci': - $sql = 'SELECT table_name FROM user_tables WHERE table_name = ?'; + $sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?'; $result = \OC_DB::executeAudited($sql, array($table)); - $exists = (bool)$result->fetchOne(); //oracle uses MDB2 and returns null break; case 'mssql': - $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; } - return $exists; + + $name = $result->fetchOne(); //FIXME checking with '$result->numRows() === 1' does not seem to work? + if ($name === $table) { + return true; + } else { + return false; + } } public function assertTableExist($table) { - $this->assertTrue($this->tableExist($table)); + $this->assertTrue($this->tableExist($table), 'Table ' . $table . ' does not exist'); } public function assertTableNotExist($table) { $type=OC_Config::getValue( "dbtype", "sqlite" ); if( $type == 'sqlite' || $type == 'sqlite3' ) { // sqlite removes the tables after closing the DB - } - else { - $this->assertFalse($this->tableExist($table)); + } else { + $this->assertFalse($this->tableExist($table), 'Table ' . $table . ' exists.'); } } } |