return false;
}
+ function set_version($application_name, $version){
+ if(
+ (
+ $data_version = $this->data_read(
+ array(
+ "table_name" => "versions",
+ "index_name" => "application",
+ "index_value" => $application_name
+ )
+ )
+ ) === false
+ ){
+ return false;
+ }
+ if($data_version){
+ if(
+ !$this->data_update(
+ array(
+ "table_name" => "versions",
+ "index_name" => "id",
+ "index_value" => $data_version["id"],
+ "values" => array(
+ "version" => $version
+ )
+ )
+ )
+ ){
+ return false;
+ }
+ }
+ else{
+ if(
+ !$this->data_insert(
+ array(
+ "table_name" => "versions",
+ "values" => array(
+ "application" => $application_name,
+ "version" => $version
+ )
+ )
+ )
+ ){
+ return false;
+ }
+ }
+ return true;
+ }
+
}
$sgbd->close_data($rst);
}
else{
- return "impossible d'ouvrir la table action_status, dans ".get_class($this);
+ return "impossible d'ouvrir la table action_status";
}
if($action_status === false){
- return "impossible de lire la table action_status, dans ".get_class($this);
+ return "impossible de lire la table action_status";
}
if($action_status){
foreach($action_status as $status){
}
}
if(!$sgbd->remove_data("action_status")){
- return "impossible de supprimer la table action_status";
+ return "impossible de supprimer la table action_status, dans ".get_class($this);
}
}
$sgbd->close_data($rst);
}
else{
- return "impossible d'ouvrir la table config, dans ".get_class($this);
+ return "impossible d'ouvrir la table config";
}
if(!$OK){
- return "impossible de mettre à jour la table config, dans ".get_class($this);
+ return "impossible de mettre à jour la table config";
}
/* ---------------------------------------------------------------------- */
/* */
if(!$sgbd->data_exists("roles")){
if(!$sgbd->create_data("roles")){
- return "impossible de creer la table roles, dans ".get_class($this);
+ return "impossible de creer la table roles";
}
$ERROR = false;
) $ERROR = true;
if($ERROR){
- return "impossible de remplir la table roles, dans ".get_class($this);
+ return "impossible de remplir la table roles";
}
}
if(!$sgbd->data_exists("users_roles")){
if(!$sgbd->create_data("users_roles")){
- return "impossible de creer la table users_roles, dans ".get_class($this);
+ return "impossible de creer la table users_roles";
}
$OK = true;
if($rst = $sgbd->open_data("users")){
$sgbd->close_data($rst);
}
else{
- return "impossible d'ouvrir la table users, dans ".get_class($this);
+ return "impossible d'ouvrir la table users";
}
if(!$OK){
- return "impossible de remplir la table users_roles, dans ".get_class($this);
+ return "impossible de remplir la table users_roles";
}
}
if(!$sgbd->data_exists("versions")){
if(!$sgbd->create_data("versions")){
- return "impossible de creer la table versions, dans ".get_class($this);
- }
- }
-
- /* ---------------------------------------------------------------------- */
- /* mise a jour de la version des donnees */
- /* */
-
- if(!($env_version = $env->version("mtweb"))){
- return "impossible de lire la version du code, dans ".get_class($this);
- }
- if(
- $data_version = $data->data_read(
- array(
- "table_name" => "versions",
- "index_name" => "application",
- "index_value" => "mtweb"
- )
- )
- ){
- if(
- !$sgbd->set_data(
- "versions",
- $data_version["id"],
- array(
- "version" => $this->version()
- )
- )
- ){
- return "impossible de mettre à jour la version, dans ".get_class($this);
- }
- }
- else{
- if(
- !$sgbd->add_data(
- "versions",
- array(
- "application" => "mtweb",
- "version" => $this->version()
- )
- )
- ){
- return "impossible d'ajouter la version, dans ".get_class($this);
+ return "impossible de creer la table versions";
}
}
if(!isset($this->versions)) return true;
foreach($this->versions as $version_number => $version){
if($version->upgrade_required() && ($res = $version->do_upgrade()) !== true){
- return $res;
+ return $res." (dans ".get_class($version).")";
+ }
+ if(!$version->set_data_version()){
+ return "impossible de mettre a jour la version des donnees pour ".$version->application_name();
}
}
return true;
return false;
}
+ function application_name(){
+ return $this->application_name;
+ }
+
function mw_data_version($env, $application_name){
$this->env = $env;
$this->application_name = $application_name;
return true;
}
+ function set_data_version(){
+ if(!isset($this->application_name)) return false;
+ $env = $this->env();
+ $data = $env->data();
+ return $data->set_version($this->application_name, $this->version());
+ }
+
}