From db420e54a15c0b50fd2445302c2d25119f1bc6d6 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 22 Aug 2016 10:55:30 +0200 Subject: [PATCH] =?UTF-8?q?[9.1]=20Before=20a=20user=20is=20getting=20scan?= =?UTF-8?q?ned=20the=20database=20connection=20is=20re-establ=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/files/lib/Command/Scan.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index 25933ae25aa0b..0234fb435a758 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -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; @@ -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) { @@ -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("Error while disconnecting from database: {$ex->getMessage()}"); + } + while (!$connection->isConnected()) { + try { + $connection->connect(); + } catch (\Exception $ex) { + $output->writeln("Error while re-connecting to database: {$ex->getMessage()}"); + sleep(60); + } + } + return $connection; + } + }