From: dj3c1t Date: Sun, 3 Nov 2013 15:01:09 +0000 (+0100) Subject: mise a jour automatique des infos de version X-Git-Tag: mtweb.0.11.3~1 X-Git-Url: http://git.dj3c1t.com/index.cgi?a=commitdiff_plain;h=cda6c6316a9f5d7bbf7f5cfa7de418bf53966be2;p=mtweb mise a jour automatique des infos de version --- diff --git a/mw/app/data/modules/share/mw_data_versions.php b/mw/app/data/modules/share/mw_data_versions.php index 26bc0ee..1f539b4 100644 --- a/mw/app/data/modules/share/mw_data_versions.php +++ b/mw/app/data/modules/share/mw_data_versions.php @@ -15,4 +15,52 @@ 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; + } + } diff --git a/mw/app/data/upgrades/xml/mtweb_xml_version_0_11_2.php b/mw/app/data/upgrades/xml/mtweb_xml_version_0_11_2.php index 9bac3d0..1de687f 100644 --- a/mw/app/data/upgrades/xml/mtweb_xml_version_0_11_2.php +++ b/mw/app/data/upgrades/xml/mtweb_xml_version_0_11_2.php @@ -37,10 +37,10 @@ $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){ @@ -58,7 +58,7 @@ } } 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); } } @@ -107,10 +107,10 @@ $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"; } /* ---------------------------------------------------------------------- */ @@ -119,7 +119,7 @@ /* */ 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; @@ -163,7 +163,7 @@ ) $ERROR = true; if($ERROR){ - return "impossible de remplir la table roles, dans ".get_class($this); + return "impossible de remplir la table roles"; } } @@ -179,7 +179,7 @@ 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")){ @@ -208,10 +208,10 @@ $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"; } } @@ -221,49 +221,7 @@ 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"; } } diff --git a/mw/env/modules/mw_env_data_upgrade.php b/mw/env/modules/mw_env_data_upgrade.php index 8a3f0c1..ff70f6a 100644 --- a/mw/env/modules/mw_env_data_upgrade.php +++ b/mw/env/modules/mw_env_data_upgrade.php @@ -120,7 +120,10 @@ 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; @@ -137,6 +140,10 @@ return false; } + function application_name(){ + return $this->application_name; + } + function mw_data_version($env, $application_name){ $this->env = $env; $this->application_name = $application_name; @@ -159,4 +166,11 @@ 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()); + } + }