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
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2016-08-29 21:25:59 +0300
committerGitHub <noreply@github.com>2016-08-29 21:25:59 +0300
commit1f8c3c153c3dc1700853f50dc745d51994761014 (patch)
tree9a5ef86549804da32454a38ba95a8f0208421d8c /apps
parent613704c58e4f9b80716df569248b381300540c98 (diff)
parenta4cf4a53f39bfabc1f34c36615bd49e7a84c8c03 (diff)
Merge pull request #1148 from nextcloud/files-scan-reconnect-database-before-each-user-master
Before a user is getting scanned the database connection is re-establ…
Diffstat (limited to 'apps')
-rw-r--r--apps/files/lib/Command/Scan.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index 25933ae25aa..0234fb435a7 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 @@ class Scan extends Base {
}
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 @@ 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;
+ }
+
}