|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Björn Schießle <[email protected]> |
|
4
|
|
|
* @author Joas Schilling <[email protected]> |
|
5
|
|
|
* @author Morris Jobke <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
$installedVersion = \OC::$server->getConfig()->getAppValue('files', 'installed_version'); |
|
24
|
|
|
$ocVersion = explode('.', \OC::$server->getSystemConfig()->getValue('version')); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* In case encryption was not enabled, we accidently set encrypted = 1 for |
|
28
|
|
|
* files inside mount points, since 8.1.0. This breaks opening the files in |
|
29
|
|
|
* 8.1.1 because we fixed the code that checks if a file is encrypted. |
|
30
|
|
|
* In order to fix the file, we need to reset the flag of the file. However, |
|
31
|
|
|
* the flag might be set because the file is in fact encrypted because it was |
|
32
|
|
|
* uploaded at a time where encryption was enabled. |
|
33
|
|
|
* |
|
34
|
|
|
* So we can only do this when: |
|
35
|
|
|
* - Current version of ownCloud before the update is 8.1.0 or 8.2.0.(0-2) |
|
36
|
|
|
* - Encryption is disabled |
|
37
|
|
|
* - files_encryption is not known in the app config |
|
38
|
|
|
* |
|
39
|
|
|
* If the first two are not the case, we are save. However, if files_encryption |
|
40
|
|
|
* values exist in the config, we might have a false negative here. |
|
41
|
|
|
* Now if there is no file with unencrypted size greater 0, that means there are |
|
42
|
|
|
* no files that are still encrypted with "files_encryption" encryption. So we |
|
43
|
|
|
* can also safely reset the flag here. |
|
44
|
|
|
* |
|
45
|
|
|
* If this is not the case, we go with "better save then sorry" and don't change |
|
46
|
|
|
* the flag but write a message to the ownCloud log file. |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \OCP\IDBConnection $conn |
|
51
|
|
|
*/ |
|
52
|
|
|
function owncloud_reset_encrypted_flag(\OCP\IDBConnection $conn) { |
|
53
|
|
|
$conn->executeUpdate('UPDATE `*PREFIX*filecache` SET `encrypted` = 0 WHERE `encrypted` = 1'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// Current version of ownCloud before the update is 8.1.0 or 8.2.0.(0-2) |
|
57
|
|
|
if ($installedVersion === '1.1.9' && ( |
|
58
|
|
|
// 8.1.0.x |
|
59
|
|
|
(((int) $ocVersion[0]) === 8 && ((int) $ocVersion[1]) === 1 && ((int) $ocVersion[2]) === 0) |
|
60
|
|
|
|| |
|
61
|
|
|
// < 8.2.0.3 |
|
62
|
|
|
(((int) $ocVersion[0]) === 8 && ((int) $ocVersion[1]) === 2 && ((int) $ocVersion[2]) === 0 && ((int) $ocVersion[3]) < 3) |
|
63
|
|
|
)) { |
|
64
|
|
|
|
|
65
|
|
|
// Encryption is not enabled |
|
66
|
|
|
if (!\OC::$server->getEncryptionManager()->isEnabled()) { |
|
67
|
|
|
$conn = \OC::$server->getDatabaseConnection(); |
|
68
|
|
|
|
|
69
|
|
|
// Old encryption is not known in app config |
|
70
|
|
|
$oldEncryption = \OC::$server->getConfig()->getAppKeys('files_encryption'); |
|
71
|
|
|
if (empty($oldEncryption)) { |
|
72
|
|
|
owncloud_reset_encrypted_flag($conn); |
|
73
|
|
|
} else { |
|
74
|
|
|
$query = $conn->prepare('SELECT * FROM `*PREFIX*filecache` WHERE `encrypted` = 1 AND `unencrypted_size` > 0', 1); |
|
75
|
|
|
$query->execute(); |
|
76
|
|
|
$empty = $query->fetch(); |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
if (empty($empty)) { |
|
|
|
|
|
|
79
|
|
|
owncloud_reset_encrypted_flag($conn); |
|
80
|
|
|
} else { |
|
81
|
|
|
/** |
|
82
|
|
|
* Sorry in case you are a false positive, but we are not 100% that |
|
83
|
|
|
* you don't have any encrypted files anymore, so we can not reset |
|
84
|
|
|
* the value safely |
|
85
|
|
|
*/ |
|
86
|
|
|
\OC::$server->getLogger()->warning( |
|
87
|
|
|
'If you have a problem with files not being accessible and ' |
|
88
|
|
|
. 'you are not using encryption, please have a look at the following' |
|
89
|
|
|
. 'issue: {issue}', |
|
90
|
|
|
[ |
|
91
|
|
|
'issue' => 'https://github.com/owncloud/core/issues/17846', |
|
92
|
|
|
] |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* migrate old constant DEBUG to new config value 'debug' |
|
101
|
|
|
* |
|
102
|
|
|
* TODO: remove this in ownCloud 8.3 |
|
103
|
|
|
*/ |
|
104
|
|
|
if(defined('DEBUG') && DEBUG === true) { |
|
105
|
|
|
\OC::$server->getConfig()->setSystemValue('debug', true); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
\OC::$server->getJobList()->add('OCA\Files\BackgroundJob\CleanupFileLocks'); |
|
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.