update.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @copyright Copyright (c) 2016, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. $installedVersion = \OC::$server->getConfig()->getAppValue('files', 'installed_version');
  25. $ocVersion = explode('.', \OC::$server->getSystemConfig()->getValue('version'));
  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. * @param \OCP\IDBConnection $conn
  50. */
  51. function owncloud_reset_encrypted_flag(\OCP\IDBConnection $conn) {
  52. $conn->executeUpdate('UPDATE `*PREFIX*filecache` SET `encrypted` = 0 WHERE `encrypted` = 1');
  53. }
  54. // Current version of ownCloud before the update is 8.1.0 or 8.2.0.(0-2)
  55. if ($installedVersion === '1.1.9' && (
  56. // 8.1.0.x
  57. (((int) $ocVersion[0]) === 8 && ((int) $ocVersion[1]) === 1 && ((int) $ocVersion[2]) === 0)
  58. ||
  59. // < 8.2.0.3
  60. (((int) $ocVersion[0]) === 8 && ((int) $ocVersion[1]) === 2 && ((int) $ocVersion[2]) === 0 && ((int) $ocVersion[3]) < 3)
  61. )) {
  62. // Encryption is not enabled
  63. if (!\OC::$server->getEncryptionManager()->isEnabled()) {
  64. $conn = \OC::$server->getDatabaseConnection();
  65. // Old encryption is not known in app config
  66. $oldEncryption = \OC::$server->getConfig()->getAppKeys('files_encryption');
  67. if (empty($oldEncryption)) {
  68. owncloud_reset_encrypted_flag($conn);
  69. } else {
  70. $query = $conn->prepare('SELECT * FROM `*PREFIX*filecache` WHERE `encrypted` = 1 AND `unencrypted_size` > 0', 1);
  71. $query->execute();
  72. $empty = $query->fetch();
  73. if (empty($empty)) {
  74. owncloud_reset_encrypted_flag($conn);
  75. } else {
  76. /**
  77. * Sorry in case you are a false positive, but we are not 100% that
  78. * you don't have any encrypted files anymore, so we can not reset
  79. * the value safely
  80. */
  81. \OC::$server->getLogger()->warning(
  82. 'If you have a problem with files not being accessible and '
  83. . 'you are not using encryption, please have a look at the following'
  84. . 'issue: {issue}',
  85. [
  86. 'issue' => 'https://github.com/owncloud/core/issues/17846',
  87. ]
  88. );
  89. }
  90. }
  91. }
  92. }
  93. // Add cron job for scanning user storages
  94. \OC::$server->getJobList()->add('OCA\Files\BackgroundJob\ScanFiles');
  95. \OC::$server->getJobList()->add('OCA\Files\BackgroundJob\DeleteOrphanedItems');