Completed
Push — master ( 738385...cbc573 )
by Blizzz
33:01 queued 15s
created
lib/private/Repair/Owncloud/CleanPreviews.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 
65 65
 	public function run(IOutput $output) {
66 66
 		if (!$this->config->getAppValue('core', 'previewsCleanedUp', false)) {
67
-			$this->userManager->callForSeenUsers(function (IUser $user) {
67
+			$this->userManager->callForSeenUsers(function(IUser $user) {
68 68
 				$this->jobList->add(CleanPreviewsBackgroundJob::class, ['uid' => $user->getUID()]);
69 69
 			});
70 70
 			$this->config->setAppValue('core', 'previewsCleanedUp', '1');
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
 use OCP\Migration\IRepairStep;
15 15
 
16 16
 class CleanPreviews implements IRepairStep {
17
-	/** @var IJobList */
18
-	private $jobList;
19
-
20
-	/** @var IUserManager */
21
-	private $userManager;
22
-
23
-	/** @var IConfig */
24
-	private $config;
25
-
26
-	/**
27
-	 * MoveAvatars constructor.
28
-	 *
29
-	 * @param IJobList $jobList
30
-	 * @param IUserManager $userManager
31
-	 * @param IConfig $config
32
-	 */
33
-	public function __construct(IJobList $jobList,
34
-		IUserManager $userManager,
35
-		IConfig $config) {
36
-		$this->jobList = $jobList;
37
-		$this->userManager = $userManager;
38
-		$this->config = $config;
39
-	}
40
-
41
-	/**
42
-	 * @return string
43
-	 */
44
-	public function getName() {
45
-		return 'Add preview cleanup background jobs';
46
-	}
47
-
48
-	public function run(IOutput $output) {
49
-		if (!$this->config->getAppValue('core', 'previewsCleanedUp', false)) {
50
-			$this->userManager->callForSeenUsers(function (IUser $user) {
51
-				$this->jobList->add(CleanPreviewsBackgroundJob::class, ['uid' => $user->getUID()]);
52
-			});
53
-			$this->config->setAppValue('core', 'previewsCleanedUp', '1');
54
-		}
55
-	}
17
+    /** @var IJobList */
18
+    private $jobList;
19
+
20
+    /** @var IUserManager */
21
+    private $userManager;
22
+
23
+    /** @var IConfig */
24
+    private $config;
25
+
26
+    /**
27
+     * MoveAvatars constructor.
28
+     *
29
+     * @param IJobList $jobList
30
+     * @param IUserManager $userManager
31
+     * @param IConfig $config
32
+     */
33
+    public function __construct(IJobList $jobList,
34
+        IUserManager $userManager,
35
+        IConfig $config) {
36
+        $this->jobList = $jobList;
37
+        $this->userManager = $userManager;
38
+        $this->config = $config;
39
+    }
40
+
41
+    /**
42
+     * @return string
43
+     */
44
+    public function getName() {
45
+        return 'Add preview cleanup background jobs';
46
+    }
47
+
48
+    public function run(IOutput $output) {
49
+        if (!$this->config->getAppValue('core', 'previewsCleanedUp', false)) {
50
+            $this->userManager->callForSeenUsers(function (IUser $user) {
51
+                $this->jobList->add(CleanPreviewsBackgroundJob::class, ['uid' => $user->getUID()]);
52
+            });
53
+            $this->config->setAppValue('core', 'previewsCleanedUp', '1');
54
+        }
55
+    }
56 56
 }
Please login to merge, or discard this patch.
lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -72,17 +72,17 @@
 block discarded – undo
72 72
 	public function run($arguments) {
73 73
 		$uid = $arguments['uid'];
74 74
 		if (!$this->userManager->userExists($uid)) {
75
-			$this->logger->info('User no longer exists, skip user ' . $uid);
75
+			$this->logger->info('User no longer exists, skip user '.$uid);
76 76
 			return;
77 77
 		}
78
-		$this->logger->info('Started preview cleanup for ' . $uid);
78
+		$this->logger->info('Started preview cleanup for '.$uid);
79 79
 		$empty = $this->cleanupPreviews($uid);
80 80
 
81 81
 		if (!$empty) {
82 82
 			$this->jobList->add(self::class, ['uid' => $uid]);
83
-			$this->logger->info('New preview cleanup scheduled for ' . $uid);
83
+			$this->logger->info('New preview cleanup scheduled for '.$uid);
84 84
 		} else {
85
-			$this->logger->info('Preview cleanup done for ' . $uid);
85
+			$this->logger->info('Preview cleanup done for '.$uid);
86 86
 		}
87 87
 	}
88 88
 
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -19,73 +19,73 @@
 block discarded – undo
19 19
 use Psr\Log\LoggerInterface;
20 20
 
21 21
 class CleanPreviewsBackgroundJob extends QueuedJob {
22
-	public function __construct(
23
-		private IRootFolder $rootFolder,
24
-		private LoggerInterface $logger,
25
-		private IJobList $jobList,
26
-		ITimeFactory $timeFactory,
27
-		private IUserManager $userManager,
28
-	) {
29
-		parent::__construct($timeFactory);
30
-	}
22
+    public function __construct(
23
+        private IRootFolder $rootFolder,
24
+        private LoggerInterface $logger,
25
+        private IJobList $jobList,
26
+        ITimeFactory $timeFactory,
27
+        private IUserManager $userManager,
28
+    ) {
29
+        parent::__construct($timeFactory);
30
+    }
31 31
 
32
-	public function run($arguments) {
33
-		$uid = $arguments['uid'];
34
-		if (!$this->userManager->userExists($uid)) {
35
-			$this->logger->info('User no longer exists, skip user ' . $uid);
36
-			return;
37
-		}
38
-		$this->logger->info('Started preview cleanup for ' . $uid);
39
-		$empty = $this->cleanupPreviews($uid);
32
+    public function run($arguments) {
33
+        $uid = $arguments['uid'];
34
+        if (!$this->userManager->userExists($uid)) {
35
+            $this->logger->info('User no longer exists, skip user ' . $uid);
36
+            return;
37
+        }
38
+        $this->logger->info('Started preview cleanup for ' . $uid);
39
+        $empty = $this->cleanupPreviews($uid);
40 40
 
41
-		if (!$empty) {
42
-			$this->jobList->add(self::class, ['uid' => $uid]);
43
-			$this->logger->info('New preview cleanup scheduled for ' . $uid);
44
-		} else {
45
-			$this->logger->info('Preview cleanup done for ' . $uid);
46
-		}
47
-	}
41
+        if (!$empty) {
42
+            $this->jobList->add(self::class, ['uid' => $uid]);
43
+            $this->logger->info('New preview cleanup scheduled for ' . $uid);
44
+        } else {
45
+            $this->logger->info('Preview cleanup done for ' . $uid);
46
+        }
47
+    }
48 48
 
49
-	/**
50
-	 * @param string $uid
51
-	 */
52
-	private function cleanupPreviews($uid): bool {
53
-		try {
54
-			$userFolder = $this->rootFolder->getUserFolder($uid);
55
-		} catch (NotFoundException $e) {
56
-			return true;
57
-		}
49
+    /**
50
+     * @param string $uid
51
+     */
52
+    private function cleanupPreviews($uid): bool {
53
+        try {
54
+            $userFolder = $this->rootFolder->getUserFolder($uid);
55
+        } catch (NotFoundException $e) {
56
+            return true;
57
+        }
58 58
 
59
-		$userRoot = $userFolder->getParent();
59
+        $userRoot = $userFolder->getParent();
60 60
 
61
-		try {
62
-			/** @var Folder $thumbnailFolder */
63
-			$thumbnailFolder = $userRoot->get('thumbnails');
64
-		} catch (NotFoundException $e) {
65
-			return true;
66
-		}
61
+        try {
62
+            /** @var Folder $thumbnailFolder */
63
+            $thumbnailFolder = $userRoot->get('thumbnails');
64
+        } catch (NotFoundException $e) {
65
+            return true;
66
+        }
67 67
 
68
-		$thumbnails = $thumbnailFolder->getDirectoryListing();
68
+        $thumbnails = $thumbnailFolder->getDirectoryListing();
69 69
 
70
-		$start = $this->time->getTime();
71
-		foreach ($thumbnails as $thumbnail) {
72
-			try {
73
-				$thumbnail->delete();
74
-			} catch (NotPermittedException $e) {
75
-				// Ignore
76
-			}
70
+        $start = $this->time->getTime();
71
+        foreach ($thumbnails as $thumbnail) {
72
+            try {
73
+                $thumbnail->delete();
74
+            } catch (NotPermittedException $e) {
75
+                // Ignore
76
+            }
77 77
 
78
-			if (($this->time->getTime() - $start) > 15) {
79
-				return false;
80
-			}
81
-		}
78
+            if (($this->time->getTime() - $start) > 15) {
79
+                return false;
80
+            }
81
+        }
82 82
 
83
-		try {
84
-			$thumbnailFolder->delete();
85
-		} catch (NotPermittedException $e) {
86
-			// Ignore
87
-		}
83
+        try {
84
+            $thumbnailFolder->delete();
85
+        } catch (NotPermittedException $e) {
86
+            // Ignore
87
+        }
88 88
 
89
-		return true;
90
-	}
89
+        return true;
90
+    }
91 91
 }
Please login to merge, or discard this patch.
lib/private/Repair/Owncloud/UpdateLanguageCodes.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 				->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR))
85 85
 				->execute();
86 86
 
87
-			$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
87
+			$output->info('Changed '.$affectedRows.' setting(s) from "'.$oldCode.'" to "'.$newCode.'" in preferences table.');
88 88
 		}
89 89
 	}
90 90
 }
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -12,60 +12,60 @@
 block discarded – undo
12 12
 use OCP\Migration\IRepairStep;
13 13
 
14 14
 class UpdateLanguageCodes implements IRepairStep {
15
-	/** @var IDBConnection */
16
-	private $connection;
15
+    /** @var IDBConnection */
16
+    private $connection;
17 17
 
18
-	/** @var IConfig */
19
-	private $config;
18
+    /** @var IConfig */
19
+    private $config;
20 20
 
21
-	/**
22
-	 * @param IDBConnection $connection
23
-	 * @param IConfig $config
24
-	 */
25
-	public function __construct(IDBConnection $connection,
26
-		IConfig $config) {
27
-		$this->connection = $connection;
28
-		$this->config = $config;
29
-	}
21
+    /**
22
+     * @param IDBConnection $connection
23
+     * @param IConfig $config
24
+     */
25
+    public function __construct(IDBConnection $connection,
26
+        IConfig $config) {
27
+        $this->connection = $connection;
28
+        $this->config = $config;
29
+    }
30 30
 
31
-	/**
32
-	 * {@inheritdoc}
33
-	 */
34
-	public function getName() {
35
-		return 'Repair language codes';
36
-	}
31
+    /**
32
+     * {@inheritdoc}
33
+     */
34
+    public function getName() {
35
+        return 'Repair language codes';
36
+    }
37 37
 
38
-	/**
39
-	 * {@inheritdoc}
40
-	 */
41
-	public function run(IOutput $output) {
42
-		$versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0');
38
+    /**
39
+     * {@inheritdoc}
40
+     */
41
+    public function run(IOutput $output) {
42
+        $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0');
43 43
 
44
-		if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) {
45
-			return;
46
-		}
44
+        if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) {
45
+            return;
46
+        }
47 47
 
48
-		$languages = [
49
-			'bg_BG' => 'bg',
50
-			'cs_CZ' => 'cs',
51
-			'fi_FI' => 'fi',
52
-			'hu_HU' => 'hu',
53
-			'nb_NO' => 'nb',
54
-			'sk_SK' => 'sk',
55
-			'th_TH' => 'th',
56
-		];
48
+        $languages = [
49
+            'bg_BG' => 'bg',
50
+            'cs_CZ' => 'cs',
51
+            'fi_FI' => 'fi',
52
+            'hu_HU' => 'hu',
53
+            'nb_NO' => 'nb',
54
+            'sk_SK' => 'sk',
55
+            'th_TH' => 'th',
56
+        ];
57 57
 
58
-		foreach ($languages as $oldCode => $newCode) {
59
-			$qb = $this->connection->getQueryBuilder();
58
+        foreach ($languages as $oldCode => $newCode) {
59
+            $qb = $this->connection->getQueryBuilder();
60 60
 
61
-			$affectedRows = $qb->update('preferences')
62
-				->set('configvalue', $qb->createNamedParameter($newCode))
63
-				->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
64
-				->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
65
-				->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR))
66
-				->execute();
61
+            $affectedRows = $qb->update('preferences')
62
+                ->set('configvalue', $qb->createNamedParameter($newCode))
63
+                ->where($qb->expr()->eq('appid', $qb->createNamedParameter('core')))
64
+                ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang')))
65
+                ->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode), IQueryBuilder::PARAM_STR))
66
+                ->execute();
67 67
 
68
-			$output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
69
-		}
70
-	}
68
+            $output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.');
69
+        }
70
+    }
71 71
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Migration/Version1010Date20200630192639.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -33,55 +33,55 @@
 block discarded – undo
33 33
 use OCP\Migration\SimpleMigrationStep;
34 34
 
35 35
 class Version1010Date20200630192639 extends SimpleMigrationStep {
36
-	/**
37
-	 * @param IOutput $output
38
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
-	 * @param array $options
40
-	 * @return null|ISchemaWrapper
41
-	 */
42
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
43
-		/** @var ISchemaWrapper $schema */
44
-		$schema = $schemaClosure();
36
+    /**
37
+     * @param IOutput $output
38
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
+     * @param array $options
40
+     * @return null|ISchemaWrapper
41
+     */
42
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
43
+        /** @var ISchemaWrapper $schema */
44
+        $schema = $schemaClosure();
45 45
 
46
-		if (!$schema->hasTable('files_trash')) {
47
-			$table = $schema->createTable('files_trash');
48
-			$table->addColumn('auto_id', Types::BIGINT, [
49
-				'autoincrement' => true,
50
-				'notnull' => true,
51
-			]);
52
-			$table->addColumn('id', Types::STRING, [
53
-				'notnull' => true,
54
-				'length' => 250,
55
-				'default' => '',
56
-			]);
57
-			$table->addColumn('user', Types::STRING, [
58
-				'notnull' => true,
59
-				'length' => 64,
60
-				'default' => '',
61
-			]);
62
-			$table->addColumn('timestamp', Types::STRING, [
63
-				'notnull' => true,
64
-				'length' => 12,
65
-				'default' => '',
66
-			]);
67
-			$table->addColumn('location', Types::STRING, [
68
-				'notnull' => true,
69
-				'length' => 512,
70
-				'default' => '',
71
-			]);
72
-			$table->addColumn('type', Types::STRING, [
73
-				'notnull' => false,
74
-				'length' => 4,
75
-			]);
76
-			$table->addColumn('mime', Types::STRING, [
77
-				'notnull' => false,
78
-				'length' => 255,
79
-			]);
80
-			$table->setPrimaryKey(['auto_id']);
81
-			$table->addIndex(['id'], 'id_index');
82
-			$table->addIndex(['timestamp'], 'timestamp_index');
83
-			$table->addIndex(['user'], 'user_index');
84
-		}
85
-		return $schema;
86
-	}
46
+        if (!$schema->hasTable('files_trash')) {
47
+            $table = $schema->createTable('files_trash');
48
+            $table->addColumn('auto_id', Types::BIGINT, [
49
+                'autoincrement' => true,
50
+                'notnull' => true,
51
+            ]);
52
+            $table->addColumn('id', Types::STRING, [
53
+                'notnull' => true,
54
+                'length' => 250,
55
+                'default' => '',
56
+            ]);
57
+            $table->addColumn('user', Types::STRING, [
58
+                'notnull' => true,
59
+                'length' => 64,
60
+                'default' => '',
61
+            ]);
62
+            $table->addColumn('timestamp', Types::STRING, [
63
+                'notnull' => true,
64
+                'length' => 12,
65
+                'default' => '',
66
+            ]);
67
+            $table->addColumn('location', Types::STRING, [
68
+                'notnull' => true,
69
+                'length' => 512,
70
+                'default' => '',
71
+            ]);
72
+            $table->addColumn('type', Types::STRING, [
73
+                'notnull' => false,
74
+                'length' => 4,
75
+            ]);
76
+            $table->addColumn('mime', Types::STRING, [
77
+                'notnull' => false,
78
+                'length' => 255,
79
+            ]);
80
+            $table->setPrimaryKey(['auto_id']);
81
+            $table->addIndex(['id'], 'id_index');
82
+            $table->addIndex(['timestamp'], 'timestamp_index');
83
+            $table->addIndex(['user'], 'user_index');
84
+        }
85
+        return $schema;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Migration/Version21000Date20201223143245.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -34,37 +34,37 @@
 block discarded – undo
34 34
 use OCP\Migration\SimpleMigrationStep;
35 35
 
36 36
 class Version21000Date20201223143245 extends SimpleMigrationStep {
37
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
38
-		/** @var ISchemaWrapper $schema */
39
-		$schema = $schemaClosure();
37
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
38
+        /** @var ISchemaWrapper $schema */
39
+        $schema = $schemaClosure();
40 40
 
41
-		if ($schema->hasTable('share_external')) {
42
-			$table = $schema->getTable('share_external');
43
-			$changed = false;
44
-			if (!$table->hasColumn('parent')) {
45
-				$table->addColumn('parent', Types::BIGINT, [
46
-					'notnull' => false,
47
-					'default' => -1,
48
-				]);
49
-				$changed = true;
50
-			}
51
-			if (!$table->hasColumn('share_type')) {
52
-				$table->addColumn('share_type', Types::INTEGER, [
53
-					'notnull' => false,
54
-					'length' => 4,
55
-				]);
56
-				$changed = true;
57
-			}
58
-			if ($table->hasColumn('lastscan')) {
59
-				$table->dropColumn('lastscan');
60
-				$changed = true;
61
-			}
41
+        if ($schema->hasTable('share_external')) {
42
+            $table = $schema->getTable('share_external');
43
+            $changed = false;
44
+            if (!$table->hasColumn('parent')) {
45
+                $table->addColumn('parent', Types::BIGINT, [
46
+                    'notnull' => false,
47
+                    'default' => -1,
48
+                ]);
49
+                $changed = true;
50
+            }
51
+            if (!$table->hasColumn('share_type')) {
52
+                $table->addColumn('share_type', Types::INTEGER, [
53
+                    'notnull' => false,
54
+                    'length' => 4,
55
+                ]);
56
+                $changed = true;
57
+            }
58
+            if ($table->hasColumn('lastscan')) {
59
+                $table->dropColumn('lastscan');
60
+                $changed = true;
61
+            }
62 62
 
63
-			if ($changed) {
64
-				return $schema;
65
-			}
66
-		}
63
+            if ($changed) {
64
+                return $schema;
65
+            }
66
+        }
67 67
 
68
-		return null;
69
-	}
68
+        return null;
69
+    }
70 70
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/BuildSocialSearchIndex.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
 		$query->select($query->func()->max('cardid'))
75 75
 			->from('cards_properties')
76 76
 			->where($query->expr()->eq('name', $query->createNamedParameter('X-SOCIALPROFILE')));
77
-		$maxId = (int)$query->execute()->fetchOne();
77
+		$maxId = (int) $query->execute()->fetchOne();
78 78
 
79 79
 		if ($maxId === 0) {
80 80
 			return;
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,52 +13,52 @@
 block discarded – undo
13 13
 
14 14
 class BuildSocialSearchIndex implements IRepairStep {
15 15
 
16
-	/**
17
-	 * @param IDBConnection $db
18
-	 * @param IJobList $jobList
19
-	 * @param IConfig $config
20
-	 */
21
-	public function __construct(
22
-		private IDBConnection $db,
23
-		private IJobList $jobList,
24
-		private IConfig $config,
25
-	) {
26
-	}
16
+    /**
17
+     * @param IDBConnection $db
18
+     * @param IJobList $jobList
19
+     * @param IConfig $config
20
+     */
21
+    public function __construct(
22
+        private IDBConnection $db,
23
+        private IJobList $jobList,
24
+        private IConfig $config,
25
+    ) {
26
+    }
27 27
 
28
-	/**
29
-	 * @return string
30
-	 */
31
-	public function getName() {
32
-		return 'Register building of social profile search index as background job';
33
-	}
28
+    /**
29
+     * @return string
30
+     */
31
+    public function getName() {
32
+        return 'Register building of social profile search index as background job';
33
+    }
34 34
 
35
-	/**
36
-	 * @param IOutput $output
37
-	 */
38
-	public function run(IOutput $output) {
39
-		// only run once
40
-		if ($this->config->getAppValue('dav', 'builtSocialSearchIndex') === 'yes') {
41
-			$output->info('Repair step already executed');
42
-			return;
43
-		}
35
+    /**
36
+     * @param IOutput $output
37
+     */
38
+    public function run(IOutput $output) {
39
+        // only run once
40
+        if ($this->config->getAppValue('dav', 'builtSocialSearchIndex') === 'yes') {
41
+            $output->info('Repair step already executed');
42
+            return;
43
+        }
44 44
 
45
-		$query = $this->db->getQueryBuilder();
46
-		$query->select($query->func()->max('cardid'))
47
-			->from('cards_properties')
48
-			->where($query->expr()->eq('name', $query->createNamedParameter('X-SOCIALPROFILE')));
49
-		$maxId = (int)$query->execute()->fetchOne();
45
+        $query = $this->db->getQueryBuilder();
46
+        $query->select($query->func()->max('cardid'))
47
+            ->from('cards_properties')
48
+            ->where($query->expr()->eq('name', $query->createNamedParameter('X-SOCIALPROFILE')));
49
+        $maxId = (int)$query->execute()->fetchOne();
50 50
 
51
-		if ($maxId === 0) {
52
-			return;
53
-		}
51
+        if ($maxId === 0) {
52
+            return;
53
+        }
54 54
 
55
-		$output->info('Add background job');
56
-		$this->jobList->add(BuildSocialSearchIndexBackgroundJob::class, [
57
-			'offset' => 0,
58
-			'stopAt' => $maxId
59
-		]);
55
+        $output->info('Add background job');
56
+        $this->jobList->add(BuildSocialSearchIndexBackgroundJob::class, [
57
+            'offset' => 0,
58
+            'stopAt' => $maxId
59
+        ]);
60 60
 
61
-		// no need to redo the repair during next upgrade
62
-		$this->config->setAppValue('dav', 'builtSocialSearchIndex', 'yes');
63
-	}
61
+        // no need to redo the repair during next upgrade
62
+        $this->config->setAppValue('dav', 'builtSocialSearchIndex', 'yes');
63
+    }
64 64
 }
Please login to merge, or discard this patch.
lib/private/DB/SQLiteSessionInit.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -31,42 +31,42 @@
 block discarded – undo
31 31
 use Doctrine\DBAL\Events;
32 32
 
33 33
 class SQLiteSessionInit implements EventSubscriber {
34
-	/**
35
-	 * @var bool
36
-	 */
37
-	private $caseSensitiveLike;
34
+    /**
35
+     * @var bool
36
+     */
37
+    private $caseSensitiveLike;
38 38
 
39
-	/**
40
-	 * @var string
41
-	 */
42
-	private $journalMode;
39
+    /**
40
+     * @var string
41
+     */
42
+    private $journalMode;
43 43
 
44
-	/**
45
-	 * Configure case sensitive like for each connection
46
-	 *
47
-	 * @param bool $caseSensitiveLike
48
-	 * @param string $journalMode
49
-	 */
50
-	public function __construct($caseSensitiveLike, $journalMode) {
51
-		$this->caseSensitiveLike = $caseSensitiveLike;
52
-		$this->journalMode = $journalMode;
53
-	}
44
+    /**
45
+     * Configure case sensitive like for each connection
46
+     *
47
+     * @param bool $caseSensitiveLike
48
+     * @param string $journalMode
49
+     */
50
+    public function __construct($caseSensitiveLike, $journalMode) {
51
+        $this->caseSensitiveLike = $caseSensitiveLike;
52
+        $this->journalMode = $journalMode;
53
+    }
54 54
 
55
-	/**
56
-	 * @param ConnectionEventArgs $args
57
-	 * @return void
58
-	 */
59
-	public function postConnect(ConnectionEventArgs $args) {
60
-		$sensitive = $this->caseSensitiveLike ? 'true' : 'false';
61
-		$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
62
-		$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
63
-		/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
64
-		$connection = $args->getConnection()->getWrappedConnection();
65
-		$pdo = $connection->getWrappedConnection();
66
-		$pdo->sqliteCreateFunction('md5', 'md5', 1);
67
-	}
55
+    /**
56
+     * @param ConnectionEventArgs $args
57
+     * @return void
58
+     */
59
+    public function postConnect(ConnectionEventArgs $args) {
60
+        $sensitive = $this->caseSensitiveLike ? 'true' : 'false';
61
+        $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
62
+        $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
63
+        /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
64
+        $connection = $args->getConnection()->getWrappedConnection();
65
+        $pdo = $connection->getWrappedConnection();
66
+        $pdo->sqliteCreateFunction('md5', 'md5', 1);
67
+    }
68 68
 
69
-	public function getSubscribedEvents() {
70
-		return [Events::postConnect];
71
-	}
69
+    public function getSubscribedEvents() {
70
+        return [Events::postConnect];
71
+    }
72 72
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,8 +58,8 @@
 block discarded – undo
58 58
 	 */
59 59
 	public function postConnect(ConnectionEventArgs $args) {
60 60
 		$sensitive = $this->caseSensitiveLike ? 'true' : 'false';
61
-		$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
62
-		$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
61
+		$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = '.$sensitive);
62
+		$args->getConnection()->executeUpdate('PRAGMA journal_mode = '.$this->journalMode);
63 63
 		/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
64 64
 		$connection = $args->getConnection()->getWrappedConnection();
65 65
 		$pdo = $connection->getWrappedConnection();
Please login to merge, or discard this patch.
apps/encryption/lib/Crypto/EncryptAll.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		$this->input = $input;
135 135
 		$this->output = $output;
136 136
 
137
-		$headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME;
137
+		$headline = 'Encrypt all files with the '.Encryption::DISPLAY_NAME;
138 138
 		$this->output->writeln("\n");
139 139
 		$this->output->writeln($headline);
140 140
 		$this->output->writeln(str_pad('', strlen($headline), '='));
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 				$users = $backend->getUsers('', $limit, $offset);
191 191
 				foreach ($users as $user) {
192 192
 					if ($this->keyManager->userHasKeys($user) === false) {
193
-						$progress->setMessage('Create key-pair for ' . $user);
193
+						$progress->setMessage('Create key-pair for '.$user);
194 194
 						$progress->advance();
195 195
 						$this->setupUserFS($user);
196 196
 						$password = $this->generateOneTimePassword($user);
@@ -264,12 +264,12 @@  discard block
 block discarded – undo
264 264
 	protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
265 265
 		$this->setupUserFS($uid);
266 266
 		$directories = [];
267
-		$directories[] = '/' . $uid . '/files';
267
+		$directories[] = '/'.$uid.'/files';
268 268
 
269 269
 		while ($root = array_pop($directories)) {
270 270
 			$content = $this->rootView->getDirectoryContent($root);
271 271
 			foreach ($content as $file) {
272
-				$path = $root . '/' . $file['name'];
272
+				$path = $root.'/'.$file['name'];
273 273
 				if ($this->rootView->is_dir($path)) {
274 274
 					$directories[] = $path;
275 275
 					continue;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		}
301 301
 
302 302
 		$source = $path;
303
-		$target = $path . '.encrypted.' . time();
303
+		$target = $path.'.encrypted.'.time();
304 304
 
305 305
 		try {
306 306
 			$this->rootView->copy($source, $target);
Please login to merge, or discard this patch.
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -29,382 +29,382 @@
 block discarded – undo
29 29
 
30 30
 class EncryptAll {
31 31
 
32
-	/** @var array */
33
-	protected $userPasswords;
34
-
35
-	/** @var OutputInterface */
36
-	protected $output;
37
-
38
-	/** @var InputInterface */
39
-	protected $input;
40
-
41
-	public function __construct(
42
-		protected Setup $userSetup,
43
-		protected IUserManager $userManager,
44
-		protected View $rootView,
45
-		protected KeyManager $keyManager,
46
-		protected Util $util,
47
-		protected IConfig $config,
48
-		protected IMailer $mailer,
49
-		protected IL10N $l,
50
-		protected IFactory $l10nFactory,
51
-		protected QuestionHelper $questionHelper,
52
-		protected ISecureRandom $secureRandom,
53
-	) {
54
-		// store one time passwords for the users
55
-		$this->userPasswords = [];
56
-	}
57
-
58
-	/**
59
-	 * start to encrypt all files
60
-	 *
61
-	 * @param InputInterface $input
62
-	 * @param OutputInterface $output
63
-	 */
64
-	public function encryptAll(InputInterface $input, OutputInterface $output) {
65
-		$this->input = $input;
66
-		$this->output = $output;
67
-
68
-		$headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME;
69
-		$this->output->writeln("\n");
70
-		$this->output->writeln($headline);
71
-		$this->output->writeln(str_pad('', strlen($headline), '='));
72
-		$this->output->writeln("\n");
73
-
74
-		if ($this->util->isMasterKeyEnabled()) {
75
-			$this->output->writeln('Use master key to encrypt all files.');
76
-			$this->keyManager->validateMasterKey();
77
-		} else {
78
-			//create private/public keys for each user and store the private key password
79
-			$this->output->writeln('Create key-pair for every user');
80
-			$this->output->writeln('------------------------------');
81
-			$this->output->writeln('');
82
-			$this->output->writeln('This module will encrypt all files in the users files folder initially.');
83
-			$this->output->writeln('Already existing versions and files in the trash bin will not be encrypted.');
84
-			$this->output->writeln('');
85
-			$this->createKeyPairs();
86
-		}
87
-
88
-
89
-		// output generated encryption key passwords
90
-		if ($this->util->isMasterKeyEnabled() === false) {
91
-			//send-out or display password list and write it to a file
92
-			$this->output->writeln("\n");
93
-			$this->output->writeln('Generated encryption key passwords');
94
-			$this->output->writeln('----------------------------------');
95
-			$this->output->writeln('');
96
-			$this->outputPasswords();
97
-		}
98
-
99
-		//setup users file system and encrypt all files one by one (take should encrypt setting of storage into account)
100
-		$this->output->writeln("\n");
101
-		$this->output->writeln('Start to encrypt users files');
102
-		$this->output->writeln('----------------------------');
103
-		$this->output->writeln('');
104
-		$this->encryptAllUsersFiles();
105
-		$this->output->writeln("\n");
106
-	}
107
-
108
-	/**
109
-	 * create key-pair for every user
110
-	 */
111
-	protected function createKeyPairs() {
112
-		$this->output->writeln("\n");
113
-		$progress = new ProgressBar($this->output);
114
-		$progress->setFormat(" %message% \n [%bar%]");
115
-		$progress->start();
116
-
117
-		foreach ($this->userManager->getBackends() as $backend) {
118
-			$limit = 500;
119
-			$offset = 0;
120
-			do {
121
-				$users = $backend->getUsers('', $limit, $offset);
122
-				foreach ($users as $user) {
123
-					if ($this->keyManager->userHasKeys($user) === false) {
124
-						$progress->setMessage('Create key-pair for ' . $user);
125
-						$progress->advance();
126
-						$this->setupUserFS($user);
127
-						$password = $this->generateOneTimePassword($user);
128
-						$this->userSetup->setupUser($user, $password);
129
-					} else {
130
-						// users which already have a key-pair will be stored with a
131
-						// empty password and filtered out later
132
-						$this->userPasswords[$user] = '';
133
-					}
134
-				}
135
-				$offset += $limit;
136
-			} while (count($users) >= $limit);
137
-		}
138
-
139
-		$progress->setMessage('Key-pair created for all users');
140
-		$progress->finish();
141
-	}
142
-
143
-	/**
144
-	 * iterate over all user and encrypt their files
145
-	 */
146
-	protected function encryptAllUsersFiles() {
147
-		$this->output->writeln("\n");
148
-		$progress = new ProgressBar($this->output);
149
-		$progress->setFormat(" %message% \n [%bar%]");
150
-		$progress->start();
151
-		$numberOfUsers = count($this->userPasswords);
152
-		$userNo = 1;
153
-		if ($this->util->isMasterKeyEnabled()) {
154
-			$this->encryptAllUserFilesWithMasterKey($progress);
155
-		} else {
156
-			foreach ($this->userPasswords as $uid => $password) {
157
-				$userCount = "$uid ($userNo of $numberOfUsers)";
158
-				$this->encryptUsersFiles($uid, $progress, $userCount);
159
-				$userNo++;
160
-			}
161
-		}
162
-		$progress->setMessage('all files encrypted');
163
-		$progress->finish();
164
-	}
165
-
166
-	/**
167
-	 * encrypt all user files with the master key
168
-	 *
169
-	 * @param ProgressBar $progress
170
-	 */
171
-	protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress) {
172
-		$userNo = 1;
173
-		foreach ($this->userManager->getBackends() as $backend) {
174
-			$limit = 500;
175
-			$offset = 0;
176
-			do {
177
-				$users = $backend->getUsers('', $limit, $offset);
178
-				foreach ($users as $user) {
179
-					$userCount = "$user ($userNo)";
180
-					$this->encryptUsersFiles($user, $progress, $userCount);
181
-					$userNo++;
182
-				}
183
-				$offset += $limit;
184
-			} while (count($users) >= $limit);
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * encrypt files from the given user
190
-	 *
191
-	 * @param string $uid
192
-	 * @param ProgressBar $progress
193
-	 * @param string $userCount
194
-	 */
195
-	protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
196
-		$this->setupUserFS($uid);
197
-		$directories = [];
198
-		$directories[] = '/' . $uid . '/files';
199
-
200
-		while ($root = array_pop($directories)) {
201
-			$content = $this->rootView->getDirectoryContent($root);
202
-			foreach ($content as $file) {
203
-				$path = $root . '/' . $file['name'];
204
-				if ($this->rootView->is_dir($path)) {
205
-					$directories[] = $path;
206
-					continue;
207
-				} else {
208
-					$progress->setMessage("encrypt files for user $userCount: $path");
209
-					$progress->advance();
210
-					if ($this->encryptFile($path) === false) {
211
-						$progress->setMessage("encrypt files for user $userCount: $path (already encrypted)");
212
-						$progress->advance();
213
-					}
214
-				}
215
-			}
216
-		}
217
-	}
218
-
219
-	/**
220
-	 * encrypt file
221
-	 *
222
-	 * @param string $path
223
-	 * @return bool
224
-	 */
225
-	protected function encryptFile($path) {
226
-
227
-		// skip already encrypted files
228
-		$fileInfo = $this->rootView->getFileInfo($path);
229
-		if ($fileInfo !== false && $fileInfo->isEncrypted()) {
230
-			return true;
231
-		}
232
-
233
-		$source = $path;
234
-		$target = $path . '.encrypted.' . time();
235
-
236
-		try {
237
-			$this->rootView->copy($source, $target);
238
-			$this->rootView->rename($target, $source);
239
-		} catch (DecryptionFailedException $e) {
240
-			if ($this->rootView->file_exists($target)) {
241
-				$this->rootView->unlink($target);
242
-			}
243
-			return false;
244
-		}
245
-
246
-		return true;
247
-	}
248
-
249
-	/**
250
-	 * output one-time encryption passwords
251
-	 */
252
-	protected function outputPasswords() {
253
-		$table = new Table($this->output);
254
-		$table->setHeaders(['Username', 'Private key password']);
255
-
256
-		//create rows
257
-		$newPasswords = [];
258
-		$unchangedPasswords = [];
259
-		foreach ($this->userPasswords as $uid => $password) {
260
-			if (empty($password)) {
261
-				$unchangedPasswords[] = $uid;
262
-			} else {
263
-				$newPasswords[] = [$uid, $password];
264
-			}
265
-		}
266
-
267
-		if (empty($newPasswords)) {
268
-			$this->output->writeln("\nAll users already had a key-pair, no further action needed.\n");
269
-			return;
270
-		}
271
-
272
-		$table->setRows($newPasswords);
273
-		$table->render();
274
-
275
-		if (!empty($unchangedPasswords)) {
276
-			$this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n");
277
-			foreach ($unchangedPasswords as $uid) {
278
-				$this->output->writeln("    $uid");
279
-			}
280
-		}
281
-
282
-		$this->writePasswordsToFile($newPasswords);
283
-
284
-		$this->output->writeln('');
285
-		$question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false);
286
-		if ($this->questionHelper->ask($this->input, $this->output, $question)) {
287
-			$this->sendPasswordsByMail();
288
-		}
289
-	}
290
-
291
-	/**
292
-	 * write one-time encryption passwords to a csv file
293
-	 *
294
-	 * @param array $passwords
295
-	 */
296
-	protected function writePasswordsToFile(array $passwords) {
297
-		$fp = $this->rootView->fopen('oneTimeEncryptionPasswords.csv', 'w');
298
-		foreach ($passwords as $pwd) {
299
-			fputcsv($fp, $pwd);
300
-		}
301
-		fclose($fp);
302
-		$this->output->writeln("\n");
303
-		$this->output->writeln('A list of all newly created passwords was written to data/oneTimeEncryptionPasswords.csv');
304
-		$this->output->writeln('');
305
-		$this->output->writeln('Each of these users need to login to the web interface, go to the');
306
-		$this->output->writeln('personal settings section "basic encryption module" and');
307
-		$this->output->writeln('update the private key password to match the login password again by');
308
-		$this->output->writeln('entering the one-time password into the "old log-in password" field');
309
-		$this->output->writeln('and their current login password');
310
-	}
311
-
312
-	/**
313
-	 * setup user file system
314
-	 *
315
-	 * @param string $uid
316
-	 */
317
-	protected function setupUserFS($uid) {
318
-		\OC_Util::tearDownFS();
319
-		\OC_Util::setupFS($uid);
320
-	}
321
-
322
-	/**
323
-	 * generate one time password for the user and store it in a array
324
-	 *
325
-	 * @param string $uid
326
-	 * @return string password
327
-	 */
328
-	protected function generateOneTimePassword($uid) {
329
-		$password = $this->secureRandom->generate(16, ISecureRandom::CHAR_HUMAN_READABLE);
330
-		$this->userPasswords[$uid] = $password;
331
-		return $password;
332
-	}
333
-
334
-	/**
335
-	 * send encryption key passwords to the users by mail
336
-	 */
337
-	protected function sendPasswordsByMail() {
338
-		$noMail = [];
339
-
340
-		$this->output->writeln('');
341
-		$progress = new ProgressBar($this->output, count($this->userPasswords));
342
-		$progress->start();
343
-
344
-		foreach ($this->userPasswords as $uid => $password) {
345
-			$progress->advance();
346
-			if (!empty($password)) {
347
-				$recipient = $this->userManager->get($uid);
348
-				if (!$recipient instanceof IUser) {
349
-					continue;
350
-				}
351
-
352
-				$recipientDisplayName = $recipient->getDisplayName();
353
-				$to = $recipient->getEMailAddress();
354
-
355
-				if ($to === '' || $to === null) {
356
-					$noMail[] = $uid;
357
-					continue;
358
-				}
359
-
360
-				$l = $this->l10nFactory->get('encryption', $this->l10nFactory->getUserLanguage($recipient));
361
-
362
-				$template = $this->mailer->createEMailTemplate('encryption.encryptAllPassword', [
363
-					'user' => $recipient->getUID(),
364
-					'password' => $password,
365
-				]);
366
-
367
-				$template->setSubject($l->t('one-time password for server-side-encryption'));
368
-				// 'Hey there,<br><br>The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>
369
-				// Please login to the web interface, go to the section "Basic encryption module" of your personal settings and update your encryption password by entering this password into the "Old log-in password" field and your current login-password.<br><br>'
370
-				$template->addHeader();
371
-				$template->addHeading($l->t('Encryption password'));
372
-				$template->addBodyText(
373
-					$l->t('The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.', [htmlspecialchars($password)]),
374
-					$l->t('The administration enabled server-side-encryption. Your files were encrypted using the password "%s".', $password)
375
-				);
376
-				$template->addBodyText(
377
-					$l->t('Please login to the web interface, go to the "Security" section of your personal settings and update your encryption password by entering this password into the "Old login password" field and your current login password.')
378
-				);
379
-				$template->addFooter();
380
-
381
-				// send it out now
382
-				try {
383
-					$message = $this->mailer->createMessage();
384
-					$message->setTo([$to => $recipientDisplayName]);
385
-					$message->useTemplate($template);
386
-					$message->setAutoSubmitted(AutoSubmitted::VALUE_AUTO_GENERATED);
387
-					$this->mailer->send($message);
388
-				} catch (\Exception $e) {
389
-					$noMail[] = $uid;
390
-				}
391
-			}
392
-		}
393
-
394
-		$progress->finish();
395
-
396
-		if (empty($noMail)) {
397
-			$this->output->writeln("\n\nPassword successfully send to all users");
398
-		} else {
399
-			$table = new Table($this->output);
400
-			$table->setHeaders(['Username', 'Private key password']);
401
-			$this->output->writeln("\n\nCould not send password to following users:\n");
402
-			$rows = [];
403
-			foreach ($noMail as $uid) {
404
-				$rows[] = [$uid, $this->userPasswords[$uid]];
405
-			}
406
-			$table->setRows($rows);
407
-			$table->render();
408
-		}
409
-	}
32
+    /** @var array */
33
+    protected $userPasswords;
34
+
35
+    /** @var OutputInterface */
36
+    protected $output;
37
+
38
+    /** @var InputInterface */
39
+    protected $input;
40
+
41
+    public function __construct(
42
+        protected Setup $userSetup,
43
+        protected IUserManager $userManager,
44
+        protected View $rootView,
45
+        protected KeyManager $keyManager,
46
+        protected Util $util,
47
+        protected IConfig $config,
48
+        protected IMailer $mailer,
49
+        protected IL10N $l,
50
+        protected IFactory $l10nFactory,
51
+        protected QuestionHelper $questionHelper,
52
+        protected ISecureRandom $secureRandom,
53
+    ) {
54
+        // store one time passwords for the users
55
+        $this->userPasswords = [];
56
+    }
57
+
58
+    /**
59
+     * start to encrypt all files
60
+     *
61
+     * @param InputInterface $input
62
+     * @param OutputInterface $output
63
+     */
64
+    public function encryptAll(InputInterface $input, OutputInterface $output) {
65
+        $this->input = $input;
66
+        $this->output = $output;
67
+
68
+        $headline = 'Encrypt all files with the ' . Encryption::DISPLAY_NAME;
69
+        $this->output->writeln("\n");
70
+        $this->output->writeln($headline);
71
+        $this->output->writeln(str_pad('', strlen($headline), '='));
72
+        $this->output->writeln("\n");
73
+
74
+        if ($this->util->isMasterKeyEnabled()) {
75
+            $this->output->writeln('Use master key to encrypt all files.');
76
+            $this->keyManager->validateMasterKey();
77
+        } else {
78
+            //create private/public keys for each user and store the private key password
79
+            $this->output->writeln('Create key-pair for every user');
80
+            $this->output->writeln('------------------------------');
81
+            $this->output->writeln('');
82
+            $this->output->writeln('This module will encrypt all files in the users files folder initially.');
83
+            $this->output->writeln('Already existing versions and files in the trash bin will not be encrypted.');
84
+            $this->output->writeln('');
85
+            $this->createKeyPairs();
86
+        }
87
+
88
+
89
+        // output generated encryption key passwords
90
+        if ($this->util->isMasterKeyEnabled() === false) {
91
+            //send-out or display password list and write it to a file
92
+            $this->output->writeln("\n");
93
+            $this->output->writeln('Generated encryption key passwords');
94
+            $this->output->writeln('----------------------------------');
95
+            $this->output->writeln('');
96
+            $this->outputPasswords();
97
+        }
98
+
99
+        //setup users file system and encrypt all files one by one (take should encrypt setting of storage into account)
100
+        $this->output->writeln("\n");
101
+        $this->output->writeln('Start to encrypt users files');
102
+        $this->output->writeln('----------------------------');
103
+        $this->output->writeln('');
104
+        $this->encryptAllUsersFiles();
105
+        $this->output->writeln("\n");
106
+    }
107
+
108
+    /**
109
+     * create key-pair for every user
110
+     */
111
+    protected function createKeyPairs() {
112
+        $this->output->writeln("\n");
113
+        $progress = new ProgressBar($this->output);
114
+        $progress->setFormat(" %message% \n [%bar%]");
115
+        $progress->start();
116
+
117
+        foreach ($this->userManager->getBackends() as $backend) {
118
+            $limit = 500;
119
+            $offset = 0;
120
+            do {
121
+                $users = $backend->getUsers('', $limit, $offset);
122
+                foreach ($users as $user) {
123
+                    if ($this->keyManager->userHasKeys($user) === false) {
124
+                        $progress->setMessage('Create key-pair for ' . $user);
125
+                        $progress->advance();
126
+                        $this->setupUserFS($user);
127
+                        $password = $this->generateOneTimePassword($user);
128
+                        $this->userSetup->setupUser($user, $password);
129
+                    } else {
130
+                        // users which already have a key-pair will be stored with a
131
+                        // empty password and filtered out later
132
+                        $this->userPasswords[$user] = '';
133
+                    }
134
+                }
135
+                $offset += $limit;
136
+            } while (count($users) >= $limit);
137
+        }
138
+
139
+        $progress->setMessage('Key-pair created for all users');
140
+        $progress->finish();
141
+    }
142
+
143
+    /**
144
+     * iterate over all user and encrypt their files
145
+     */
146
+    protected function encryptAllUsersFiles() {
147
+        $this->output->writeln("\n");
148
+        $progress = new ProgressBar($this->output);
149
+        $progress->setFormat(" %message% \n [%bar%]");
150
+        $progress->start();
151
+        $numberOfUsers = count($this->userPasswords);
152
+        $userNo = 1;
153
+        if ($this->util->isMasterKeyEnabled()) {
154
+            $this->encryptAllUserFilesWithMasterKey($progress);
155
+        } else {
156
+            foreach ($this->userPasswords as $uid => $password) {
157
+                $userCount = "$uid ($userNo of $numberOfUsers)";
158
+                $this->encryptUsersFiles($uid, $progress, $userCount);
159
+                $userNo++;
160
+            }
161
+        }
162
+        $progress->setMessage('all files encrypted');
163
+        $progress->finish();
164
+    }
165
+
166
+    /**
167
+     * encrypt all user files with the master key
168
+     *
169
+     * @param ProgressBar $progress
170
+     */
171
+    protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress) {
172
+        $userNo = 1;
173
+        foreach ($this->userManager->getBackends() as $backend) {
174
+            $limit = 500;
175
+            $offset = 0;
176
+            do {
177
+                $users = $backend->getUsers('', $limit, $offset);
178
+                foreach ($users as $user) {
179
+                    $userCount = "$user ($userNo)";
180
+                    $this->encryptUsersFiles($user, $progress, $userCount);
181
+                    $userNo++;
182
+                }
183
+                $offset += $limit;
184
+            } while (count($users) >= $limit);
185
+        }
186
+    }
187
+
188
+    /**
189
+     * encrypt files from the given user
190
+     *
191
+     * @param string $uid
192
+     * @param ProgressBar $progress
193
+     * @param string $userCount
194
+     */
195
+    protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
196
+        $this->setupUserFS($uid);
197
+        $directories = [];
198
+        $directories[] = '/' . $uid . '/files';
199
+
200
+        while ($root = array_pop($directories)) {
201
+            $content = $this->rootView->getDirectoryContent($root);
202
+            foreach ($content as $file) {
203
+                $path = $root . '/' . $file['name'];
204
+                if ($this->rootView->is_dir($path)) {
205
+                    $directories[] = $path;
206
+                    continue;
207
+                } else {
208
+                    $progress->setMessage("encrypt files for user $userCount: $path");
209
+                    $progress->advance();
210
+                    if ($this->encryptFile($path) === false) {
211
+                        $progress->setMessage("encrypt files for user $userCount: $path (already encrypted)");
212
+                        $progress->advance();
213
+                    }
214
+                }
215
+            }
216
+        }
217
+    }
218
+
219
+    /**
220
+     * encrypt file
221
+     *
222
+     * @param string $path
223
+     * @return bool
224
+     */
225
+    protected function encryptFile($path) {
226
+
227
+        // skip already encrypted files
228
+        $fileInfo = $this->rootView->getFileInfo($path);
229
+        if ($fileInfo !== false && $fileInfo->isEncrypted()) {
230
+            return true;
231
+        }
232
+
233
+        $source = $path;
234
+        $target = $path . '.encrypted.' . time();
235
+
236
+        try {
237
+            $this->rootView->copy($source, $target);
238
+            $this->rootView->rename($target, $source);
239
+        } catch (DecryptionFailedException $e) {
240
+            if ($this->rootView->file_exists($target)) {
241
+                $this->rootView->unlink($target);
242
+            }
243
+            return false;
244
+        }
245
+
246
+        return true;
247
+    }
248
+
249
+    /**
250
+     * output one-time encryption passwords
251
+     */
252
+    protected function outputPasswords() {
253
+        $table = new Table($this->output);
254
+        $table->setHeaders(['Username', 'Private key password']);
255
+
256
+        //create rows
257
+        $newPasswords = [];
258
+        $unchangedPasswords = [];
259
+        foreach ($this->userPasswords as $uid => $password) {
260
+            if (empty($password)) {
261
+                $unchangedPasswords[] = $uid;
262
+            } else {
263
+                $newPasswords[] = [$uid, $password];
264
+            }
265
+        }
266
+
267
+        if (empty($newPasswords)) {
268
+            $this->output->writeln("\nAll users already had a key-pair, no further action needed.\n");
269
+            return;
270
+        }
271
+
272
+        $table->setRows($newPasswords);
273
+        $table->render();
274
+
275
+        if (!empty($unchangedPasswords)) {
276
+            $this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n");
277
+            foreach ($unchangedPasswords as $uid) {
278
+                $this->output->writeln("    $uid");
279
+            }
280
+        }
281
+
282
+        $this->writePasswordsToFile($newPasswords);
283
+
284
+        $this->output->writeln('');
285
+        $question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false);
286
+        if ($this->questionHelper->ask($this->input, $this->output, $question)) {
287
+            $this->sendPasswordsByMail();
288
+        }
289
+    }
290
+
291
+    /**
292
+     * write one-time encryption passwords to a csv file
293
+     *
294
+     * @param array $passwords
295
+     */
296
+    protected function writePasswordsToFile(array $passwords) {
297
+        $fp = $this->rootView->fopen('oneTimeEncryptionPasswords.csv', 'w');
298
+        foreach ($passwords as $pwd) {
299
+            fputcsv($fp, $pwd);
300
+        }
301
+        fclose($fp);
302
+        $this->output->writeln("\n");
303
+        $this->output->writeln('A list of all newly created passwords was written to data/oneTimeEncryptionPasswords.csv');
304
+        $this->output->writeln('');
305
+        $this->output->writeln('Each of these users need to login to the web interface, go to the');
306
+        $this->output->writeln('personal settings section "basic encryption module" and');
307
+        $this->output->writeln('update the private key password to match the login password again by');
308
+        $this->output->writeln('entering the one-time password into the "old log-in password" field');
309
+        $this->output->writeln('and their current login password');
310
+    }
311
+
312
+    /**
313
+     * setup user file system
314
+     *
315
+     * @param string $uid
316
+     */
317
+    protected function setupUserFS($uid) {
318
+        \OC_Util::tearDownFS();
319
+        \OC_Util::setupFS($uid);
320
+    }
321
+
322
+    /**
323
+     * generate one time password for the user and store it in a array
324
+     *
325
+     * @param string $uid
326
+     * @return string password
327
+     */
328
+    protected function generateOneTimePassword($uid) {
329
+        $password = $this->secureRandom->generate(16, ISecureRandom::CHAR_HUMAN_READABLE);
330
+        $this->userPasswords[$uid] = $password;
331
+        return $password;
332
+    }
333
+
334
+    /**
335
+     * send encryption key passwords to the users by mail
336
+     */
337
+    protected function sendPasswordsByMail() {
338
+        $noMail = [];
339
+
340
+        $this->output->writeln('');
341
+        $progress = new ProgressBar($this->output, count($this->userPasswords));
342
+        $progress->start();
343
+
344
+        foreach ($this->userPasswords as $uid => $password) {
345
+            $progress->advance();
346
+            if (!empty($password)) {
347
+                $recipient = $this->userManager->get($uid);
348
+                if (!$recipient instanceof IUser) {
349
+                    continue;
350
+                }
351
+
352
+                $recipientDisplayName = $recipient->getDisplayName();
353
+                $to = $recipient->getEMailAddress();
354
+
355
+                if ($to === '' || $to === null) {
356
+                    $noMail[] = $uid;
357
+                    continue;
358
+                }
359
+
360
+                $l = $this->l10nFactory->get('encryption', $this->l10nFactory->getUserLanguage($recipient));
361
+
362
+                $template = $this->mailer->createEMailTemplate('encryption.encryptAllPassword', [
363
+                    'user' => $recipient->getUID(),
364
+                    'password' => $password,
365
+                ]);
366
+
367
+                $template->setSubject($l->t('one-time password for server-side-encryption'));
368
+                // 'Hey there,<br><br>The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>
369
+                // Please login to the web interface, go to the section "Basic encryption module" of your personal settings and update your encryption password by entering this password into the "Old log-in password" field and your current login-password.<br><br>'
370
+                $template->addHeader();
371
+                $template->addHeading($l->t('Encryption password'));
372
+                $template->addBodyText(
373
+                    $l->t('The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.', [htmlspecialchars($password)]),
374
+                    $l->t('The administration enabled server-side-encryption. Your files were encrypted using the password "%s".', $password)
375
+                );
376
+                $template->addBodyText(
377
+                    $l->t('Please login to the web interface, go to the "Security" section of your personal settings and update your encryption password by entering this password into the "Old login password" field and your current login password.')
378
+                );
379
+                $template->addFooter();
380
+
381
+                // send it out now
382
+                try {
383
+                    $message = $this->mailer->createMessage();
384
+                    $message->setTo([$to => $recipientDisplayName]);
385
+                    $message->useTemplate($template);
386
+                    $message->setAutoSubmitted(AutoSubmitted::VALUE_AUTO_GENERATED);
387
+                    $this->mailer->send($message);
388
+                } catch (\Exception $e) {
389
+                    $noMail[] = $uid;
390
+                }
391
+            }
392
+        }
393
+
394
+        $progress->finish();
395
+
396
+        if (empty($noMail)) {
397
+            $this->output->writeln("\n\nPassword successfully send to all users");
398
+        } else {
399
+            $table = new Table($this->output);
400
+            $table->setHeaders(['Username', 'Private key password']);
401
+            $this->output->writeln("\n\nCould not send password to following users:\n");
402
+            $rows = [];
403
+            foreach ($noMail as $uid) {
404
+                $rows[] = [$uid, $this->userPasswords[$uid]];
405
+            }
406
+            $table->setRows($rows);
407
+            $table->render();
408
+        }
409
+    }
410 410
 }
Please login to merge, or discard this patch.
core/Migrations/Version21000Date20210119195004.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,21 +35,21 @@
 block discarded – undo
35 35
  * Auto-generated migration step: Please modify to your needs!
36 36
  */
37 37
 class Version21000Date20210119195004 extends SimpleMigrationStep {
38
-	/**
39
-	 * @param IOutput $output
40
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
41
-	 * @param array $options
42
-	 * @return null|ISchemaWrapper
43
-	 */
44
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
45
-		/** @var ISchemaWrapper $schema */
46
-		$schema = $schemaClosure();
38
+    /**
39
+     * @param IOutput $output
40
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
41
+     * @param array $options
42
+     * @return null|ISchemaWrapper
43
+     */
44
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
45
+        /** @var ISchemaWrapper $schema */
46
+        $schema = $schemaClosure();
47 47
 
48
-		$table = $schema->getTable('authtoken');
49
-		if ($table->hasIndex('authtoken_version_index')) {
50
-			$table->dropIndex('authtoken_version_index');
51
-		}
48
+        $table = $schema->getTable('authtoken');
49
+        if ($table->hasIndex('authtoken_version_index')) {
50
+            $table->dropIndex('authtoken_version_index');
51
+        }
52 52
 
53
-		return $schema;
54
-	}
53
+        return $schema;
54
+    }
55 55
 }
Please login to merge, or discard this patch.