|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Victor Dubiniuk <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
|
7
|
|
|
* @license AGPL-3.0 |
|
8
|
|
|
* |
|
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Owncloud\Updater\Command; |
|
24
|
|
|
|
|
25
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
27
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
28
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
29
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
|
30
|
|
|
use Owncloud\Updater\Utils\OccRunner; |
|
31
|
|
|
use Owncloud\Updater\Utils\ZipExtractor; |
|
32
|
|
|
use Owncloud\Updater\Utils\BzipExtractor; |
|
33
|
|
|
|
|
34
|
|
|
class ExecuteCoreUpgradeScriptsCommand extends Command { |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var OccRunner $occRunner |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $occRunner; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct($occRunner){ |
|
42
|
|
|
parent::__construct(); |
|
43
|
|
|
$this->occRunner = $occRunner; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function configure(){ |
|
47
|
|
|
$this |
|
48
|
|
|
->setName('upgrade:executeCoreUpgradeScripts') |
|
49
|
|
|
->setDescription('execute core upgrade scripts [danger, might take long]'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output){ |
|
53
|
|
|
$locator = $this->container['utils.locator']; |
|
54
|
|
|
$fsHelper = $this->container['utils.filesystemhelper']; |
|
55
|
|
|
$registry = $this->container['utils.registry']; |
|
56
|
|
|
$fetcher = $this->container['utils.fetcher']; |
|
57
|
|
|
|
|
58
|
|
|
$feed = $registry->get('feed'); |
|
59
|
|
|
|
|
60
|
|
|
if ($feed){ |
|
61
|
|
|
$path = $fetcher->getBaseDownloadPath($feed); |
|
62
|
|
|
$fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion(); |
|
63
|
|
|
|
|
64
|
|
|
if (file_exists($fullExtractionPath)){ |
|
65
|
|
|
$fsHelper->removeIfExists($fullExtractionPath); |
|
66
|
|
|
} |
|
67
|
|
|
try{ |
|
68
|
|
|
$fsHelper->mkdir($fullExtractionPath, true); |
|
69
|
|
|
} catch (\Exception $e){ |
|
70
|
|
|
$output->writeln('Unable create directory ' . $fullExtractionPath); |
|
71
|
|
|
throw $e; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$output->writeln('Extracting source into ' . $fullExtractionPath); |
|
75
|
|
|
if (preg_match('|\.tar\.bz2$|', $path)){ |
|
76
|
|
|
$extractor = new BzipExtractor($path, $fullExtractionPath); |
|
77
|
|
|
} else { |
|
78
|
|
|
$extractor = new ZipExtractor($path, $fullExtractionPath); |
|
79
|
|
|
} |
|
80
|
|
|
try{ |
|
81
|
|
|
$extractor->extract(); |
|
82
|
|
|
} catch (\Exception $e){ |
|
83
|
|
|
$output->writeln('Extraction has been failed'); |
|
84
|
|
|
$fsHelper->removeIfExists($locator->getExtractionBaseDir()); |
|
85
|
|
|
throw $e; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$tmpDir = $locator->getExtractionBaseDir() . '/' . implode('.', $locator->getInstalledVersion()); |
|
89
|
|
|
$fsHelper->removeIfExists($tmpDir); |
|
90
|
|
|
$fsHelper->mkdir($tmpDir); |
|
91
|
|
|
$fsHelper->mkdir($tmpDir . '/config'); |
|
92
|
|
|
$oldSourcesDir = $locator->getOwncloudRootPath(); |
|
93
|
|
|
$newSourcesDir = $fullExtractionPath . '/owncloud'; |
|
94
|
|
|
$newSources = $locator->getRootDirContent(); |
|
95
|
|
|
foreach ($newSources as $dir){ |
|
96
|
|
|
$this->getApplication()->getLogger()->debug('Moving ' . $dir); |
|
|
|
|
|
|
97
|
|
|
if (file_exists($oldSourcesDir . '/' . $dir)){ |
|
98
|
|
|
$fsHelper->move($oldSourcesDir . '/' . $dir, $tmpDir . '/' . $dir); |
|
99
|
|
|
} |
|
100
|
|
|
if (file_exists($newSourcesDir . '/' . $dir)){ |
|
101
|
|
|
$fsHelper->move($newSourcesDir . '/' . $dir, $oldSourcesDir . '/' . $dir); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
try { |
|
106
|
|
|
$plain = $this->occRunner->run('upgrade'); |
|
107
|
|
|
$output->writeln($plain); |
|
108
|
|
|
} catch (ProcessFailedException $e){ |
|
109
|
|
|
if ($e->getProcess()->getExitCode != 3){ |
|
|
|
|
|
|
110
|
|
|
throw ($e); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: