Passed
Push — master ( b58333...85a890 )
by Anthony
03:13
created
core/images/Images.class.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@
 block discarded – undo
43 43
 		//-------------------------- GETTER ----------------------------------------------------------------------------//
44 44
 
45 45
 		public function getOldImage() {
46
-		    return $this->old_image;
46
+			return $this->old_image;
47 47
 		}
48 48
 		public function getCheminImage() {
49
-		    return $this->chemin_image;
49
+			return $this->chemin_image;
50 50
 		}
51 51
 		public function getErreur() {
52
-		    return $this->erreur;
52
+			return $this->erreur;
53 53
 		}
54 54
 		public function getNomImage() {
55 55
 			return $this->nom_image;
Please login to merge, or discard this patch.
core/images/Resize.class.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		{
22 22
 			// *** Class variables
23 23
 			private $image;
24
-		    private $width;
25
-		    private $height;
24
+			private $width;
25
+			private $height;
26 26
 			private $imageResized;
27 27
 
28 28
 			function __construct($fileName)
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 				// *** Open up the file
31 31
 				$this->image = $this->openImage($fileName);
32 32
 
33
-			    // *** Get width and height
34
-			    $this->width  = imagesx($this->image);
35
-			    $this->height = imagesy($this->image);
33
+				// *** Get width and height
34
+				$this->width  = imagesx($this->image);
35
+				$this->height = imagesy($this->image);
36 36
 			}
37 37
 
38 38
 			## --------------------------------------------------------
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 			public function saveImage($savePath, $imageQuality="100")
207 207
 			{
208 208
 				// *** Get extension
209
-        		$extension = strrchr($savePath, '.');
210
-       			$extension = strtolower($extension);
209
+				$extension = strrchr($savePath, '.');
210
+	   			$extension = strtolower($extension);
211 211
 
212 212
 				switch($extension)
213 213
 				{
Please login to merge, or discard this patch.
core/admin/droitsacces/GestionDroitAcces.class.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    namespace core\admin\droitsacces;
2
+	namespace core\admin\droitsacces;
3 3
 
4
-    use core\App;
4
+	use core\App;
5 5
 
6 6
 	class GestionDroitAcces extends DroitAcces {
7 7
 		//pour les droit_acces standard
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
27
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
28 28
 		public function __construct($id_liste_droit_acces=null) {
29 29
 			$dbc = App::getDb();
30 30
 
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 				$this->id_liste_droit_acces = $id_liste_droit_acces;
65 65
 			}
66 66
 		}
67
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
67
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
68 68
 
69 69
 
70 70
 
71
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
71
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
72 72
 		//pour les droit_acces standard
73 73
 		public function getIdListeDroitAcces() {
74 74
 			return $this->id_liste_droit_acces;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			return $this->pseudo;
109 109
 		}
110 110
 		public function getNbUser(){
111
-		    return $this->nb_user;
111
+			return $this->nb_user;
112 112
 		}
113 113
 
114 114
 		/**
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 		 * @param $id_liste_droit_acces
117 117
 		 */
118 118
 		public function getListeDroitAccesDetailDroit($id_liste_droit_acces=null){
119
-		    $dbc = \core\App::getDb();
119
+			$dbc = \core\App::getDb();
120 120
 
121 121
 			if ($id_liste_droit_acces == null) $id_liste_droit_acces = $this->id_liste_droit_acces;
122 122
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param $id_liste_droit_acces
161 161
 		 */
162 162
 		public function getListeDroitAccesDetailPage($id_liste_droit_acces=null){
163
-		    $dbc = \core\App::getDb();
163
+			$dbc = \core\App::getDb();
164 164
 
165 165
 			if ($id_liste_droit_acces == null) $id_liste_droit_acces = $this->id_liste_droit_acces;
166 166
 
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 				$this->setListeDroitAccesDetailPage($id_page, $titre_page);
180 180
 			}
181 181
 		}
182
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
182
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
183 183
 
184 184
 
185 185
 
186
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
186
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
187 187
 		private function setListeDroitAcces($id_liste_droit_acces, $nom_liste, $nb_droit_acces, $nb_droit_acces_page, $nb_user){
188 188
 			$this->id_liste_droit_acces = $id_liste_droit_acces;
189 189
 			$this->nom_liste = $nom_liste;
@@ -205,4 +205,4 @@  discard block
 block discarded – undo
205 205
 			$this->prenom = $prenom;
206 206
 		}
207 207
 		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
208
-    }
209 208
\ No newline at end of file
209
+	}
210 210
\ No newline at end of file
Please login to merge, or discard this patch.
core/admin/droitsacces/DroitAcces.class.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    namespace core\admin\droitsacces;
2
+	namespace core\admin\droitsacces;
3 3
 
4 4
 	use core\App;
5 5
 
6 6
 	class DroitAcces {
7
-    	private $logged;
7
+		private $logged;
8 8
 
9 9
 		//pour la table identite
10 10
 		private $id_identite;
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 
22 22
 
23 23
 		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
24
-        public function __construct() {
24
+		public function __construct() {
25 25
 			$dbc = \core\App::getDb();
26 26
 
27
-            if (isset($_SESSION["idlogin".CLEF_SITE])) {
27
+			if (isset($_SESSION["idlogin".CLEF_SITE])) {
28 28
 				$this->logged = true;
29 29
 				$this->id_identite = $_SESSION["idlogin".CLEF_SITE];
30 30
 
@@ -44,36 +44,36 @@  discard block
 block discarded – undo
44 44
 			else {
45 45
 				$this->logged = false;
46 46
 			}
47
-        }
48
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
47
+		}
48
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
49 49
     
50 50
     
51 51
     
52
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
52
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
53 53
 		public function getLogged(){
54
-		    return $this->logged;
54
+			return $this->logged;
55 55
 		}
56 56
 		public function getSuperAdmin(){
57
-		    return $this->super_admin;
57
+			return $this->super_admin;
58 58
 		}
59 59
 
60 60
 		//pour la table liste_droit_acces
61 61
 		public function getIdListeDroitAcces(){
62
-		    return $this->id_liste_droit_acces;
62
+			return $this->id_liste_droit_acces;
63 63
 		}
64 64
 
65 65
 		//pour les droits sur la gestion des contenus
66 66
 		public function getModifSeo(){
67
-		    return $this->modif_seo;
67
+			return $this->modif_seo;
68 68
 		}
69 69
 		public function getModifContenu(){
70
-		    return $this->modif_contenu;
70
+			return $this->modif_contenu;
71 71
 		}
72 72
 		public function getModifNavigation(){
73
-		    return $this->modif_navigation;
73
+			return $this->modif_navigation;
74 74
 		}
75 75
 		public function getSupprimerPage(){
76
-		    return $this->supprimer_page;
76
+			return $this->supprimer_page;
77 77
 		}
78 78
 
79 79
 		//autres getter
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 				return true;
241 241
 			}
242 242
 		}
243
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
243
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
244 244
     
245 245
     
246 246
     
247
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
247
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
248 248
 
249
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
250
-    }
251 249
\ No newline at end of file
250
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
251
+	}
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
core/form/FormValidator.class.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,48 +1,48 @@
 block discarded – undo
1 1
 <?php
2
-    namespace core\form;
2
+	namespace core\form;
3 3
 
4
-    class FormValidator {
5
-        private $datas = [];
6
-        private $errors = [];
4
+	class FormValidator {
5
+		private $datas = [];
6
+		private $errors = [];
7 7
 
8 8
 
9
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
-        public function __construct($datas) {
11
-            $this->datas = $datas;
12
-        }
13
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
9
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
+		public function __construct($datas) {
11
+			$this->datas = $datas;
12
+		}
13
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
14 14
 
15 15
 
16
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
17
-        public function Check($name, $rule, $option=null) {
18
-            $validator = "validate".ucfirst($rule);
16
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
17
+		public function Check($name, $rule, $option=null) {
18
+			$validator = "validate".ucfirst($rule);
19 19
 
20
-            if (!$this->$validator($name, $option)) {
21
-                $this->errors[$name] = "Le champ $name n'a pas été rempli correctement";
22
-            }
23
-        }
20
+			if (!$this->$validator($name, $option)) {
21
+				$this->errors[$name] = "Le champ $name n'a pas été rempli correctement";
22
+			}
23
+		}
24 24
 
25
-        public function getErrors() {
26
-            if ($this->errors) {
27
-                $errors = "<ul>";
28
-                foreach ($this->errors as $error) {
29
-                    $errors .= "<li>".$error."</li>";
30
-                }
31
-                $errors .= "</ul>";
25
+		public function getErrors() {
26
+			if ($this->errors) {
27
+				$errors = "<ul>";
28
+				foreach ($this->errors as $error) {
29
+					$errors .= "<li>".$error."</li>";
30
+				}
31
+				$errors .= "</ul>";
32 32
 
33
-                return $errors;
34
-            }
35
-        }
36
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
33
+				return $errors;
34
+			}
35
+		}
36
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
37 37
 
38 38
 
39
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
40
-        public function validateRequired($name) {
41
-            return array_key_exists($name, $this->datas) && $this->datas[$name] != "";
42
-        }
39
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
40
+		public function validateRequired($name) {
41
+			return array_key_exists($name, $this->datas) && $this->datas[$name] != "";
42
+		}
43 43
 
44
-        public function validateEmail($name) {
45
-            return array_key_exists($name, $this->datas) && filter_var($this->datas[$name], FILTER_VALIDATE_EMAIL);
46
-        }
47
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
48
-    }
49 44
\ No newline at end of file
45
+		public function validateEmail($name) {
46
+			return array_key_exists($name, $this->datas) && filter_var($this->datas[$name], FILTER_VALIDATE_EMAIL);
47
+		}
48
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
49
+	}
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
core/Configuration.class.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    namespace core;
2
+	namespace core;
3 3
 
4 4
 
5
-    use core\HTML\flashmessage\FlashMessage;
5
+	use core\HTML\flashmessage\FlashMessage;
6 6
 
7 7
 	class Configuration {
8 8
 		//pour la configuration générale du site
9
-        private $nom_site; //-> nom du site
10
-        private $mail_site; //-> pour le gérant du site contact@nomdedomaine;com
11
-        private $gerant_site; //->nom du gérant du site
12
-        private $url_site; //-> url de site
13
-        private $mail_administrateur; //-> mail de l'administrateur [email protected]
9
+		private $nom_site; //-> nom du site
10
+		private $mail_site; //-> pour le gérant du site contact@nomdedomaine;com
11
+		private $gerant_site; //->nom du gérant du site
12
+		private $url_site; //-> url de site
13
+		private $mail_administrateur; //-> mail de l'administrateur [email protected]
14 14
 		private $last_save; //-> derniere sauvegarde de la bdd
15 15
 		private $acces_admin; //-> si == 1 on a acces à l'admin
16 16
 		private $contenu_dynamique; //->savoir si es contenus sont dynamique (stockés in DB)
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 		private $activer_connexion;
24 24
 
25 25
 
26
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
27
-        public function __construct() {
28
-            $dbc = \core\App::getDb();
26
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
27
+		public function __construct() {
28
+			$dbc = \core\App::getDb();
29 29
 
30 30
 			//pour la configuration générale du site
31
-            $query = $dbc->query("SELECT * FROM configuration WHERE ID_configuration=1");
32
-            foreach ($query as $obj) {
33
-                $this->nom_site = $obj->nom_site;
34
-                $this->mail_site = $obj->mail_site;
35
-                $this->gerant_site = $obj->gerant_site;
36
-                $this->url_site = $obj->url_site;
37
-                $this->mail_administrateur = $obj->mail_administrateur;
38
-                $this->last_save = $obj->last_save;
31
+			$query = $dbc->query("SELECT * FROM configuration WHERE ID_configuration=1");
32
+			foreach ($query as $obj) {
33
+				$this->nom_site = $obj->nom_site;
34
+				$this->mail_site = $obj->mail_site;
35
+				$this->gerant_site = $obj->gerant_site;
36
+				$this->url_site = $obj->url_site;
37
+				$this->mail_administrateur = $obj->mail_administrateur;
38
+				$this->last_save = $obj->last_save;
39 39
 				$this->acces_admin = $obj->acces_admin;
40 40
 				$this->contenu_dynamique = $obj->contenu_dynamique;
41 41
 				$this->responsive = $obj->responsive;
42 42
 				$this->cache = $obj->cache;
43
-            }
43
+			}
44 44
 
45 45
 			//pour la configuration des comptes
46 46
 			$query = $dbc->query("SELECT * FROM configuration_compte WHERE ID_configuration_compte=1");
@@ -49,31 +49,31 @@  discard block
 block discarded – undo
49 49
 				$this->activer_inscription = $obj->activer_inscription;
50 50
 				$this->activer_connexion = $obj->activer_connexion;
51 51
 			}
52
-        }
53
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
52
+		}
53
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
54 54
 
55 55
 
56 56
 
57
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
57
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
58 58
 		//pour la configuration générale du site
59
-        public function getNomSite(){
60
-            return $this->nom_site;
61
-        }
62
-        public function getMailSite(){
63
-            return $this->mail_site;
64
-        }
65
-        public function getGerantSite(){
66
-            return $this->gerant_site;
67
-        }
68
-        public function getUrlSite(){
69
-            return $this->url_site;
70
-        }
71
-        public function getMailAdministrateur(){
72
-            return $this->mail_administrateur;
73
-        }
74
-        public function getLastSave(){
75
-            return $this->last_save;
76
-        }
59
+		public function getNomSite(){
60
+			return $this->nom_site;
61
+		}
62
+		public function getMailSite(){
63
+			return $this->mail_site;
64
+		}
65
+		public function getGerantSite(){
66
+			return $this->gerant_site;
67
+		}
68
+		public function getUrlSite(){
69
+			return $this->url_site;
70
+		}
71
+		public function getMailAdministrateur(){
72
+			return $this->mail_administrateur;
73
+		}
74
+		public function getLastSave(){
75
+			return $this->last_save;
76
+		}
77 77
 		public function getAccesAdmin() {
78 78
 			return $this->acces_admin;
79 79
 		}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 		public function getActiverConnexion() {
98 98
 			return $this->activer_connexion;
99 99
 		}
100
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
100
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
101 101
 
102 102
 
103 103
 
104
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
104
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
105 105
 		/**
106 106
 		 * fonction qui permet de mettre à jour la date de la derniere save de la bdd
107 107
 		 * + supprimer la sauverde ancienne d'il y a 1 mois
@@ -125,5 +125,5 @@  discard block
 block discarded – undo
125 125
 				unlink(ROOT."bdd_backup/".$nom_save);
126 126
 			}
127 127
 		}
128
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
129
-    }
130 128
\ No newline at end of file
129
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
130
+	}
131 131
\ No newline at end of file
Please login to merge, or discard this patch.
core/mail/Mail.class.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,69 +1,69 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-    namespace core\mail;
3
+	namespace core\mail;
4 4
         
5
-    class Mail {
6
-        private $mail;
5
+	class Mail {
6
+		private $mail;
7 7
     
8 8
     
9
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
-        public function __construct($mail=null) {
11
-            $this->mail = $mail;
12
-        }
13
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
9
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
+		public function __construct($mail=null) {
11
+			$this->mail = $mail;
12
+		}
13
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
14 14
     
15 15
     
16 16
     
17
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
18
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
17
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
18
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
19 19
 
20 20
 
21 21
     
22
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
23
-        /**
24
-         * fonction qui permet de valider si un E-mail est valide
25
-         * @return bool
26
-         */
27
-        public function setVerifierMail() {
28
-            if (filter_var($this->mail, FILTER_VALIDATE_EMAIL)) {
29
-                return true;
30
-            }
31
-            else {
32
-                return false;
33
-            }
34
-        }
22
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
23
+		/**
24
+		 * fonction qui permet de valider si un E-mail est valide
25
+		 * @return bool
26
+		 */
27
+		public function setVerifierMail() {
28
+			if (filter_var($this->mail, FILTER_VALIDATE_EMAIL)) {
29
+				return true;
30
+			}
31
+			else {
32
+				return false;
33
+			}
34
+		}
35 35
 
36
-        /**
37
-         * fonction qui permet d'envoyer un mail
38
-         * @param $sujet
39
-         * @param $message
40
-         * @param null $destinataire -> si  null on envoi un mail au gerant du site
41
-         * @param null $destinataire -> si  null on emet le gerant du site car mail vient depuis l'admin
42
-         * @return bool
43
-         */
44
-        public function setEnvoyerMail($sujet, $message, $destinataire=null, $from=null) {
45
-            //on récupere le mail du site
46
-            $config = new \core\Configuration();
36
+		/**
37
+		 * fonction qui permet d'envoyer un mail
38
+		 * @param $sujet
39
+		 * @param $message
40
+		 * @param null $destinataire -> si  null on envoi un mail au gerant du site
41
+		 * @param null $destinataire -> si  null on emet le gerant du site car mail vient depuis l'admin
42
+		 * @return bool
43
+		 */
44
+		public function setEnvoyerMail($sujet, $message, $destinataire=null, $from=null) {
45
+			//on récupere le mail du site
46
+			$config = new \core\Configuration();
47 47
 
48
-            if ($from == null) $from = $config->getMailSite();
48
+			if ($from == null) $from = $config->getMailSite();
49 49
 
50
-            $headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
51
-            $headers .= "From: ".$from;
50
+			$headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
51
+			$headers .= "From: ".$from;
52 52
 
53
-            //si pas de destinataire on envoi le mail au gérant du site car c'est un mail envoyé par le site lui même
54
-            if (($destinataire == null) && ($this->mail == null)) {
55
-                $destinataire = $config->getMailSite();
56
-            }
57
-            else if ($destinataire == null) {
58
-                $destinataire = $this->mail;
59
-            }
53
+			//si pas de destinataire on envoi le mail au gérant du site car c'est un mail envoyé par le site lui même
54
+			if (($destinataire == null) && ($this->mail == null)) {
55
+				$destinataire = $config->getMailSite();
56
+			}
57
+			else if ($destinataire == null) {
58
+				$destinataire = $this->mail;
59
+			}
60 60
 
61
-            if (mail($destinataire, $sujet, $message, $headers)) {
62
-                return true;
63
-            }
64
-            else {
65
-                return false;
66
-            }
67
-        }
68
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
69
-    }
70 61
\ No newline at end of file
62
+			if (mail($destinataire, $sujet, $message, $headers)) {
63
+				return true;
64
+			}
65
+			else {
66
+				return false;
67
+			}
68
+		}
69
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
70
+	}
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
core/App.class.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    namespace core;
2
+	namespace core;
3 3
 
4
-    class App {
5
-    	private static $database;
4
+	class App {
5
+		private static $database;
6 6
 		private static $erreur;
7 7
     
8 8
     
9
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
-        public function __construct() {
9
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
10
+		public function __construct() {
11 11
             
12
-        }
13
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
12
+		}
13
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
14 14
     
15 15
     
16 16
     
17
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
17
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
18 18
 		public static function getErreur(){
19
-		    return self::$erreur;
19
+			return self::$erreur;
20 20
 		}
21 21
 
22 22
 		/**
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 				return "<li>$err_egalite</li>";
55 55
 			}
56 56
 		}
57
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
57
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
58 58
     
59 59
     
60 60
     
61
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
62
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
63
-    }
64 61
\ No newline at end of file
62
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
63
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
64
+	}
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
core/save/Mysqldump.class.php 1 patch
Indentation   +1427 added lines, -1427 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Mysqldump File Doc Comment
4
- *
5
- * PHP version 5
6
- *
7
- * @category Library
8
- * @package  Ifsnop\Mysqldump
9
- * @author   Michael J. Calkins <[email protected]>
10
- * @author   Diego Torres <[email protected]>
11
- * @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
12
- * @link     https://github.com/ifsnop/mysqldump-php
13
- *
14
- */
3
+	 * Mysqldump File Doc Comment
4
+	 *
5
+	 * PHP version 5
6
+	 *
7
+	 * @category Library
8
+	 * @package  Ifsnop\Mysqldump
9
+	 * @author   Michael J. Calkins <[email protected]>
10
+	 * @author   Diego Torres <[email protected]>
11
+	 * @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
12
+	 * @link     https://github.com/ifsnop/mysqldump-php
13
+	 *
14
+	 */
15 15
 
16 16
 namespace core\save;
17 17
 
@@ -33,696 +33,696 @@  discard block
 block discarded – undo
33 33
 class Mysqldump
34 34
 {
35 35
 
36
-    // Same as mysqldump
37
-    const MAXLINESIZE = 1000000;
38
-
39
-    // Available compression methods as constants
40
-    const GZIP = 'Gzip';
41
-    const BZIP2 = 'Bzip2';
42
-    const NONE = 'None';
43
-
44
-    // Available connection strings
45
-    const UTF8 = 'utf8';
46
-    const UTF8MB4 = 'utf8mb4';
47
-
48
-    // This can be set both on constructor or manually
49
-    public $host;
50
-    public $port;
51
-    public $user;
52
-    public $pass;
53
-    public $db;
54
-    public $fileName;
55
-
56
-    // Internal stuff
57
-    private $tables = array();
58
-    private $views = array();
59
-    private $triggers = array();
60
-    private $dbHandler;
61
-    private $dbType;
62
-    private $compressManager;
63
-    private $typeAdapter;
64
-    private $dumpSettings = array();
65
-    private $pdoSettings = array();
66
-    private $version;
67
-    private $tableColumnTypes = array();
68
-
69
-    /**
70
-     * Constructor of Mysqldump. Note that in the case of an SQLite database
71
-     * connection, the filename must be in the $db parameter.
72
-     *
73
-     * @param string $db         Database name
74
-     * @param string $user       SQL account username
75
-     * @param string $pass       SQL account password
76
-     * @param string $host       SQL server to connect to
77
-     * @param string $type       SQL database type
78
-     * @param array  $dumpSettings SQL database settings
79
-     * @param array  $pdoSettings  PDO configured attributes
80
-     */
81
-    public function __construct(
82
-        $db = '',
83
-        $user = '',
84
-        $pass = '',
85
-        $host = 'localhost',
86
-        $type = 'mysql',
87
-        $dumpSettings = array(),
88
-        $pdoSettings = array()
89
-    ) {
90
-        $dumpSettingsDefault = array(
91
-            'include-tables' => array(),
92
-            'exclude-tables' => array(),
93
-            'compress' => Mysqldump::NONE,
94
-            'no-data' => false,
95
-            'add-drop-table' => false,
96
-            'single-transaction' => true,
97
-            'lock-tables' => true,
98
-            'add-locks' => true,
99
-            'extended-insert' => true,
100
-            'disable-keys' => true,
101
-            'where' => '',
102
-            'no-create-info' => false,
103
-            'skip-triggers' => false,
104
-            'add-drop-trigger' => true,
105
-            'hex-blob' => true,
106
-            'databases' => false,
107
-            'add-drop-database' => false,
108
-            'skip-tz-utz' => false,
109
-            'no-autocommit' => true,
110
-            'default-character-set' => Mysqldump::UTF8,
111
-            'skip-comments' => false,
112
-            'skip-dump-date' => false,
113
-            /* deprecated */
114
-            'disable-foreign-keys-check' => true
115
-        );
116
-
117
-        $pdoSettingsDefault = array(
118
-            PDO::ATTR_PERSISTENT => true,
119
-            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
120
-            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
121
-        );
122
-
123
-        $this->db = $db;
124
-        $this->user = $user;
125
-        $this->pass = $pass;
126
-
127
-        $colonPos = strpos($host, ':');
128
-        if (false !== $colonPos) {
129
-            $this->port = substr($host, $colonPos + 1);
130
-            $this->host = substr($host, 0, $colonPos);
131
-        } else {
132
-            $this->port = null;
133
-            $this->host = $host;
134
-        }
135
-
136
-        $this->dbType = strtolower($type);
137
-        $this->pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
138
-        $this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
139
-
140
-        if (!isset($this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND])) {
141
-            $this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->dumpSettings['default-character-set'];
142
-        }
143
-
144
-        $diff = array_diff(array_keys($this->dumpSettings), array_keys($dumpSettingsDefault));
145
-        if (count($diff)>0) {
146
-            throw new Exception("Unexpected value in dumpSettings: (" . implode(",", $diff) . ")");
147
-        }
148
-
149
-        // Create a new compressManager to manage compressed output
150
-        $this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
151
-    }
152
-
153
-    /**
154
-     * Custom array_replace_recursive to be used if PHP < 5.3
155
-     * Replaces elements from passed arrays into the first array recursively
156
-     *
157
-     * @param array $array1 The array in which elements are replaced
158
-     * @param array $array2 The array from which elements will be extracted
159
-     *
160
-     * @return array Returns an array, or NULL if an error occurs.
161
-     */
162
-    public static function array_replace_recursive($array1, $array2)
163
-    {
164
-        if (function_exists('array_replace_recursive')) {
165
-            return array_replace_recursive($array1, $array2);
166
-        }
167
-
168
-        foreach ($array2 as $key => $value) {
169
-            if (is_array($value)) {
170
-                $array1[$key] = self::array_replace_recursive($array1[$key], $value);
171
-            } else {
172
-                $array1[$key] = $value;
173
-            }
174
-        }
175
-        return $array1;
176
-    }
177
-
178
-    /**
179
-     * Connect with PDO
180
-     *
181
-     * @return null
182
-     */
183
-    private function connect()
184
-    {
185
-        // Connecting with PDO
186
-        try {
187
-            switch ($this->dbType) {
188
-                case 'sqlite':
189
-                    $this->dbHandler = @new PDO("sqlite:" . $this->db, null, null, $this->pdoSettings);
190
-                    break;
191
-                case 'mysql':
192
-                case 'pgsql':
193
-                case 'dblib':
194
-                    $dsn =  $this->dbType .
195
-                        ":host=" . $this->host .
196
-                         (isset($this->port) ? ";port=" . $this->port : "") .
197
-                        ";dbname=" . $this->db;
198
-                    $this->dbHandler = @new PDO(
199
-                        $dsn,
200
-                        $this->user,
201
-                        $this->pass,
202
-                        $this->pdoSettings
203
-                    );
204
-                    // Fix for always-unicode output
205
-                    $this->dbHandler->exec("SET NAMES " . $this->dumpSettings['default-character-set']);
206
-                    // Store server version
207
-                    $this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
208
-                    break;
209
-                default:
210
-                    throw new Exception("Unsupported database type (" . $this->dbType . ")");
211
-            }
212
-        } catch (PDOException $e) {
213
-            throw new Exception(
214
-                "Connection to " . $this->dbType . " failed with message: " .
215
-                $e->getMessage()
216
-            );
217
-        }
218
-
219
-        $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
220
-        $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler);
221
-    }
222
-
223
-    /**
224
-     * Main call
225
-     *
226
-     * @param string $filename  Name of file to write sql dump to
227
-     * @return null
228
-     */
229
-    public function start($filename = '')
230
-    {
231
-        // Output file can be redefined here
232
-        if (!empty($filename)) {
233
-            $this->fileName = $filename;
234
-        }
235
-        // We must set a name to continue
236
-        if (empty($this->fileName)) {
237
-            throw new Exception("Output file name is not set");
238
-        }
239
-
240
-        // Connect to database
241
-        $this->connect();
242
-
243
-        // Create output file
244
-        $this->compressManager->open($this->fileName);
245
-
246
-        // Write some basic info to output file
247
-        $this->compressManager->write($this->getDumpFileHeader());
248
-
249
-        // Store server settings and use sanner defaults to dump
250
-        $this->compressManager->write(
251
-            $this->typeAdapter->backup_parameters($this->dumpSettings)
252
-        );
253
-
254
-        if ($this->dumpSettings['databases']) {
255
-            $this->compressManager->write(
256
-                $this->typeAdapter->getDatabaseHeader($this->db)
257
-            );
258
-            if ($this->dumpSettings['add-drop-database']) {
259
-                $this->compressManager->write(
260
-                    $this->typeAdapter->add_drop_database($this->db)
261
-                );
262
-            }
263
-        }
264
-
265
-        // Get table, view and trigger structures from database
266
-        $this->getDatabaseStructure();
267
-
268
-        if ($this->dumpSettings['databases']) {
269
-            $this->compressManager->write(
270
-                $this->typeAdapter->databases($this->db)
271
-            );
272
-        }
273
-
274
-        // If there still are some tables/views in include-tables array,
275
-        // that means that some tables or views weren't found.
276
-        // Give proper error and exit.
277
-        if (0 < count($this->dumpSettings['include-tables'])) {
278
-            $name = implode(",", $this->dumpSettings['include-tables']);
279
-            throw new Exception("Table or View (" . $name . ") not found in database");
280
-        }
281
-
282
-        $this->exportTables();
283
-        $this->exportViews();
284
-        $this->exportTriggers();
285
-
286
-        // Restore saved parameters
287
-        $this->compressManager->write(
288
-            $this->typeAdapter->restore_parameters($this->dumpSettings)
289
-        );
290
-        // Write some stats to output file
291
-        $this->compressManager->write($this->getDumpFileFooter());
292
-        // Close output file
293
-        $this->compressManager->close();
294
-    }
295
-
296
-    /**
297
-     * Returns header for dump file
298
-     *
299
-     * @return string
300
-     */
301
-    private function getDumpFileHeader()
302
-    {
303
-        $header = '';
304
-        if (!$this->dumpSettings['skip-comments']) {
305
-            // Some info about software, source and time
306
-            $header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
307
-                    "--" . PHP_EOL .
308
-                    "-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
309
-                    "-- ------------------------------------------------------" . PHP_EOL;
310
-
311
-            if (!empty($this->version)) {
312
-                $header .= "-- Server version \t" . $this->version . PHP_EOL;
313
-            }
314
-
315
-            $header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
316
-        }
317
-        return $header;
318
-    }
319
-
320
-    /**
321
-     * Returns footer for dump file
322
-     *
323
-     * @return string
324
-     */
325
-    private function getDumpFileFooter()
326
-    {
327
-        $footer = '';
328
-        if (!$this->dumpSettings['skip-comments']) {
329
-            $footer .= '-- Dump completed';
330
-            if (!$this->dumpSettings['skip-dump-date']) {
331
-                $footer .= ' on: ' . date('r');
332
-            }
333
-            $footer .= PHP_EOL;
334
-        }
335
-
336
-        return $footer;
337
-    }
338
-
339
-    /**
340
-     * Reads table and views names from database.
341
-     * Fills $this->tables array so they will be dumped later.
342
-     *
343
-     * @return null
344
-     */
345
-    private function getDatabaseStructure()
346
-    {
347
-        // Listing all tables from database
348
-        if (empty($this->dumpSettings['include-tables'])) {
349
-            // include all tables for now, blacklisting happens later
350
-            foreach ($this->dbHandler->query($this->typeAdapter->show_tables($this->db)) as $row) {
351
-                array_push($this->tables, current($row));
352
-            }
353
-        } else {
354
-            // include only the tables mentioned in include-tables
355
-            foreach ($this->dbHandler->query($this->typeAdapter->show_tables($this->db)) as $row) {
356
-                if (in_array(current($row), $this->dumpSettings['include-tables'], true)) {
357
-                    array_push($this->tables, current($row));
358
-                    $elem = array_search(
359
-                        current($row),
360
-                        $this->dumpSettings['include-tables']
361
-                    );
362
-                    unset($this->dumpSettings['include-tables'][$elem]);
363
-                }
364
-            }
365
-        }
366
-
367
-        // Listing all views from database
368
-        if (empty($this->dumpSettings['include-tables'])) {
369
-            // include all views for now, blacklisting happens later
370
-            foreach ($this->dbHandler->query($this->typeAdapter->show_views($this->db)) as $row) {
371
-                array_push($this->views, current($row));
372
-            }
373
-        } else {
374
-            // include only the tables mentioned in include-tables
375
-            foreach ($this->dbHandler->query($this->typeAdapter->show_views($this->db)) as $row) {
376
-                if (in_array(current($row), $this->dumpSettings['include-tables'], true)) {
377
-                    array_push($this->views, current($row));
378
-                    $elem = array_search(
379
-                        current($row),
380
-                        $this->dumpSettings['include-tables']
381
-                    );
382
-                    unset($this->dumpSettings['include-tables'][$elem]);
383
-                }
384
-            }
385
-        }
386
-
387
-        // Listing all triggers from database
388
-        if (false === $this->dumpSettings['skip-triggers']) {
389
-            foreach ($this->dbHandler->query($this->typeAdapter->show_triggers($this->db)) as $row) {
390
-                array_push($this->triggers, $row['Trigger']);
391
-            }
392
-        }
393
-    }
394
-
395
-    /**
396
-     * Exports all the tables selected from database
397
-     *
398
-     * @return null
399
-     */
400
-    private function exportTables()
401
-    {
402
-        // Exporting tables one by one
403
-        foreach ($this->tables as $table) {
404
-            if (in_array($table, $this->dumpSettings['exclude-tables'], true)) {
405
-                continue;
406
-            }
407
-            $this->getTableStructure($table);
408
-            if (false === $this->dumpSettings['no-data']) {
409
-                $this->listValues($table);
410
-            }
411
-        }
412
-    }
413
-
414
-    /**
415
-     * Exports all the views found in database
416
-     *
417
-     * @return null
418
-     */
419
-    private function exportViews()
420
-    {
421
-        if (false === $this->dumpSettings['no-create-info']) {
422
-            // Exporting views one by one
423
-            foreach ($this->views as $view) {
424
-                if (in_array($view, $this->dumpSettings['exclude-tables'], true)) {
425
-                    continue;
426
-                }
427
-                $this->getViewStructure($view);
428
-            }
429
-        }
430
-    }
431
-
432
-    /**
433
-     * Exports all the triggers found in database
434
-     *
435
-     * @return null
436
-     */
437
-    private function exportTriggers()
438
-    {
439
-        // Exporting triggers one by one
440
-        foreach ($this->triggers as $trigger) {
441
-            $this->getTriggerStructure($trigger);
442
-        }
443
-    }
444
-
445
-
446
-    private function getTableStructure($tableName)
447
-    {
448
-        if (!$this->dumpSettings['no-create-info']) {
449
-            $ret = '';
450
-            if (!$this->dumpSettings['skip-comments']) {
451
-                $ret = "--" . PHP_EOL .
452
-                    "-- Table structure for table `$tableName`" . PHP_EOL .
453
-                    "--" . PHP_EOL . PHP_EOL;
454
-            }
455
-            $stmt = $this->typeAdapter->show_create_table($tableName);
456
-            foreach ($this->dbHandler->query($stmt) as $r) {
457
-                $this->compressManager->write($ret);
458
-                if ($this->dumpSettings['add-drop-table']) {
459
-                    $this->compressManager->write(
460
-                        $this->typeAdapter->drop_table($tableName)
461
-                    );
462
-                }
463
-                $this->compressManager->write(
464
-                    $this->typeAdapter->create_table($r, $this->dumpSettings)
465
-                );
466
-                break;
467
-            }
468
-        }
469
-
470
-        $columnTypes = array();
471
-        $columns = $this->dbHandler->query(
472
-            $this->typeAdapter->show_columns($tableName)
473
-        );
474
-        $columns->setFetchMode(PDO::FETCH_ASSOC);
475
-
476
-        foreach($columns as $key => $col) {
477
-            $types = $this->typeAdapter->parseColumnType($col);
478
-            $columnTypes[$col['Field']] = array(
479
-                'is_numeric'=> $types['is_numeric'],
480
-                'is_blob' => $types['is_blob'],
481
-                'type' => $types['type']
482
-            );
483
-        }
484
-        $this->tableColumnTypes[$tableName] = $columnTypes;
485
-        return;
486
-    }
487
-
488
-
489
-    private function getViewStructure($viewName)
490
-    {
491
-        $ret = '';
492
-        if (!$this->dumpSettings['skip-comments']) {
493
-            $ret = "--" . PHP_EOL .
494
-                "-- Table structure for view `${viewName}`" . PHP_EOL .
495
-                "--" . PHP_EOL . PHP_EOL;
496
-        }
497
-        $this->compressManager->write($ret);
498
-        $stmt = $this->typeAdapter->show_create_view($viewName);
499
-        foreach ($this->dbHandler->query($stmt) as $r) {
500
-            if ($this->dumpSettings['add-drop-table']) {
501
-                $this->compressManager->write(
502
-                    $this->typeAdapter->drop_view($viewName)
503
-                );
504
-            }
505
-            $this->compressManager->write(
506
-                $this->typeAdapter->create_view($r)
507
-            );
508
-            break;
509
-        }
510
-    }
511
-
512
-    /**
513
-     * Trigger structure extractor
514
-     *
515
-     * @param string $triggerName  Name of trigger to export
516
-     * @return null
517
-     */
518
-    private function getTriggerStructure($triggerName)
519
-    {
520
-        $stmt = $this->typeAdapter->show_create_trigger($triggerName);
521
-        foreach ($this->dbHandler->query($stmt) as $r) {
522
-            if ($this->dumpSettings['add-drop-trigger']) {
523
-                $this->compressManager->write(
524
-                    $this->typeAdapter->add_drop_trigger($triggerName)
525
-                );
526
-            }
527
-            $this->compressManager->write(
528
-                $this->typeAdapter->create_trigger($r)
529
-            );
530
-            return;
531
-        }
532
-
533
-    }
534
-
535
-
536
-    /**
537
-     * Escape values with quotes when needed
538
-     *
539
-     * @param string $tableName Name of table which contains rows
540
-     * @param array $row Associative array of column names and values to be quoted
541
-     *
542
-     * @return string
543
-     */
544
-    private function escape($tableName, $row)
545
-    {
546
-        $ret = array();
547
-        $columnTypes = $this->tableColumnTypes[$tableName];
548
-        foreach ($row as $colName => $colValue) {
549
-            if (is_null($colValue)) {
550
-                $ret[] = "NULL";
551
-            } elseif ($this->dumpSettings['hex-blob'] && $columnTypes[$colName]['is_blob']) {
552
-                if ($columnTypes[$colName]['type'] == 'bit' || !empty($colValue)) {
553
-                    $ret[] = "0x${colValue}";
554
-                } else {
555
-                    $ret[] = "''";
556
-                }
557
-            } elseif ($columnTypes[$colName]['is_numeric']) {
558
-                $ret[] = $colValue;
559
-            } else {
560
-                $ret[] = $this->dbHandler->quote($colValue);
561
-            }
562
-        }
563
-        return $ret;
564
-    }
565
-
566
-    /**
567
-     * Table rows extractor
568
-     *
569
-     * @param string $tableName  Name of table to export
570
-     *
571
-     * @return null
572
-     */
573
-    private function listValues($tableName)
574
-    {
575
-        $this->prepareListValues($tableName);
576
-
577
-        $onlyOnce = true;
578
-        $lineSize = 0;
579
-
580
-        $colStmt = $this->getColumnStmt($tableName);
581
-        $stmt = "SELECT $colStmt FROM `$tableName`";
582
-
583
-        if ($this->dumpSettings['where']) {
584
-            $stmt .= " WHERE {$this->dumpSettings['where']}";
585
-        }
586
-        $resultSet = $this->dbHandler->query($stmt);
587
-        $resultSet->setFetchMode(PDO::FETCH_ASSOC);
588
-
589
-        foreach ($resultSet as $row) {
590
-            $vals = $this->escape($tableName, $row);
591
-            if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
592
-                $lineSize += $this->compressManager->write(
593
-                    "INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
594
-                );
595
-                $onlyOnce = false;
596
-            } else {
597
-                $lineSize += $this->compressManager->write(",(" . implode(",", $vals) . ")");
598
-            }
599
-            if (($lineSize > self::MAXLINESIZE) ||
600
-                    !$this->dumpSettings['extended-insert']) {
601
-                $onlyOnce = true;
602
-                $lineSize = $this->compressManager->write(";" . PHP_EOL);
603
-            }
604
-        }
605
-        $resultSet->closeCursor();
606
-
607
-        if (!$onlyOnce) {
608
-            $this->compressManager->write(";" . PHP_EOL);
609
-        }
610
-
611
-        $this->endListValues($tableName);
612
-    }
613
-
614
-    /**
615
-     * Table rows extractor, append information prior to dump
616
-     *
617
-     * @param string $tableName  Name of table to export
618
-     *
619
-     * @return null
620
-     */
621
-    function prepareListValues($tableName)
622
-    {
623
-        if (!$this->dumpSettings['skip-comments']) {
624
-            $this->compressManager->write(
625
-                "--" . PHP_EOL .
626
-                "-- Dumping data for table `$tableName`" .  PHP_EOL .
627
-                "--" . PHP_EOL . PHP_EOL
628
-            );
629
-        }
630
-
631
-        if ($this->dumpSettings['single-transaction']) {
632
-            $this->dbHandler->exec($this->typeAdapter->setup_transaction());
633
-            $this->dbHandler->exec($this->typeAdapter->start_transaction());
634
-        }
635
-
636
-        if ($this->dumpSettings['lock-tables']) {
637
-            $this->typeAdapter->lock_table($tableName);
638
-        }
639
-
640
-        if ($this->dumpSettings['add-locks']) {
641
-            $this->compressManager->write(
642
-                $this->typeAdapter->start_add_lock_table($tableName)
643
-            );
644
-        }
645
-
646
-        if ($this->dumpSettings['disable-keys']) {
647
-            $this->compressManager->write(
648
-                $this->typeAdapter->start_add_disable_keys($tableName)
649
-            );
650
-        }
651
-
652
-        // Disable autocommit for faster reload
653
-        if ($this->dumpSettings['no-autocommit']) {
654
-            $this->compressManager->write(
655
-                $this->typeAdapter->start_disable_autocommit()
656
-            );
657
-        }
658
-
659
-        return;
660
-    }
661
-
662
-    /**
663
-     * Table rows extractor, close locks and commits after dump
664
-     *
665
-     * @param string $tableName  Name of table to export
666
-     *
667
-     * @return null
668
-     */
669
-    function endListValues($tableName)
670
-    {
671
-        if ($this->dumpSettings['disable-keys']) {
672
-            $this->compressManager->write(
673
-                $this->typeAdapter->end_add_disable_keys($tableName)
674
-            );
675
-        }
676
-
677
-        if ($this->dumpSettings['add-locks']) {
678
-            $this->compressManager->write(
679
-                $this->typeAdapter->end_add_lock_table($tableName)
680
-            );
681
-        }
682
-
683
-        if ($this->dumpSettings['single-transaction']) {
684
-            $this->dbHandler->exec($this->typeAdapter->commit_transaction());
685
-        }
686
-
687
-        if ($this->dumpSettings['lock-tables']) {
688
-            $this->typeAdapter->unlock_table($tableName);
689
-        }
690
-
691
-        // Commit to enable autocommit
692
-        if ($this->dumpSettings['no-autocommit']) {
693
-            $this->compressManager->write(
694
-                $this->typeAdapter->end_disable_autocommit()
695
-            );
696
-        }
697
-
698
-        $this->compressManager->write(PHP_EOL);
699
-
700
-        return;
701
-    }
702
-
703
-    /**
704
-     * Build SQL List of all columns on current table
705
-     *
706
-     * @param string $tableName  Name of table to get columns
707
-     *
708
-     * @return string SQL sentence with columns
709
-     */
710
-    function getColumnStmt($tableName)
711
-    {
712
-        $colStmt = array();
713
-        foreach($this->tableColumnTypes[$tableName] as $colName => $colType) {
714
-            if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
715
-                $colStmt[] = "LPAD(HEX(`${colName}`),2,'0') AS `${colName}`";
716
-            } else if ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
717
-                $colStmt[] = "HEX(`${colName}`) AS `${colName}`";
718
-            } else {
719
-                $colStmt[] = "`${colName}`";
720
-            }
721
-        }
722
-        $colStmt = implode($colStmt, ",");
723
-
724
-        return $colStmt;
725
-    }
36
+	// Same as mysqldump
37
+	const MAXLINESIZE = 1000000;
38
+
39
+	// Available compression methods as constants
40
+	const GZIP = 'Gzip';
41
+	const BZIP2 = 'Bzip2';
42
+	const NONE = 'None';
43
+
44
+	// Available connection strings
45
+	const UTF8 = 'utf8';
46
+	const UTF8MB4 = 'utf8mb4';
47
+
48
+	// This can be set both on constructor or manually
49
+	public $host;
50
+	public $port;
51
+	public $user;
52
+	public $pass;
53
+	public $db;
54
+	public $fileName;
55
+
56
+	// Internal stuff
57
+	private $tables = array();
58
+	private $views = array();
59
+	private $triggers = array();
60
+	private $dbHandler;
61
+	private $dbType;
62
+	private $compressManager;
63
+	private $typeAdapter;
64
+	private $dumpSettings = array();
65
+	private $pdoSettings = array();
66
+	private $version;
67
+	private $tableColumnTypes = array();
68
+
69
+	/**
70
+	 * Constructor of Mysqldump. Note that in the case of an SQLite database
71
+	 * connection, the filename must be in the $db parameter.
72
+	 *
73
+	 * @param string $db         Database name
74
+	 * @param string $user       SQL account username
75
+	 * @param string $pass       SQL account password
76
+	 * @param string $host       SQL server to connect to
77
+	 * @param string $type       SQL database type
78
+	 * @param array  $dumpSettings SQL database settings
79
+	 * @param array  $pdoSettings  PDO configured attributes
80
+	 */
81
+	public function __construct(
82
+		$db = '',
83
+		$user = '',
84
+		$pass = '',
85
+		$host = 'localhost',
86
+		$type = 'mysql',
87
+		$dumpSettings = array(),
88
+		$pdoSettings = array()
89
+	) {
90
+		$dumpSettingsDefault = array(
91
+			'include-tables' => array(),
92
+			'exclude-tables' => array(),
93
+			'compress' => Mysqldump::NONE,
94
+			'no-data' => false,
95
+			'add-drop-table' => false,
96
+			'single-transaction' => true,
97
+			'lock-tables' => true,
98
+			'add-locks' => true,
99
+			'extended-insert' => true,
100
+			'disable-keys' => true,
101
+			'where' => '',
102
+			'no-create-info' => false,
103
+			'skip-triggers' => false,
104
+			'add-drop-trigger' => true,
105
+			'hex-blob' => true,
106
+			'databases' => false,
107
+			'add-drop-database' => false,
108
+			'skip-tz-utz' => false,
109
+			'no-autocommit' => true,
110
+			'default-character-set' => Mysqldump::UTF8,
111
+			'skip-comments' => false,
112
+			'skip-dump-date' => false,
113
+			/* deprecated */
114
+			'disable-foreign-keys-check' => true
115
+		);
116
+
117
+		$pdoSettingsDefault = array(
118
+			PDO::ATTR_PERSISTENT => true,
119
+			PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
120
+			PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
121
+		);
122
+
123
+		$this->db = $db;
124
+		$this->user = $user;
125
+		$this->pass = $pass;
126
+
127
+		$colonPos = strpos($host, ':');
128
+		if (false !== $colonPos) {
129
+			$this->port = substr($host, $colonPos + 1);
130
+			$this->host = substr($host, 0, $colonPos);
131
+		} else {
132
+			$this->port = null;
133
+			$this->host = $host;
134
+		}
135
+
136
+		$this->dbType = strtolower($type);
137
+		$this->pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
138
+		$this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
139
+
140
+		if (!isset($this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND])) {
141
+			$this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->dumpSettings['default-character-set'];
142
+		}
143
+
144
+		$diff = array_diff(array_keys($this->dumpSettings), array_keys($dumpSettingsDefault));
145
+		if (count($diff)>0) {
146
+			throw new Exception("Unexpected value in dumpSettings: (" . implode(",", $diff) . ")");
147
+		}
148
+
149
+		// Create a new compressManager to manage compressed output
150
+		$this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
151
+	}
152
+
153
+	/**
154
+	 * Custom array_replace_recursive to be used if PHP < 5.3
155
+	 * Replaces elements from passed arrays into the first array recursively
156
+	 *
157
+	 * @param array $array1 The array in which elements are replaced
158
+	 * @param array $array2 The array from which elements will be extracted
159
+	 *
160
+	 * @return array Returns an array, or NULL if an error occurs.
161
+	 */
162
+	public static function array_replace_recursive($array1, $array2)
163
+	{
164
+		if (function_exists('array_replace_recursive')) {
165
+			return array_replace_recursive($array1, $array2);
166
+		}
167
+
168
+		foreach ($array2 as $key => $value) {
169
+			if (is_array($value)) {
170
+				$array1[$key] = self::array_replace_recursive($array1[$key], $value);
171
+			} else {
172
+				$array1[$key] = $value;
173
+			}
174
+		}
175
+		return $array1;
176
+	}
177
+
178
+	/**
179
+	 * Connect with PDO
180
+	 *
181
+	 * @return null
182
+	 */
183
+	private function connect()
184
+	{
185
+		// Connecting with PDO
186
+		try {
187
+			switch ($this->dbType) {
188
+				case 'sqlite':
189
+					$this->dbHandler = @new PDO("sqlite:" . $this->db, null, null, $this->pdoSettings);
190
+					break;
191
+				case 'mysql':
192
+				case 'pgsql':
193
+				case 'dblib':
194
+					$dsn =  $this->dbType .
195
+						":host=" . $this->host .
196
+						 (isset($this->port) ? ";port=" . $this->port : "") .
197
+						";dbname=" . $this->db;
198
+					$this->dbHandler = @new PDO(
199
+						$dsn,
200
+						$this->user,
201
+						$this->pass,
202
+						$this->pdoSettings
203
+					);
204
+					// Fix for always-unicode output
205
+					$this->dbHandler->exec("SET NAMES " . $this->dumpSettings['default-character-set']);
206
+					// Store server version
207
+					$this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
208
+					break;
209
+				default:
210
+					throw new Exception("Unsupported database type (" . $this->dbType . ")");
211
+			}
212
+		} catch (PDOException $e) {
213
+			throw new Exception(
214
+				"Connection to " . $this->dbType . " failed with message: " .
215
+				$e->getMessage()
216
+			);
217
+		}
218
+
219
+		$this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
220
+		$this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler);
221
+	}
222
+
223
+	/**
224
+	 * Main call
225
+	 *
226
+	 * @param string $filename  Name of file to write sql dump to
227
+	 * @return null
228
+	 */
229
+	public function start($filename = '')
230
+	{
231
+		// Output file can be redefined here
232
+		if (!empty($filename)) {
233
+			$this->fileName = $filename;
234
+		}
235
+		// We must set a name to continue
236
+		if (empty($this->fileName)) {
237
+			throw new Exception("Output file name is not set");
238
+		}
239
+
240
+		// Connect to database
241
+		$this->connect();
242
+
243
+		// Create output file
244
+		$this->compressManager->open($this->fileName);
245
+
246
+		// Write some basic info to output file
247
+		$this->compressManager->write($this->getDumpFileHeader());
248
+
249
+		// Store server settings and use sanner defaults to dump
250
+		$this->compressManager->write(
251
+			$this->typeAdapter->backup_parameters($this->dumpSettings)
252
+		);
253
+
254
+		if ($this->dumpSettings['databases']) {
255
+			$this->compressManager->write(
256
+				$this->typeAdapter->getDatabaseHeader($this->db)
257
+			);
258
+			if ($this->dumpSettings['add-drop-database']) {
259
+				$this->compressManager->write(
260
+					$this->typeAdapter->add_drop_database($this->db)
261
+				);
262
+			}
263
+		}
264
+
265
+		// Get table, view and trigger structures from database
266
+		$this->getDatabaseStructure();
267
+
268
+		if ($this->dumpSettings['databases']) {
269
+			$this->compressManager->write(
270
+				$this->typeAdapter->databases($this->db)
271
+			);
272
+		}
273
+
274
+		// If there still are some tables/views in include-tables array,
275
+		// that means that some tables or views weren't found.
276
+		// Give proper error and exit.
277
+		if (0 < count($this->dumpSettings['include-tables'])) {
278
+			$name = implode(",", $this->dumpSettings['include-tables']);
279
+			throw new Exception("Table or View (" . $name . ") not found in database");
280
+		}
281
+
282
+		$this->exportTables();
283
+		$this->exportViews();
284
+		$this->exportTriggers();
285
+
286
+		// Restore saved parameters
287
+		$this->compressManager->write(
288
+			$this->typeAdapter->restore_parameters($this->dumpSettings)
289
+		);
290
+		// Write some stats to output file
291
+		$this->compressManager->write($this->getDumpFileFooter());
292
+		// Close output file
293
+		$this->compressManager->close();
294
+	}
295
+
296
+	/**
297
+	 * Returns header for dump file
298
+	 *
299
+	 * @return string
300
+	 */
301
+	private function getDumpFileHeader()
302
+	{
303
+		$header = '';
304
+		if (!$this->dumpSettings['skip-comments']) {
305
+			// Some info about software, source and time
306
+			$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
307
+					"--" . PHP_EOL .
308
+					"-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
309
+					"-- ------------------------------------------------------" . PHP_EOL;
310
+
311
+			if (!empty($this->version)) {
312
+				$header .= "-- Server version \t" . $this->version . PHP_EOL;
313
+			}
314
+
315
+			$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
316
+		}
317
+		return $header;
318
+	}
319
+
320
+	/**
321
+	 * Returns footer for dump file
322
+	 *
323
+	 * @return string
324
+	 */
325
+	private function getDumpFileFooter()
326
+	{
327
+		$footer = '';
328
+		if (!$this->dumpSettings['skip-comments']) {
329
+			$footer .= '-- Dump completed';
330
+			if (!$this->dumpSettings['skip-dump-date']) {
331
+				$footer .= ' on: ' . date('r');
332
+			}
333
+			$footer .= PHP_EOL;
334
+		}
335
+
336
+		return $footer;
337
+	}
338
+
339
+	/**
340
+	 * Reads table and views names from database.
341
+	 * Fills $this->tables array so they will be dumped later.
342
+	 *
343
+	 * @return null
344
+	 */
345
+	private function getDatabaseStructure()
346
+	{
347
+		// Listing all tables from database
348
+		if (empty($this->dumpSettings['include-tables'])) {
349
+			// include all tables for now, blacklisting happens later
350
+			foreach ($this->dbHandler->query($this->typeAdapter->show_tables($this->db)) as $row) {
351
+				array_push($this->tables, current($row));
352
+			}
353
+		} else {
354
+			// include only the tables mentioned in include-tables
355
+			foreach ($this->dbHandler->query($this->typeAdapter->show_tables($this->db)) as $row) {
356
+				if (in_array(current($row), $this->dumpSettings['include-tables'], true)) {
357
+					array_push($this->tables, current($row));
358
+					$elem = array_search(
359
+						current($row),
360
+						$this->dumpSettings['include-tables']
361
+					);
362
+					unset($this->dumpSettings['include-tables'][$elem]);
363
+				}
364
+			}
365
+		}
366
+
367
+		// Listing all views from database
368
+		if (empty($this->dumpSettings['include-tables'])) {
369
+			// include all views for now, blacklisting happens later
370
+			foreach ($this->dbHandler->query($this->typeAdapter->show_views($this->db)) as $row) {
371
+				array_push($this->views, current($row));
372
+			}
373
+		} else {
374
+			// include only the tables mentioned in include-tables
375
+			foreach ($this->dbHandler->query($this->typeAdapter->show_views($this->db)) as $row) {
376
+				if (in_array(current($row), $this->dumpSettings['include-tables'], true)) {
377
+					array_push($this->views, current($row));
378
+					$elem = array_search(
379
+						current($row),
380
+						$this->dumpSettings['include-tables']
381
+					);
382
+					unset($this->dumpSettings['include-tables'][$elem]);
383
+				}
384
+			}
385
+		}
386
+
387
+		// Listing all triggers from database
388
+		if (false === $this->dumpSettings['skip-triggers']) {
389
+			foreach ($this->dbHandler->query($this->typeAdapter->show_triggers($this->db)) as $row) {
390
+				array_push($this->triggers, $row['Trigger']);
391
+			}
392
+		}
393
+	}
394
+
395
+	/**
396
+	 * Exports all the tables selected from database
397
+	 *
398
+	 * @return null
399
+	 */
400
+	private function exportTables()
401
+	{
402
+		// Exporting tables one by one
403
+		foreach ($this->tables as $table) {
404
+			if (in_array($table, $this->dumpSettings['exclude-tables'], true)) {
405
+				continue;
406
+			}
407
+			$this->getTableStructure($table);
408
+			if (false === $this->dumpSettings['no-data']) {
409
+				$this->listValues($table);
410
+			}
411
+		}
412
+	}
413
+
414
+	/**
415
+	 * Exports all the views found in database
416
+	 *
417
+	 * @return null
418
+	 */
419
+	private function exportViews()
420
+	{
421
+		if (false === $this->dumpSettings['no-create-info']) {
422
+			// Exporting views one by one
423
+			foreach ($this->views as $view) {
424
+				if (in_array($view, $this->dumpSettings['exclude-tables'], true)) {
425
+					continue;
426
+				}
427
+				$this->getViewStructure($view);
428
+			}
429
+		}
430
+	}
431
+
432
+	/**
433
+	 * Exports all the triggers found in database
434
+	 *
435
+	 * @return null
436
+	 */
437
+	private function exportTriggers()
438
+	{
439
+		// Exporting triggers one by one
440
+		foreach ($this->triggers as $trigger) {
441
+			$this->getTriggerStructure($trigger);
442
+		}
443
+	}
444
+
445
+
446
+	private function getTableStructure($tableName)
447
+	{
448
+		if (!$this->dumpSettings['no-create-info']) {
449
+			$ret = '';
450
+			if (!$this->dumpSettings['skip-comments']) {
451
+				$ret = "--" . PHP_EOL .
452
+					"-- Table structure for table `$tableName`" . PHP_EOL .
453
+					"--" . PHP_EOL . PHP_EOL;
454
+			}
455
+			$stmt = $this->typeAdapter->show_create_table($tableName);
456
+			foreach ($this->dbHandler->query($stmt) as $r) {
457
+				$this->compressManager->write($ret);
458
+				if ($this->dumpSettings['add-drop-table']) {
459
+					$this->compressManager->write(
460
+						$this->typeAdapter->drop_table($tableName)
461
+					);
462
+				}
463
+				$this->compressManager->write(
464
+					$this->typeAdapter->create_table($r, $this->dumpSettings)
465
+				);
466
+				break;
467
+			}
468
+		}
469
+
470
+		$columnTypes = array();
471
+		$columns = $this->dbHandler->query(
472
+			$this->typeAdapter->show_columns($tableName)
473
+		);
474
+		$columns->setFetchMode(PDO::FETCH_ASSOC);
475
+
476
+		foreach($columns as $key => $col) {
477
+			$types = $this->typeAdapter->parseColumnType($col);
478
+			$columnTypes[$col['Field']] = array(
479
+				'is_numeric'=> $types['is_numeric'],
480
+				'is_blob' => $types['is_blob'],
481
+				'type' => $types['type']
482
+			);
483
+		}
484
+		$this->tableColumnTypes[$tableName] = $columnTypes;
485
+		return;
486
+	}
487
+
488
+
489
+	private function getViewStructure($viewName)
490
+	{
491
+		$ret = '';
492
+		if (!$this->dumpSettings['skip-comments']) {
493
+			$ret = "--" . PHP_EOL .
494
+				"-- Table structure for view `${viewName}`" . PHP_EOL .
495
+				"--" . PHP_EOL . PHP_EOL;
496
+		}
497
+		$this->compressManager->write($ret);
498
+		$stmt = $this->typeAdapter->show_create_view($viewName);
499
+		foreach ($this->dbHandler->query($stmt) as $r) {
500
+			if ($this->dumpSettings['add-drop-table']) {
501
+				$this->compressManager->write(
502
+					$this->typeAdapter->drop_view($viewName)
503
+				);
504
+			}
505
+			$this->compressManager->write(
506
+				$this->typeAdapter->create_view($r)
507
+			);
508
+			break;
509
+		}
510
+	}
511
+
512
+	/**
513
+	 * Trigger structure extractor
514
+	 *
515
+	 * @param string $triggerName  Name of trigger to export
516
+	 * @return null
517
+	 */
518
+	private function getTriggerStructure($triggerName)
519
+	{
520
+		$stmt = $this->typeAdapter->show_create_trigger($triggerName);
521
+		foreach ($this->dbHandler->query($stmt) as $r) {
522
+			if ($this->dumpSettings['add-drop-trigger']) {
523
+				$this->compressManager->write(
524
+					$this->typeAdapter->add_drop_trigger($triggerName)
525
+				);
526
+			}
527
+			$this->compressManager->write(
528
+				$this->typeAdapter->create_trigger($r)
529
+			);
530
+			return;
531
+		}
532
+
533
+	}
534
+
535
+
536
+	/**
537
+	 * Escape values with quotes when needed
538
+	 *
539
+	 * @param string $tableName Name of table which contains rows
540
+	 * @param array $row Associative array of column names and values to be quoted
541
+	 *
542
+	 * @return string
543
+	 */
544
+	private function escape($tableName, $row)
545
+	{
546
+		$ret = array();
547
+		$columnTypes = $this->tableColumnTypes[$tableName];
548
+		foreach ($row as $colName => $colValue) {
549
+			if (is_null($colValue)) {
550
+				$ret[] = "NULL";
551
+			} elseif ($this->dumpSettings['hex-blob'] && $columnTypes[$colName]['is_blob']) {
552
+				if ($columnTypes[$colName]['type'] == 'bit' || !empty($colValue)) {
553
+					$ret[] = "0x${colValue}";
554
+				} else {
555
+					$ret[] = "''";
556
+				}
557
+			} elseif ($columnTypes[$colName]['is_numeric']) {
558
+				$ret[] = $colValue;
559
+			} else {
560
+				$ret[] = $this->dbHandler->quote($colValue);
561
+			}
562
+		}
563
+		return $ret;
564
+	}
565
+
566
+	/**
567
+	 * Table rows extractor
568
+	 *
569
+	 * @param string $tableName  Name of table to export
570
+	 *
571
+	 * @return null
572
+	 */
573
+	private function listValues($tableName)
574
+	{
575
+		$this->prepareListValues($tableName);
576
+
577
+		$onlyOnce = true;
578
+		$lineSize = 0;
579
+
580
+		$colStmt = $this->getColumnStmt($tableName);
581
+		$stmt = "SELECT $colStmt FROM `$tableName`";
582
+
583
+		if ($this->dumpSettings['where']) {
584
+			$stmt .= " WHERE {$this->dumpSettings['where']}";
585
+		}
586
+		$resultSet = $this->dbHandler->query($stmt);
587
+		$resultSet->setFetchMode(PDO::FETCH_ASSOC);
588
+
589
+		foreach ($resultSet as $row) {
590
+			$vals = $this->escape($tableName, $row);
591
+			if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
592
+				$lineSize += $this->compressManager->write(
593
+					"INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
594
+				);
595
+				$onlyOnce = false;
596
+			} else {
597
+				$lineSize += $this->compressManager->write(",(" . implode(",", $vals) . ")");
598
+			}
599
+			if (($lineSize > self::MAXLINESIZE) ||
600
+					!$this->dumpSettings['extended-insert']) {
601
+				$onlyOnce = true;
602
+				$lineSize = $this->compressManager->write(";" . PHP_EOL);
603
+			}
604
+		}
605
+		$resultSet->closeCursor();
606
+
607
+		if (!$onlyOnce) {
608
+			$this->compressManager->write(";" . PHP_EOL);
609
+		}
610
+
611
+		$this->endListValues($tableName);
612
+	}
613
+
614
+	/**
615
+	 * Table rows extractor, append information prior to dump
616
+	 *
617
+	 * @param string $tableName  Name of table to export
618
+	 *
619
+	 * @return null
620
+	 */
621
+	function prepareListValues($tableName)
622
+	{
623
+		if (!$this->dumpSettings['skip-comments']) {
624
+			$this->compressManager->write(
625
+				"--" . PHP_EOL .
626
+				"-- Dumping data for table `$tableName`" .  PHP_EOL .
627
+				"--" . PHP_EOL . PHP_EOL
628
+			);
629
+		}
630
+
631
+		if ($this->dumpSettings['single-transaction']) {
632
+			$this->dbHandler->exec($this->typeAdapter->setup_transaction());
633
+			$this->dbHandler->exec($this->typeAdapter->start_transaction());
634
+		}
635
+
636
+		if ($this->dumpSettings['lock-tables']) {
637
+			$this->typeAdapter->lock_table($tableName);
638
+		}
639
+
640
+		if ($this->dumpSettings['add-locks']) {
641
+			$this->compressManager->write(
642
+				$this->typeAdapter->start_add_lock_table($tableName)
643
+			);
644
+		}
645
+
646
+		if ($this->dumpSettings['disable-keys']) {
647
+			$this->compressManager->write(
648
+				$this->typeAdapter->start_add_disable_keys($tableName)
649
+			);
650
+		}
651
+
652
+		// Disable autocommit for faster reload
653
+		if ($this->dumpSettings['no-autocommit']) {
654
+			$this->compressManager->write(
655
+				$this->typeAdapter->start_disable_autocommit()
656
+			);
657
+		}
658
+
659
+		return;
660
+	}
661
+
662
+	/**
663
+	 * Table rows extractor, close locks and commits after dump
664
+	 *
665
+	 * @param string $tableName  Name of table to export
666
+	 *
667
+	 * @return null
668
+	 */
669
+	function endListValues($tableName)
670
+	{
671
+		if ($this->dumpSettings['disable-keys']) {
672
+			$this->compressManager->write(
673
+				$this->typeAdapter->end_add_disable_keys($tableName)
674
+			);
675
+		}
676
+
677
+		if ($this->dumpSettings['add-locks']) {
678
+			$this->compressManager->write(
679
+				$this->typeAdapter->end_add_lock_table($tableName)
680
+			);
681
+		}
682
+
683
+		if ($this->dumpSettings['single-transaction']) {
684
+			$this->dbHandler->exec($this->typeAdapter->commit_transaction());
685
+		}
686
+
687
+		if ($this->dumpSettings['lock-tables']) {
688
+			$this->typeAdapter->unlock_table($tableName);
689
+		}
690
+
691
+		// Commit to enable autocommit
692
+		if ($this->dumpSettings['no-autocommit']) {
693
+			$this->compressManager->write(
694
+				$this->typeAdapter->end_disable_autocommit()
695
+			);
696
+		}
697
+
698
+		$this->compressManager->write(PHP_EOL);
699
+
700
+		return;
701
+	}
702
+
703
+	/**
704
+	 * Build SQL List of all columns on current table
705
+	 *
706
+	 * @param string $tableName  Name of table to get columns
707
+	 *
708
+	 * @return string SQL sentence with columns
709
+	 */
710
+	function getColumnStmt($tableName)
711
+	{
712
+		$colStmt = array();
713
+		foreach($this->tableColumnTypes[$tableName] as $colName => $colType) {
714
+			if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
715
+				$colStmt[] = "LPAD(HEX(`${colName}`),2,'0') AS `${colName}`";
716
+			} else if ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
717
+				$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
718
+			} else {
719
+				$colStmt[] = "`${colName}`";
720
+			}
721
+		}
722
+		$colStmt = implode($colStmt, ",");
723
+
724
+		return $colStmt;
725
+	}
726 726
 }
727 727
 
728 728
 /**
@@ -731,137 +731,137 @@  discard block
 block discarded – undo
731 731
  */
732 732
 abstract class CompressMethod
733 733
 {
734
-    public static $enums = array(
735
-        "None",
736
-        "Gzip",
737
-        "Bzip2"
738
-    );
739
-
740
-    /**
741
-     * @param string $c
742
-     * @return boolean
743
-     */
744
-    public static function isValid($c)
745
-    {
746
-        return in_array($c, self::$enums);
747
-    }
734
+	public static $enums = array(
735
+		"None",
736
+		"Gzip",
737
+		"Bzip2"
738
+	);
739
+
740
+	/**
741
+	 * @param string $c
742
+	 * @return boolean
743
+	 */
744
+	public static function isValid($c)
745
+	{
746
+		return in_array($c, self::$enums);
747
+	}
748 748
 }
749 749
 
750 750
 abstract class CompressManagerFactory
751 751
 {
752
-    /**
753
-     * @param string $c
754
-     * @return CompressBzip2|CompressGzip|CompressNone
755
-     */
756
-    public static function create($c)
757
-    {
758
-        $c = ucfirst(strtolower($c));
759
-        if (! CompressMethod::isValid($c)) {
760
-            throw new Exception("Compression method ($c) is not defined yet");
761
-        }
762
-
763
-        $method =  __NAMESPACE__ . "\\" . "Compress" . $c;
764
-
765
-        return new $method;
766
-    }
752
+	/**
753
+	 * @param string $c
754
+	 * @return CompressBzip2|CompressGzip|CompressNone
755
+	 */
756
+	public static function create($c)
757
+	{
758
+		$c = ucfirst(strtolower($c));
759
+		if (! CompressMethod::isValid($c)) {
760
+			throw new Exception("Compression method ($c) is not defined yet");
761
+		}
762
+
763
+		$method =  __NAMESPACE__ . "\\" . "Compress" . $c;
764
+
765
+		return new $method;
766
+	}
767 767
 }
768 768
 
769 769
 class CompressBzip2 extends CompressManagerFactory
770 770
 {
771
-    private $fileHandler = null;
772
-
773
-    public function __construct()
774
-    {
775
-        if (! function_exists("bzopen")) {
776
-            throw new Exception("Compression is enabled, but bzip2 lib is not installed or configured properly");
777
-        }
778
-    }
779
-
780
-    public function open($filename)
781
-    {
782
-        $this->fileHandler = bzopen($filename, "w");
783
-        if (false === $this->fileHandler) {
784
-            throw new Exception("Output file is not writable");
785
-        }
786
-
787
-        return true;
788
-    }
789
-
790
-    public function write($str)
791
-    {
792
-        if (false === ($bytesWritten = bzwrite($this->fileHandler, $str))) {
793
-            throw new Exception("Writting to file failed! Probably, there is no more free space left?");
794
-        }
795
-        return $bytesWritten;
796
-    }
797
-
798
-    public function close()
799
-    {
800
-        return bzclose($this->fileHandler);
801
-    }
771
+	private $fileHandler = null;
772
+
773
+	public function __construct()
774
+	{
775
+		if (! function_exists("bzopen")) {
776
+			throw new Exception("Compression is enabled, but bzip2 lib is not installed or configured properly");
777
+		}
778
+	}
779
+
780
+	public function open($filename)
781
+	{
782
+		$this->fileHandler = bzopen($filename, "w");
783
+		if (false === $this->fileHandler) {
784
+			throw new Exception("Output file is not writable");
785
+		}
786
+
787
+		return true;
788
+	}
789
+
790
+	public function write($str)
791
+	{
792
+		if (false === ($bytesWritten = bzwrite($this->fileHandler, $str))) {
793
+			throw new Exception("Writting to file failed! Probably, there is no more free space left?");
794
+		}
795
+		return $bytesWritten;
796
+	}
797
+
798
+	public function close()
799
+	{
800
+		return bzclose($this->fileHandler);
801
+	}
802 802
 }
803 803
 
804 804
 class CompressGzip extends CompressManagerFactory
805 805
 {
806
-    private $fileHandler = null;
807
-
808
-    public function __construct()
809
-    {
810
-        if (! function_exists("gzopen")) {
811
-            throw new Exception("Compression is enabled, but gzip lib is not installed or configured properly");
812
-        }
813
-    }
814
-
815
-    public function open($filename)
816
-    {
817
-        $this->fileHandler = gzopen($filename, "wb");
818
-        if (false === $this->fileHandler) {
819
-            throw new Exception("Output file is not writable");
820
-        }
821
-
822
-        return true;
823
-    }
824
-
825
-    public function write($str)
826
-    {
827
-        if (false === ($bytesWritten = gzwrite($this->fileHandler, $str))) {
828
-            throw new Exception("Writting to file failed! Probably, there is no more free space left?");
829
-        }
830
-        return $bytesWritten;
831
-    }
832
-
833
-    public function close()
834
-    {
835
-        return gzclose($this->fileHandler);
836
-    }
806
+	private $fileHandler = null;
807
+
808
+	public function __construct()
809
+	{
810
+		if (! function_exists("gzopen")) {
811
+			throw new Exception("Compression is enabled, but gzip lib is not installed or configured properly");
812
+		}
813
+	}
814
+
815
+	public function open($filename)
816
+	{
817
+		$this->fileHandler = gzopen($filename, "wb");
818
+		if (false === $this->fileHandler) {
819
+			throw new Exception("Output file is not writable");
820
+		}
821
+
822
+		return true;
823
+	}
824
+
825
+	public function write($str)
826
+	{
827
+		if (false === ($bytesWritten = gzwrite($this->fileHandler, $str))) {
828
+			throw new Exception("Writting to file failed! Probably, there is no more free space left?");
829
+		}
830
+		return $bytesWritten;
831
+	}
832
+
833
+	public function close()
834
+	{
835
+		return gzclose($this->fileHandler);
836
+	}
837 837
 }
838 838
 
839 839
 class CompressNone extends CompressManagerFactory
840 840
 {
841
-    private $fileHandler = null;
842
-
843
-    public function open($filename)
844
-    {
845
-        $this->fileHandler = fopen($filename, "wb");
846
-        if (false === $this->fileHandler) {
847
-            throw new Exception("Output file is not writable");
848
-        }
849
-
850
-        return true;
851
-    }
852
-
853
-    public function write($str)
854
-    {
855
-        if (false === ($bytesWritten = fwrite($this->fileHandler, $str))) {
856
-            throw new Exception("Writting to file failed! Probably, there is no more free space left?");
857
-        }
858
-        return $bytesWritten;
859
-    }
860
-
861
-    public function close()
862
-    {
863
-        return fclose($this->fileHandler);
864
-    }
841
+	private $fileHandler = null;
842
+
843
+	public function open($filename)
844
+	{
845
+		$this->fileHandler = fopen($filename, "wb");
846
+		if (false === $this->fileHandler) {
847
+			throw new Exception("Output file is not writable");
848
+		}
849
+
850
+		return true;
851
+	}
852
+
853
+	public function write($str)
854
+	{
855
+		if (false === ($bytesWritten = fwrite($this->fileHandler, $str))) {
856
+			throw new Exception("Writting to file failed! Probably, there is no more free space left?");
857
+		}
858
+		return $bytesWritten;
859
+	}
860
+
861
+	public function close()
862
+	{
863
+		return fclose($this->fileHandler);
864
+	}
865 865
 }
866 866
 
867 867
 /**
@@ -870,19 +870,19 @@  discard block
 block discarded – undo
870 870
  */
871 871
 abstract class TypeAdapter
872 872
 {
873
-    public static $enums = array(
874
-        "Sqlite",
875
-        "Mysql"
876
-    );
877
-
878
-    /**
879
-     * @param string $c
880
-     * @return boolean
881
-     */
882
-    public static function isValid($c)
883
-    {
884
-        return in_array($c, self::$enums);
885
-    }
873
+	public static $enums = array(
874
+		"Sqlite",
875
+		"Mysql"
876
+	);
877
+
878
+	/**
879
+	 * @param string $c
880
+	 * @return boolean
881
+	 */
882
+	public static function isValid($c)
883
+	{
884
+		return in_array($c, self::$enums);
885
+	}
886 886
 }
887 887
 
888 888
 /**
@@ -891,186 +891,186 @@  discard block
 block discarded – undo
891 891
  */
892 892
 abstract class TypeAdapterFactory
893 893
 {
894
-    /**
895
-     * @param string $c Type of database factory to create (Mysql, Sqlite,...)
896
-     * @param PDO $dbHandler
897
-     */
898
-    public static function create($c, $dbHandler = null)
899
-    {
900
-        $c = ucfirst(strtolower($c));
901
-        if (! TypeAdapter::isValid($c)) {
902
-            throw new Exception("Database type support for ($c) not yet available");
903
-        }
904
-        $method =  __NAMESPACE__ . "\\" . "TypeAdapter" . $c;
905
-        return new $method($dbHandler);
906
-    }
907
-
908
-
909
-    public function databases()
910
-    {
911
-        return "";
912
-    }
913
-
914
-    public function show_create_table($tableName)
915
-    {
916
-        return "SELECT tbl_name as 'Table', sql as 'Create Table' " .
917
-            "FROM sqlite_master " .
918
-            "WHERE type='table' AND tbl_name='$tableName'";
919
-    }
920
-
921
-
922
-    public function create_table($row, $dumpSettings)
923
-    {
924
-        return "";
925
-    }
926
-
927
-    public function show_create_view($viewName)
928
-    {
929
-        return "SELECT tbl_name as 'View', sql as 'Create View' " .
930
-            "FROM sqlite_master " .
931
-            "WHERE type='view' AND tbl_name='$viewName'";
932
-    }
933
-
934
-
935
-    public function create_view($row)
936
-    {
937
-        return "";
938
-    }
939
-
940
-
941
-    public function show_create_trigger($triggerName)
942
-    {
943
-        return "";
944
-    }
945
-
946
-
947
-    public function create_trigger($triggerName)
948
-    {
949
-        return "";
950
-    }
951
-
952
-    public function show_tables()
953
-    {
954
-        return "SELECT tbl_name FROM sqlite_master WHERE type='table'";
955
-    }
956
-
957
-    public function show_views()
958
-    {
959
-        return "SELECT tbl_name FROM sqlite_master WHERE type='view'";
960
-    }
961
-
962
-    public function show_triggers()
963
-    {
964
-        return "SELECT name FROM sqlite_master WHERE type='trigger'";
965
-    }
966
-
967
-    public function show_columns()
968
-    {
969
-        if (func_num_args() != 1) {
970
-            return "";
971
-        }
972
-
973
-        $args = func_get_args();
974
-
975
-        return "pragma table_info(${args[0]})";
976
-    }
977
-
978
-    public function setup_transaction()
979
-    {
980
-        return "";
981
-    }
982
-
983
-    public function start_transaction()
984
-    {
985
-        return "BEGIN EXCLUSIVE";
986
-    }
987
-
988
-    public function commit_transaction()
989
-    {
990
-        return "COMMIT";
991
-    }
992
-
993
-    public function lock_table()
994
-    {
995
-        return "";
996
-    }
997
-
998
-    public function unlock_table()
999
-    {
1000
-        return "";
1001
-    }
1002
-
1003
-    public function start_add_lock_table()
1004
-    {
1005
-        return PHP_EOL;
1006
-    }
1007
-
1008
-    public function end_add_lock_table()
1009
-    {
1010
-        return PHP_EOL;
1011
-    }
1012
-
1013
-    public function start_add_disable_keys()
1014
-    {
1015
-        return PHP_EOL;
1016
-    }
1017
-
1018
-    public function end_add_disable_keys()
1019
-    {
1020
-        return PHP_EOL;
1021
-    }
1022
-
1023
-    public function start_disable_foreign_keys_check()
1024
-    {
1025
-        return PHP_EOL;
1026
-    }
1027
-
1028
-    public function end_disable_foreign_keys_check()
1029
-    {
1030
-        return PHP_EOL;
1031
-    }
1032
-
1033
-    public function add_drop_database()
1034
-    {
1035
-        return PHP_EOL;
1036
-    }
1037
-
1038
-    public function add_drop_trigger()
1039
-    {
1040
-        return PHP_EOL;
1041
-    }
1042
-
1043
-    public function drop_table()
1044
-    {
1045
-        return PHP_EOL;
1046
-    }
1047
-
1048
-    public function drop_view()
1049
-    {
1050
-        return PHP_EOL;
1051
-    }
1052
-
1053
-    /**
1054
-     * Decode column metadata and fill info structure.
1055
-     * type, is_numeric and is_blob will always be available.
1056
-     *
1057
-     * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
1058
-     * @return array
1059
-     */
1060
-    public function parseColumnType($colType)
1061
-    {
1062
-        return array();
1063
-    }
1064
-
1065
-    public function backup_parameters()
1066
-    {
1067
-        return PHP_EOL;
1068
-    }
1069
-
1070
-    public function restore_parameters()
1071
-    {
1072
-        return PHP_EOL;
1073
-    }
894
+	/**
895
+	 * @param string $c Type of database factory to create (Mysql, Sqlite,...)
896
+	 * @param PDO $dbHandler
897
+	 */
898
+	public static function create($c, $dbHandler = null)
899
+	{
900
+		$c = ucfirst(strtolower($c));
901
+		if (! TypeAdapter::isValid($c)) {
902
+			throw new Exception("Database type support for ($c) not yet available");
903
+		}
904
+		$method =  __NAMESPACE__ . "\\" . "TypeAdapter" . $c;
905
+		return new $method($dbHandler);
906
+	}
907
+
908
+
909
+	public function databases()
910
+	{
911
+		return "";
912
+	}
913
+
914
+	public function show_create_table($tableName)
915
+	{
916
+		return "SELECT tbl_name as 'Table', sql as 'Create Table' " .
917
+			"FROM sqlite_master " .
918
+			"WHERE type='table' AND tbl_name='$tableName'";
919
+	}
920
+
921
+
922
+	public function create_table($row, $dumpSettings)
923
+	{
924
+		return "";
925
+	}
926
+
927
+	public function show_create_view($viewName)
928
+	{
929
+		return "SELECT tbl_name as 'View', sql as 'Create View' " .
930
+			"FROM sqlite_master " .
931
+			"WHERE type='view' AND tbl_name='$viewName'";
932
+	}
933
+
934
+
935
+	public function create_view($row)
936
+	{
937
+		return "";
938
+	}
939
+
940
+
941
+	public function show_create_trigger($triggerName)
942
+	{
943
+		return "";
944
+	}
945
+
946
+
947
+	public function create_trigger($triggerName)
948
+	{
949
+		return "";
950
+	}
951
+
952
+	public function show_tables()
953
+	{
954
+		return "SELECT tbl_name FROM sqlite_master WHERE type='table'";
955
+	}
956
+
957
+	public function show_views()
958
+	{
959
+		return "SELECT tbl_name FROM sqlite_master WHERE type='view'";
960
+	}
961
+
962
+	public function show_triggers()
963
+	{
964
+		return "SELECT name FROM sqlite_master WHERE type='trigger'";
965
+	}
966
+
967
+	public function show_columns()
968
+	{
969
+		if (func_num_args() != 1) {
970
+			return "";
971
+		}
972
+
973
+		$args = func_get_args();
974
+
975
+		return "pragma table_info(${args[0]})";
976
+	}
977
+
978
+	public function setup_transaction()
979
+	{
980
+		return "";
981
+	}
982
+
983
+	public function start_transaction()
984
+	{
985
+		return "BEGIN EXCLUSIVE";
986
+	}
987
+
988
+	public function commit_transaction()
989
+	{
990
+		return "COMMIT";
991
+	}
992
+
993
+	public function lock_table()
994
+	{
995
+		return "";
996
+	}
997
+
998
+	public function unlock_table()
999
+	{
1000
+		return "";
1001
+	}
1002
+
1003
+	public function start_add_lock_table()
1004
+	{
1005
+		return PHP_EOL;
1006
+	}
1007
+
1008
+	public function end_add_lock_table()
1009
+	{
1010
+		return PHP_EOL;
1011
+	}
1012
+
1013
+	public function start_add_disable_keys()
1014
+	{
1015
+		return PHP_EOL;
1016
+	}
1017
+
1018
+	public function end_add_disable_keys()
1019
+	{
1020
+		return PHP_EOL;
1021
+	}
1022
+
1023
+	public function start_disable_foreign_keys_check()
1024
+	{
1025
+		return PHP_EOL;
1026
+	}
1027
+
1028
+	public function end_disable_foreign_keys_check()
1029
+	{
1030
+		return PHP_EOL;
1031
+	}
1032
+
1033
+	public function add_drop_database()
1034
+	{
1035
+		return PHP_EOL;
1036
+	}
1037
+
1038
+	public function add_drop_trigger()
1039
+	{
1040
+		return PHP_EOL;
1041
+	}
1042
+
1043
+	public function drop_table()
1044
+	{
1045
+		return PHP_EOL;
1046
+	}
1047
+
1048
+	public function drop_view()
1049
+	{
1050
+		return PHP_EOL;
1051
+	}
1052
+
1053
+	/**
1054
+	 * Decode column metadata and fill info structure.
1055
+	 * type, is_numeric and is_blob will always be available.
1056
+	 *
1057
+	 * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
1058
+	 * @return array
1059
+	 */
1060
+	public function parseColumnType($colType)
1061
+	{
1062
+		return array();
1063
+	}
1064
+
1065
+	public function backup_parameters()
1066
+	{
1067
+		return PHP_EOL;
1068
+	}
1069
+
1070
+	public function restore_parameters()
1071
+	{
1072
+		return PHP_EOL;
1073
+	}
1074 1074
 }
1075 1075
 
1076 1076
 class TypeAdapterPgsql extends TypeAdapterFactory
@@ -1088,421 +1088,421 @@  discard block
 block discarded – undo
1088 1088
 class TypeAdapterMysql extends TypeAdapterFactory
1089 1089
 {
1090 1090
 
1091
-    private $dbHandler = null;
1092
-
1093
-    // Numerical Mysql types
1094
-    public $mysqlTypes = array(
1095
-        'numerical' => array(
1096
-            'bit',
1097
-            'tinyint',
1098
-            'smallint',
1099
-            'mediumint',
1100
-            'int',
1101
-            'integer',
1102
-            'bigint',
1103
-            'real',
1104
-            'double',
1105
-            'float',
1106
-            'decimal',
1107
-            'numeric'
1108
-        ),
1109
-        'blob' => array(
1110
-            'tinyblob',
1111
-            'blob',
1112
-            'mediumblob',
1113
-            'longblob',
1114
-            'binary',
1115
-            'varbinary',
1116
-            'bit'
1117
-        )
1118
-    );
1119
-
1120
-    public function __construct ($dbHandler)
1121
-    {
1122
-        $this->dbHandler = $dbHandler;
1123
-    }
1124
-
1125
-    public function databases()
1126
-    {
1127
-        if (func_num_args() != 1) {
1128
-            throw new Exception("Unexpected parameter passed to " . __METHOD__);
1129
-        }
1130
-
1131
-        $args = func_get_args();
1132
-        $databaseName = $args[0];
1133
-
1134
-        $resultSet = $this->dbHandler->query("SHOW VARIABLES LIKE 'character_set_database';");
1135
-        $characterSet = $resultSet->fetchColumn(1);
1136
-        $resultSet->closeCursor();
1137
-
1138
-        $resultSet = $this->dbHandler->query("SHOW VARIABLES LIKE 'collation_database';");
1139
-        $collationDb = $resultSet->fetchColumn(1);
1140
-        $resultSet->closeCursor();
1141
-        $ret = "";
1142
-
1143
-        $ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${databaseName}`".
1144
-            " /*!40100 DEFAULT CHARACTER SET ${characterSet} " .
1145
-            " COLLATE ${collationDb} */;" . PHP_EOL . PHP_EOL .
1146
-            "USE `${databaseName}`;" . PHP_EOL . PHP_EOL;
1147
-
1148
-        return $ret;
1149
-    }
1150
-
1151
-    public function show_create_table($tableName)
1152
-    {
1153
-        return "SHOW CREATE TABLE `$tableName`";
1154
-    }
1155
-
1156
-    public function show_create_view($viewName)
1157
-    {
1158
-        return "SHOW CREATE VIEW `$viewName`";
1159
-    }
1160
-
1161
-    public function show_create_trigger($triggerName)
1162
-    {
1163
-        return "SHOW CREATE TRIGGER `$triggerName`";
1164
-    }
1165
-
1166
-    public function create_table($row, $dumpSettings)
1167
-    {
1168
-        if (!isset($row['Create Table'])) {
1169
-            throw new Exception("Error getting table code, unknown output");
1170
-        }
1171
-
1172
-        $ret = "/*!40101 SET @saved_cs_client     = @@character_set_client */;" . PHP_EOL .
1173
-            "/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
1174
-            $row['Create Table'] . ";" . PHP_EOL .
1175
-            "/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL .
1176
-            PHP_EOL;
1177
-        return $ret;
1178
-    }
1179
-
1180
-    public function create_view($row)
1181
-    {
1182
-        $ret = "";
1183
-        if (!isset($row['Create View'])) {
1184
-                throw new Exception("Error getting view structure, unknown output");
1185
-        }
1186
-
1187
-        $triggerStmt = $row['Create View'];
1188
-        $triggerStmtReplaced1 = str_replace(
1189
-            "CREATE ALGORITHM",
1190
-            "/*!50001 CREATE ALGORITHM",
1191
-            $triggerStmt
1192
-        );
1193
-        $triggerStmtReplaced2 = str_replace(
1194
-            " DEFINER=",
1195
-            " */" . PHP_EOL . "/*!50013 DEFINER=",
1196
-            $triggerStmtReplaced1
1197
-        );
1198
-        $triggerStmtReplaced3 = str_replace(
1199
-            " VIEW ",
1200
-            " */" . PHP_EOL . "/*!50001 VIEW ",
1201
-            $triggerStmtReplaced2
1202
-        );
1203
-        if (false === $triggerStmtReplaced1 ||
1204
-            false === $triggerStmtReplaced2 ||
1205
-            false === $triggerStmtReplaced3) {
1206
-            $triggerStmtReplaced = $triggerStmt;
1207
-        } else {
1208
-            $triggerStmtReplaced = $triggerStmtReplaced3 . " */;";
1209
-        }
1210
-
1211
-        $ret .= $triggerStmtReplaced . PHP_EOL . PHP_EOL;
1212
-        return $ret;
1213
-    }
1214
-
1215
-    public function create_trigger($row)
1216
-    {
1217
-        $ret = "";
1218
-        if (!isset($row['SQL Original Statement'])) {
1219
-            throw new Exception("Error getting trigger code, unknown output");
1220
-        }
1221
-
1222
-        $triggerStmt = $row['SQL Original Statement'];
1223
-        $triggerStmtReplaced = str_replace(
1224
-            "CREATE DEFINER",
1225
-            "/*!50003 CREATE*/ /*!50017 DEFINER",
1226
-            $triggerStmt
1227
-        );
1228
-        $triggerStmtReplaced = str_replace(
1229
-            " TRIGGER",
1230
-            "*/ /*!50003 TRIGGER",
1231
-            $triggerStmtReplaced
1232
-        );
1233
-        if ( false === $triggerStmtReplaced ) {
1234
-            $triggerStmtReplaced = $triggerStmt;
1235
-        }
1236
-
1237
-        $ret .= "DELIMITER ;;" . PHP_EOL .
1238
-            $triggerStmtReplaced . "*/;;" . PHP_EOL .
1239
-            "DELIMITER ;" . PHP_EOL . PHP_EOL;
1240
-        return $ret;
1241
-    }
1242
-
1243
-    public function show_tables()
1244
-    {
1245
-        if (func_num_args() != 1) {
1246
-            return "";
1247
-        }
1248
-
1249
-        $args = func_get_args();
1250
-
1251
-        return "SELECT TABLE_NAME AS tbl_name " .
1252
-            "FROM INFORMATION_SCHEMA.TABLES " .
1253
-            "WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='${args[0]}'";
1254
-    }
1255
-
1256
-    public function show_views()
1257
-    {
1258
-        if (func_num_args() != 1) {
1259
-            return "";
1260
-        }
1261
-
1262
-        $args = func_get_args();
1263
-
1264
-        return "SELECT TABLE_NAME AS tbl_name " .
1265
-            "FROM INFORMATION_SCHEMA.TABLES " .
1266
-            "WHERE TABLE_TYPE='VIEW' AND TABLE_SCHEMA='${args[0]}'";
1267
-    }
1268
-
1269
-    public function show_triggers()
1270
-    {
1271
-        if (func_num_args() != 1) {
1272
-            return "";
1273
-        }
1274
-
1275
-        $args = func_get_args();
1276
-
1277
-        return "SHOW TRIGGERS FROM `${args[0]}`;";
1278
-    }
1279
-
1280
-
1281
-    public function show_columns()
1282
-    {
1283
-        if (func_num_args() != 1) {
1284
-            return "";
1285
-        }
1286
-
1287
-        $args = func_get_args();
1288
-
1289
-        return "SHOW COLUMNS FROM `${args[0]}`;";
1290
-    }
1291
-
1292
-    public function setup_transaction()
1293
-    {
1294
-        return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
1295
-    }
1296
-
1297
-    public function start_transaction()
1298
-    {
1299
-        return "START TRANSACTION";
1300
-    }
1301
-
1302
-    public function commit_transaction()
1303
-    {
1304
-        return "COMMIT";
1305
-    }
1306
-
1307
-    public function lock_table()
1308
-    {
1309
-        if (func_num_args() != 1) {
1310
-            return "";
1311
-        }
1312
-
1313
-        $args = func_get_args();
1314
-        //$tableName = $args[0];
1315
-        //return "LOCK TABLES `$tableName` READ LOCAL";
1316
-        return $this->dbHandler->exec("LOCK TABLES `${args[0]}` READ LOCAL");
1317
-
1318
-    }
1319
-
1320
-    public function unlock_table()
1321
-    {
1322
-        return $this->dbHandler->exec("UNLOCK TABLES");
1323
-    }
1324
-
1325
-    public function start_add_lock_table()
1326
-    {
1327
-        if (func_num_args() != 1) {
1328
-            return "";
1329
-        }
1330
-
1331
-        $args = func_get_args();
1332
-
1333
-        return "LOCK TABLES `${args[0]}` WRITE;" . PHP_EOL;
1334
-    }
1335
-
1336
-    public function end_add_lock_table()
1337
-    {
1338
-        return "UNLOCK TABLES;" . PHP_EOL;
1339
-    }
1340
-
1341
-    public function start_add_disable_keys()
1342
-    {
1343
-        if (func_num_args() != 1) {
1344
-            return "";
1345
-        }
1346
-        $args = func_get_args();
1347
-        return "/*!40000 ALTER TABLE `${args[0]}` DISABLE KEYS */;" .
1348
-            PHP_EOL;
1349
-    }
1350
-
1351
-    public function end_add_disable_keys()
1352
-    {
1353
-        if (func_num_args() != 1) {
1354
-            return "";
1355
-        }
1356
-        $args = func_get_args();
1357
-        return "/*!40000 ALTER TABLE `${args[0]}` ENABLE KEYS */;" .
1358
-            PHP_EOL;
1359
-    }
1360
-
1361
-    public function start_disable_autocommit()
1362
-    {
1363
-        return "SET autocommit=0;" . PHP_EOL;
1364
-    }
1365
-
1366
-    public function end_disable_autocommit()
1367
-    {
1368
-        return "COMMIT;" . PHP_EOL;
1369
-    }
1370
-
1371
-    public function add_drop_database()
1372
-    {
1373
-        if (func_num_args() != 1) {
1374
-             return "";
1375
-        }
1376
-
1377
-        $args = func_get_args();
1378
-
1379
-        return "/*!40000 DROP DATABASE IF EXISTS `${args[0]}`*/;" .
1380
-            PHP_EOL . PHP_EOL;
1381
-    }
1382
-
1383
-    public function add_drop_trigger()
1384
-    {
1385
-        if (func_num_args() != 1) {
1386
-            return "";
1387
-        }
1388
-
1389
-        $args = func_get_args();
1390
-
1391
-        return "DROP TRIGGER IF EXISTS `${args[0]}`;" . PHP_EOL;
1392
-    }
1393
-
1394
-    public function drop_table()
1395
-    {
1396
-        if (func_num_args() != 1) {
1397
-            return "";
1398
-        }
1399
-
1400
-        $args = func_get_args();
1401
-
1402
-        return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL;
1403
-    }
1404
-
1405
-    public function drop_view()
1406
-    {
1407
-        if (func_num_args() != 1) {
1408
-            return "";
1409
-        }
1410
-
1411
-        $args = func_get_args();
1412
-
1413
-        return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL .
1414
-                "/*!50001 DROP VIEW IF EXISTS `${args[0]}`*/;" . PHP_EOL;
1415
-    }
1416
-
1417
-    public function getDatabaseHeader()
1418
-    {
1419
-        if (func_num_args() != 1) {
1420
-            return "";
1421
-        }
1422
-
1423
-        $args = func_get_args();
1424
-
1425
-        return "--" . PHP_EOL .
1426
-            "-- Current Database: `${args[0]}`" . PHP_EOL .
1427
-            "--" . PHP_EOL . PHP_EOL;
1428
-    }
1429
-
1430
-    /**
1431
-     * Decode column metadata and fill info structure.
1432
-     * type, is_numeric and is_blob will always be available.
1433
-     *
1434
-     * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
1435
-     * @return array
1436
-     */
1437
-    public function parseColumnType($colType)
1438
-    {
1439
-        $colInfo = array();
1440
-        $colParts = explode(" ", $colType['Type']);
1441
-
1442
-        if($fparen = strpos($colParts[0], "("))
1443
-        {
1444
-            $colInfo['type'] = substr($colParts[0], 0, $fparen);
1445
-            $colInfo['length']  = str_replace(")", "", substr($colParts[0], $fparen+1));
1446
-            $colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : NULL;
1447
-        }
1448
-        else
1449
-        {
1450
-            $colInfo['type'] = $colParts[0];
1451
-        }
1452
-        $colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
1453
-        $colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
1454
-
1455
-        return $colInfo;
1456
-    }
1457
-
1458
-    public function backup_parameters()
1459
-    {
1460
-        if (func_num_args() != 1) {
1461
-            throw new Exception("Unexpected parameter passed to " . __METHOD__);
1462
-        }
1463
-
1464
-        $args = func_get_args();
1465
-        $dumpSettings = $args[0];
1466
-        $ret = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" . PHP_EOL .
1467
-            "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" . PHP_EOL .
1468
-            "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" . PHP_EOL .
1469
-            "/*!40101 SET NAMES " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL;
1470
-
1471
-        if (false === $dumpSettings['skip-tz-utz']) {
1472
-            $ret .= "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;" . PHP_EOL .
1473
-                "/*!40103 SET TIME_ZONE='+00:00' */;" . PHP_EOL;
1474
-        }
1475
-
1476
-        $ret .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;" . PHP_EOL .
1477
-            "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;" . PHP_EOL .
1478
-            "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" . PHP_EOL .
1479
-            "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;" . PHP_EOL .PHP_EOL;
1480
-
1481
-        return $ret;
1482
-    }
1483
-
1484
-    public function restore_parameters()
1485
-    {
1486
-        if (func_num_args() != 1) {
1487
-            throw new Exception("Unexpected parameter passed to " . __METHOD__);
1488
-        }
1489
-
1490
-        $args = func_get_args();
1491
-        $dumpSettings = $args[0];
1492
-        $ret = "";
1493
-
1494
-        if (false === $dumpSettings['skip-tz-utz']) {
1495
-            $ret .= "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL;
1496
-        }
1497
-
1498
-        $ret .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;" . PHP_EOL .
1499
-            "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;" . PHP_EOL .
1500
-            "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;" . PHP_EOL .
1501
-            "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;" . PHP_EOL .
1502
-            "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;" . PHP_EOL .
1503
-            "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;" . PHP_EOL .
1504
-            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;" . PHP_EOL . PHP_EOL;
1505
-
1506
-        return $ret;
1507
-    }
1091
+	private $dbHandler = null;
1092
+
1093
+	// Numerical Mysql types
1094
+	public $mysqlTypes = array(
1095
+		'numerical' => array(
1096
+			'bit',
1097
+			'tinyint',
1098
+			'smallint',
1099
+			'mediumint',
1100
+			'int',
1101
+			'integer',
1102
+			'bigint',
1103
+			'real',
1104
+			'double',
1105
+			'float',
1106
+			'decimal',
1107
+			'numeric'
1108
+		),
1109
+		'blob' => array(
1110
+			'tinyblob',
1111
+			'blob',
1112
+			'mediumblob',
1113
+			'longblob',
1114
+			'binary',
1115
+			'varbinary',
1116
+			'bit'
1117
+		)
1118
+	);
1119
+
1120
+	public function __construct ($dbHandler)
1121
+	{
1122
+		$this->dbHandler = $dbHandler;
1123
+	}
1124
+
1125
+	public function databases()
1126
+	{
1127
+		if (func_num_args() != 1) {
1128
+			throw new Exception("Unexpected parameter passed to " . __METHOD__);
1129
+		}
1130
+
1131
+		$args = func_get_args();
1132
+		$databaseName = $args[0];
1133
+
1134
+		$resultSet = $this->dbHandler->query("SHOW VARIABLES LIKE 'character_set_database';");
1135
+		$characterSet = $resultSet->fetchColumn(1);
1136
+		$resultSet->closeCursor();
1137
+
1138
+		$resultSet = $this->dbHandler->query("SHOW VARIABLES LIKE 'collation_database';");
1139
+		$collationDb = $resultSet->fetchColumn(1);
1140
+		$resultSet->closeCursor();
1141
+		$ret = "";
1142
+
1143
+		$ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${databaseName}`".
1144
+			" /*!40100 DEFAULT CHARACTER SET ${characterSet} " .
1145
+			" COLLATE ${collationDb} */;" . PHP_EOL . PHP_EOL .
1146
+			"USE `${databaseName}`;" . PHP_EOL . PHP_EOL;
1147
+
1148
+		return $ret;
1149
+	}
1150
+
1151
+	public function show_create_table($tableName)
1152
+	{
1153
+		return "SHOW CREATE TABLE `$tableName`";
1154
+	}
1155
+
1156
+	public function show_create_view($viewName)
1157
+	{
1158
+		return "SHOW CREATE VIEW `$viewName`";
1159
+	}
1160
+
1161
+	public function show_create_trigger($triggerName)
1162
+	{
1163
+		return "SHOW CREATE TRIGGER `$triggerName`";
1164
+	}
1165
+
1166
+	public function create_table($row, $dumpSettings)
1167
+	{
1168
+		if (!isset($row['Create Table'])) {
1169
+			throw new Exception("Error getting table code, unknown output");
1170
+		}
1171
+
1172
+		$ret = "/*!40101 SET @saved_cs_client     = @@character_set_client */;" . PHP_EOL .
1173
+			"/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
1174
+			$row['Create Table'] . ";" . PHP_EOL .
1175
+			"/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL .
1176
+			PHP_EOL;
1177
+		return $ret;
1178
+	}
1179
+
1180
+	public function create_view($row)
1181
+	{
1182
+		$ret = "";
1183
+		if (!isset($row['Create View'])) {
1184
+				throw new Exception("Error getting view structure, unknown output");
1185
+		}
1186
+
1187
+		$triggerStmt = $row['Create View'];
1188
+		$triggerStmtReplaced1 = str_replace(
1189
+			"CREATE ALGORITHM",
1190
+			"/*!50001 CREATE ALGORITHM",
1191
+			$triggerStmt
1192
+		);
1193
+		$triggerStmtReplaced2 = str_replace(
1194
+			" DEFINER=",
1195
+			" */" . PHP_EOL . "/*!50013 DEFINER=",
1196
+			$triggerStmtReplaced1
1197
+		);
1198
+		$triggerStmtReplaced3 = str_replace(
1199
+			" VIEW ",
1200
+			" */" . PHP_EOL . "/*!50001 VIEW ",
1201
+			$triggerStmtReplaced2
1202
+		);
1203
+		if (false === $triggerStmtReplaced1 ||
1204
+			false === $triggerStmtReplaced2 ||
1205
+			false === $triggerStmtReplaced3) {
1206
+			$triggerStmtReplaced = $triggerStmt;
1207
+		} else {
1208
+			$triggerStmtReplaced = $triggerStmtReplaced3 . " */;";
1209
+		}
1210
+
1211
+		$ret .= $triggerStmtReplaced . PHP_EOL . PHP_EOL;
1212
+		return $ret;
1213
+	}
1214
+
1215
+	public function create_trigger($row)
1216
+	{
1217
+		$ret = "";
1218
+		if (!isset($row['SQL Original Statement'])) {
1219
+			throw new Exception("Error getting trigger code, unknown output");
1220
+		}
1221
+
1222
+		$triggerStmt = $row['SQL Original Statement'];
1223
+		$triggerStmtReplaced = str_replace(
1224
+			"CREATE DEFINER",
1225
+			"/*!50003 CREATE*/ /*!50017 DEFINER",
1226
+			$triggerStmt
1227
+		);
1228
+		$triggerStmtReplaced = str_replace(
1229
+			" TRIGGER",
1230
+			"*/ /*!50003 TRIGGER",
1231
+			$triggerStmtReplaced
1232
+		);
1233
+		if ( false === $triggerStmtReplaced ) {
1234
+			$triggerStmtReplaced = $triggerStmt;
1235
+		}
1236
+
1237
+		$ret .= "DELIMITER ;;" . PHP_EOL .
1238
+			$triggerStmtReplaced . "*/;;" . PHP_EOL .
1239
+			"DELIMITER ;" . PHP_EOL . PHP_EOL;
1240
+		return $ret;
1241
+	}
1242
+
1243
+	public function show_tables()
1244
+	{
1245
+		if (func_num_args() != 1) {
1246
+			return "";
1247
+		}
1248
+
1249
+		$args = func_get_args();
1250
+
1251
+		return "SELECT TABLE_NAME AS tbl_name " .
1252
+			"FROM INFORMATION_SCHEMA.TABLES " .
1253
+			"WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='${args[0]}'";
1254
+	}
1255
+
1256
+	public function show_views()
1257
+	{
1258
+		if (func_num_args() != 1) {
1259
+			return "";
1260
+		}
1261
+
1262
+		$args = func_get_args();
1263
+
1264
+		return "SELECT TABLE_NAME AS tbl_name " .
1265
+			"FROM INFORMATION_SCHEMA.TABLES " .
1266
+			"WHERE TABLE_TYPE='VIEW' AND TABLE_SCHEMA='${args[0]}'";
1267
+	}
1268
+
1269
+	public function show_triggers()
1270
+	{
1271
+		if (func_num_args() != 1) {
1272
+			return "";
1273
+		}
1274
+
1275
+		$args = func_get_args();
1276
+
1277
+		return "SHOW TRIGGERS FROM `${args[0]}`;";
1278
+	}
1279
+
1280
+
1281
+	public function show_columns()
1282
+	{
1283
+		if (func_num_args() != 1) {
1284
+			return "";
1285
+		}
1286
+
1287
+		$args = func_get_args();
1288
+
1289
+		return "SHOW COLUMNS FROM `${args[0]}`;";
1290
+	}
1291
+
1292
+	public function setup_transaction()
1293
+	{
1294
+		return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
1295
+	}
1296
+
1297
+	public function start_transaction()
1298
+	{
1299
+		return "START TRANSACTION";
1300
+	}
1301
+
1302
+	public function commit_transaction()
1303
+	{
1304
+		return "COMMIT";
1305
+	}
1306
+
1307
+	public function lock_table()
1308
+	{
1309
+		if (func_num_args() != 1) {
1310
+			return "";
1311
+		}
1312
+
1313
+		$args = func_get_args();
1314
+		//$tableName = $args[0];
1315
+		//return "LOCK TABLES `$tableName` READ LOCAL";
1316
+		return $this->dbHandler->exec("LOCK TABLES `${args[0]}` READ LOCAL");
1317
+
1318
+	}
1319
+
1320
+	public function unlock_table()
1321
+	{
1322
+		return $this->dbHandler->exec("UNLOCK TABLES");
1323
+	}
1324
+
1325
+	public function start_add_lock_table()
1326
+	{
1327
+		if (func_num_args() != 1) {
1328
+			return "";
1329
+		}
1330
+
1331
+		$args = func_get_args();
1332
+
1333
+		return "LOCK TABLES `${args[0]}` WRITE;" . PHP_EOL;
1334
+	}
1335
+
1336
+	public function end_add_lock_table()
1337
+	{
1338
+		return "UNLOCK TABLES;" . PHP_EOL;
1339
+	}
1340
+
1341
+	public function start_add_disable_keys()
1342
+	{
1343
+		if (func_num_args() != 1) {
1344
+			return "";
1345
+		}
1346
+		$args = func_get_args();
1347
+		return "/*!40000 ALTER TABLE `${args[0]}` DISABLE KEYS */;" .
1348
+			PHP_EOL;
1349
+	}
1350
+
1351
+	public function end_add_disable_keys()
1352
+	{
1353
+		if (func_num_args() != 1) {
1354
+			return "";
1355
+		}
1356
+		$args = func_get_args();
1357
+		return "/*!40000 ALTER TABLE `${args[0]}` ENABLE KEYS */;" .
1358
+			PHP_EOL;
1359
+	}
1360
+
1361
+	public function start_disable_autocommit()
1362
+	{
1363
+		return "SET autocommit=0;" . PHP_EOL;
1364
+	}
1365
+
1366
+	public function end_disable_autocommit()
1367
+	{
1368
+		return "COMMIT;" . PHP_EOL;
1369
+	}
1370
+
1371
+	public function add_drop_database()
1372
+	{
1373
+		if (func_num_args() != 1) {
1374
+			 return "";
1375
+		}
1376
+
1377
+		$args = func_get_args();
1378
+
1379
+		return "/*!40000 DROP DATABASE IF EXISTS `${args[0]}`*/;" .
1380
+			PHP_EOL . PHP_EOL;
1381
+	}
1382
+
1383
+	public function add_drop_trigger()
1384
+	{
1385
+		if (func_num_args() != 1) {
1386
+			return "";
1387
+		}
1388
+
1389
+		$args = func_get_args();
1390
+
1391
+		return "DROP TRIGGER IF EXISTS `${args[0]}`;" . PHP_EOL;
1392
+	}
1393
+
1394
+	public function drop_table()
1395
+	{
1396
+		if (func_num_args() != 1) {
1397
+			return "";
1398
+		}
1399
+
1400
+		$args = func_get_args();
1401
+
1402
+		return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL;
1403
+	}
1404
+
1405
+	public function drop_view()
1406
+	{
1407
+		if (func_num_args() != 1) {
1408
+			return "";
1409
+		}
1410
+
1411
+		$args = func_get_args();
1412
+
1413
+		return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL .
1414
+				"/*!50001 DROP VIEW IF EXISTS `${args[0]}`*/;" . PHP_EOL;
1415
+	}
1416
+
1417
+	public function getDatabaseHeader()
1418
+	{
1419
+		if (func_num_args() != 1) {
1420
+			return "";
1421
+		}
1422
+
1423
+		$args = func_get_args();
1424
+
1425
+		return "--" . PHP_EOL .
1426
+			"-- Current Database: `${args[0]}`" . PHP_EOL .
1427
+			"--" . PHP_EOL . PHP_EOL;
1428
+	}
1429
+
1430
+	/**
1431
+	 * Decode column metadata and fill info structure.
1432
+	 * type, is_numeric and is_blob will always be available.
1433
+	 *
1434
+	 * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
1435
+	 * @return array
1436
+	 */
1437
+	public function parseColumnType($colType)
1438
+	{
1439
+		$colInfo = array();
1440
+		$colParts = explode(" ", $colType['Type']);
1441
+
1442
+		if($fparen = strpos($colParts[0], "("))
1443
+		{
1444
+			$colInfo['type'] = substr($colParts[0], 0, $fparen);
1445
+			$colInfo['length']  = str_replace(")", "", substr($colParts[0], $fparen+1));
1446
+			$colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : NULL;
1447
+		}
1448
+		else
1449
+		{
1450
+			$colInfo['type'] = $colParts[0];
1451
+		}
1452
+		$colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
1453
+		$colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
1454
+
1455
+		return $colInfo;
1456
+	}
1457
+
1458
+	public function backup_parameters()
1459
+	{
1460
+		if (func_num_args() != 1) {
1461
+			throw new Exception("Unexpected parameter passed to " . __METHOD__);
1462
+		}
1463
+
1464
+		$args = func_get_args();
1465
+		$dumpSettings = $args[0];
1466
+		$ret = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" . PHP_EOL .
1467
+			"/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" . PHP_EOL .
1468
+			"/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" . PHP_EOL .
1469
+			"/*!40101 SET NAMES " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL;
1470
+
1471
+		if (false === $dumpSettings['skip-tz-utz']) {
1472
+			$ret .= "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;" . PHP_EOL .
1473
+				"/*!40103 SET TIME_ZONE='+00:00' */;" . PHP_EOL;
1474
+		}
1475
+
1476
+		$ret .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;" . PHP_EOL .
1477
+			"/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;" . PHP_EOL .
1478
+			"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" . PHP_EOL .
1479
+			"/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;" . PHP_EOL .PHP_EOL;
1480
+
1481
+		return $ret;
1482
+	}
1483
+
1484
+	public function restore_parameters()
1485
+	{
1486
+		if (func_num_args() != 1) {
1487
+			throw new Exception("Unexpected parameter passed to " . __METHOD__);
1488
+		}
1489
+
1490
+		$args = func_get_args();
1491
+		$dumpSettings = $args[0];
1492
+		$ret = "";
1493
+
1494
+		if (false === $dumpSettings['skip-tz-utz']) {
1495
+			$ret .= "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL;
1496
+		}
1497
+
1498
+		$ret .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;" . PHP_EOL .
1499
+			"/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;" . PHP_EOL .
1500
+			"/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;" . PHP_EOL .
1501
+			"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;" . PHP_EOL .
1502
+			"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;" . PHP_EOL .
1503
+			"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;" . PHP_EOL .
1504
+			"/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;" . PHP_EOL . PHP_EOL;
1505
+
1506
+		return $ret;
1507
+	}
1508 1508
 }
Please login to merge, or discard this patch.