1
|
|
|
<?php |
2
|
|
|
namespace installation\controller; |
3
|
|
|
use core\functions\ChaineCaractere; |
4
|
|
|
use core\HTML\flashmessage\FlashMessage; |
5
|
|
|
use core\iniparser\IniParser; |
6
|
|
|
|
7
|
|
|
class InstallRibs { |
8
|
|
|
private $db_type; |
9
|
|
|
private $db_name; |
10
|
|
|
private $db_user; |
11
|
|
|
private $db_pass; |
12
|
|
|
private $db_host; |
13
|
|
|
|
14
|
|
|
private $dbc; |
15
|
|
|
|
16
|
|
|
private $erreur; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
20
|
|
|
public function __construct($db_type, $db_host, $db_name, $db_user, $db_pass) { |
21
|
|
|
$this->db_type = $db_type; |
22
|
|
|
$this->db_name = $db_name; |
23
|
|
|
$this->db_user = $db_user; |
24
|
|
|
$this->db_pass = $db_pass; |
25
|
|
|
$this->db_host = $db_host; |
26
|
|
|
|
27
|
|
|
try { |
28
|
|
|
$this->dbc = new \PDO($this->db_type.':host='.$this->db_host.';dbname='.$this->db_name, $this->db_user, $this->db_pass); |
29
|
|
|
|
30
|
|
|
$this->setinstallbdd(); |
31
|
|
|
} |
32
|
|
|
catch (\PDOException $e) { |
33
|
|
|
//on tente de créer la bdd |
34
|
|
|
$erreur = "getErreur".$e->getCode(); |
35
|
|
|
$this->$erreur(); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
43
|
|
|
public function getErreur() { |
44
|
|
|
return $this->erreur; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* server adress not ok |
49
|
|
|
*/ |
50
|
|
|
private function getErreur2002() { |
51
|
|
|
FlashMessage::setFlash("Le serveur : ".$this->db_host." est introuvable"); |
52
|
|
|
|
53
|
|
|
$this->erreur = true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* seerver type not correct |
58
|
|
|
*/ |
59
|
|
|
private function getErreur0() { |
60
|
|
|
FlashMessage::setFlash("Le type : ".$this->db_type." n'est pas un type de base de données correct"); |
61
|
|
|
|
62
|
|
|
$this->erreur = true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* couldn't find database |
67
|
|
|
*/ |
68
|
|
|
private function getErreur1049() { |
69
|
|
|
//si on ne trouve pas la bdd on la créée |
70
|
|
|
$dbc = new \PDO($this->db_type.':host='.$this->db_host, $this->db_user, $this->db_pass); |
71
|
|
|
|
72
|
|
|
$dbc->query("CREATE DATABASE ".$this->db_name." DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
73
|
|
|
|
74
|
|
|
$this->dbc = new \PDO($this->db_type.':host='.$this->db_host.';dbname='.$this->db_name, $this->db_user, $this->db_pass); |
75
|
|
|
|
76
|
|
|
$this->setinstallbdd(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* user uncorrect |
81
|
|
|
*/ |
82
|
|
|
private function getErreur1044() { |
83
|
|
|
FlashMessage::setFlash("Le nom d'utilisateur : ".$this->db_user." est incorrect"); |
84
|
|
|
|
85
|
|
|
$this->erreur = true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* password uncorrect |
90
|
|
|
*/ |
91
|
|
|
private function getErreur1045() { |
92
|
|
|
FlashMessage::setFlash("Le mot de passe : ".$this->db_pass." est incorrect"); |
93
|
|
|
|
94
|
|
|
$this->erreur = true; |
95
|
|
|
} |
96
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
101
|
|
|
private function setinstallbdd() { |
102
|
|
|
$this->dbc->query(file_get_contents(ROOT.'installation/controller/sql/install.sql')); |
103
|
|
|
|
104
|
|
|
$dev_info = [$this->db_type, $this->db_name, $this->db_user, $this->db_pass, $this->db_host, "/app/images/", "/app/images/pages"]; |
105
|
|
|
$prod_info = ["", "", "", "", "", "/app/images/", "/app/images/pages"]; |
106
|
|
|
|
107
|
|
|
$ini = new IniParser(); |
108
|
|
|
$ini->setModifierConfigIni("on", $dev_info, $prod_info); |
109
|
|
|
} |
110
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
111
|
|
|
} |