public function run(IOutput $output) { $qb = $this->connection->getQueryBuilder(); $qb->update('filecache')->set('etag', $qb->expr()->literal('xxx'))->where($qb->expr()->eq('etag', $qb->expr()->literal('')))->orWhere($qb->expr()->isNull('etag')); $result = $qb->execute(); $output->info("ETags have been fixed for {$result} files/folders."); }
public function run() { $qb = $this->connection->getQueryBuilder(); $qb->update('filecache')->set('etag', $qb->expr()->literal('xxx'))->where($qb->expr()->eq('etag', $qb->expr()->literal('')))->orWhere($qb->expr()->isNull('etag')); $result = $qb->execute(); $this->emit('\\OC\\Repair', 'info', array("ETags have been fixed for {$result} files/folders.")); }
public function test() { // insert test data $builder = $this->db->getQueryBuilder(); $builder->insert('clndr_calendars')->values(['userid' => $builder->createNamedParameter('test-user-666'), 'displayname' => $builder->createNamedParameter('Display Name'), 'uri' => $builder->createNamedParameter('events'), 'ctag' => $builder->createNamedParameter('112233'), 'active' => $builder->createNamedParameter('1')])->execute(); $builder = $this->db->getQueryBuilder(); $builder->insert('clndr_objects')->values(['calendarid' => $builder->createNamedParameter(6666), 'objecttype' => $builder->createNamedParameter('VEVENT'), 'startdate' => $builder->createNamedParameter(new \DateTime(), 'datetime'), 'enddate' => $builder->createNamedParameter(new \DateTime(), 'datetime'), 'repeating' => $builder->createNamedParameter(0), 'summary' => $builder->createNamedParameter('Something crazy will happen'), 'uri' => $builder->createNamedParameter('event.ics'), 'lastmodified' => $builder->createNamedParameter('112233')])->execute(); $builder = $this->db->getQueryBuilder(); $builder->insert('share')->values(['share_type' => $builder->createNamedParameter(1), 'share_with' => $builder->createNamedParameter('user01'), 'uid_owner' => $builder->createNamedParameter('user02'), 'item_type' => $builder->createNamedParameter('calendar'), 'item_source' => $builder->createNamedParameter(6666), 'item_target' => $builder->createNamedParameter('Contacts (user02)')])->execute(); // test the adapter $this->adapter->foreachCalendar('test-user-666', function ($row) { $this->cals[] = $row; }); $this->assertArrayHasKey('id', $this->cals[0]); $this->assertEquals('test-user-666', $this->cals[0]['userid']); $this->assertEquals('Display Name', $this->cals[0]['displayname']); $this->assertEquals('events', $this->cals[0]['uri']); $this->assertEquals('112233', $this->cals[0]['ctag']); $this->adapter->foreachCalendarObject(6666, function ($row) { $this->calObjs[] = $row; }); $this->assertArrayHasKey('id', $this->calObjs[0]); $this->assertEquals(6666, $this->calObjs[0]['calendarid']); // test getShares $shares = $this->adapter->getShares(6666); $this->assertEquals(1, count($shares)); }
/** * Test remove shares where the parent share does not exist anymore */ public function testSharesNonExistingParent() { $qb = $this->connection->getQueryBuilder(); $shareValues = ['share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('recipientuser1'), 'uid_owner' => $qb->expr()->literal('user1'), 'item_type' => $qb->expr()->literal('folder'), 'item_source' => $qb->expr()->literal(123), 'item_target' => $qb->expr()->literal('/123'), 'file_source' => $qb->expr()->literal(123), 'file_target' => $qb->expr()->literal('/test'), 'permissions' => $qb->expr()->literal(1), 'stime' => $qb->expr()->literal(time()), 'expiration' => $qb->expr()->literal('2015-09-25 00:00:00')]; // valid share $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values($shareValues)->execute(); $parent = $this->getLastShareId(); // share with existing parent $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(array_merge($shareValues, ['parent' => $qb->expr()->literal($parent)]))->execute(); $validChild = $this->getLastShareId(); // share with non-existing parent $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(array_merge($shareValues, ['parent' => $qb->expr()->literal($parent + 100)]))->execute(); $invalidChild = $this->getLastShareId(); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertEquals([['id' => $parent], ['id' => $validChild], ['id' => $invalidChild]], $rows); $result->closeCursor(); $this->repair->run(); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertEquals([['id' => $parent], ['id' => $validChild]], $rows); $result->closeCursor(); }
public function test() { // insert test data $builder = $this->db->getQueryBuilder(); $builder->insert('contacts_addressbooks')->values(['userid' => $builder->createNamedParameter('test-user-666'), 'displayname' => $builder->createNamedParameter('Display Name'), 'uri' => $builder->createNamedParameter('contacts'), 'description' => $builder->createNamedParameter('An address book for testing'), 'ctag' => $builder->createNamedParameter('112233'), 'active' => $builder->createNamedParameter('1')])->execute(); $builder = $this->db->getQueryBuilder(); $builder->insert('contacts_cards')->values(['addressbookid' => $builder->createNamedParameter(6666), 'fullname' => $builder->createNamedParameter('Full Name'), 'carddata' => $builder->createNamedParameter('datadatadata'), 'uri' => $builder->createNamedParameter('some-card.vcf'), 'lastmodified' => $builder->createNamedParameter('112233')])->execute(); $builder = $this->db->getQueryBuilder(); $builder->insert('share')->values(['share_type' => $builder->createNamedParameter(1), 'share_with' => $builder->createNamedParameter('user01'), 'uid_owner' => $builder->createNamedParameter('user02'), 'item_type' => $builder->createNamedParameter('addressbook'), 'item_source' => $builder->createNamedParameter(6666), 'item_target' => $builder->createNamedParameter('Contacts (user02)')])->execute(); // test the adapter $this->adapter->foreachBook('test-user-666', function ($row) { $this->books[] = $row; }); $this->assertArrayHasKey('id', $this->books[0]); $this->assertEquals('test-user-666', $this->books[0]['userid']); $this->assertEquals('Display Name', $this->books[0]['displayname']); $this->assertEquals('contacts', $this->books[0]['uri']); $this->assertEquals('An address book for testing', $this->books[0]['description']); $this->assertEquals('112233', $this->books[0]['ctag']); $this->adapter->foreachCard(6666, function ($row) { $this->cards[] = $row; }); $this->assertArrayHasKey('id', $this->cards[0]); $this->assertEquals(6666, $this->cards[0]['addressbookid']); // test getShares $shares = $this->adapter->getShares(6666); $this->assertEquals(1, count($shares)); }
/** * Make sure all avatar files in the user roots have permission 27 */ protected function fixAvatarPermissions() { $qb = $this->connection->getQueryBuilder(); $qb2 = $this->connection->getQueryBuilder(); $qb->select('numeric_id')->from('storages')->where($qb->expr()->like('id', $qb2->createParameter('like'))); $qb2->update('filecache')->set('permissions', $qb2->createNamedParameter(27))->where($qb2->expr()->like('path', $qb2->createNamedParameter('avatar.%')))->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL())))->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(27)))->setParameter('like', 'home::%'); $qb2->execute(); }
/** * Past bugs would make it possible to set an expiration date on user shares even * though it is not supported. This functions removes the expiration date from such entries. */ private function removeExpirationDateFromNonLinkShares() { $builder = $this->connection->getQueryBuilder(); $builder->update('share')->set('expiration', 'null')->where($builder->expr()->isNotNull('expiration'))->andWhere($builder->expr()->neq('share_type', $builder->expr()->literal(\OC\Share\Constants::SHARE_TYPE_LINK))); $updatedEntries = $builder->execute(); if ($updatedEntries > 0) { $this->emit('\\OC\\Repair', 'info', array('Removed invalid expiration date from ' . $updatedEntries . ' shares')); } }
public function tearDown() { $builder = $this->connection->getQueryBuilder(); $builder->delete('mounts')->execute(); $builder = $this->connection->getQueryBuilder(); foreach ($this->fileIds as $fileId) { $builder->delete('filecache')->where($builder->expr()->eq('fileid', new Literal($fileId)))->execute(); } }
/** * @return int */ protected function getLastShareId() { // select because lastInsertId does not work with OCI $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'DESC')->execute(); $row = $result->fetch(); $result->closeCursor(); return $row['id']; }
/** * Deleting orphaned user tag mappings * * @return int Number of deleted entries */ protected function cleanUserTags() { $subQuery = $this->connection->getQueryBuilder(); $subQuery->select($subQuery->expr()->literal('1'))->from('filecache', 'f')->where($subQuery->expr()->eq('objid', 'f.fileid')); $query = $this->connection->getQueryBuilder(); $deletedEntries = $query->delete('vcategory_to_object')->where($query->expr()->eq('type', $query->expr()->literal('files')))->andWhere($query->expr()->isNull($query->createFunction('(' . $subQuery->getSql() . ')')))->execute(); $this->logger->debug("{$deletedEntries} orphaned user tag relations deleted", ['app' => 'DeleteOrphanedTagsJob']); return $deletedEntries; }
public function testDeleteSubAdmin() { $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); $this->assertTrue($subAdmin->createSubAdmin($this->users[0], $this->groups[0])); $this->assertTrue($subAdmin->deleteSubAdmin($this->users[0], $this->groups[0])); // DB query should be empty $qb = $this->dbConn->getQueryBuilder(); $result = $qb->select(['gid', 'uid'])->from('group_admin')->where($qb->expr()->eq('gid', $qb->createNamedParameter($this->groups[0]->getGID())))->andWHere($qb->expr()->eq('uid', $qb->createNamedParameter($this->users[0]->getUID())))->execute()->fetch(); $this->assertEmpty($result); }
/** * @param string $shareType * @param string $shareWith * @param null|int $parent * @return int */ protected function createShare($shareType, $shareWith, $parent) { $qb = $this->connection->getQueryBuilder(); $shareValues = ['share_type' => $qb->expr()->literal($shareType), 'share_with' => $qb->expr()->literal($shareWith), 'uid_owner' => $qb->expr()->literal('user1'), 'item_type' => $qb->expr()->literal('folder'), 'item_source' => $qb->expr()->literal(123), 'item_target' => $qb->expr()->literal('/123'), 'file_source' => $qb->expr()->literal(123), 'file_target' => $qb->expr()->literal('/test'), 'permissions' => $qb->expr()->literal(1), 'stime' => $qb->expr()->literal(time()), 'expiration' => $qb->expr()->literal('2015-09-25 00:00:00')]; if ($parent) { $shareValues['parent'] = $qb->expr()->literal($parent); } $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values($shareValues)->execute(); return $this->connection->lastInsertId('*PREFIX*share'); }
/** * @param IOutput $output */ private function removeContactShares(IOutput $output) { $qb = $this->connection->getQueryBuilder(); $qb->delete('share')->where($qb->expr()->eq('item_type', $qb->createNamedParameter('contact'))); $qb->execute(); $output->advance(); $qb = $this->connection->getQueryBuilder(); $qb->delete('share')->where($qb->expr()->eq('item_type', $qb->createNamedParameter('addressbook'))); $qb->execute(); $output->advance(); }
public function testStore() { $this->assertFalse($this->loader->exists('testing/mymimetype')); $mimetypeId = $this->loader->getId('testing/mymimetype'); $qb = $this->db->getQueryBuilder(); $qb->select('mimetype')->from('mimetypes')->where($qb->expr()->eq('id', $qb->createPositionalParameter($mimetypeId))); $mimetype = $qb->execute()->fetch(); $this->assertEquals('testing/mymimetype', $mimetype['mimetype']); $this->assertEquals('testing/mymimetype', $this->loader->getMimetypeById($mimetypeId)); $this->assertEquals($mimetypeId, $this->loader->getId('testing/mymimetype')); }
public function tearDown() { $sql = $this->connection->getQueryBuilder(); $sql->delete('appconfig'); $sql->execute(); $sql = $this->connection->getQueryBuilder(); $sql->insert('appconfig')->values(['appid' => $sql->createParameter('appid'), 'configkey' => $sql->createParameter('configkey'), 'configvalue' => $sql->createParameter('configvalue')]); foreach ($this->originalConfig as $configs) { $sql->setParameter('appid', $configs['appid'])->setParameter('configkey', $configs['configkey'])->setParameter('configvalue', $configs['configvalue']); $sql->execute(); } $this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection())); parent::tearDown(); }
public function testRun() { $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('file'), 'item_source' => $qb->createNamedParameter(42), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter(42), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('calendar'), 'item_source' => $qb->createNamedParameter(42), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter(42), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('event'), 'item_source' => $qb->createNamedParameter(42), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter(42), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('contact'), 'item_source' => $qb->createNamedParameter(42), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter(42), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('addressbook'), 'item_source' => $qb->createNamedParameter(42), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter(42), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $qb = $this->connection->getQueryBuilder(); $qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')->from('share'); $cursor = $qb->execute(); $data = $cursor->fetchAll(); $cursor->closeCursor(); $this->assertEquals(5, $data[0]['count']); $this->repair->run($this->outputMock); $qb = $this->connection->getQueryBuilder(); $qb->select('*')->from('share'); $cursor = $qb->execute(); $data = $cursor->fetchAll(); $cursor->closeCursor(); $this->assertCount(1, $data); $this->assertEquals('file', $data[0]['item_type']); }
/** * Deleting orphaned comment read markers * * @return int Number of deleted entries */ protected function cleanCommentMarkers() { $qb = $this->connection->getQueryBuilder(); $deletedEntries = $this->cleanUp('comments_read_markers', $qb->expr()->castColumn('object_id', IQueryBuilder::PARAM_INT), 'object_type'); $this->logger->debug("{$deletedEntries} orphaned comment read marks deleted", ['app' => 'DeleteOrphanedItems']); return $deletedEntries; }
/** * Remove shares where the parent share does not exist anymore */ private function removeSharesNonExistingParent() { $deletedEntries = 0; $query = $this->connection->getQueryBuilder(); $query->select('s1.parent')->from('share', 's1')->where($query->expr()->isNotNull('s1.parent'))->andWhere($query->expr()->isNull('s2.id'))->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))->groupBy('s1.parent'); $deleteQuery = $this->connection->getQueryBuilder(); $deleteQuery->delete('share')->where($query->expr()->eq('parent', $deleteQuery->createParameter('parent'))); $result = $query->execute(); while ($row = $result->fetch()) { $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])->execute(); } $result->closeCursor(); if ($deletedEntries) { $this->emit('\\OC\\Repair', 'info', array('Removed ' . $deletedEntries . ' shares where the parent did not exist')); } }
/** * update database */ public function updateDB() { // make sure that we don't update the file cache multiple times // only update during the first run if ($this->installedVersion === '-1') { return; } // delete left-over from old encryption which is no longer needed $this->config->deleteAppValue('files_encryption', 'ocsid'); $this->config->deleteAppValue('files_encryption', 'types'); $this->config->deleteAppValue('files_encryption', 'enabled'); $oldAppValues = $this->connection->getQueryBuilder(); $oldAppValues->select('*')->from('appconfig')->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid')))->setParameter('appid', 'files_encryption'); $appSettings = $oldAppValues->execute(); while ($row = $appSettings->fetch()) { // 'installed_version' gets deleted at the end of the migration process if ($row['configkey'] !== 'installed_version') { $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']); $this->config->deleteAppValue('files_encryption', $row['configkey']); } } $oldPreferences = $this->connection->getQueryBuilder(); $oldPreferences->select('*')->from('preferences')->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid')))->setParameter('appid', 'files_encryption'); $preferenceSettings = $oldPreferences->execute(); while ($row = $preferenceSettings->fetch()) { $this->config->setUserValue($row['userid'], 'encryption', $row['configkey'], $row['configvalue']); $this->config->deleteUserValue($row['userid'], 'files_encryption', $row['configkey']); } }
/** * {@inheritdoc} */ public function deleteTags($tagIds) { if (!is_array($tagIds)) { $tagIds = [$tagIds]; } $tagNotFoundException = null; $tags = []; try { $tags = $this->getTagsByIds($tagIds); } catch (TagNotFoundException $e) { $tagNotFoundException = $e; // Get existing tag objects for the hooks later $existingTags = array_diff($tagIds, $tagNotFoundException->getMissingTags()); if (!empty($existingTags)) { try { $tags = $this->getTagsByIds($existingTags); } catch (TagNotFoundException $e) { // Ignore further errors... } } } // delete relationships first $query = $this->connection->getQueryBuilder(); $query->delete(SystemTagObjectMapper::RELATION_TABLE)->where($query->expr()->in('systemtagid', $query->createParameter('tagids')))->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY)->execute(); $query = $this->connection->getQueryBuilder(); $query->delete(self::TAG_TABLE)->where($query->expr()->in('id', $query->createParameter('tagids')))->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY)->execute(); foreach ($tags as $tag) { $this->dispatcher->dispatch(ManagerEvent::EVENT_DELETE, new ManagerEvent(ManagerEvent::EVENT_DELETE, $tag)); } if ($tagNotFoundException !== null) { throw new TagNotFoundException('Tag id(s) not found', 0, $tagNotFoundException, $tagNotFoundException->getMissingTags()); } }
/** * Commit the active propagation batch */ public function commitBatch() { if (!$this->inBatch) { throw new \BadMethodCallException('Not in batch'); } $this->inBatch = false; $this->connection->beginTransaction(); $query = $this->connection->getQueryBuilder(); $storageId = (int) $this->storage->getStorageCache()->getNumericId(); $query->update('filecache')->set('mtime', $query->createFunction('GREATEST(`mtime`, ' . $query->createParameter('time') . ')'))->set('etag', $query->expr()->literal(uniqid()))->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))); $sizeQuery = $this->connection->getQueryBuilder(); $sizeQuery->update('filecache')->set('size', $sizeQuery->createFunction('`size` + ' . $sizeQuery->createParameter('size')))->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT)))->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash')))->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT))); foreach ($this->batch as $item) { $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT); $query->setParameter('hash', $item['hash']); $query->execute(); if ($item['size']) { $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT); $sizeQuery->setParameter('hash', $item['hash']); $sizeQuery->execute(); } } $this->batch = []; $this->connection->commit(); }
private function getTextValueByIntergerField($integerField) { $builder = $this->connection->getQueryBuilder(); $query = $builder->select('textfield')->from('table')->where($builder->expr()->eq('integerfield', $builder->createNamedParameter($integerField, IQueryBuilder::PARAM_INT))); $result = $query->execute(); return $result->fetchColumn(); }
/** * Delete all mail queue entries * * @param IDBConnection $connection * @param string $user */ protected static function deleteUserMailQueue(IDBConnection $connection, $user) { // Delete entries from mail queue $queryBuilder = $connection->getQueryBuilder(); $queryBuilder->delete('activity_mq')->where($queryBuilder->expr()->eq('amq_affecteduser', $queryBuilder->createParameter('user')))->setParameter('user', $user); $queryBuilder->execute(); }
/** * @dataProvider dataExpireLinkShare * * @param bool addExpiration Should we add an expire date * @param string $interval The dateInterval * @param bool $addInterval If true add to the current time if false subtract * @param bool $shouldExpire Should this share be expired */ public function testExpireLinkShare($addExpiration, $interval, $addInterval, $shouldExpire) { $this->loginAsUser($this->user1); $view = new \OC\Files\View('/' . $this->user1 . '/'); $view->mkdir('files/test'); $fileInfo = $view->getFileInfo('files/test'); $this->assertNotNull(\OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ), 'Failed asserting that user 1 successfully shared "test" by link.'); $shares = $this->getShares(); $this->assertCount(1, $shares); reset($shares); $share = current($shares); if ($addExpiration) { $expire = new \DateTime(); $expire->setTime(0, 0, 0); if ($addInterval) { $expire->add(new \DateInterval($interval)); } else { $expire->sub(new \DateInterval($interval)); } $expire = $expire->format('Y-m-d 00:00:00'); // Set expiration date to yesterday $qb = $this->connection->getQueryBuilder(); $qb->update('share')->set('expiration', $qb->createParameter('expiration'))->where($qb->expr()->eq('id', $qb->createParameter('id')))->setParameter('id', $share['id'])->setParameter('expiration', $expire)->execute(); $shares = $this->getShares(); $this->assertCount(1, $shares); } $this->logout(); $this->job->run([]); $shares = $this->getShares(); if ($shouldExpire) { $this->assertCount(0, $shares); } else { $this->assertCount(1, $shares); } }
public function testRun() { //Add test user $user1 = $this->userManager->createUser('test1', 'test1'); $userFolder = $this->rootFolder->getUserFolder('test1'); $fileId = $userFolder->getId(); //Now insert cyclic share $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('file'), 'item_source' => $qb->createNamedParameter($fileId), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter($fileId), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); //Add test user $user2 = $this->userManager->createUser('test2', 'test2'); $userFolder = $this->rootFolder->getUserFolder('test2'); $folder = $userFolder->newFolder('foo'); $fileId = $folder->getId(); //Now insert cyclic share $qb = $this->connection->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(0), 'share_with' => $qb->createNamedParameter('foo'), 'uid_owner' => $qb->createNamedParameter('owner'), 'item_type' => $qb->createNamedParameter('file'), 'item_source' => $qb->createNamedParameter($fileId), 'item_target' => $qb->createNamedParameter('/target'), 'file_source' => $qb->createNamedParameter($fileId), 'file_target' => $qb->createNamedParameter('/target'), 'permissions' => $qb->createNamedParameter(1)]); $qb->execute(); $this->repair->run($this->outputMock); //Verify $qb = $this->connection->getQueryBuilder(); $qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')->from('share'); $cursor = $qb->execute(); $data = $cursor->fetch(); $cursor->closeCursor(); $count = (int) $data['count']; $this->assertEquals(1, $count); $user1->delete(); $user2->delete(); }
public function testCollectCardProperties() { $query = $this->db->getQueryBuilder(); $query->insert($this->dbCardsPropertiesTable)->values(['addressbookid' => $query->createNamedParameter(666), 'cardid' => $query->createNamedParameter(777), 'name' => $query->createNamedParameter('FN'), 'value' => $query->createNamedParameter('John Doe'), 'preferred' => $query->createNamedParameter(0)])->execute(); $result = $this->backend->collectCardProperties(666, 'FN'); $this->assertEquals(['John Doe'], $result); }
/** * @return array (string => string|int) */ public function getData() { $query = $this->connection->getQueryBuilder(); $query->select('*')->from('appconfig')->where($query->expr()->in('configkey', $query->createNamedParameter(['enabled', 'installed_version'], Connection::PARAM_STR_ARRAY))); $result = $query->execute(); $data = []; while ($row = $result->fetch()) { if ($row['configkey'] === 'enabled' && $row['configvalue'] === 'no') { $data[$row['appid']] = 'disabled'; } if ($row['configkey'] === 'installed_version' && !isset($data[$row['appid']])) { $data[$row['appid']] = $row['configvalue']; } } $result->closeCursor(); return $data; }
/** * get server status * * @param string $url * @return int */ public function getServerStatus($url) { $hash = $this->hash($url); $query = $this->connection->getQueryBuilder(); $query->select('status')->from($this->dbTable)->where($query->expr()->eq('url_hash', $query->createParameter('url_hash')))->setParameter('url_hash', $hash); $result = $query->execute()->fetch(); return (int) $result['status']; }
/** * deletes all comments made of a specific object (e.g. on file delete) * * @param string $objectType the object type (e.g. 'file') * @param string $objectId e.g. the file id * @return boolean * @since 9.0.0 */ public function deleteCommentsAtObject($objectType, $objectId) { $this->checkRoleParameters('Object', $objectType, $objectId); $qb = $this->dbConn->getQueryBuilder(); $affectedRows = $qb->delete('comments')->where($qb->expr()->eq('object_type', $qb->createParameter('type')))->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id')))->setParameter('type', $objectType)->setParameter('id', $objectId)->execute(); $this->commentsCache = []; return is_int($affectedRows); }
public function testUpdateGroupSubShares() { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user2', 'file', 42, 'target', 31, null, null); $id2 = $this->addShareToDB(2, 'user0', 'user1', 'user2', 'file', 42, 'mytarget', 31, null, null, $id); $id3 = $this->addShareToDB(2, 'user3', 'user1', 'user2', 'file', 42, 'mytarget2', 0, null, null, $id); $users = []; for ($i = 0; $i < 6; $i++) { $user = $this->getMock('\\OCP\\IUser'); $user->method('getUID')->willReturn('user' . $i); $users['user' . $i] = $user; } $this->userManager->method('get')->will($this->returnCallback(function ($userId) use($users) { return $users[$userId]; })); $groups = []; for ($i = 0; $i < 2; $i++) { $group = $this->getMock('\\OCP\\IGroup'); $group->method('getGID')->willReturn('group' . $i); $groups['group' . $i] = $group; } $this->groupManager->method('get')->will($this->returnCallback(function ($groupId) use($groups) { return $groups[$groupId]; })); $file1 = $this->getMock('\\OCP\\Files\\File'); $file1->method('getId')->willReturn(42); $file2 = $this->getMock('\\OCP\\Files\\File'); $file2->method('getId')->willReturn(43); $folder1 = $this->getMock('\\OCP\\Files\\Folder'); $folder1->method('getById')->with(42)->willReturn([$file1]); $folder2 = $this->getMock('\\OCP\\Files\\Folder'); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['user2', $folder1], ['user5', $folder2]])); $share = $this->provider->getShareById($id); $share->setSharedWith('group0'); $share->setSharedBy('user4'); $share->setShareOwner('user5'); $share->setNode($file2); $share->setPermissions(1); $share2 = $this->provider->update($share); $this->assertEquals($id, $share2->getId()); // Group shares do not allow updating the recipient $this->assertSame('group0', $share2->getSharedWith()); $this->assertSame('user4', $share2->getSharedBy()); $this->assertSame('user5', $share2->getShareOwner()); $this->assertSame(1, $share2->getPermissions()); $qb = $this->dbConn->getQueryBuilder(); $stmt = $qb->select('*')->from('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($id)))->orderBy('id')->execute(); $shares = $stmt->fetchAll(); $this->assertSame('user0', $shares[0]['share_with']); $this->assertSame('user4', $shares[0]['uid_initiator']); $this->assertSame('user5', $shares[0]['uid_owner']); $this->assertSame(1, (int) $shares[0]['permissions']); $this->assertSame('user3', $shares[1]['share_with']); $this->assertSame('user4', $shares[1]['uid_initiator']); $this->assertSame('user5', $shares[1]['uid_owner']); $this->assertSame(0, (int) $shares[1]['permissions']); $stmt->closeCursor(); }