function cleanDB() { $query1 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks'); $query1->execute(); $query2 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks_tags'); $query2->execute(); }
public static function check() { // get mimetype code for directory $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?'); $result = $query->execute(array('httpd/unix-directory')); if ($row = $result->fetchRow()) { $dir_mimetype = $row['id']; } else { $dir_mimetype = 0; } // locate files that are not checked yet $sql = 'SELECT `*PREFIX*filecache`.`fileid`, `path`, `*PREFIX*storages`.`id`' . ' FROM `*PREFIX*filecache`' . ' LEFT JOIN `*PREFIX*files_antivirus` ON `*PREFIX*files_antivirus`.`fileid` = `*PREFIX*filecache`.`fileid`' . ' JOIN `*PREFIX*storages` ON `*PREFIX*storages`.`numeric_id` = `*PREFIX*filecache`.`storage`' . ' WHERE `mimetype` != ? AND `*PREFIX*storages`.`id` LIKE ? AND (`*PREFIX*files_antivirus`.`fileid` IS NULL OR `mtime` > `check_time`)'; $stmt = OCP\DB::prepare($sql, 5); try { $result = $stmt->execute(array($dir_mimetype, 'local::%')); if (\OC_DB::isError($result)) { \OC_Log::write('files_antivirus', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return; } } catch (\Exception $e) { \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return; } // scan the found files while ($row = $result->fetchRow()) { $storage = self::getStorage($row['id']); if ($storage !== null) { self::scan($row['fileid'], $row['path'], $storage); } else { \OCP\Util::writeLog('files_antivirus', 'File "' . $row['path'] . '" has a non local storage backend "' . $row['id'] . '"', \OCP\Util::ERROR); } } }
/** * test if the mount point moves up if the parent folder no longer exists */ function testShareMountLoseParentFolder() { // share to user $fileinfo = $this->view->getFileInfo($this->folder); $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); $statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?"; $query = \OC_DB::prepare($statement); $arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2); $query->execute($arguments); $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); $result = $query->execute(); $shares = $result->fetchAll(); $this->assertSame(1, count($shares)); $share = reset($shares); $this->assertSame('/foo/bar' . $this->folder, $share['file_target']); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); // share should have moved up $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); $result = $query->execute(); $shares = $result->fetchAll(); $this->assertSame(1, count($shares)); $share = reset($shares); $this->assertSame($this->folder, $share['file_target']); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $this->view->unlink($this->folder); }
public function getChildren($itemSource) { $children = array(); $parents = array($itemSource); $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?'); $result = $query->execute(array('httpd/unix-directory')); if ($row = $result->fetchRow()) { $mimetype = $row['id']; } else { $mimetype = -1; } while (!empty($parents)) { $parents = "'" . implode("','", $parents) . "'"; $query = OC_DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`' . ' WHERE `parent` IN (' . $parents . ')'); $result = $query->execute(); $parents = array(); while ($file = $result->fetchRow()) { $children[] = array('source' => $file['fileid'], 'file_path' => $file['name']); // If a child folder is found look inside it if ($file['mimetype'] == $mimetype) { $parents[] = $file['fileid']; } } } return $children; }
/** * lookup file path and owner by fetching it from the fscache * needed becaus OC_FileCache::getPath($id, $user) already requires the user * @param int $id * @return array */ function getPathAndUser($id) { $query = \OC_DB::prepare('SELECT `user`, `path` FROM `*PREFIX*fscache` WHERE `id` = ?'); $result = $query->execute(array($id)); $row = $result->fetchRow(); return $row; }
/** * Function that is called after a user is added to a group. * TODO what does it do? * @param array $arguments */ public static function post_addToGroup($arguments) { // Find the group shares and check if the user needs a unique target $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'])); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,' . ' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,' . ' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)'); while ($item = $result->fetchRow()) { $sourceExists = \OC\Share\Share::getItemSharedWithBySource($item['item_type'], $item['item_source'], self::FORMAT_NONE, null, true, $arguments['uid']); if ($sourceExists) { $fileTarget = $sourceExists['file_target']; $itemTarget = $sourceExists['item_target']; } else { $itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']); // do we also need a file target if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') { $fileTarget = Helper::generateTarget('file', $item['file_target'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']); } else { $fileTarget = null; } } // Insert an extra row for the group share if the item or file target is unique for this user if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) { $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget)); \OC_DB::insertid('*PREFIX*share'); } } }
private static function updateByNameStmt() { return \OC_DB::prepare(' UPDATE `*PREFIX*filecache` SET `mimetype` = ? WHERE `mimetype` <> ? AND `name` ILIKE ? '); }
/** * find the user that can be authenticated with an openid identity */ public static function findUserForIdentity($identity) { $query = OC_DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?'); $result = $query->execute(array('user_openid', 'identity', $identity))->fetchAll(); if (count($result) > 0) { return $result[0]['userid']; } else { return false; } }
/** * Retrieves the contents of a trash bin directory. * @param string $dir path to the directory inside the trashbin * or empty to retrieve the root of the trashbin * @return array of files */ public static function getTrashFiles($dir) { $result = array(); $user = \OCP\User::getUser(); if ($dir && $dir !== '/') { $view = new \OC_Filesystemview('/' . $user . '/files_trashbin/files'); $dirContent = $view->opendir($dir); if ($dirContent === false) { return null; } if (is_resource($dirContent)) { while (($entryName = readdir($dirContent)) !== false) { if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) { $pos = strpos($dir . '/', '/', 1); $tmp = substr($dir, 0, $pos); $pos = strrpos($tmp, '.d'); $timestamp = substr($tmp, $pos + 2); $result[] = array('id' => $entryName, 'timestamp' => $timestamp, 'mime' => $view->getMimeType($dir . '/' . $entryName), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'location' => $dir); } } closedir($dirContent); } } else { $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?'); $result = $query->execute(array($user))->fetchAll(); } $files = array(); $id = 0; foreach ($result as $r) { $i = array(); $i['id'] = $id++; $i['name'] = $r['id']; $i['date'] = \OCP\Util::formatDate($r['timestamp']); $i['timestamp'] = $r['timestamp']; $i['etag'] = $i['timestamp']; // dummy etag $i['mimetype'] = $r['mime']; $i['type'] = $r['type']; if ($i['type'] === 'file') { $fileinfo = pathinfo($r['id']); $i['basename'] = $fileinfo['filename']; $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : ''; } $i['directory'] = $r['location']; if ($i['directory'] === '/') { $i['directory'] = ''; } $i['permissions'] = \OCP\PERMISSION_READ; $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']); $i['icon'] = \OCA\Files\Helper::determineIcon($i); $files[] = $i; } usort($files, array('\\OCA\\Files\\Helper', 'fileCmp')); return $files; }
private static function updateByNameStmt() { return \OC_DB::prepare(' UPDATE `*PREFIX*filecache` SET `mimetype` = ( SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ? ) WHERE `name` LIKE ? '); }
/** * Function that is called after a user is deleted. Cleans up the shares of that user. * @param array $arguments */ public static function post_deleteUser($arguments) { // Delete any items shared with the deleted user $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`' . ' WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?'); $query->execute(array($arguments['uid'], self::SHARE_TYPE_USER, self::$shareTypeGroupUserUnique)); // Delete any items the deleted user shared $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `uid_owner` = ?'); $result = $query->execute(array($arguments['uid'])); while ($item = $result->fetchRow()) { Helper::delete($item['id']); } }
/** * @param array $data * @return array */ public function add(array $data) { $SQL = "INSERT INTO {$this->tableName} (`id`, `type`, `text`, `users`, `start_date`, `end_date`, `duration`, `order`, `progress`, `sortorder`, `parent`, `open`, `buffers`) VALUES "; //$this->connect->setSessionTimeZoneToZero(); //$this->connect->db->executeQuery("SET @@session.time_zone = '00:00'"); //$query = \OC_DB::prepare('SET @@session.time_zone = "00:00"'); //$query = \OC_DB::prepare('SET GLOBAL time_zone = "00:00"'); $query = \OC_DB::prepare("set @@session.time_zone = '+00:00'"); $query->execute(); //$this->connect->db->executeQuery("SET time_zone = 'UTC'"); $rowData = []; for ($iRow = 0; $iRow < count($data); $iRow++) { $SQL .= (empty($rowData) ? '' : ',') . "( :id_{$iRow}, :type_{$iRow}, :text_{$iRow}, :users_{$iRow}, :start_date_{$iRow}, :end_date_{$iRow}, :duration_{$iRow}, :order_{$iRow}, :progress_{$iRow}, :sortorder_{$iRow}, :parent_{$iRow}, :open_{$iRow}, :buffers_{$iRow} )"; for ($i = 0; $i < count($this->fields); $i++) { $field = $this->fields[$i]; $value = $data[$iRow][$field]; if (isset($data[$iRow][$field])) { if ($field == 'id') { $value = (int) $value; } elseif ($field == 'type') { $value = (string) $value; } elseif ($field == 'text') { $value = (string) $value; } elseif ($field == 'users') { $value = (string) $value; } elseif ($field == 'start_date') { $value = empty($value) ? date("Y-m-d H:i:s", time()) : $value; } elseif ($field == 'end_date') { $value = empty($value) ? date("Y-m-d H:i:s", time() + 3600 * 24 * 7) : $value; } elseif ($field == 'duration') { $value = (int) (empty($value) ? 0 : $value); } elseif ($field == 'order') { $value = (int) (empty($value) ? 0 : $value); } elseif ($field == 'progress') { $value = (double) (empty($value) ? 0 : $value); } elseif ($field == 'sortorder') { $value = (int) (empty($value) ? 0 : $value); } elseif ($field == 'parent') { $value = (int) (empty($value) ? 1 : $value); } elseif ($field == 'open') { $value = (int) (empty($value) ? 1 : $value); } elseif ($field == 'buffers') { $value = (string) (empty($value) ? '' : $value); } $rowData[":{$field}_{$iRow}"] = $value; } else { $rowData[":{$field}_{$iRow}"] = null; } } } return $this->connect->db->prepare($SQL)->execute($rowData); }
/** * @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]); }
private static function addToken($token, $appUrl, $userAddress, $dataScope) { $user = OC_User::getUser(); $query = OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`userAddress`,`dataScope`) VALUES(?,?,?,?,?)"); $result = $query->execute(array($token, $appUrl, $user, $userAddress, $dataScope)); if (PEAR::isError($result)) { $entry = 'DB Error: "' . $result->getMessage() . '"<br />'; $entry .= 'Offending command was: ' . $result->getDebugInfo() . '<br />'; if (defined("DEBUG") && DEBUG) { error_log($entry); } die($entry); } }
/** * 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; } }
function index() { $fileIds = OCA\Search_Lucene\Indexer::getUnindexed(); $eventSource = new OC_EventSource(); $eventSource->send('count', count($fileIds)); $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr')); $query = OC_DB::prepare('INSERT INTO `*PREFIX*lucene_status` VALUES (?,?)'); foreach ($fileIds as $id) { $skipped = false; try { //before we start mark the file as error so we know there was a problem when the php execution dies $result = $query->execute(array($id, 'E')); $path = OC\Files\Filesystem::getPath($id); $eventSource->send('indexing', $path); //clean jobs for indexed file $param = json_encode(array('path' => $path, 'user' => OCP\User::getUser())); $cleanjobquery = OC_DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=? AND `parameters`=?'); $cleanjobquery->execute(array('search_lucene', $param)); foreach ($skippedDirs as $skippedDir) { if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) { $result = $query->execute(array($id, 'S')); $skipped = true; break; } } if (!$skipped) { if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) { $result = $query->execute(array($id, 'I')); } } if (!$result) { OC_JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $path); } } catch (PDOException $e) { //sqlite might report database locked errors when stock filescan is in progress //this also catches db locked exception that might come up when using sqlite \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR); OC_JSON::error(array('message' => 'Could not index file.')); $eventSource->send('error', $e->getMessage()); //try to mark the file as new to let it reindex $query->execute(array($id, 'N')); // Add UI to trigger rescan of files with status 'E'rror? } } $eventSource->send('done', ''); $eventSource->close(); }
public static function saveDomains($dom) { if (is_array($dom)) { $query = OC_DB::prepare('DELETE FROM *PREFIX*users_vd_domains'); $query->execute(); } else { return false; } $query = OC_DB::prepare('INSERT INTO *PREFIX*users_vd_domains (domain,fqdn) VALUES (?,?)'); foreach ($dom as $domain => $fqdn) { $fqdn = explode(',', $fqdn); foreach ($fqdn as $f) { $result = $query->execute(array($domain, $f)); } } }
/** * provide numRows */ public function numRows() { $type = OC_Config::getValue("dbtype", "sqlite"); if ($type == 'oci') { // OCI doesn't have a queryString, just do a rowCount for now return $this->statement->rowCount(); } $regex = '/^SELECT\\s+(?:ALL\\s+|DISTINCT\\s+)?(?:.*?)\\s+FROM\\s+(.*)$/i'; $queryString = $this->statement->getWrappedStatement()->queryString; if (preg_match($regex, $queryString, $output) > 0) { $query = OC_DB::prepare("SELECT COUNT(*) FROM {$output[1]}"); return $query->execute($this->lastArguments)->fetchColumn(); } else { return $this->statement->rowCount(); } }
/** * get the sha256 hash of the password needed for ampache * @param array $params, parameters passed from OC_Hook */ public static function loginListener($params) { if (isset($_POST['user']) and $_POST['password']) { if (defined("DEBUG") && DEBUG) { error_log('postlogin'); } $name = $_POST['user']; $query = OC_DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?"); $uid = $query->execute(array($name))->fetchAll(); if (count($uid) == 0) { $password = hash('sha256', $_POST['password']); $query = OC_DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);"); $query->execute(array($name, $password)); } } }
/** * update fileTarget in the database if the mount point changed * @param string $newPath * @param array $share reference to the share which should be modified * @return bool */ private static function updateFileTarget($newPath, &$share) { // if the user renames a mount point from a group share we need to create a new db entry // for the unique name if ($share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP && empty($share['unique_name'])) { $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,' . ' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,' . ' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)'); $arguments = array($share['item_type'], $share['item_source'], $share['item_target'], 2, \OCP\User::getUser(), $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'], $newPath, $share['token'], $share['id']); } else { // rename mount point $query = \OC_DB::prepare('Update `*PREFIX*share` SET `file_target` = ? WHERE `id` = ?'); $arguments = array($newPath, $share['id']); } $result = $query->execute($arguments); return $result === 1 ? true : false; }
/** * get all files and folders in a folder * @param string path * @param string root (optional) * @return array * * returns an array of assiciative arrays with the following keys: * - path * - name * - size * - mtime * - ctime * - mimetype * - encrypted * - versioned */ public static function getFolderContent($path, $root = false, $mimetype_filter = '') { if ($root === false) { $root = OC_Filesystem::getRoot(); } $parent = OC_FileCache::getId($path, $root); if ($parent == -1) { return array(); } $query = OC_DB::prepare('SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)'); $result = $query->execute(array($parent, $mimetype_filter . '%', 'httpd/unix-directory'))->fetchAll(); if (is_array($result)) { return $result; } else { OC_Log::write('files', 'getFolderContent(): file not found in cache (' . $path . ')', OC_Log::DEBUG); return false; } }
public function checkUid($uid) { if (strpos($uid, '@')) { $uide = explode('@', $uid); $nuid = $uide[0]; $fqdn = $uide[1]; } else { $nuid = $uid; $fqdn = $_SERVER['SERVER_NAME']; } $query = OC_DB::prepare('SELECT domain FROM *PREFIX*users_vd_domains WHERE LOWER(domain)=LOWER(?) OR LOWER(fqdn)=LOWER(?)'); $result = $query->execute(array($fqdn, $fqdn)); $row = $result->fetchRow(); if ($row) { return $nuid . '@' . $row['domain']; } else { return $uid; } }
/** * The FileCache Upgrade routine * * @param UpdateWatcher $watcher */ function __doFileCacheUpgrade($watcher) { try { $query = \OC_DB::prepare(' SELECT DISTINCT `user` FROM `*PREFIX*fscache` '); $result = $query->execute(); } catch (\Exception $e) { return; } $users = $result->fetchAll(); if (count($users) == 0) { return; } $step = 100 / count($users); $percentCompleted = 0; $lastPercentCompletedOutput = 0; $startInfoShown = false; foreach ($users as $userRow) { $user = $userRow['user']; \OC\Files\Filesystem::initMountPoints($user); \OC\Files\Cache\Upgrade::doSilentUpgrade($user); if (!$startInfoShown) { //We show it only now, because otherwise Info about upgraded apps //will appear between this and progress info $watcher->success('Updating filecache, this may take really long...'); $startInfoShown = true; } $percentCompleted += $step; $out = floor($percentCompleted); if ($out != $lastPercentCompletedOutput) { $watcher->success('... ' . $out . '% done ...'); $lastPercentCompletedOutput = $out; } } $watcher->success('Updated filecache'); }
public function checkLastIndexId() { $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' . ' `item_type`, `item_source`, `item_target`, `share_type`,' . ' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,' . ' `file_target`, `token`, `parent`, `expiration`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)'); $query->bindValue(1, 'file'); $query->bindValue(2, 949); $query->bindValue(3, '/949'); $query->bindValue(4, 0); $query->bindValue(5, 'migrate-test-user'); $query->bindValue(6, 'migrate-test-owner'); $query->bindValue(7, 23); $query->bindValue(8, 1402493312); $query->bindValue(9, 0); $query->bindValue(10, '/migration.txt'); $query->bindValue(11, null); $query->bindValue(12, null); $query->bindValue(13, null); $this->assertEquals(1, $query->execute()); $this->assertNotEquals('0', \OC_DB::insertid('*PREFIX*share')); // cleanup $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_target` = ?'); $query->bindValue(1, '/migration.txt'); $this->assertEquals(1, $query->execute()); }
/** * resolve reshares to return the correct source item * @param array $source * @return array source item */ protected static function resolveReshares($source) { if (isset($source['parent'])) { $parent = $source['parent']; while (isset($parent)) { $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); $item = $query->execute(array($parent))->fetchRow(); if (isset($item['parent'])) { $parent = $item['parent']; } else { $fileOwner = $item['uid_owner']; break; } } } else { $fileOwner = $source['uid_owner']; } if (isset($fileOwner)) { $source['fileOwner'] = $fileOwner; } else { \OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR); } return $source; }
/** * get the storage id of the storage for a file and the internal path of the file * * @return array, first element holding the storage id, second the path */ public static function getById($id) { $query = \OC_DB::prepare('SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); $result = $query->execute(array($id)); if ($row = $result->fetchRow()) { $numericId = $row['storage']; $path = $row['path']; } else { return null; } $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); $result = $query->execute(array($numericId)); if ($row = $result->fetchRow()) { return array($row['id'], $path); } else { return null; } }
/** * get the installed version of all apps */ public static function getAppVersions() { static $versions; if (isset($versions)) { // simple cache, needs to be fixed return $versions; // when function is used besides in checkUpgrade } $versions = array(); try { $query = OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig`' . ' WHERE `configkey` = \'installed_version\''); $result = $query->execute(); while ($row = $result->fetchRow()) { $versions[$row['appid']] = $row['configvalue']; } return $versions; } catch (\Exception $e) { return array(); } }
/** * @param integer $id * @return array */ private function getParentInfo($id) { $sql = 'SELECT `parent`, `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; $query = \OC_DB::prepare($sql); $result = $query->execute(array($id)); if ($row = $result->fetchRow()) { return array((int) $row['parent'], $row['name']); } else { return array(-1, ''); } }
function testDisableHook() { // encryption is enabled and running so we should have some user specific // settings in oc_preferences $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*preferences` WHERE `appid` = ?'); $result = $query->execute(array('files_encryption')); $row = $result->fetchRow(); $this->assertTrue(is_array($row)); // disabling the app should delete all user specific settings \OCA\Files_Encryption\Hooks::preDisable(array('app' => 'files_encryption')); // check if user specific settings for the encryption app are really gone $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*preferences` WHERE `appid` = ?'); $result = $query->execute(array('files_encryption')); $row = $result->fetchRow(); $this->assertFalse($row); // relogin user to initialize the encryption again $user = \OCP\User::getUser(); self::loginHelper($user); }
/** * @brief check if a user exists * @param string $uid the username * @return boolean */ public function userExists($uid) { $query = OC_DB::prepare("SELECT * FROM `*PREFIX*users` WHERE uid = ?"); $result = $query->execute(array($uid)); return $result->numRows() > 0; }