env(); $data = $env->data(); $sgbd = $data->sgbd(); /* ---------------------------------------------------------------------- */ /* action_status */ /* devient actions_roles */ /* element id_status devient id_role */ if(!$sgbd->data_exists("actions_roles")){ if(!$sgbd->create_data("actions_roles")){ return "impossible de créer la table actions_roles"; } } if($sgbd->data_exists("action_status")){ $action_status = array(); if($rst = $sgbd->open_data("action_status")){ while($v_rst = $sgbd->fetch_data($rst)){ if(isset($v_rst)){ $action_status[$v_rst["id"]] = $v_rst; } else{ $action_status = false; break; } } $sgbd->close_data($rst); } else{ return "impossible d'ouvrir la table action_status"; } if($action_status === false){ return "impossible de lire la table action_status"; } if($action_status){ foreach($action_status as $status){ if( !$sgbd->add_data( "actions_roles", array( "action" => $status["action"], "id_role" => $status["id_status"] ) ) ){ return "erreur lors de la migration de action_status vers actions_roles"; } } } if( !$sgbd->add_data( "actions_roles", array( "action" => "config", "id_role" => 3 ) ) ){ return "impossible d'ajouter la protection d'accès webmaster dans actions_roles"; } if(!$sgbd->remove_data("action_status")){ return "impossible de supprimer la table action_status, dans ".get_class($this); } } /* ---------------------------------------------------------------------- */ /* config */ /* elements key et value */ /* */ $OK = true; if($rst = $sgbd->open_data("config")){ while($v_rst = $sgbd->fetch_data($rst)){ if(isset($v_rst)){ if(!isset($v_rst["key"]) || !isset($v_rst["value"])){ $config_key = ""; $config_value = ""; foreach($v_rst as $key => $value){ if($key != "id"){ $config_key = $key; $config_value = $value; break; } } if($config_key){ if( !$sgbd->set_data( "config", $v_rst["id"], array( "key" => $config_key, "value" => $config_value ) ) ){ $OK = false; break; } } } } else{ $OK = false; break; } } $sgbd->close_data($rst); } else{ return "impossible d'ouvrir la table config"; } if(!$OK){ return "impossible de mettre à jour la table config"; } /* ---------------------------------------------------------------------- */ /* user_status */ /* devient roles */ /* */ if(!$sgbd->data_exists("roles")){ if(!$sgbd->create_data("roles")){ return "impossible de creer la table roles"; } $ERROR = false; if(!$ERROR){ $res = $sgbd->add_data( "roles", array( "nom" => "guest", "intitule" => "invité" ), 0 ); if(!isset($res)) $ERROR = true; } if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "admin", "intitule" => "administrateur" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "membre", "intitule" => "membre" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "webmaster", "intitule" => "webmaster" ) ) ) $ERROR = true; if($ERROR){ return "impossible de remplir la table roles"; } } if($sgbd->data_exists("user_status")){ if(!$sgbd->remove_data("user_status")){ return "impossible de supprimer la table user_status"; } } /* ---------------------------------------------------------------------- */ /* nouvelle table users_roles */ /* importer users.status dans users_roles.id_role */ if(!$sgbd->data_exists("users_roles")){ if(!$sgbd->create_data("users_roles")){ return "impossible de creer la table users_roles"; } $OK = true; if($rst = $sgbd->open_data("users")){ while($v_rst = $sgbd->fetch_data($rst)){ if(isset($v_rst)){ if(isset($v_rst["status"])){ if( !$sgbd->add_data( "users_roles", array( "id_user" => $v_rst["id"], "id_role" => $v_rst["status"] ) ) ){ $OK = false; break; } } } else{ $OK = false; break; } } $sgbd->close_data($rst); } else{ return "impossible d'ouvrir la table users"; } if(!$OK){ return "impossible de remplir la table users_roles"; } } /* ---------------------------------------------------------------------- */ /* nouvelle table versions */ /* */ if(!$sgbd->data_exists("versions")){ if(!$sgbd->create_data("versions")){ return "impossible de creer la table versions"; } } return true; } }