3 class mw_data_sql_install extends mw_data{
5 public function install_sql($params){
9 $host = isset($params["host"]) ? $params["host"] : "";
10 $base = isset($params["base"]) ? $params["base"] : "";
11 $user = isset($params["user"]) ? $params["user"] : "";
12 $password = isset($params["password"]) ? $params["password"] : "";
20 $sgbd->select_db($base);
23 return $e->getMessage();
25 if(!($version = $env->version("mtweb"))){
26 return "impossible de lire la version de mtweb";
30 $sgbd->table_exists("#--actions_roles")
31 || $sgbd->table_exists("#--config")
32 || $sgbd->table_exists("#--roles")
33 || $sgbd->table_exists("#--users")
34 || $sgbd->table_exists("#--users_roles")
35 || $sgbd->table_exists("#--versions");
38 return "impossible de savoir si les tables existent deja";
41 return "des tables a installer existent deja en base. installation annulee";
46 "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
50 "CREATE TABLE #--actions_roles("
\r
51 ." id int(11) NOT NULL AUTO_INCREMENT,"
\r
52 ." `action` varchar(255) NOT NULL,"
\r
53 ." id_role int(11) NOT NULL,"
\r
54 ." PRIMARY KEY (id),"
\r
55 ." KEY id_role(id_role)"
\r
56 .") DEFAULT CHARSET=utf8";
60 "CREATE TABLE #--config("
\r
61 ." id int(11) NOT NULL AUTO_INCREMENT,"
\r
62 ." `key` varchar(255) NOT NULL,"
\r
63 ." `value` text NOT NULL,"
\r
64 ." PRIMARY KEY (id)"
\r
65 .") DEFAULT CHARSET=utf8";
69 "CREATE TABLE #--roles("
\r
70 ." id int(11) NOT NULL AUTO_INCREMENT,"
\r
71 ." nom varchar(255) NOT NULL,"
\r
72 ." intitule varchar(255) NOT NULL,"
\r
74 .") DEFAULT CHARSET=utf8";
78 "CREATE TABLE #--users("
\r
79 ." id int(11) NOT NULL AUTO_INCREMENT,"
\r
80 ." login varchar(255) NOT NULL,"
\r
81 ." password varchar(255) NOT NULL,"
\r
82 ." email varchar(255) NOT NULL,"
\r
83 ." PRIMARY KEY (id)"
\r
84 .") DEFAULT CHARSET=utf8";
88 "CREATE TABLE #--users_roles("
\r
89 ." id_user int(11) NOT NULL,"
\r
90 ." id_role int(11) NOT NULL,"
\r
91 ." PRIMARY KEY (id_user,id_role),"
\r
92 ." KEY id_role(id_role)"
\r
93 .") DEFAULT CHARSET=utf8";
97 "CREATE TABLE #--versions("
98 ." id INT(11) NOT NULL AUTO_INCREMENT,"
99 ." application VARCHAR(255) NOT NULL,"
100 ." version VARCHAR(255) NOT NULL,"
102 .") DEFAULT CHARSET=utf8";
107 return "imposible de creer les tables en base";
111 "INSERT INTO #--actions_roles(`id`, `action`, `id_role`) VALUES"
\r
112 ."(13, 'admin', 1),"
\r
113 ."(14, 'users', 2),"
\r
114 ."(19, 'users/identification', 0),"
\r
115 ."(20, 'config', 3)";
119 "INSERT INTO #--config(id, `key`, `value`) VALUES"
\r
120 ."(1, 'site_name', 'mtweb'),"
\r
121 ."(2, 'max_list', '10'),"
\r
122 ."(3, 'description', ''),"
\r
123 ."(4, 'out', 'default'),"
\r
124 ."(5, 'start_action', ''),"
\r
125 ."(6, 'contact_form', '0'),"
\r
126 ."(8, 'email', ''),"
\r
127 ."(9, 'captcha', '0'),"
\r
128 ."(16, 'start_action_params', ''),"
\r
129 ."(20, 'out_navig_menu_top', 'on'),"
\r
130 ."(22, 'out_colonne', 'on'),"
\r
131 ."(29, 'default_allow', '1')";
135 "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES"
\r
136 ."(0, 'guest', 'invité'),"
\r
137 ."(1, 'admin', 'administrateur'),"
\r
138 ."(2, 'membre', 'membre'),"
\r
139 ."(3, 'webmaster', 'webmaster')";
143 "INSERT INTO #--versions(`application`, `version`) VALUES"
\r
144 ."('mtweb', ".$this->eq($version).")";
149 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";