InstallRibs::getErreur1049()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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