|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\Bundle\CoreInstallerBundle\Helper; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Filesystem\Exception\FileNotFoundException; |
|
17
|
|
|
use Zikula\Bundle\CoreBundle\Helper\LocalDotEnvHelper; |
|
18
|
|
|
use Zikula\Bundle\CoreBundle\YamlDumper; |
|
19
|
|
|
|
|
20
|
|
|
class PreCore3UpgradeHelper |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $projectDir; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(string $projectDir) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->projectDir = $projectDir; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function preUpgrade(): bool |
|
33
|
|
|
{ |
|
34
|
|
|
if (!file_exists($this->projectDir . '/config/services_custom.yaml')) { |
|
35
|
|
|
throw new FileNotFoundException(sprintf('Could not find file %s', $this->projectDir . '/config/services_custom.yaml')); |
|
36
|
|
|
} |
|
37
|
|
|
$yamlHelper = new YamlDumper($this->projectDir . '/config', 'services_custom.yaml'); |
|
38
|
|
|
$params = $yamlHelper->getParameters(); |
|
39
|
|
|
if (isset($params['core_installed_version']) && version_compare($params['core_installed_version'], '3.0.0', '<')) { |
|
40
|
|
|
$params['database_driver'] = mb_substr($params['database_driver'], 4); // remove pdo_ prefix |
|
41
|
|
|
(new DbCredsHelper($this->projectDir))->writeDatabaseDsn($params); |
|
42
|
|
|
(new LocalDotEnvHelper($this->projectDir))->writeLocalEnvVars(['ZIKULA_INSTALLED' => $params['core_installed_version']]); |
|
43
|
|
|
unset($params['core_installed_version']); |
|
44
|
|
|
$params['datadir'] = 'public/uploads'; |
|
45
|
|
|
$params['upgrading'] = true; |
|
46
|
|
|
$params['installed'] = '%env(ZIKULA_INSTALLED)%'; |
|
47
|
|
|
$params['zikula_asset_manager.combine'] = false; |
|
48
|
|
|
$yamlHelper->setParameters($params); |
|
49
|
|
|
|
|
50
|
|
|
return true; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return false; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|