Exemplo n.º 1
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->getQueryBuilder();
         $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->getQueryBuilder();
         $result = $getAllQuery->select('id')->from($this->trashTable)->execute()->fetchAll();
         $this->assertSame(10, count($result));
     }
 }
Exemplo n.º 2
0
 protected function copyTable(Connection $fromDB, Connection $toDB, $table, InputInterface $input, OutputInterface $output)
 {
     $chunkSize = $input->getOption('chunk-size');
     /** @var $progress \Symfony\Component\Console\Helper\ProgressHelper */
     $progress = $this->getHelperSet()->get('progress');
     $query = $fromDB->getQueryBuilder();
     $query->automaticTablePrefix(false);
     $query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')->from($table);
     $result = $query->execute();
     $count = $result->fetchColumn();
     $result->closeCursor();
     $numChunks = ceil($count / $chunkSize);
     if ($numChunks > 1) {
         $output->writeln('chunked query, ' . $numChunks . ' chunks');
     }
     $progress->start($output, $count);
     $redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1);
     $progress->setRedrawFrequency($redraw);
     $query = $fromDB->getQueryBuilder();
     $query->automaticTablePrefix(false);
     $query->select('*')->from($table)->setMaxResults($chunkSize);
     $insertQuery = $toDB->getQueryBuilder();
     $insertQuery->automaticTablePrefix(false);
     $insertQuery->insert($table);
     $parametersCreated = false;
     for ($chunk = 0; $chunk < $numChunks; $chunk++) {
         $query->setFirstResult($chunk * $chunkSize);
         $result = $query->execute();
         while ($row = $result->fetch()) {
             $progress->advance();
             if (!$parametersCreated) {
                 foreach ($row as $key => $value) {
                     $insertQuery->setValue($key, $insertQuery->createParameter($key));
                 }
                 $parametersCreated = true;
             }
             foreach ($row as $key => $value) {
                 $insertQuery->setParameter($key, $value);
             }
             $insertQuery->execute();
         }
         $result->closeCursor();
     }
     $progress->finish();
 }