-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
103 lines (83 loc) · 2.83 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace SourceBroker\Typo3Upgrade;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Process\Process;
function clearCache()
{
clearstatcache(true);
if (function_exists('opcache_reset')) {
opcache_reset();
}
}
function run($command, $return = false)
{
$commandWithDirChange = 'cd '. escapeshellarg(T3U_TYPO3_DIR) .' && '. $command;
$process1 = new Process('echo "------------------>>> ' . $command . '"');
$process1->setTty(true);
$process1->setTimeout(3600);
$process1->run();
$process = new Process($commandWithDirChange);
if (!$return) {
$process->setTty(true);
}
$process->setTimeout(3600);
$process->run();
if ($return) {
return $process->getOutput();
}
}
function getCurrentInstance()
{
$dotenv = new Dotenv(true);
$dotenv->load(T3U_TYPO3_DIR . '.env');
return getenv('INSTANCE');
}
function getUpgradeBranches()
{
$branchesRaw = run('git ls-remote 2>/dev/null | grep -ohE \'upgrade_([0-9]*)\'', true);
$branchesRawEntries = explode("\n", $branchesRaw);
$branches = [];
foreach ($branchesRawEntries as $branchRaw) {
$branchRaw = trim($branchRaw);
if (!$branchRaw) {
continue;
}
$version = str_replace('upgrade_','', $branchRaw);
$branches[$version] = $branchRaw;
}
ksort($branches, SORT_ASC | SORT_NUMERIC);
return $branches;
}
function getDbConfiguration()
{
$configurationJson = run('php ./vendor/bin/typo3cms configuration:showactive DB --json', true);
// cleanup depreciations and any other stuff before json
$configurationJson = substr($configurationJson, strpos($configurationJson,'{'), strlen($configurationJson));
$configuration = json_decode($configurationJson, true);
if (isset($configuration['Connections']['Default'])) {
return [
'database' => $configuration['Connections']['Default']['dbname'],
'host' => $configuration['Connections']['Default']['host'],
'port' => $configuration['Connections']['Default']['port'],
'username' => $configuration['Connections']['Default']['user'] ,
'password' => $configuration['Connections']['Default']['password'],
];
} else {
return [
'database' => $configuration['database'],
'host' => $configuration['host'],
'port' => $configuration['port'],
'username' => $configuration['username'],
'password' => $configuration['password'],
];
}
}
function dbUpdate($filePath)
{
if (!file_exists($filePath)) {
return;
}
$filePathAbs = realpath($filePath);
$configuration = getDbConfiguration();
run('mysql -u ' . $configuration['username'] . ' -p' . $configuration['password'] . ' ' . $configuration['database'] . ' < ' . $filePathAbs);
}