MoveUpdaterStepFile.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  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
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Repair;
  24. use OCP\Migration\IOutput;
  25. use OCP\Migration\IRepairStep;
  26. class MoveUpdaterStepFile implements IRepairStep {
  27. /** @var \OCP\IConfig */
  28. protected $config;
  29. /**
  30. * @param \OCP\IConfig $config
  31. */
  32. public function __construct($config) {
  33. $this->config = $config;
  34. }
  35. public function getName() {
  36. return 'Move .step file of updater to backup location';
  37. }
  38. public function run(IOutput $output) {
  39. $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
  40. $instanceId = $this->config->getSystemValue('instanceid', null);
  41. if(!is_string($instanceId) || empty($instanceId)) {
  42. return;
  43. }
  44. $updaterFolderPath = $dataDir . '/updater-' . $instanceId;
  45. $stepFile = $updaterFolderPath . '/.step';
  46. if(file_exists($stepFile)) {
  47. $output->info('.step file exists');
  48. $previousStepFile = $updaterFolderPath . '/.step-previous-update';
  49. // cleanup
  50. if(file_exists($previousStepFile)) {
  51. if(\OC_Helper::rmdirr($previousStepFile)) {
  52. $output->info('.step-previous-update removed');
  53. } else {
  54. $output->info('.step-previous-update can\'t be removed - abort move of .step file');
  55. return;
  56. }
  57. }
  58. // move step file
  59. if(rename($stepFile, $previousStepFile)) {
  60. $output->info('.step file moved to .step-previous-update');
  61. } else {
  62. $output->warning('.step file can\'t be moved');
  63. }
  64. }
  65. }
  66. }