3 class mw_data_sqlite_install extends mw_data{
5 public function install_sqlite($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"] : "";
13 if(!$host || !$base) return "paramètres manquant pour la base SQLite";
15 $parent_dir = dirname($host);
16 if(is_dir($parent_dir)) @mkdir($host);
17 if(!is_dir($host)) return "impossible de créer le répertoire des données SQLite";
26 $sgbd->select_db($base);
29 return $e->getMessage();
31 if(!($version = $env->version("mtweb"))){
32 return "impossible de lire la version de mtweb";
36 $sgbd->table_exists("#--actions_roles")
37 || $sgbd->table_exists("#--config")
38 || $sgbd->table_exists("#--roles")
39 || $sgbd->table_exists("#--users")
40 || $sgbd->table_exists("#--users_roles")
41 || $sgbd->table_exists("#--versions");
44 return "impossible de savoir si les tables existent deja";
47 return "des tables a installer existent deja en base. installation annulee";
52 "CREATE TABLE #--actions_roles("
\r
53 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
54 ." `action` TEXT NOT NULL,"
\r
55 ." id_role INTEGER NOT NULL"
\r
60 "CREATE TABLE #--config("
\r
61 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
\r
62 ." `key` TEXT NOT NULL,"
\r
63 ." `value` TEXT NOT NULL"
\r
68 "CREATE TABLE #--roles("
\r
69 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
\r
70 ." nom TEXT NOT NULL,"
\r
71 ." intitule TEXT NOT NULL"
\r
76 "CREATE TABLE #--users("
\r
77 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
\r
78 ." login TEXT NOT NULL,"
\r
79 ." password TEXT NOT NULL,"
\r
80 ." email TEXT NOT NULL"
\r
85 "CREATE TABLE #--users_roles("
\r
86 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
\r
87 ." id_user INTEGER NOT NULL,"
\r
88 ." id_role INTEGER NOT NULL"
93 "CREATE TABLE #--versions("
94 ." id INTEGER PRIMARY KEY AUTOINCREMENT,"
95 ." application TEXT NOT NULL,"
96 ." version TEXT NOT NULL"
102 return "imposible de creer les tables en base. ".$e->getMessage();
106 "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (13, 'admin', 1)";
\r
109 "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (14, 'users', 2)";
112 "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (19, 'users/identification', 0)";
115 "INSERT INTO #--actions_roles (`id`, `action`, `id_role`) VALUES (20, 'config', 3)";
\r
119 "INSERT INTO #--config(id, `key`, `value`) VALUES (1, 'site_name', 'mtweb')";
\r
122 "INSERT INTO #--config(id, `key`, `value`) VALUES (2, 'max_list', '10')";
125 "INSERT INTO #--config(id, `key`, `value`) VALUES (3, 'description', '')";
\r
128 "INSERT INTO #--config(id, `key`, `value`) VALUES (4, 'out', 'default')";
131 "INSERT INTO #--config(id, `key`, `value`) VALUES (5, 'start_action', '')";
\r
134 "INSERT INTO #--config(id, `key`, `value`) VALUES (6, 'contact_form', '0')";
137 "INSERT INTO #--config(id, `key`, `value`) VALUES (8, 'email', '')";
\r
140 "INSERT INTO #--config(id, `key`, `value`) VALUES (9, 'captcha', '0')";
143 "INSERT INTO #--config(id, `key`, `value`) VALUES (16, 'start_action_params', '')";
\r
146 "INSERT INTO #--config(id, `key`, `value`) VALUES (20, 'out_navig_menu_top', 'on')";
149 "INSERT INTO #--config(id, `key`, `value`) VALUES (22, 'out_colonne', 'on')";
\r
152 "INSERT INTO #--config(id, `key`, `value`) VALUES (29, 'default_allow', '1')";
156 "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (0, 'guest', 'invité')";
\r
159 "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')";
162 "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (2, 'membre', 'membre')";
165 "INSERT INTO #--roles(`id`, `nom`, `intitule`) VALUES (3, 'webmaster', 'webmaster')";
169 "INSERT INTO #--versions(`application`, `version`) VALUES ('mtweb', ".$this->eq($version).")";
174 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";