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 Owncloud\Updater\Utils\OccRunner; |
30
|
|
|
use Owncloud\Updater\Utils\ZipExtractor; |
31
|
|
|
use Owncloud\Updater\Utils\BzipExtractor; |
32
|
|
|
|
33
|
|
|
class ExecuteCoreUpgradeScriptsCommand extends Command { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var OccRunner $occRunner |
37
|
|
|
*/ |
38
|
|
|
protected $occRunner; |
39
|
|
|
|
40
|
|
|
public function __construct($occRunner){ |
41
|
|
|
parent::__construct(); |
42
|
|
|
$this->occRunner = $occRunner; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function configure(){ |
46
|
|
|
$this |
47
|
|
|
->setName('upgrade:executeCoreUpgradeScripts') |
48
|
|
|
->setDescription('execute core upgrade scripts [danger, might take long]'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output){ |
52
|
|
|
$locator = $this->container['utils.locator']; |
53
|
|
|
$fsHelper = $this->container['utils.filesystemhelper']; |
54
|
|
|
$registry = $this->container['utils.registry']; |
55
|
|
|
$fetcher = $this->container['utils.fetcher']; |
56
|
|
|
|
57
|
|
|
$feed = $registry->get('feed'); |
58
|
|
|
|
59
|
|
|
if ($feed){ |
60
|
|
|
$path = $fetcher->getBaseDownloadPath($feed); |
61
|
|
|
$fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion(); |
62
|
|
|
|
63
|
|
|
if (!file_exists($fullExtractionPath)){ |
64
|
|
|
try{ |
65
|
|
|
$fsHelper->mkdir($fullExtractionPath, true); |
66
|
|
|
} catch (\Exception $ex){ |
67
|
|
|
$output->writeln('Unable create directory ' . $fullExtractionPath); |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$fsHelper->removeIfExists($fullExtractionPath); |
71
|
|
|
} |
72
|
|
|
$output->writeln('Extracting source into ' . $fullExtractionPath); |
73
|
|
|
if (preg_match('|\.tar\.bz2$|', $path)){ |
74
|
|
|
$extractor = new BzipExtractor($path, $fullExtractionPath); |
75
|
|
|
} else { |
76
|
|
|
$extractor = new ZipExtractor($path, $fullExtractionPath); |
77
|
|
|
} |
78
|
|
|
try{ |
79
|
|
|
$extractor->extract(); |
80
|
|
|
} catch (\Exception $e){ |
81
|
|
|
$output->writeln('Extraction has been failed'); |
82
|
|
|
$fsHelper->removeIfExists($locator->getExtractionBaseDir()); |
83
|
|
|
throw $e; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$tmpDir = $locator->getExtractionBaseDir() . '/' . implode('.', $locator->getInstalledVersion()); |
87
|
|
|
$fsHelper->removeIfExists($tmpDir); |
88
|
|
|
$fsHelper->mkdir($tmpDir); |
89
|
|
|
$fsHelper->mkdir($tmpDir . '/config'); |
90
|
|
|
$oldSourcesDir = $locator->getOwncloudRootPath(); |
91
|
|
|
$newSourcesDir = $fullExtractionPath . '/owncloud'; |
92
|
|
|
$newSources = $locator->getRootDirContent(); |
93
|
|
|
foreach ($newSources as $dir){ |
94
|
|
|
$this->getApplication()->getLogger()->debug('Moving ' . $dir); |
|
|
|
|
95
|
|
|
if (file_exists($oldSourcesDir . '/' . $dir)){ |
96
|
|
|
$fsHelper->move($oldSourcesDir . '/' . $dir, $tmpDir . '/' . $dir); |
97
|
|
|
} |
98
|
|
|
if (file_exists($newSourcesDir . '/' . $dir)){ |
99
|
|
|
$fsHelper->move($newSourcesDir . '/' . $dir, $oldSourcesDir . '/' . $dir); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$plain = $this->occRunner->run('upgrade'); |
104
|
|
|
$output->writeln($plain); |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
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: