Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,19 @@ public function unshare($id) {

$token = isset($_POST['token']) ? $_POST['token'] : null;

$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?');
$query->execute(array($id, $token));
$share = $query->fetchRow();
$qb = $this->connection->getQueryBuilder();
$qb->select('*')
->from('share_external')
->where(
$qb->expr()->andX(
$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
)
);

$result = $qb->execute();
$share = $result->fetch();
$result->closeCursor();

if ($token && $id && !empty($share)) {

Expand All @@ -439,8 +449,17 @@ public function unshare($id) {
$mountpoint = $share['mountpoint'];
$user = $share['user'];

$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?');
$query->execute(array($id, $token));
$qb = $this->connection->getQueryBuilder();
$qb->delete('share_external')
->where(
$qb->expr()->andX(
$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
)
);

$result = $qb->execute();
$result->closeCursor();

if ($share['accepted']) {
$path = trim($mountpoint, '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ protected function setUp() {
}

protected function tearDown() {
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external`');
$query->execute();
$qb = $this->connection->getQueryBuilder();
$qb->delete('share_external');
$qb->execute();

$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
$query->execute();
$qb = $this->connection->getQueryBuilder();
$qb->delete('share');
$qb->execute();

parent::tearDown();
}
Expand All @@ -142,9 +144,15 @@ function testCreateShare() {

$this->s2s->createShare(null);

$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ?');
$result = $query->execute(array('1'));
$data = $result->fetchRow();
$qb = $this->connection->getQueryBuilder();
$qb->select('*')
->from('share_external')
->where(
$qb->expr()->eq('remote_id', $qb->createNamedParameter(1))
);
$result = $qb->execute();
$data = $result->fetch();
$result->closeCursor();

$this->assertSame('localhost', $data['remote']);
$this->assertSame('token', $data['share_token']);
Expand Down Expand Up @@ -187,23 +195,23 @@ function XtestDeclineShareMultiple() {

$this->share->expects($this->any())->method('verifyShare')->willReturn(true);

$dummy = \OCP\DB::prepare('
$dummy = \OC_DB::prepare('
INSERT INTO `*PREFIX*share`
(`share_type`, `uid_owner`, `item_type`, `item_source`, `item_target`, `file_source`, `file_target`, `permissions`, `stime`, `token`, `share_with`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
');
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token1', 'foo@bar'));
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token2', 'bar@bar'));

$verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertCount(2, $data);

$_POST['token'] = 'token1';
$this->s2s->declineShare(array('id' => $data[0]['id']));

$verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertCount(1, $data);
Expand All @@ -212,7 +220,7 @@ function XtestDeclineShareMultiple() {
$_POST['token'] = 'token2';
$this->s2s->declineShare(array('id' => $data[0]['id']));

$verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertEmpty($data);
Expand Down
11 changes: 9 additions & 2 deletions apps/files_sharing/lib/ShareBackend/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ protected static function resolveReshares($source) {
if (isset($source['parent'])) {
$parent = $source['parent'];
while (isset($parent)) {
$query = \OCP\DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
$item = $query->execute(array($parent))->fetchRow();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->select('parent', 'uid_owner')
->from('share')
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($parent))
);
$result = $qb->execute();
$item = $result->fetch();
$result->closeCursor();
if (isset($item['parent'])) {
$parent = $item['parent'];
} else {
Expand Down
47 changes: 37 additions & 10 deletions apps/files_sharing/lib/ShareBackend/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,62 @@ public function getParents($itemSource, $shareWith = null, $owner = null) {
* @return mixed parent ID or null
*/
private function getParentId($child) {
$query = \OCP\DB::prepare('SELECT `parent` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
$result = $query->execute(array($child));
$row = $result->fetchRow();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->select('parent')
->from('filecache')
->where(
$qb->expr()->eq('fileid', $qb->createNamedParameter($child))
);
$result = $qb->execute();
$row = $result->fetch();
$result->closeCursor();
return $row ? $row['parent'] : null;
}

public function getChildren($itemSource) {
$children = array();
$parents = array($itemSource);
$query = \OCP\DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
$result = $query->execute(array('httpd/unix-directory'));

$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->select('id')
->from('mimetypes')
->where(
$qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory'))
);
$result = $qb->execute();
$row = $result->fetch();
$result->closeCursor();

if ($row = $result->fetchRow()) {
$mimetype = (int) $row['id'];
} else {
$mimetype = -1;
}
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
$query = \OCP\DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`'
.' WHERE `parent` IN ('.$parents.')');
$result = $query->execute();

$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();

$parents = array_map(function($parent) use ($qb) {
return $qb->createNamedParameter($parent);
}, $parents);

$qb->select('`fileid', 'name', '`mimetype')
->from('filecache')
->where(
$qb->expr()->in('parent', $parents)
);

$result = $qb->execute();

$parents = array();
while ($file = $result->fetchRow()) {
while ($file = $result->fetch()) {
$children[] = array('source' => $file['fileid'], 'file_path' => $file['name']);
// If a child folder is found look inside it
if ((int) $file['mimetype'] === $mimetype) {
$parents[] = $file['fileid'];
}
}
$result->closeCursor();
}
return $children;
}
Expand Down
4 changes: 0 additions & 4 deletions apps/files_sharing/tests/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ protected function tearDown() {

self::$tempStorage = null;

// clear database table
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
$query->execute();

parent::tearDown();
}

Expand Down
24 changes: 12 additions & 12 deletions apps/files_sharing/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ protected function setUp() {
}

protected function tearDown() {
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
$query->execute();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('share');
$qb->execute();

parent::tearDown();
}
Expand Down Expand Up @@ -206,16 +207,15 @@ protected static function resetStorage() {
* @return array with: item_source, share_type, share_with, item_type, permissions
*/
protected function getShareFromId($shareID) {
$sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?';
$args = array($shareID);
$query = \OCP\DB::prepare($sql);
$result = $query->execute($args);

$share = Null;

if ($result) {
$share = $result->fetchRow();
}
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->select('item_source', '`share_type', 'share_with', 'item_type', 'permissions')
->from('share')
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($shareID))
);
$result = $qb->execute();
$share = $result->fetch();
$result->closeCursor();

return $share;

Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function deleteServerConfiguration($prefix) {
$saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
}

$query = \OCP\DB::prepare('
$query = \OC_DB::prepare('
DELETE
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
Expand Down
8 changes: 4 additions & 4 deletions apps/user_ldap/lib/Jobs/UpdateGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static private function getRefreshInterval() {
*/
static private function handleKnownGroups($groups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', \OCP\Util::DEBUG);
$query = \OCP\DB::prepare('
$query = \OC_DB::prepare('
UPDATE `*PREFIX*ldap_group_members`
SET `owncloudusers` = ?
WHERE `owncloudname` = ?
Expand Down Expand Up @@ -131,7 +131,7 @@ static private function handleKnownGroups($groups) {
*/
static private function handleCreatedGroups($createdGroups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with created Groups.', \OCP\Util::DEBUG);
$query = \OCP\DB::prepare('
$query = \OC_DB::prepare('
INSERT
INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`)
VALUES (?, ?)
Expand All @@ -153,7 +153,7 @@ static private function handleCreatedGroups($createdGroups) {
*/
static private function handleRemovedGroups($removedGroups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with removed groups.', \OCP\Util::DEBUG);
$query = \OCP\DB::prepare('
$query = \OC_DB::prepare('
DELETE
FROM `*PREFIX*ldap_group_members`
WHERE `owncloudname` = ?
Expand Down Expand Up @@ -212,7 +212,7 @@ static private function getKnownGroups() {
if(is_array(self::$groupsFromDB)) {
return self::$groupsFromDB;
}
$query = \OCP\DB::prepare('
$query = \OC_DB::prepare('
SELECT `owncloudname`, `owncloudusers`
FROM `*PREFIX*ldap_group_members`
');
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
'OCP\\Contacts\\ContactsMenu\\ILinkAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/ILinkAction.php',
'OCP\\Contacts\\ContactsMenu\\IProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IProvider.php',
'OCP\\Contacts\\IManager' => $baseDir . '/lib/public/Contacts/IManager.php',
'OCP\\DB' => $baseDir . '/lib/public/DB.php',
'OCP\\DB\\ISchemaWrapper' => $baseDir . '/lib/public/DB/ISchemaWrapper.php',
'OCP\\DB\\QueryBuilder\\ICompositeExpression' => $baseDir . '/lib/public/DB/QueryBuilder/ICompositeExpression.php',
'OCP\\DB\\QueryBuilder\\IExpressionBuilder' => $baseDir . '/lib/public/DB/QueryBuilder/IExpressionBuilder.php',
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Contacts\\ContactsMenu\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/ILinkAction.php',
'OCP\\Contacts\\ContactsMenu\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IProvider.php',
'OCP\\Contacts\\IManager' => __DIR__ . '/../../..' . '/lib/public/Contacts/IManager.php',
'OCP\\DB' => __DIR__ . '/../../..' . '/lib/public/DB.php',
'OCP\\DB\\ISchemaWrapper' => __DIR__ . '/../../..' . '/lib/public/DB/ISchemaWrapper.php',
'OCP\\DB\\QueryBuilder\\ICompositeExpression' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/ICompositeExpression.php',
'OCP\\DB\\QueryBuilder\\IExpressionBuilder' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/IExpressionBuilder.php',
Expand Down
14 changes: 7 additions & 7 deletions lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function getIdsForTag($tag) {
. '` WHERE `categoryid` = ?';

try {
$stmt = \OCP\DB::prepare($sql);
$stmt = \OC_DB::prepare($sql);
$result = $stmt->execute(array($tagId));
if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR);
Expand Down Expand Up @@ -530,7 +530,7 @@ public static function post_deleteUser($arguments) {
// Find all objectid/tagId pairs.
$result = null;
try {
$stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
$stmt = \OC_DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
. 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid']));
if ($result === null) {
Expand All @@ -546,7 +546,7 @@ public static function post_deleteUser($arguments) {

if(!is_null($result)) {
try {
$stmt = \OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
$stmt = \OC_DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
. 'WHERE `categoryid` = ?');
while( $row = $result->fetchRow()) {
try {
Expand All @@ -568,7 +568,7 @@ public static function post_deleteUser($arguments) {
}
}
try {
$stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
$stmt = \OC_DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
. 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid']));
if ($result === null) {
Expand Down Expand Up @@ -600,7 +600,7 @@ public function purgeObjects(array $ids) {
$query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) ';
$query .= 'AND `type`= ?';
$updates[] = $this->type;
$stmt = \OCP\DB::prepare($query);
$stmt = \OC_DB::prepare($query);
$result = $stmt->execute($updates);
if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR);
Expand Down Expand Up @@ -719,7 +719,7 @@ public function unTag($objid, $tag) {
try {
$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
. 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?';
$stmt = \OCP\DB::prepare($sql);
$stmt = \OC_DB::prepare($sql);
$stmt->execute(array($objid, $tagId, $this->type));
} catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [
Expand Down Expand Up @@ -769,7 +769,7 @@ public function delete($names) {
try {
$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
. 'WHERE `categoryid` = ?';
$stmt = \OCP\DB::prepare($sql);
$stmt = \OC_DB::prepare($sql);
$result = $stmt->execute(array($id));
if ($result === null) {
\OCP\Util::writeLog('core',
Expand Down
Loading