|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2016 Morris Jobke <[email protected]> |
| 4 | + * |
| 5 | + * @author Morris Jobke <[email protected]> |
| 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 | + |
| 24 | +namespace OC\Repair; |
| 25 | + |
| 26 | +use OCP\Migration\IOutput; |
| 27 | +use OCP\Migration\IRepairStep; |
| 28 | + |
| 29 | +class MoveUpdaterStepFile implements IRepairStep { |
| 30 | + |
| 31 | + /** @var \OCP\IConfig */ |
| 32 | + protected $config; |
| 33 | + |
| 34 | + /** |
| 35 | + * @param \OCP\IConfig $config |
| 36 | + */ |
| 37 | + public function __construct($config) { |
| 38 | + $this->config = $config; |
| 39 | + } |
| 40 | + |
| 41 | + public function getName() { |
| 42 | + return 'Move .step file of updater to backup location'; |
| 43 | + } |
| 44 | + |
| 45 | + public function run(IOutput $output) { |
| 46 | + |
| 47 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT); |
| 48 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
| 49 | + |
| 50 | + if(!is_string($instanceId) || empty($instanceId)) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
| 55 | + $stepFile = $updaterFolderPath . '/.step'; |
| 56 | + if(file_exists($stepFile)) { |
| 57 | + $output->info('.step file exists'); |
| 58 | + |
| 59 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
| 60 | + |
| 61 | + // cleanup |
| 62 | + if(file_exists($previousStepFile)) { |
| 63 | + if(\OC_Helper::rmdirr($previousStepFile)) { |
| 64 | + $output->info('.step-previous-update removed'); |
| 65 | + } else { |
| 66 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
| 67 | + return; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + // move step file |
| 72 | + if(rename($stepFile, $previousStepFile)) { |
| 73 | + $output->info('.step file moved to .step-previous-update'); |
| 74 | + } else { |
| 75 | + $output->warning('.step file can\'t be moved'); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
0 commit comments