/** * get the size of a folder and set it in the cache * * @param string $path * @return int */ public function calculateFolderSize($path) { if ($path !== '/' and $path !== '' and $path !== 'files') { return parent::calculateFolderSize($path); } $totalSize = 0; $entry = $this->get($path); if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { $id = $entry['fileid']; $sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0'; $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); if ($row = $result->fetchRow()) { list($sum, $unencryptedSum) = array_values($row); $totalSize = (int) $sum; $unencryptedSize = (int) $unencryptedSum; if ($entry['size'] !== $totalSize) { $this->update($id, array('size' => $totalSize)); } if ($entry['unencrypted_size'] !== $unencryptedSize) { $this->update($id, array('unencrypted_size' => $unencryptedSize)); } } } return $totalSize; }
/** * get the size of a folder and set it in the cache * * @param string $path * @param array $entry (optional) meta data of the folder * @return int */ public function calculateFolderSize($path, $entry = null) { if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') { return parent::calculateFolderSize($path, $entry); } elseif ($path === '' or $path === '/') { // since the size of / isn't used (the size of /files is used instead) there is no use in calculating it return 0; } $totalSize = 0; if (is_null($entry)) { $entry = $this->get($path); } if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { $id = $entry['fileid']; $sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0'; $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); if ($row = $result->fetchRow()) { list($sum, $unencryptedSum) = array_values($row); $totalSize = 0 + $sum; $unencryptedSize = 0 + $unencryptedSum; $entry['size'] += 0; $entry['unencrypted_size'] += 0; if ($entry['size'] !== $totalSize) { $this->update($id, array('size' => $totalSize)); } if ($entry['unencrypted_size'] !== $unencryptedSize) { $this->update($id, array('unencrypted_size' => $unencryptedSize)); } } } return $totalSize; }
/** * Returns the id of a given mime type or null * if it does not exist. */ private function getMimeTypeIdFromDB($mimeType) { $sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?'; $results = \OC_DB::executeAudited($sql, [$mimeType]); $result = $results->fetchOne(); if ($result) { return $result['id']; } return null; }
/** * @brief remove all shares for a given file if the file was deleted * * @param string $path */ private static function removeShare($path) { $fileSource = self::$toRemove[$path]; if (!\OC\Files\Filesystem::file_exists($path)) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source`=?'); try { \OC_DB::executeAudited($query, array($fileSource)); } catch (\Exception $e) { \OCP\Util::writeLog('files_sharing', "can't remove share: " . $e->getMessage(), \OCP\Util::WARN); } } unset(self::$toRemove[$path]); }
public static function exists($storageId) { if (strlen($storageId) > 64) { $storageId = md5($storageId); } $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?'; $result = \OC_DB::executeAudited($sql, array($storageId)); if ($row = $result->fetchRow()) { return true; } else { return false; } }
/** * get the next fileid in the cache * * @param int $previous * @param bool $folder * @return int */ private static function getNextFileId($previous, $folder) { if ($folder) { $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` = ? ORDER BY `fileid` ASC', 1); } else { $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` != ? ORDER BY `fileid` ASC', 1); } $result = \OC_DB::executeAudited($stmt, array($previous, self::getFolderMimetype())); if ($row = $result->fetchRow()) { return $row['fileid']; } else { return 0; } }
/** * Check if the password is correct without logging in the user * * @param string $uid The username * @param string $password The password * * @return true/false */ public function checkPassword($uid, $password) { $user = OC_DB::executeAudited( 'SELECT * FROM `*PREFIX*users`' . ' WHERE `uid` = ?', array($uid) )->fetchRow(); OCP\Util::writeLog('user_external', 'LOG: $user is now:'.print_r($user)); $Hasher = new PasswordHash(8, false); $hashed_password = $Hasher->HashPassword($password); if($hashed_password === $user['password']){ $uid=mb_strtolower($uid); $this->storeUser($uid); return $uid; }else{ return false; } /* if (!function_exists('imap_open')) { OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR); return false; } $mbox = @imap_open($this->mailbox, $uid, $password, OP_HALFOPEN, 1); imap_errors(); imap_alerts(); if($mbox !== FALSE) { imap_close($mbox); $uid = mb_strtolower($uid); $this->storeUser($uid); return $uid; }else{ return false; }*/ }
/** * remove the entry for the storage * * @param string $storageId */ public static function remove($storageId) { $storageCache = new Storage($storageId); $numericId = $storageCache->getNumericId(); if (strlen($storageId) > 64) { $storageId = md5($storageId); } $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; \OC_DB::executeAudited($sql, array($storageId)); $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; \OC_DB::executeAudited($sql, array($numericId)); }
/** * Get the item of item type shared with a given user by source * @param string $itemType * @param string $itemSource * @param string $user User to whom the item was shared * @param string $owner Owner of the share * @param int $shareType only look for a specific share type * @return array Return list of items with file_target, permissions and expiration */ public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null, $shareType = null) { $shares = array(); $fileDependent = false; $where = 'WHERE'; $fileDependentWhere = ''; if ($itemType === 'file' || $itemType === 'folder') { $fileDependent = true; $column = 'file_source'; $fileDependentWhere = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` '; $fileDependentWhere .= 'INNER JOIN `*PREFIX*storages` ON `numeric_id` = `*PREFIX*filecache`.`storage` '; } else { $column = 'item_source'; } $select = self::createSelectStatement(self::FORMAT_NONE, $fileDependent); $where .= ' `' . $column . '` = ? AND `item_type` = ? '; $arguments = array($itemSource, $itemType); // for link shares $user === null if ($user !== null) { $where .= ' AND `share_with` = ? '; $arguments[] = $user; } if ($shareType !== null) { $where .= ' AND `share_type` = ? '; $arguments[] = $shareType; } if ($owner !== null) { $where .= ' AND `uid_owner` = ? '; $arguments[] = $owner; } $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` ' . $fileDependentWhere . $where); $result = \OC_DB::executeAudited($query, $arguments); while ($row = $result->fetchRow()) { if ($fileDependent && !self::isFileReachable($row['path'], $row['storage_id'])) { continue; } if ($fileDependent && (int) $row['file_parent'] === -1) { // if it is a mount point we need to get the path from the mount manager $mountManager = \OC\Files\Filesystem::getMountManager(); $mountPoint = $mountManager->findByStorageId($row['storage_id']); if (!empty($mountPoint)) { $path = $mountPoint[0]->getMountPoint(); $path = trim($path, '/'); $path = substr($path, strlen($owner) + 1); //normalize path to 'files/foo.txt` $row['path'] = $path; } else { \OC::$server->getLogger()->warning('Could not resolve mount point for ' . $row['storage_id'], ['app' => 'OCP\\Share']); } } $shares[] = $row; } //if didn't found a result than let's look for a group share. if (empty($shares) && $user !== null) { $groups = \OC_Group::getUserGroups($user); if (!empty($groups)) { $where = $fileDependentWhere . ' WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'; $arguments = array($itemSource, $itemType, $groups); $types = array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY); if ($owner !== null) { $where .= ' AND `uid_owner` = ?'; $arguments[] = $owner; $types[] = null; } // TODO: inject connection, hopefully one day in the future when this // class isn't static anymore... $conn = \OC_DB::getConnection(); $result = $conn->executeQuery('SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where, $arguments, $types); while ($row = $result->fetch()) { $shares[] = $row; } } } return $shares; }
/** * Get the item of item type shared with a given user by source * @param string $itemType * @param string $itemSource * @param string $user User user to whom the item was shared * @param int $shareType only look for a specific share type * @return array Return list of items with file_target, permissions and expiration */ public static function getItemSharedWithUser($itemType, $itemSource, $user, $shareType = null) { $shares = array(); $fileDependend = false; if ($itemType === 'file' || $itemType === 'folder') { $fileDependend = true; $column = 'file_source'; $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE'; } else { $column = 'item_source'; $where = 'WHERE'; } $select = self::createSelectStatement(self::FORMAT_NONE, $fileDependend); $where .= ' `' . $column . '` = ? AND `item_type` = ? '; $arguments = array($itemSource, $itemType); // for link shares $user === null if ($user !== null) { $where .= ' AND `share_with` = ? '; $arguments[] = $user; } if ($shareType !== null) { $where .= ' AND `share_type` = ? '; $arguments[] = $shareType; } $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where); $result = \OC_DB::executeAudited($query, $arguments); while ($row = $result->fetchRow()) { $shares[] = $row; } //if didn't found a result than let's look for a group share. if (empty($shares) && $user !== null) { $groups = \OC_Group::getUserGroups($user); $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'); $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups))); while ($row = $result->fetchRow()) { $shares[] = $row; } } return $shares; }
public function testLastInsertId() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1')); $id1 = OC_DB::insertid('*PREFIX*'.$this->table2); // we don't know the id we should expect, so insert another row $result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2')); $id2 = OC_DB::insertid('*PREFIX*'.$this->table2); // now we can check if the two ids are in correct order $this->assertGreaterThan($id1, $id2); }
/** * remove the entry for the storage * * @param string $storageId */ public static function remove($storageId) { $storageId = self::adjustStorageId($storageId); $numericId = self::getNumericStorageId($storageId); $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; \OC_DB::executeAudited($sql, array($storageId)); if (!is_null($numericId)) { $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; \OC_DB::executeAudited($sql, array($numericId)); } }
/** * get all child items of an item from the legacy cache * * @param int $id * @return array */ function getChildren($id) { $result = \OC_DB::executeAudited('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?', array($id)); $data = $result->fetchAll(); foreach ($data as $i => $item) { $data[$i]['etag'] = $this->getEtag($item['path'], $item['user']); } return $data; }
private function fixOfficeMimeTypes() { // update wrong mimetypes $wrongMimetypes = array('application/mspowerpoint' => 'application/vnd.ms-powerpoint', 'application/msexcel' => 'application/vnd.ms-excel'); $existsStmt = \OC_DB::prepare(' SELECT count(`mimetype`) FROM `*PREFIX*mimetypes` WHERE `mimetype` = ? '); $getIdStmt = \OC_DB::prepare(' SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ? '); $insertStmt = \OC_DB::prepare(' INSERT INTO `*PREFIX*mimetypes` ( `mimetype` ) VALUES ( ? ) '); $updateWrongStmt = \OC_DB::prepare(' UPDATE `*PREFIX*filecache` SET `mimetype` = ( SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ? ) WHERE `mimetype` = ? '); $deleteStmt = \OC_DB::prepare(' DELETE FROM `*PREFIX*mimetypes` WHERE `id` = ? '); foreach ($wrongMimetypes as $wrong => $correct) { // do we need to remove a wrong mimetype? $result = \OC_DB::executeAudited($getIdStmt, array($wrong)); $wrongId = $result->fetchOne(); if ($wrongId !== false) { // do we need to insert the correct mimetype? $result = \OC_DB::executeAudited($existsStmt, array($correct)); $exists = $result->fetchOne(); if (!$exists) { // insert mimetype \OC_DB::executeAudited($insertStmt, array($correct)); } // change wrong mimetype to correct mimetype in filecache \OC_DB::executeAudited($updateWrongStmt, array($correct, $wrongId)); // delete wrong mimetype \OC_DB::executeAudited($deleteStmt, array($wrongId)); } } $updatedMimetypes = array('docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'); $updateByNameStmt = \OC_DB::prepare(' UPDATE `*PREFIX*filecache` SET `mimetype` = ( SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ? ) WHERE `name` LIKE ? '); // separate doc from docx etc foreach ($updatedMimetypes as $extension => $mimetype) { $result = \OC_DB::executeAudited($existsStmt, array($mimetype)); $exists = $result->fetchOne(); if (!$exists) { // insert mimetype \OC_DB::executeAudited($insertStmt, array($mimetype)); } // change mimetype for files with x extension \OC_DB::executeAudited($updateByNameStmt, array($mimetype, '%.' . $extension)); } }
/** * @return array */ public function all() { $sql = 'SELECT * from `*PREFIX*hub_notifications` ORDER BY `timestamp` DESC'; $result = \OC_DB::executeAudited($sql); return $result->fetchAll(); }
/** * check if an item is already in the new cache * * @param string $storage * @param string $pathHash * @param string $id * @return bool */ function inCache($storage, $pathHash, $id) { static $query = null; if (is_null($query)) { $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?'); } $result = \OC_DB::executeAudited($query, array($storage, $pathHash, $id)); return (bool) $result->fetchRow(); }
<?php $installedVersion = OCP\Config::getAppValue('files_trashbin', 'installed_version'); if (version_compare($installedVersion, '0.5', '<=')) { $connection = OC_DB::getConnection(); $platform = $connection->getDatabasePlatform(); if ($platform->getName() === 'oracle') { try { $connection->beginTransaction(); $sql1 = 'ALTER TABLE `*PREFIX*files_trash` ADD `auto_id` NUMBER(10) DEFAULT NULL'; \OC_DB::executeAudited($sql1, array()); $sql2 = 'CREATE SEQUENCE `*PREFIX*files_trash_seq` start with 1 increment by 1 nomaxvalue'; \OC_DB::executeAudited($sql2, array()); $sql3 = 'UPDATE `*PREFIX*files_trash` SET `auto_id` = `*PREFIX*files_trash_seq`.nextval'; \OC_DB::executeAudited($sql3, array()); $connection->commit(); } catch (\DatabaseException $e) { \OCP\Util::writeLog('files_trashbin', "Oracle upgrade fixup failed: " . $e->getMessage(), \OCP\Util::WARN); } } }
public function testRepairParentShallow() { $this->fillTestFolders(); $this->scanner->scan(''); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the childs $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; \OC_DB::executeAudited($sql, array($oldFolderId)); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertEquals($oldFolderId, $cachedData['parent']); $this->assertFalse($this->cache->inCache('folder')); $this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertTrue($this->cache->inCache('folder')); $newFolderId = $this->cache->getId('folder'); $this->assertNotEquals($oldFolderId, $newFolderId); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertEquals($newFolderId, $cachedData['parent']); }
private function updateMimetypes($updatedMimetypes) { if (empty($this->folderMimeTypeId)) { $result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory')); $this->folderMimeTypeId = (int) $result->fetchOne(); } foreach ($updatedMimetypes as $extension => $mimetype) { $result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype)); $exists = $result->fetchOne(); if (!$exists) { // insert mimetype \OC_DB::executeAudited(self::insertStmt(), array($mimetype)); } // get target mimetype id $result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype)); $mimetypeId = $result->fetchOne(); // change mimetype for files with x extension \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension)); } }
/** * Get the item of item type shared with a given user by source * @param string $itemType * @param string $itemSource * @param string $user User user to whom the item was shared * @return array Return list of items with file_target, permissions and expiration */ public static function getItemSharedWithUser($itemType, $itemSource, $user) { $shares = array(); // first check if there is a db entry for the specific user $query = \OC_DB::prepare('SELECT `file_target`, `permissions`, `expiration` FROM `*PREFIX*share` WHERE `item_source` = ? AND `item_type` = ? AND `share_with` = ?'); $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user)); while ($row = $result->fetchRow()) { $shares[] = $row; } //if didn't found a result than let's look for a group share. if (empty($shares)) { $groups = \OC_Group::getUserGroups($user); $query = \OC_DB::prepare('SELECT `file_target`, `permissions`, `expiration` FROM `*PREFIX*share` WHERE `item_source` = ? AND `item_type` = ? AND `share_with` in (?)'); $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups))); while ($row = $result->fetchRow()) { $shares[] = $row; } } return $shares; }
/** * get the storage id of the storage for a file and the internal path of the file * * @param int $id * @return array, first element holding the storage id, second the path */ public static function getById($id) { $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; $result = \OC_DB::executeAudited($sql, array($id)); if ($row = $result->fetchRow()) { $numericId = $row['storage']; $path = $row['path']; } else { return null; } if ($id = Storage::getStorageId($numericId)) { return array($id, $path); } else { return null; } }
/** * Get the item of item type shared with a given user by source * @param string $itemType * @param string $itemSource * @param string $user User to whom the item was shared * @param int $shareType only look for a specific share type * @return array Return list of items with file_target, permissions and expiration */ public static function getItemSharedWithUser($itemType, $itemSource, $user, $shareType = null) { $shares = array(); $fileDependend = false; if ($itemType === 'file' || $itemType === 'folder') { $fileDependend = true; $column = 'file_source'; $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE'; } else { $column = 'item_source'; $where = 'WHERE'; } $select = self::createSelectStatement(self::FORMAT_NONE, $fileDependend); $where .= ' `' . $column . '` = ? AND `item_type` = ? '; $arguments = array($itemSource, $itemType); // for link shares $user === null if ($user !== null) { $where .= ' AND `share_with` = ? '; $arguments[] = $user; } if ($shareType !== null) { $where .= ' AND `share_type` = ? '; $arguments[] = $shareType; } $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where); $result = \OC_DB::executeAudited($query, $arguments); while ($row = $result->fetchRow()) { $shares[] = $row; } //if didn't found a result than let's look for a group share. if (empty($shares) && $user !== null) { $groups = \OC_Group::getUserGroups($user); if (!empty($groups)) { $where = 'WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'; $arguments = array($itemSource, $itemType, $groups); $types = array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY); // TODO: inject connection, hopefully one day in the future when this // class isn't static anymore... $conn = \OC_DB::getConnection(); $result = $conn->executeQuery('SELECT * FROM `*PREFIX*share` ' . $where, $arguments, $types); while ($row = $result->fetch()) { $shares[] = $row; } } } return $shares; }
public function testDuplicateDataMigration() { // create test table OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml'); // in case of duplicate entries we want to preserve 0 on migration status and 1 on recovery $data = array(array('user1', 'server-side', 1, 1), array('user1', 'server-side', 1, 0), array('user1', 'server-side', 0, 1), array('user1', 'server-side', 0, 0)); foreach ($data as $d) { OC_DB::executeAudited('INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)', $d); } // preform migration $migration = new Migration('encryption_test'); $migration->dropTableEncryption(); // assert $this->assertTableNotExist('encryption_test'); $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled'); $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status'); $this->assertEquals(1, $rec); $this->assertEquals(0, $mig); }
private function updateMimetypes($updatedMimetypes) { foreach ($updatedMimetypes as $extension => $mimetype) { $result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype)); $exists = $result->fetchOne(); if (!$exists) { // insert mimetype \OC_DB::executeAudited(self::insertStmt(), array($mimetype)); } // get target mimetype id $result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype)); $mimetypeId = $result->fetchOne(); // change mimetype for files with x extension \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $mimetypeId, '%.' . $extension)); } }
/** * Check the database version * * @return array errors array */ public static function checkDatabaseVersion() { $l = \OC::$server->getL10N('lib'); $errors = array(); $dbType = \OC_Config::getValue('dbtype', 'sqlite'); if ($dbType === 'pgsql') { // check PostgreSQL version try { $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); $data = $result->fetchRow(); if (isset($data['server_version'])) { $version = $data['server_version']; if (version_compare($version, '9.0.0', '<')) { $errors[] = array('error' => $l->t('PostgreSQL >= 9 required'), 'hint' => $l->t('Please upgrade your database version')); } } } catch (\Doctrine\DBAL\DBALException $e) { \OCP\Util::logException('core', $e); $errors[] = array('error' => $l->t('Error occurred while checking PostgreSQL version'), 'hint' => $l->t('Please make sure you have PostgreSQL >= 9 or' . ' check the logs for more information about the error')); } } return $errors; }
/** * Check the database version * * @return array errors array */ public static function checkDatabaseVersion() { $l = \OC::$server->getL10N('lib'); $errors = array(); $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); if ($dbType === 'pgsql') { // check PostgreSQL version try { $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); $data = $result->fetchRow(); if (isset($data['server_version'])) { $version = $data['server_version']; if (version_compare($version, '9.0.0', '<')) { $errors[] = array('error' => $l->t('PostgreSQL >= 9 required'), 'hint' => $l->t('Please upgrade your database version')); } } } catch (\Doctrine\DBAL\DBALException $e) { $logger = \OC::$server->getLogger(); $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); $logger->logException($e); } } return $errors; }
/** * Checks if a table exists in the database - the database prefix will be prepended * * @param string $table * @return bool * @throws DatabaseException */ public static function tableExists($table) { $table = OC_Config::getValue('dbtableprefix', 'oc_') . trim($table); $dbType = OC_Config::getValue('dbtype', 'sqlite'); switch ($dbType) { case 'sqlite': case 'sqlite3': $sql = "SELECT name FROM sqlite_master " . "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 ?'; $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 = ?'; $result = \OC_DB::executeAudited($sql, array($table)); break; case 'oci': $sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?'; $result = \OC_DB::executeAudited($sql, array($table)); break; case 'mssql': $sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?'; $result = \OC_DB::executeAudited($sql, array($table)); break; default: throw new DatabaseException("Unknown database type: {$dbType}"); } return $result->fetchOne() === $table; }
private function insert($logicPath, $physicalPath) { $sql = 'INSERT INTO `*PREFIX*file_map` (`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`) VALUES (?, ?, ?, ?)'; \OC_DB::executeAudited($sql, array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath))); }
/** * Function that is called after a group is removed. Cleans up the shares to that group. * @param array $arguments */ public static function post_deleteGroup($arguments) { $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'; $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'])); while ($item = $result->fetchRow()) { Helper::delete($item['id']); } }
/** * Returns a list of properties for this nodes.; * @param array $properties * @return array * @note The properties list is a list of propertynames the client * requested, encoded as xmlnamespace#tagName, for example: * http://www.example.org/namespace#author If the array is empty, all * properties should be returned */ public function getProperties($properties) { if (is_null($this->property_cache)) { $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; $result = OC_DB::executeAudited($sql, array(OC_User::getUser(), $this->path)); $this->property_cache = array(); while ($row = $result->fetchRow()) { $this->property_cache[$row['propertyname']] = $row['propertyvalue']; } $this->property_cache[self::GETETAG_PROPERTYNAME] = '"' . $this->info->getEtag() . '"'; } // if the array was empty, we need to return everything if (count($properties) == 0) { return $this->property_cache; } $props = array(); foreach ($properties as $property) { if (isset($this->property_cache[$property])) { $props[$property] = $this->property_cache[$property]; } } return $props; }