forked from ExFace/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreInstaller.php
97 lines (88 loc) · 3.06 KB
/
CoreInstaller.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
<?php
namespace exface\Core;
use exface\Core\CommonLogic\AppInstallers\AbstractAppInstaller;
use exface\Core\CommonLogic\Filemanager;
/**
*
* @method CoreApp getApp()
*
* @author Andrej Kabachnik
*
*/
class CoreInstaller extends AbstractAppInstaller
{
/**
*
* {@inheritDoc}
* @see \exface\Core\Interfaces\InstallerInterface::install()
*/
public function install($source_absolute_path)
{
// Install model DB
$modelLoaderInstaller = $this->getWorkbench()->model()->getModelLoader()->getInstaller();
$result = $modelLoaderInstaller->install($this->getWorkbench()->filemanager()->getPathToVendorFolder() . DIRECTORY_SEPARATOR . $modelLoaderInstaller->getSelectorInstalling()->getFolderRelativePath());
// Add required files to root folder
$result .= $this->createApiPhp($source_absolute_path);
$result .= $this->removeLegacyFiles($source_absolute_path);
return $result;
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\Interfaces\InstallerInterface::uninstall()
*/
public function uninstall()
{
return 'Uninstall not implemented for installer "' . $this->getSelectorInstalling()->getAliasWithNamespace() . '"!';
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\Interfaces\InstallerInterface::backup()
*/
public function backup($destination_absolute_path)
{
return 'Backup not implemented for' . $this->getSelectorInstalling()->getAliasWithNamespace() . '!';
}
protected function createApiPhp(string $source_absolute_path) : string
{
$result = '';
// Copy default .htaccess to the root of the installation
$file = Filemanager::pathJoin([$this->getWorkbench()->getInstallationPath(), 'api.php']);
if (! file_exists($file)) {
$content = <<<PHP
<?php
error_reporting(E_ALL & ~E_NOTICE);
require_once('vendor/exface/Core/index.php');
?>
PHP;
try {
file_put_contents($file, $content);
$result .= "\nGenerated default api.php file in plattform root.";
} catch (\Exception $e) {
$result .= "\nFailed to copy default api.php file: " . $e->getMessage() . ' in ' . $e->getFile() . ' at ' . $e->getLine() . '.';
}
}
return $result;
}
protected function removeLegacyFiles(string $source_absolute_path) : string
{
$files = [
'exface.php'
];
foreach ($files as $file) {
$filepath = Filemanager::pathJoin([$this->getWorkbench()->getInstallationPath(), $file]);
if (file_exists($filepath)) {
try {
unlink($filepath);
} catch (\Throwable $e) {
return "\n" . 'Could not remove legacy file "' . $filepath . '" - please delete the file manually!';
}
}
}
return '';
}
}
?>