Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2016-08-29 21:27:39 +0300
committerGitHub <noreply@github.com>2016-08-29 21:27:39 +0300
commit1062583a2ef13fde27c69287ea072d0e02be304a (patch)
tree354a41e4e918edbd0ab4d13752e2affe165e527d
parentd2d15082764badd43ed2aa8d44253ff94b7d1b18 (diff)
parent90cafa3c9b5a3278ea25f3d50c59ad541dca645f (diff)
Merge pull request #1149 from nextcloud/stable9-database-reconnect
[9.0] Before a user is getting scanned the database connection is re-…
-rw-r--r--apps/files/command/scan.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php
index 2b316fac7c0..64b1473cc1c 100644
--- a/apps/files/command/scan.php
+++ b/apps/files/command/scan.php
@@ -27,9 +27,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;
@@ -91,7 +93,8 @@ class Scan extends Base {
}
protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
- $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) {
@@ -291,4 +294,26 @@ class Scan extends Base {
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;
+ }
+
}