1
0

MoveUpdaterStepFile.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Repair;
  7. use OCP\Migration\IOutput;
  8. use OCP\Migration\IRepairStep;
  9. class MoveUpdaterStepFile implements IRepairStep {
  10. /** @var \OCP\IConfig */
  11. protected $config;
  12. /**
  13. * @param \OCP\IConfig $config
  14. */
  15. public function __construct($config) {
  16. $this->config = $config;
  17. }
  18. public function getName() {
  19. return 'Move .step file of updater to backup location';
  20. }
  21. public function run(IOutput $output) {
  22. $updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
  23. $instanceId = $this->config->getSystemValueString('instanceid');
  24. if (empty($instanceId)) {
  25. return;
  26. }
  27. $updaterFolderPath = $updateDir . '/updater-' . $instanceId;
  28. $stepFile = $updaterFolderPath . '/.step';
  29. if (file_exists($stepFile)) {
  30. $output->info('.step file exists');
  31. $previousStepFile = $updaterFolderPath . '/.step-previous-update';
  32. // cleanup
  33. if (file_exists($previousStepFile)) {
  34. if (\OC_Helper::rmdirr($previousStepFile)) {
  35. $output->info('.step-previous-update removed');
  36. } else {
  37. $output->info('.step-previous-update can\'t be removed - abort move of .step file');
  38. return;
  39. }
  40. }
  41. // move step file
  42. if (rename($stepFile, $previousStepFile)) {
  43. $output->info('.step file moved to .step-previous-update');
  44. } else {
  45. $output->warning('.step file can\'t be moved');
  46. }
  47. }
  48. }
  49. }