public function testRun()
 {
     $userName = '******';
     $data = [[$userName, '/abc.def.txt', '{DAV:}getetag', 'abcdef'], [$userName, '/abc.def.txt', '{DAV:}anotherRandomProperty', 'ghi']];
     // insert test data
     $sqlToInsertProperties = 'INSERT INTO `*PREFIX*properties` (`userid`, `propertypath`, `propertyname`, `propertyvalue`) VALUES (?, ?, ? ,?)';
     foreach ($data as $entry) {
         $this->connection->executeUpdate($sqlToInsertProperties, $entry);
     }
     // check if test data is written to DB
     $sqlToFetchProperties = 'SELECT `userid`, `propertypath`, `propertyname`, `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ?';
     $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
     $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
     $this->assertCount(2, $entries, 'Asserts that two entries are returned as we have inserted two');
     foreach ($entries as $entry) {
         $this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set');
     }
     /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder('\\OCP\\Migration\\IOutput')->disableOriginalConstructor()->getMock();
     // run repair step
     $repair = new RemoveGetETagEntries($this->connection);
     $repair->run($outputMock);
     // check if test data is correctly modified in DB
     $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
     $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
     $this->assertCount(1, $entries, 'Asserts that only one entry is returned after the repair step - the other one has to be removed');
     $this->assertSame($data[1], $entries[0], 'Asserts that the returned entry is the correct one from the test data set');
     // remove test data
     $sqlToRemoveProperties = 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ?';
     $this->connection->executeUpdate($sqlToRemoveProperties, [$userName]);
 }
예제 #2
0
 /**
  * Test clearing orphaned files
  */
 public function testClearFiles()
 {
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->disableOriginalConstructor()->getMock();
     $output = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->disableOriginalConstructor()->getMock();
     $this->loginAsUser($this->user1);
     $view = new \OC\Files\View('/' . $this->user1 . '/');
     $view->mkdir('files/test');
     $fileInfo = $view->getFileInfo('files/test');
     $storageId = $fileInfo->getStorage()->getId();
     $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is available');
     $this->command->execute($input, $output);
     $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is still available');
     $deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]);
     $this->assertNotNull($deletedRows, 'Asserts that storage got deleted');
     $this->assertSame(1, $deletedRows, 'Asserts that storage got deleted');
     // parent folder, `files`, ´test` and `welcome.txt` => 4 elements
     $output->expects($this->once())->method('writeln')->with('4 orphaned file cache entries deleted');
     $this->command->execute($input, $output);
     $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up');
     // since we deleted the storage it might throw a (valid) StorageNotAvailableException
     try {
         $view->unlink('files/test');
     } catch (StorageNotAvailableException $e) {
     }
 }
 /**
  * @param string $path
  * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
  */
 public function releaseLock($path, $type)
 {
     // we DONT keep shared locks till the end of the request
     if ($type === self::LOCK_SHARED) {
         $this->db->executeUpdate('UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1', [$path]);
     }
     parent::releaseLock($path, $type);
 }
예제 #4
0
 /**
  * @param IDBConnection $connection
  * @throws \OC\DatabaseSetupException
  */
 private function createDBUser($connection)
 {
     $name = $this->dbUser;
     $password = $this->dbPassword;
     // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
     // the anonymous user would take precedence when there is one.
     $query = "CREATE USER '{$name}'@'localhost' IDENTIFIED BY '{$password}'";
     $connection->executeUpdate($query);
     $query = "CREATE USER '{$name}'@'%' IDENTIFIED BY '{$password}'";
     $connection->executeUpdate($query);
 }
예제 #5
0
 protected function tearDown()
 {
     $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
     $userManager = \OC::$server->getUserManager();
     $user1 = $userManager->get($this->user1);
     if ($user1) {
         $user1->delete();
     }
     $user2 = $userManager->get($this->user2);
     if ($user2) {
         $user2->delete();
     }
     $this->logout();
     parent::tearDown();
 }
예제 #6
0
	public function testGetUsersForUserValue() {
		// mock the check for the database to run the correct SQL statements for each database type
		$systemConfig = $this->getMock('\OC\SystemConfig');
		$systemConfig->expects($this->once())
			->method('getValue')
			->with($this->equalTo('dbtype'),
				$this->equalTo('sqlite'))
			->will($this->returnValue(\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite')));
		$config = $this->getConfig($systemConfig);

		// preparation - add something to the database
		$data = array(
			array('user1', 'appFetch9', 'keyFetch9', 'value9'),
			array('user2', 'appFetch9', 'keyFetch9', 'value9'),
			array('user3', 'appFetch9', 'keyFetch9', 'value8'),
			array('user4', 'appFetch9', 'keyFetch8', 'value9'),
			array('user5', 'appFetch8', 'keyFetch9', 'value9'),
			array('user6', 'appFetch9', 'keyFetch9', 'value9'),
		);
		foreach ($data as $entry) {
			$this->connection->executeUpdate(
				'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
				'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
				$entry
			);
		}

		$value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9');
		$this->assertEquals(array('user1', 'user2', 'user6'), $value);

		// cleanup
		$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
	}
 /**
  * Update properties
  *
  * @param Node $node node for which to update properties
  * @param array $properties array of properties to update
  *
  * @return bool
  */
 private function updateProperties($node, $properties)
 {
     $path = $node->getPath();
     $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
     $insertStatement = 'INSERT INTO `*PREFIX*properties`' . ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
     $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
     // TODO: use "insert or update" strategy ?
     $existing = $this->getProperties($node, array());
     $this->connection->beginTransaction();
     foreach ($properties as $propertyName => $propertyValue) {
         // If it was null, we need to delete the property
         if (is_null($propertyValue)) {
             if (array_key_exists($propertyName, $existing)) {
                 $this->connection->executeUpdate($deleteStatement, array($this->user, $path, $propertyName));
             }
         } else {
             if (!array_key_exists($propertyName, $existing)) {
                 $this->connection->executeUpdate($insertStatement, array($this->user, $path, $propertyName, $propertyValue));
             } else {
                 $this->connection->executeUpdate($updateStatement, array($propertyValue, $this->user, $path, $propertyName));
             }
         }
     }
     $this->connection->commit();
     unset($this->cache[$path]);
     return true;
 }
예제 #8
0
 /**
  * Create a storage entry
  *
  * @param string $storageId
  * @return int
  */
 private function createStorage($storageId)
 {
     $sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)';
     $storageId = Storage::adjustStorageId($storageId);
     $numRows = $this->connection->executeUpdate($sql, array($storageId));
     $this->assertEquals(1, $numRows);
     return \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages');
 }
예제 #9
0
 /**
  * Create a storage entry
  *
  * @param string $storageId
  * @return int
  */
 private function createStorage($storageId)
 {
     $sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)';
     $storageId = Storage::adjustStorageId($storageId);
     $numRows = $this->connection->executeUpdate($sql, array($storageId));
     $this->assertEquals(1, $numRows);
     return \OC_DB::insertid('*PREFIX*storages');
 }
예제 #10
0
 /**
  * Delete all user related values of one app
  *
  * @param string $appName the appName of the app that we want to remove all values from
  */
 public function deleteAppFromAllUsers($appName)
 {
     // TODO - FIXME
     $this->fixDIInit();
     $sql = 'DELETE FROM `*PREFIX*preferences` ' . 'WHERE `appid` = ?';
     $this->connection->executeUpdate($sql, array($appName));
     foreach ($this->userCache as &$userCache) {
         unset($userCache[$appName]);
     }
 }
예제 #11
0
 /**
  * release all lock acquired by this instance which were marked using the mark* methods
  */
 public function releaseAll()
 {
     parent::releaseAll();
     // since we keep shared locks we need to manually clean those
     foreach ($this->sharedLocks as $path => $lock) {
         if ($lock) {
             $this->connection->executeUpdate('UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `key` = ? AND `lock` > 0', [$path]);
         }
     }
 }
예제 #12
0
 /**
  * cleanup empty locks
  */
 public function cleanExpiredLocks()
 {
     $expire = $this->timeFactory->getTime();
     try {
         $this->connection->executeUpdate('DELETE FROM `*PREFIX*file_locks` WHERE `ttl` < ?', [$expire]);
     } catch (\Exception $e) {
         // If the table is missing, the clean up was successful
         if ($this->connection->tableExists('file_locks')) {
             throw $e;
         }
     }
 }
예제 #13
0
 /**
  * Update music path
  */
 public function updatePath($path, $userId = null)
 {
     // TODO currently this function is quite dumb
     // it just drops all entries of an user from the tables
     if ($userId === null) {
         $userId = $this->userId;
     }
     $sqls = array('DELETE FROM `*PREFIX*music_tracks` WHERE `user_id` = ?;', 'DELETE FROM `*PREFIX*music_albums` WHERE `user_id` = ?;', 'DELETE FROM `*PREFIX*music_artists` WHERE `user_id` = ?;');
     foreach ($sqls as $sql) {
         $this->db->executeUpdate($sql, array($userId));
     }
     $this->db->executeUpdate('DELETE FROM `*PREFIX*music_album_artists` WHERE `album_id` NOT IN (SELECT `id` FROM `*PREFIX*music_albums` GROUP BY `id`);');
 }
예제 #14
0
 /**
  * cleanup empty locks
  */
 public function cleanEmptyLocks()
 {
     $this->connection->executeUpdate('DELETE FROM `*PREFIX*file_locks` WHERE `lock` = 0');
 }
예제 #15
0
/**
 * @param \OCP\IDBConnection $conn
 */
function owncloud_reset_encrypted_flag(\OCP\IDBConnection $conn)
{
    $conn->executeUpdate('UPDATE `*PREFIX*filecache` SET `encrypted` = 0 WHERE `encrypted` = 1');
}
예제 #16
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $sql = 'DELETE FROM `*PREFIX*filecache` ' . 'WHERE NOT EXISTS ' . '(SELECT 1 FROM `*PREFIX*storages` WHERE `storage` = `numeric_id`)';
     $deletedEntries = $this->connection->executeUpdate($sql);
     $output->writeln("{$deletedEntries} orphaned file cache entries deleted");
 }
예제 #17
0
 /**
  * Removes all entries with the key "{DAV:}getetag" from the table properties
  */
 public function run(IOutput $out)
 {
     $sql = 'DELETE FROM `*PREFIX*properties`' . ' WHERE `propertyname` = ?';
     $deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
     $out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
 }
예제 #18
0
파일: db.php 프로젝트: farukuzun/core-1
 /**
  * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  * and returns the number of affected rows.
  *
  * This method supports PDO binding types as well as DBAL mapping types.
  *
  * @param string $query The SQL query.
  * @param array $params The query parameters.
  * @param array $types The parameter types.
  * @return integer The number of affected rows.
  */
 public function executeUpdate($query, array $params = array(), array $types = array())
 {
     return $this->connection->executeUpdate($query, $params, $types);
 }
예제 #19
0
 /**
  * cleanup empty locks
  */
 public function cleanEmptyLocks()
 {
     $expire = $this->timeFactory->getTime();
     $this->connection->executeUpdate('DELETE FROM `*PREFIX*file_locks` WHERE `lock` = 0 AND `ttl` < ?', [$expire]);
 }
예제 #20
0
 /**
  * Removes all entries with the key "{DAV:}getetag" from the table properties
  */
 public function run()
 {
     $sql = 'DELETE FROM `*PREFIX*properties`' . ' WHERE `propertyname` = ?';
     $deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
     $this->emit('\\OC\\Repair', 'info', ['Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.']);
 }