Skip to content

Commit

Permalink
Merge pull request #1159 from nextcloud/stable9.1-27a5be96f108d4ab2b9…
Browse files Browse the repository at this point in the history
…1bcd765433e1646ba9bf2

[9.1] Before a user is getting scanned the database connection is re-…
  • Loading branch information
LukasReschke authored Aug 29, 2016
2 parents 0a1b1d5 + db420e5 commit dbc860e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/files/lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

namespace OCA\Files\Command;

use Doctrine\DBAL\Connection;
use OC\Core\Command\Base;
use OC\ForbiddenException;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -106,7 +108,8 @@ public function checkScanWarning($fullPath, OutputInterface $output) {
}

protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false) {
$scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$connection = $this->reconnectToDatabase($output);
$scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger());
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
# printout and count
if ($verbose) {
Expand Down Expand Up @@ -318,4 +321,26 @@ protected function formatExecTime() {
return date('H:i:s', $secs);
}

/**
* @return \OCP\IDBConnection
*/
protected function reconnectToDatabase(OutputInterface $output) {
/** @var Connection | IDBConnection $connection*/
$connection = \OC::$server->getDatabaseConnection();
try {
$connection->close();
} catch (\Exception $ex) {
$output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
}
while (!$connection->isConnected()) {
try {
$connection->connect();
} catch (\Exception $ex) {
$output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>");
sleep(60);
}
}
return $connection;
}

}

0 comments on commit dbc860e

Please sign in to comment.