-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInstall.php
More file actions
109 lines (88 loc) · 3.28 KB
/
Install.php
File metadata and controls
109 lines (88 loc) · 3.28 KB
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
104
105
106
107
108
109
<?php
namespace Foolz\FoolFrame\Model;
use Foolz\FoolFrame\Model\Config;
class Install extends Model
{
/**
* @var Config
*/
protected $config;
public function __construct(Context $context)
{
parent::__construct($context);
$this->config = $context->getService('config');
}
public static function check_database($array)
{
try {
switch ($array['type']) {
case 'pdo_mysql':
new \PDO(
'mysql:dbname='.$array['database'].';host='.$array['hostname'],
$array['username'],
$array['password']
);
break;
case 'pdo_pgsql':
new \PDO(
'pgsql:dbname='.$array['database'].';host='.$array['hostname'],
$array['username'],
$array['password']
);
break;
default:
return false;
}
} catch (\PDOException $e) {
return false;
}
return true;
}
public function setup_database($array)
{
$this->config->set('foolz/foolframe', 'db', 'default', array(
'driver' => $array['type'],
'host' => $array['hostname'],
'port' => '3306',
'dbname' => $array['database'],
'user' => $array['username'],
'password' => $array['password'],
'prefix' => $array['prefix'],
'charset' => 'utf8mb4',
));
$this->config->save('foolz/foolframe', 'db');
}
public function create_salts()
{
// config without slash is the custom foolz one
$this->config->set('foolz/foolframe', 'config', 'config.cookie_prefix', 'foolframe_'.Util::randomString(3).'_');
$this->config->save('foolz/foolframe', 'config');
$this->config->set('foolz/foolframe', 'cache', 'prefix', 'foolframe_'.Util::randomString(3).'_');
$this->config->save('foolz/foolframe', 'cache');
}
public function install_modules()
{
$this->config->addPackage('unknown', ASSETSPATH);
$class_name = $this->config->get('unknown', 'package', 'main.class_name');
$name_lowercase = strtolower($class_name);
$modules = [
'foolframe' => [
'context' => '\\Foolz\\FoolFrame\\Model\\Context',
'namespace' => 'foolz/foolframe'
],
$name_lowercase => [
'context' => $this->config->get('unknown', 'package', 'main.class_context'),
'namespace' => 'foolz/'.$name_lowercase
]
];
$dc = new DoctrineConnection($this->getContext(), $this->config);
$sm = SchemaManager::forge($dc->getConnection(), $dc->getPrefix());
Schema::load($this->getContext(), $sm);
$schema_class = '\\Foolz\\'.$class_name.'\\Model\\Schema';
$schema_class::load($this->getContext(), $sm);
$sm->commit();
$this->config->set('foolz/foolframe', 'config', 'modules.installed', $modules);
$this->config->set('foolz/foolframe', 'config', 'install.installed', true);
$this->config->save('foolz/foolframe', 'config');
}
}