Exemplo n.º 1
0
 public function run()
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->update('`*PREFIX*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."));
 }
Exemplo n.º 2
0
 /**
  * @dataProvider dataTestRemoveDeletedFiles
  * @param boolean $nodeExists
  */
 public function testRemoveDeletedFiles($nodeExists)
 {
     $this->initTable();
     $this->rootFolder->expects($this->once())->method('nodeExists')->with('/' . $this->user0 . '/files_trashbin')->willReturn($nodeExists);
     if ($nodeExists) {
         $this->rootFolder->expects($this->once())->method('get')->with('/' . $this->user0 . '/files_trashbin')->willReturn($this->rootFolder);
         $this->rootFolder->expects($this->once())->method('delete');
     } else {
         $this->rootFolder->expects($this->never())->method('get');
         $this->rootFolder->expects($this->never())->method('delete');
     }
     $this->invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0]);
     if ($nodeExists) {
         // if the delete operation was execute only files from user1
         // should be left.
         $query = $this->dbConnection->createQueryBuilder();
         $result = $query->select('`user`')->from($this->trashTable)->execute()->fetchAll();
         $this->assertSame(5, count($result));
         foreach ($result as $r) {
             $this->assertSame('user1', $r['user']);
         }
     } else {
         // if no delete operation was execute we should still have all 10
         // database entries
         $getAllQuery = $this->dbConnection->createQueryBuilder();
         $result = $getAllQuery->select('`id`')->from($this->trashTable)->execute()->fetchAll();
         $this->assertSame(10, count($result));
     }
 }
Exemplo n.º 3
0
 /**
  * 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->createQueryBuilder();
     $oldAppValues->select('*')->from('`*PREFIX*appconfig`')->where($oldAppValues->expr()->eq('`appid`', ':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->createQueryBuilder();
     $oldPreferences->select('*')->from('`*PREFIX*preferences`')->where($oldPreferences->expr()->eq('`appid`', ':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']);
     }
 }
Exemplo n.º 4
0
 /**
  * remove deleted files for the given user
  *
  * @param string $uid
  */
 protected function removeDeletedFiles($uid)
 {
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($uid);
     if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) {
         $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete();
         $query = $this->dbConnection->createQueryBuilder();
         $query->delete('`*PREFIX*files_trash`')->where($query->expr()->eq('`user`', ':uid'))->setParameter('uid', $uid);
         $query->execute();
     }
 }
Exemplo n.º 5
0
 /**
  * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable
  *
  * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks
  * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable
  * is being deleted.
  *
  * @param string $repairInfo
  * @param string $deleteTable
  * @param string $deleteId
  * @param string $sourceTable
  * @param string $sourceId
  * @param string $sourceNullColumn	If this column is null in the source table,
  * 								the entry is deleted in the $deleteTable
  */
 protected function deleteOrphanEntries($repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn)
 {
     $qb = $this->connection->createQueryBuilder();
     $qb->select('d.`' . $deleteId . '`')->from('`' . $deleteTable . '`', 'd')->leftJoin('d', '`' . $sourceTable . '`', 's', 'd.`' . $deleteId . '` = s.`' . $sourceId . '`')->where('d.`type` = ' . $qb->expr()->literal('files'))->andWhere($qb->expr()->isNull('s.`' . $sourceNullColumn . '`'));
     $result = $qb->execute();
     $orphanItems = array();
     while ($row = $result->fetch()) {
         $orphanItems[] = (int) $row[$deleteId];
     }
     if (!empty($orphanItems)) {
         $orphanItemsBatch = array_chunk($orphanItems, 200);
         foreach ($orphanItemsBatch as $items) {
             $qb->delete('`' . $deleteTable . '`')->where('`type` = ' . $qb->expr()->literal('files'))->andWhere($qb->expr()->in('`' . $deleteId . '`', ':ids'));
             $qb->setParameter('ids', $items, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY);
             $qb->execute();
         }
     }
     if ($repairInfo) {
         $this->emit('\\OC\\Repair', 'info', array(sprintf($repairInfo, sizeof($orphanItems))));
     }
 }
Exemplo n.º 6
0
 /**
  * update database
  */
 public function updateDB()
 {
     // 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');
     $query = $this->connection->createQueryBuilder();
     $query->update('`*PREFIX*appconfig`')->set('`appid`', ':newappid')->where($query->expr()->eq('`appid`', ':oldappid'))->setParameter('oldappid', 'files_encryption')->setParameter('newappid', 'encryption');
     $query->execute();
     $query = $this->connection->createQueryBuilder();
     $query->update('`*PREFIX*preferences`')->set('`appid`', ':newappid')->where($query->expr()->eq('`appid`', ':oldappid'))->setParameter('oldappid', 'files_encryption')->setParameter('newappid', 'encryption');
     $query->execute();
 }
Exemplo n.º 7
0
 /**
  * Retrieve the owner of a connection
  *
  * @param Connection $connection
  * @param int $shareId
  * @throws \Exception
  * @return string uid of share owner
  */
 private static function getShareOwner(Connection $connection, $shareId)
 {
     $qb = $connection->createQueryBuilder();
     $qb->select('`uid_owner`')->from('`*PREFIX*share`')->where('`id` = :shareId')->setParameter(':shareId', $shareId);
     $result = $qb->execute();
     $result = $result->fetch();
     if (empty($result)) {
         throw new \Exception('Share not found');
     }
     return $result['uid_owner'];
 }