From 37049b502efdf68a562ce63d8f37a820c66bc887 Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Sun, 10 Nov 2013 22:34:52 +0100 Subject: [PATCH] upgrade 1.1.2 pour XML, MySql et SQLite --- app/config.xml | 2 +- app/controllers/content/sources.php | 5 +- app/controllers/users/morceaux.php | 2 +- app/controllers/users/pistes.php | 5 +- .../modules/share/sml_data_sources_xml_format.php | 3 + app/data/modules/sql/sml_data_authors.php | 2 + app/data/modules/sql/sml_data_sources.php | 14 + app/data/modules/xml/sml_data_authors.php | 18 +- app/data/modules/xml/sml_data_install.php | 6 - app/data/modules/xml/sml_data_sources.php | 18 +- .../upgrades/sql/mw_sourceml_sql_version_1_1_2.php | 603 +++++++++++++++++++++ .../upgrades/xml/mw_sourceml_xml_version_1_1_2.php | 469 ++++++++++++++++ app/out/default/views/sources/groupe/view.php | 2 +- app/out/default/views/sources/source/header.php | 5 +- 14 files changed, 1131 insertions(+), 23 deletions(-) create mode 100644 app/data/upgrades/sql/mw_sourceml_sql_version_1_1_2.php create mode 100644 app/data/upgrades/xml/mw_sourceml_xml_version_1_1_2.php diff --git a/app/config.xml b/app/config.xml index fef3e9b..89dcfa9 100644 --- a/app/config.xml +++ b/app/config.xml @@ -1,7 +1,7 @@ - 1.1.1 + 1.1.2 parent diff --git a/app/controllers/content/sources.php b/app/controllers/content/sources.php index f76d956..82d9b6d 100644 --- a/app/controllers/content/sources.php +++ b/app/controllers/content/sources.php @@ -113,7 +113,10 @@ { if(isset($_sources[$this->source["id"]]) && $_sources[$this->source["id"]]) { foreach($_sources[$this->source["id"]] as $id_source) { if(($sources["list"][$id_source] = $data->source($id_source, true)) !== false) - { $sources["total"]++; + { if(!isset($sources["list"][$id_source]["ordre"])){ + $sources["list"][$id_source]["ordre"] = 0; + } + $sources["total"]++; } else { $this->erreur("Impossible de lire les informations de l'une des sources"); diff --git a/app/controllers/users/morceaux.php b/app/controllers/users/morceaux.php index 75414bc..092da62 100644 --- a/app/controllers/users/morceaux.php +++ b/app/controllers/users/morceaux.php @@ -243,7 +243,7 @@ $morceau["groupes"], $morceau["titre"], $this->morceau_status_id, - $morceau["licence"]["id"], + isset($morceau["licence"]["id"]) ? $morceau["licence"]["id"] : null, $morceau["documents"], $morceau["reference"], $morceau["derivations"], diff --git a/app/controllers/users/pistes.php b/app/controllers/users/pistes.php index eeab45b..60190de 100644 --- a/app/controllers/users/pistes.php +++ b/app/controllers/users/pistes.php @@ -128,7 +128,8 @@ if($groupes["total"] > 0){ $select = array( "status" => $this->morceau_status_id, - "id_user" => $this->user["id"] + "id_user" => $this->user["id"], + "is_reference" => false ); foreach($groupes["list"] as $id_groupe => $groupe){ $select["id_groupe"] = $id_groupe; @@ -248,7 +249,7 @@ $piste["groupes"], $piste["titre"], $this->piste_status_id, - $piste["licence"]["id"], + isset($piste["licence"]["id"]) ? $piste["licence"]["id"] : null, $piste["documents"], $piste["reference"], $piste["derivations"], diff --git a/app/data/modules/share/sml_data_sources_xml_format.php b/app/data/modules/share/sml_data_sources_xml_format.php index ae67cab..676262a 100644 --- a/app/data/modules/share/sml_data_sources_xml_format.php +++ b/app/data/modules/share/sml_data_sources_xml_format.php @@ -20,6 +20,9 @@ if($this->status !== false){ $this->source = isset($params["source"]) ? $params["source"] : $this->source($id, true); if($this->source !== false){ + if($this->source["reference"]){ + return $this->source["reference"]["xml"]["content"]; + } if($this->source["groupes"]) $this->groupes = $this->source["groupes"]; if(isset($params["groupes"])) $this->groupes = $params["groupes"]; if(!isset($this->groupes)) $this->groupes = $this->source_groupes($id); diff --git a/app/data/modules/sql/sml_data_authors.php b/app/data/modules/sql/sml_data_authors.php index 72779a8..81d308d 100644 --- a/app/data/modules/sql/sml_data_authors.php +++ b/app/data/modules/sql/sml_data_authors.php @@ -26,6 +26,7 @@ $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res"; $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)){ + if(!isset($v_rst["image"])) $v_rst["image"] = ""; $groupes["list"][$v_rst["id"]] = $v_rst; $groupes["list"][$v_rst["id"]]["image_uri"] = ( $v_rst["image"] ? @@ -50,6 +51,7 @@ $sql = "SELECT * from #--sml_authors WHERE id=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)){ + if(!isset($v_rst["image"])) $v_rst["image"] = ""; $groupe = $v_rst; $groupe["image_uri"] = ( $groupe["image"] ? diff --git a/app/data/modules/sql/sml_data_sources.php b/app/data/modules/sql/sml_data_sources.php index c7eb45c..4c85c2b 100644 --- a/app/data/modules/sql/sml_data_sources.php +++ b/app/data/modules/sql/sml_data_sources.php @@ -44,6 +44,7 @@ $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $id_source_derivation = isset($params["id_source_derivation"]) ? $params["id_source_derivation"] : null; $id_licence = isset($params["id_licence"]) ? $params["id_licence"] : null; + $is_reference = isset($params["is_reference"]) ? $params["is_reference"] : null; $order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre"; $order = isset($params["order"]) ? $params["order"] : "ASC"; $sgbd = $this->sgbd(); @@ -117,6 +118,19 @@ if(isset($id_licence)) $WHERE .= ($WHERE ? " AND " : " WHERE ") ." #--sml_sources.licence=".$this->eq($id_licence); + if(isset($is_reference)){ + $WHERE .= ($WHERE ? " AND " : " WHERE "); + if($is_reference){ + $WHERE .= + " #--sml_sources.reference IS NOT NULL" + ." AND LENGTH(#--sml_sources.reference) > 0"; + } + else{ + $WHERE .= + " (#--sml_sources.reference IS NULL" + ." OR (LENGTH(#--sml_sources.reference) = 0))"; + } + } $ORDER_BY = " ORDER BY ".$order_by." ".$order; $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : ""); try{ diff --git a/app/data/modules/xml/sml_data_authors.php b/app/data/modules/xml/sml_data_authors.php index 247bc3d..953ccfe 100644 --- a/app/data/modules/xml/sml_data_authors.php +++ b/app/data/modules/xml/sml_data_authors.php @@ -37,10 +37,11 @@ if(isset($start) && $env->config("max_list") && ($n < $start || $n >= ($start + $env->config("max_list")))) { unset($groupes["list"][$id_groupe]); } - else - { $groupes["list"][$id_groupe]["image_uri"] = - ( $groupe["image"] ? - $env->path("content")."uploads/".$groupe["image"] + else{ + if(!isset($groupes["list"][$id_groupe]["image"])) $groupes["list"][$id_groupe]["image"] = ""; + $groupes["list"][$id_groupe]["image_uri"] = + ( $groupes["list"][$id_groupe]["image"] ? + $env->path("content")."uploads/".$groupes["list"][$id_groupe]["image"] : "" ); } @@ -52,13 +53,14 @@ return $groupes; } - function groupe($id) - { if(!isset($this->groupes)) $this->groupes = array(); + function groupe($id){ + if(!isset($this->groupes)) $this->groupes = array(); if(isset($this->groupes[$id])) return $this->groupes[$id]; $sgbd = $this->sgbd(); $env = $this->env(); - if(($groupe = $sgbd->get_data("sml_authors", $id)) !== null) - { $groupe["image_uri"] = + if(($groupe = $sgbd->get_data("sml_authors", $id)) !== null){ + if(!isset($groupe["image"])) $groupe["image"] = ""; + $groupe["image_uri"] = ( $groupe["image"] ? $env->path("content")."uploads/".$groupe["image"] : "" diff --git a/app/data/modules/xml/sml_data_install.php b/app/data/modules/xml/sml_data_install.php index e3c49a0..0b9ea55 100644 --- a/app/data/modules/xml/sml_data_install.php +++ b/app/data/modules/xml/sml_data_install.php @@ -16,11 +16,9 @@ $res = $sgbd->data_exists("sml_sources"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_sources_access"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_sources_authors"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; - $res = $sgbd->data_exists("sml_sources_infos"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_source_cache"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_source_compositions"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_source_derivations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; - $res = $sgbd->data_exists("sml_source_documents"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; $res = $sgbd->data_exists("sml_sources_invitations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1; if($RES === -1) return "impossible de savoir si les tables existent deja. installation annulee"; @@ -36,11 +34,9 @@ if(!$sgbd->create_data("sml_sources")) return "impossible de creer la table sml_sources"; if(!$sgbd->create_data("sml_sources_access")) return "impossible de creer la table sml_sources_access"; if(!$sgbd->create_data("sml_sources_authors")) return "impossible de creer la table sml_sources_authors"; - if(!$sgbd->create_data("sml_sources_infos")) return "impossible de creer la table sml_sources_infos"; if(!$sgbd->create_data("sml_source_cache")) return "impossible de creer la table sml_source_cache"; if(!$sgbd->create_data("sml_source_compositions")) return "impossible de creer la table sml_source_compositions"; if(!$sgbd->create_data("sml_source_derivations")) return "impossible de creer la table sml_source_derivations"; - if(!$sgbd->create_data("sml_source_documents")) return "impossible de creer la table sml_source_documents"; if(!$sgbd->create_data("sml_sources_invitations")) return "impossible de creer la table sml_sources_invitations"; $ERROR = false; @@ -239,11 +235,9 @@ if(!$ERROR) if(!$sgbd->remove_data("sml_sources")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_sources_access")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_sources_authors")) $ERROR = true; - if(!$ERROR) if(!$sgbd->remove_data("sml_sources_infos")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_source_cache")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_source_compositions")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_source_derivations")) $ERROR = true; - if(!$ERROR) if(!$sgbd->remove_data("sml_source_documents")) $ERROR = true; if(!$ERROR) if(!$sgbd->remove_data("sml_sources_invitations")) $ERROR = true; if(!$ERROR) if( diff --git a/app/data/modules/xml/sml_data_sources.php b/app/data/modules/xml/sml_data_sources.php index b4a4d1b..fb8dc2b 100644 --- a/app/data/modules/xml/sml_data_sources.php +++ b/app/data/modules/xml/sml_data_sources.php @@ -56,6 +56,7 @@ $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $id_source_derivation = isset($params["id_source_derivation"]) ? $params["id_source_derivation"] : null; $id_licence = isset($params["id_licence"]) ? $params["id_licence"] : null; + $is_reference = isset($params["is_reference"]) ? $params["is_reference"] : null; $order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre"; $order = isset($params["order"]) ? $params["order"] : "ASC"; @@ -112,7 +113,10 @@ $res = array(); if($rst = $sgbd->open_data("sml_sources")) { while($v_rst = $sgbd->fetch_data($rst)) - { if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst; + { if(isset($v_rst)){ + $res[$v_rst["id"]] = $v_rst; + if(!isset($res[$v_rst["id"]]["ordre"])) $res[$v_rst["id"]]["ordre"] = 0; + } else { $res = false; break; @@ -197,6 +201,18 @@ } } + // -------------------------------- filtre sur is_reference + if($MATCH){ + if(isset($is_reference)){ + if($is_reference){ + $MATCH = isset($v_rst["reference"]) && $v_rst["reference"]; + } + else{ + $MATCH = !isset($v_rst["reference"]) || !$v_rst["reference"]; + } + } + } + // -------------------------------- filtre sur quantite de resultats if($MATCH) { $sources["total"]++; diff --git a/app/data/upgrades/sql/mw_sourceml_sql_version_1_1_2.php b/app/data/upgrades/sql/mw_sourceml_sql_version_1_1_2.php new file mode 100644 index 0000000..50769d3 --- /dev/null +++ b/app/data/upgrades/sql/mw_sourceml_sql_version_1_1_2.php @@ -0,0 +1,603 @@ +env(); + $data = $env->data(); + $sgbd = $data->sgbd(); + + if($sgbd->table_exists("#--sources")){ + + /* ---------------------------------------------------------------------- + nouvelle table groupe_status + */ + + if(!$sgbd->table_exists("#--groupe_status")){ + if( + !$data->data_create_table( + array( + "table_name" => "groupe_status", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "nom" => array("type" => "varchar") + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table groupe_status"; + } + try{ + $sql = "INSERT INTO #--groupe_status(id, nom) VALUES (1, 'admin')"; + $sgbd->query($sql); + $sql = "INSERT INTO #--groupe_status(id, nom) VALUES (2, 'editeur')"; + $sgbd->query($sql); + $sql = "INSERT INTO #--groupe_status(id, nom) VALUES (3, 'contributeur')"; + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible de remplir la table groupe_status"; + } + } + + /* ---------------------------------------------------------------------- + nouvelle table source_groupes + sources.id_groupe passe dans source_groupes.id_groupe + */ + + if(!$sgbd->table_exists("#--source_groupes")){ + if( + !$data->data_create_table( + array( + "table_name" => "source_groupes", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "id_source" => array("type" => "int"), + "id_groupe" => array("type" => "int"), + "id_groupe_status" => array("type" => "int") + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table source_groupes"; + } + $sql = + "INSERT INTO #--source_groupes(id_source, id_groupe, id_groupe_status)" + ." SELECT" + ." id" + .", id_groupe" + .", 1" + ." FROM #--sources"; + try{ + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible d'importer les id_groupes dans source_groupes"; + } + } + + /* ---------------------------------------------------------------------- + nouvelle table source_derivations + sources.derivation devient source_derivations.derivation + */ + + if(!$sgbd->table_exists("#--source_derivations")){ + if( + !$data->data_create_table( + array( + "table_name" => "source_derivations", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "id_source" => array("type" => "int"), + "derivation" => array("type" => "varchar") + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table source_derivations"; + } + $sql = + "INSERT INTO #--source_derivations(id_source, derivation)" + ." SELECT" + ." id" + .", derivation" + ." FROM #--sources WHERE derivation IS NOT NULL"; + try{ + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible d'importer les derivation dans source_derivations"; + } + } + + /* ---------------------------------------------------------------------- + sources + maj source_infos : image avec id user + */ + + $SOURCE_HAS_ID_GROUPE = false; + try{ + $sources_desc = $sgbd->desc_table("#--sources"); + if(isset($sources_desc["attributs"]["id_groupe"])){ + $SOURCE_HAS_ID_GROUPE = true; + } + } + catch(Exception $e){ + return "impossible de lire les champs de la table sources"; + } + if($SOURCE_HAS_ID_GROUPE){ + try{ + $sql = + "SELECT #--sources.id as id_source, #--sources.id_groupe" + .", #--source_infos.id as id_source_info, #--source_infos.`value` as image" + ." FROM #--sources" + ." LEFT JOIN #--source_infos" + ." ON (#--source_infos.id_source=#--sources.id AND #--source_infos.`key`='image')"; + $rst = $sgbd->query($sql); + while($v_rst = $sgbd->fetch_assoc($rst)){ + if($v_rst["image"] && !preg_match("/^[0-9]+\/.*$/", $v_rst["image"])){ + if( + ( + $groupe = $data->data_read( + array( + "table_name" => "groupes", + "index_name" => "id", + "index_value" => $v_rst["id_groupe"] + ) + ) + ) === false + ){ + return "erreur lors de la lecture de l'utilisateur du groupe"; + } + if( + !$data->data_update( + array( + "table_name" => "source_infos", + "index_name" => "id", + "index_value" => $v_rst["id_source_info"], + "values" => array( + "value" => $groupe["id_user"]."/".$v_rst["image"] + ) + ) + ) + ){ + return "impossible de mettre a jour l'image des sources dans source_infos"; + } + } + } + $sgbd->free_result($rst); + } + catch(Exception $e){ + return "impossible de mettre a jour les images des sources"; + } + } + + + /* ---------------------------------------------------------------------- + groupes + maj image avec id user + */ + + try{ + $sql ="SELECT * FROM #--groupes"; + $rst = $sgbd->query($sql); + while($v_rst = $sgbd->fetch_assoc($rst)){ + if($v_rst["image"] && !preg_match("/^[0-9]+\/.*$/", $v_rst["image"])){ + if( + !$data->data_update( + array( + "table_name" => "groupes", + "index_name" => "id", + "index_value" => $v_rst["id"], + "values" => array( + "image" => $v_rst["id_user"]."/".$v_rst["image"] + ) + ) + ) + ){ + return "impossible de mettre a jour l'image des groupes"; + } + } + } + $sgbd->free_result($rst); + } + catch(Exception $e){ + return "impossible de mettre a jour les images des groupes"; + } + + /* ---------------------------------------------------------------------- + sources + sources.nom devient sources.titre + sources.status devient sources.id_class + suppression de sources.id_groupe + suppression de sources.derivation + */ + + try{ + $sources_desc = $sgbd->desc_table("#--sources"); + } + catch(Exception $e){ + return "impossible de lire les champs de la table sources"; + } + if( + !isset($sources_desc["attributs"]["titre"]) + || isset($sources_desc["attributs"]["nom"]) + || isset($sources_desc["attributs"]["status"]) + || isset($sources_desc["attributs"]["id_groupe"]) + || isset($sources_desc["attributs"]["derivation"]) + ){ + $sql = "ALTER TABLE #--sources RENAME TO #--sources_tmp"; + try{ + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible de renommer la table sources en sources_tmp"; + } + if( + !$data->data_create_table( + array( + "table_name" => "sources", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "id_class" => array("type" => "int"), + "reference" => array("type" => "varchar", "null" => true), + "titre" => array("type" => "varchar", "null" => true), + "licence" => array("type" => "int", "null" => true), + "date_creation" => array("type" => "date", "null" => true), + "date_inscription" => array("type" => "datetime") + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ), + array( + "fields" => array("id_class") + ), + array( + "fields" => array("licence") + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table sources"; + } + $attribut_names = array( + "id_class" => isset($sources_desc["attributs"]["status"]) ? "status" : "id_class", + "titre" => isset($sources_desc["attributs"]["nom"]) ? "nom" : "titre", + ); + $sql = + "INSERT INTO #--sources(id, id_class, reference, titre, licence, date_creation, date_inscription)" + ." SELECT" + ." id" + .", ".$attribut_names["id_class"] + .", reference" + .", ".$attribut_names["titre"] + .", licence" + .", date_creation" + .", date_inscription" + ." FROM #--sources_tmp"; + try{ + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible d'importer sources_tmp dans sources"; + } + try{ + $sgbd->query("DROP TABLE #--sources_tmp"); + } + catch(Exception $e){ + return "impossible de supprimer la table sources_tmp"; + } + } + + /* ---------------------------------------------------------------------- + suppression de la table source_status_composition + */ + + if($sgbd->table_exists("#--source_status_composition")){ + try{ + $sgbd->query("DROP TABLE #--source_status_composition"); + } + catch(Exception $e){ + return "impossible de supprimer la table source_status_composition"; + } + } + + } // if($sgbd->data_exists("sources")) + + + /* ###################################################################### */ + /* ###################################################################### */ + /* ---------------------------------------------------------------------- + migration vers les tables en sml_(...) du plugin mw_sourceml + */ + + /* ---------------------------------------------------------------------- + sources devient sml_sources + */ + + if($sgbd->table_exists("#--sources")){ + try{ + $sgbd->query("ALTER TABLE #--sources RENAME TO #--sml_sources"); + } + catch(Exception $e){ + return "impossible de renommer sources en sml_sources"; + } + } + + + /* ---------------------------------------------------------------------- + source_groupes devient sml_sources_authors + elt id_groupe devient id_author + elt id_groupe_status devient id_sources_access + */ + + if($sgbd->table_exists("#--source_groupes")){ + if( + !$data->data_create_table( + array( + "table_name" => "sml_sources_authors", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "id_source" => array("type" => "int"), + "id_author" => array("type" => "int"), + "id_sources_access" => array("type" => "int"), + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ), + array( + "fields" => array("id_source") + ), + array( + "fields" => array("id_author") + ), + array( + "fields" => array("id_sources_access") + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table sources"; + } + $sql = + "INSERT INTO #--sml_sources_authors(id_source, id_author, id_sources_access)" + ." SELECT" + ." id_source" + .", id_groupe" + .", id_groupe_status" + ." FROM #--source_groupes"; + try{ + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible d'importer les derivation dans source_derivations"; + } + try{ + $sgbd->query("DROP TABLE #--source_groupes"); + } + catch(Exception $e){ + return "impossible de supprimer la table source_groupes"; + } + } + + + /* ---------------------------------------------------------------------- + groupe_status devient sml_sources_access + nouvel elt intitule + */ + + if($sgbd->table_exists("#--groupe_status")){ + if( + !$data->data_create_table( + array( + "table_name" => "sml_sources_access", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "nom" => array("type" => "varchar"), + "intitule" => array("type" => "varchar"), + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table sources"; + } + try{ + $sql = "INSERT INTO #--sml_sources_access(id, nom, intitule) VALUES (1, 'admin', 'administrateur')"; + $sgbd->query($sql); + $sql = "INSERT INTO #--sml_sources_access(id, nom, intitule) VALUES (2, 'editeur', 'éditeur')"; + $sgbd->query($sql); + $sql = "INSERT INTO #--sml_sources_access(id, nom, intitule) VALUES (3, 'contributeur', 'contributeur')"; + $sgbd->query($sql); + } + catch(Exception $e){ + return "impossible de remplir la table sml_sources_access"; + } + try{ + $sgbd->query("DROP TABLE #--groupe_status"); + } + catch(Exception $e){ + return "impossible de supprimer la table groupe_status"; + } + } + + /* ---------------------------------------------------------------------- + groupes devient sml_authors + */ + + if($sgbd->table_exists("#--groupes")){ + try{ + $sgbd->query("ALTER TABLE #--groupes RENAME TO #--sml_authors"); + } + catch(Exception $e){ + return "impossible de renommer groupes en sml_authors"; + } + } + + /* ---------------------------------------------------------------------- + licences devient sml_licences + */ + + if($sgbd->table_exists("#--licences")){ + try{ + $sgbd->query("ALTER TABLE #--licences RENAME TO #--sml_licences"); + } + catch(Exception $e){ + return "impossible de renommer licences en sml_licences"; + } + } + + /* ---------------------------------------------------------------------- + source_compositions devient sml_source_compositions + */ + + if($sgbd->table_exists("#--source_compositions")){ + try{ + $sgbd->query("ALTER TABLE #--source_compositions RENAME TO #--sml_source_compositions"); + } + catch(Exception $e){ + return "impossible de renommer source_compositions en sml_source_compositions"; + } + } + + /* ---------------------------------------------------------------------- + source_derivations devient sml_source_derivations + */ + + if($sgbd->table_exists("#--source_derivations")){ + try{ + $sgbd->query("ALTER TABLE #--source_derivations RENAME TO #--sml_source_derivations"); + } + catch(Exception $e){ + return "impossible de renommer source_derivations en sml_source_derivations"; + } + } + + /* ---------------------------------------------------------------------- + source_cache devient sml_source_cache + */ + + if($sgbd->table_exists("#--source_cache")){ + try{ + $sgbd->query("ALTER TABLE #--source_cache RENAME TO #--sml_source_cache"); + } + catch(Exception $e){ + return "impossible de renommer source_cache en sml_source_cache"; + } + } + + /* ---------------------------------------------------------------------- + source_status devient sml_classes + */ + + if($sgbd->table_exists("#--source_status")){ + try{ + $sgbd->query("ALTER TABLE #--source_status RENAME TO #--sml_classes"); + } + catch(Exception $e){ + return "impossible de renommer source_status en sml_classes"; + } + } + + /* ---------------------------------------------------------------------- + source_infos devient sml_sources_infos + */ + + if($sgbd->table_exists("#--source_infos")){ + try{ + $sgbd->query("ALTER TABLE #--source_infos RENAME TO #--sml_sources_infos"); + } + catch(Exception $e){ + return "impossible de renommer source_infos en sml_sources_infos"; + } + } + + /* ---------------------------------------------------------------------- + source_documents devient sml_source_documents + */ + + if($sgbd->table_exists("#--source_documents")){ + try{ + $sgbd->query("ALTER TABLE #--source_documents RENAME TO #--sml_source_documents"); + } + catch(Exception $e){ + return "impossible de renommer source_documents en sml_source_documents"; + } + } + + + /* ---------------------------------------------------------------------- + nouvelle table sml_sources_invitations + */ + + if(!$sgbd->table_exists("#--sml_sources_invitations")){ + if( + !$data->data_create_table( + array( + "table_name" => "sml_sources_invitations", + "fields" => array( + "id" => array("type" => "int", "autoincrement" => true), + "id_user" => array("type" => "int"), + "id_source" => array("type" => "int"), + "id_author" => array("type" => "int"), + "id_sources_access" => array("type" => "int"), + "date_invitation" => array("type" => "datetime") + ), + "keys" => array( + array( + "fields" => array("id"), + "primary" => true + ) + ), + "options" => array("default_charset" => "utf8") + ) + ) + ){ + return "impossible de créer la table sml_sources_invitations"; + } + } + + return true; + } + + } diff --git a/app/data/upgrades/xml/mw_sourceml_xml_version_1_1_2.php b/app/data/upgrades/xml/mw_sourceml_xml_version_1_1_2.php new file mode 100644 index 0000000..196adde --- /dev/null +++ b/app/data/upgrades/xml/mw_sourceml_xml_version_1_1_2.php @@ -0,0 +1,469 @@ +env(); + $data = $env->data(); + $sgbd = $data->sgbd(); + + if($sgbd->data_exists("sources")){ + + /* ---------------------------------------------------------------------- + nouvelle table groupe_status + */ + + if(!$sgbd->data_exists("groupe_status")){ + if(!$sgbd->create_data("groupe_status")) return "impossible de creer la table groupe_status"; + if + ( !$sgbd->add_data("groupe_status", array("nom" => "admin")) + || !$sgbd->add_data("groupe_status", array("nom" => "editeur")) + || !$sgbd->add_data("groupe_status", array("nom" => "contributeur")) + ){ + return "impossible de renseigner la table groupe_status"; + } + } + + /* ---------------------------------------------------------------------- + nouvelle table source_groupes + sources.id_groupe devient source_groupes.id_groupe + maj sources.image avec id user + */ + + if(!$sgbd->data_exists("source_groupes")){ + if(!$sgbd->create_data("source_groupes")) return "impossible de creer la table source_groupes"; + if(!($rst = $sgbd->open_data("sources"))){ + return "impossible de lire la liste des sources"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"]) && isset($v_rst["id_groupe"])){ + $id_source = $v_rst["id"]; + unset($v_rst["id"]); + $id_groupe = $v_rst["id_groupe"]; + unset($v_rst["id_groupe"]); + if(isset($v_rst["image"]) && $v_rst["image"] && !preg_match("/^[0-9]+\/.*$/", $v_rst["image"])){ + if($groupe = $sgbd->get_data("groupes", $id_groupe)){ + $v_rst["image"] = $groupe["id_user"]."/".$v_rst["image"]; + } + } + if( + !$sgbd->set_data( + "sources", + $id_source, + $v_rst + ) + ){ + $erreur = "impossible de mettre a jour les informations des sources (champ id_groupe)"; + break; + } + if( + !$sgbd->add_data( + "source_groupes", + array( + "id_source" => $id_source, + "id_groupe" => $id_groupe, + "id_groupe_status" => 1 + ) + ) + ){ + $erreur = "impossible de mettre a jour les informations des sources (source_groupes)"; + break; + } + } + } + else{ + $erreur = "erreur lors de lecture des sources pour mettre a jour les derivations"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + } + + /* ---------------------------------------------------------------------- + nouvelle table source_derivations + sources.derivation devient source_derivations.derivation + */ + + if(!$sgbd->data_exists("source_derivations")){ + if(!$sgbd->create_data("source_derivations")){ + return "impossible de créer la table source_derivations"; + } + if(!($rst = $sgbd->open_data("sources"))){ + return "impossible de lire la liste des sources"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"]) && isset($v_rst["derivation"])){ + $id_source = $v_rst["id"]; + unset($v_rst["id"]); + $derivation = $v_rst["derivation"]; + unset($v_rst["derivation"]); + if( + !$sgbd->set_data( + "sources", + $id_source, + $v_rst + ) + ){ + $erreur = "impossible de mettre a jour les informations des sources (champ derivation)"; + break; + } + if( + !$sgbd->add_data( + "source_derivations", + array( + "id_source" => $id_source, + "derivation" => $derivation + ) + ) + ){ + $erreur = "impossible de mettre a jour les derivations"; + break; + } + } + } + else{ + $erreur = "erreur lors de lecture des sources pour mettre a jour les derivations"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + } + + /* ---------------------------------------------------------------------- + groupes + maj image avec id user + */ + + if($sgbd->data_exists("groupes")){ + if(!($rst = $sgbd->open_data("groupes"))){ + return "impossible de lire la liste des groupes pour mettre a jour les chemins des images"; + } + $res = true; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"]) && isset($v_rst["id_user"]) && isset($v_rst["image"]) && $v_rst["image"]){ + if(!preg_match("/^[0-9]+\/.*$/", $v_rst["image"])){ + $id_groupe = $v_rst["id"]; + unset($v_rst["id"]); + $v_rst["image"] = $v_rst["id_user"]."/".$v_rst["image"]; + if( + !$sgbd->set_data( + "groupes", + $id_groupe, + $v_rst + ) + ){ + $res = "impossible de mettre a jour les images des groupes"; + break; + } + } + } + } + else{ + $res = "erreur lors de lecture des groupes pour mettre a jour les images"; + break; + } + } + $sgbd->close_data($rst); + if($res !== true) return $res; + } + + /* ---------------------------------------------------------------------- + sources + sources.nom devient sources.titre + */ + + if(!($rst = $sgbd->open_data("sources"))){ + return "impossible de lire la liste des sources"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"])){ + $id_source = $v_rst["id"]; + unset($v_rst["id"]); + $NEED_UPDATE = false; + if(!isset($v_rst["titre"])){ + $v_rst["titre"] = isset($v_rst["nom"]) ? $v_rst["nom"] : ""; + $NEED_UPDATE = true; + } + if(isset($v_rst["nom"])){ + unset($v_rst["nom"]); + $NEED_UPDATE = true; + } + if($NEED_UPDATE){ + if( + !$sgbd->set_data( + "sources", + $id_source, + $v_rst + ) + ){ + $erreur = "impossible de mettre a jour les informations des sources"; + break; + } + } + } + } + else{ + $erreur = "erreur lors de lecture des sources pour mettre a jour leurs informations"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + + /* ---------------------------------------------------------------------- + suppression de la table source_status_composition + */ + + if($sgbd->data_exists("source_status_composition")){ + if(!$sgbd->remove_data("source_status_composition")){ + return "impossible de supprimer la table source_status_composition"; + } + } + + } // if($sgbd->data_exists("sources")) + + + /* ###################################################################### */ + /* ###################################################################### */ + /* ---------------------------------------------------------------------- + migration vers les tables en sml_(...) du plugin mw_sourceml + */ + + $base_dir = $env->path("content")."data/xml/".$env->bdd("base"); + $base_dir .= substr($base_dir, -1) != "/" ? "/" : ""; + + if(!is_dir($base_dir)){ + return "impossible de trouver le dossier de la base"; + } + + /* ---------------------------------------------------------------------- + sources devient sml_sources + elt status devient id_class + */ + + if($sgbd->data_exists("sources")){ + if(!@rename($base_dir."sources", $base_dir."sml_sources")){ + return "impossible de renommer sources en sml_sources"; + } + if(!($rst = $sgbd->open_data("sml_sources"))){ + return "impossible de lire sml_sources"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"])){ + $NEED_UPDATE = false; + if(isset($v_rst["status"])){ + $id_class = $v_rst["status"]; + unset($v_rst["status"]); + $v_rst["id_class"] = $id_class; + $NEED_UPDATE = true; + } + if(!$NEED_UPDATE) continue; + if( + !$sgbd->set_data( + "sml_sources", + $v_rst["id"], + $v_rst + ) + ){ + $erreur = "impossible de mettre a jour les informations de sml_sources"; + break; + } + } + } + else{ + $erreur = "erreur lors de lecture de sml_sources"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + } + + /* ---------------------------------------------------------------------- + source_groupes devient sml_sources_authors + elt id_groupe devient id_author + elt id_groupe_status devient id_sources_access + */ + + if($sgbd->data_exists("source_groupes")){ + if(!@rename($base_dir."source_groupes", $base_dir."sml_sources_authors")){ + return "impossible de renommer source_groupes en sml_sources_authors"; + } + if(!($rst = $sgbd->open_data("sml_sources_authors"))){ + return "impossible de lire sml_sources_authors"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"])){ + $NEED_UPDATE = false; + if(isset($v_rst["id_groupe"])){ + $id_author = $v_rst["id_groupe"]; + unset($v_rst["id_groupe"]); + $v_rst["id_author"] = $id_author; + $NEED_UPDATE = true; + } + if(isset($v_rst["id_groupe_status"])){ + $id_sources_access = $v_rst["id_groupe_status"]; + unset($v_rst["id_groupe_status"]); + $v_rst["id_sources_access"] = $id_sources_access; + $NEED_UPDATE = true; + } + if(!$NEED_UPDATE) continue; + if( + !$sgbd->set_data( + "sml_sources_authors", + $v_rst["id"], + $v_rst + ) + ){ + $erreur = "impossible de mettre a jour les informations de sml_sources_authors"; + break; + } + } + } + else{ + $erreur = "erreur lors de lecture de sml_sources_authors"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + } + + /* ---------------------------------------------------------------------- + groupe_status devient sml_sources_access + nouvel elt intitule + */ + + if($sgbd->data_exists("groupe_status")){ + if(!@rename($base_dir."groupe_status", $base_dir."sml_sources_access")){ + return "impossible de renommer groupe_status en sml_sources_access"; + } + if(!($rst = $sgbd->open_data("sml_sources_access"))){ + return "impossible de lire sml_sources_access"; + } + $erreur = ""; + while($v_rst = $sgbd->fetch_data($rst)){ + if(isset($v_rst)){ + if(isset($v_rst["id"]) && isset($v_rst["nom"]) && !isset($v_rst["intitule"])){ + $intitule = ""; + if($v_rst["nom"] == "admin") $intitule = "administrateur"; + elseif($v_rst["nom"] == "editeur") $intitule = "éditeur"; + elseif($v_rst["nom"] == "contributeur") $intitule = "contributeur"; + if( + !$sgbd->set_data( + "sml_sources_access", + $v_rst["id"], + array( + "nom" => $v_rst["nom"], + "intitule" => $intitule + ) + ) + ){ + $erreur = "impossible de mettre a jour les informations de sml_sources_access"; + break; + } + } + } + else{ + $erreur = "erreur lors de lecture de sml_sources_access"; + break; + } + } + $sgbd->close_data($rst); + if($erreur) return $erreur; + } + + /* ---------------------------------------------------------------------- + groupes devient sml_authors + */ + + if($sgbd->data_exists("groupes")){ + if(!@rename($base_dir."groupes", $base_dir."sml_authors")){ + return "impossible de renommer groupes en sml_authors"; + } + } + + /* ---------------------------------------------------------------------- + licences devient sml_licences + */ + + if($sgbd->data_exists("licences")){ + if(!@rename($base_dir."licences", $base_dir."sml_licences")){ + return "impossible de renommer licences en sml_licences"; + } + } + + /* ---------------------------------------------------------------------- + source_compositions devient sml_source_compositions + */ + + if($sgbd->data_exists("source_compositions")){ + if(!@rename($base_dir."source_compositions", $base_dir."sml_source_compositions")){ + return "impossible de renommer source_compositions en sml_source_compositions"; + } + } + + /* ---------------------------------------------------------------------- + source_derivations devient sml_source_derivations + */ + + if($sgbd->data_exists("source_derivations")){ + if(!@rename($base_dir."source_derivations", $base_dir."sml_source_derivations")){ + return "impossible de renommer source_derivations en sml_source_derivations"; + } + } + + /* ---------------------------------------------------------------------- + cache/sources devient sml_source_cache + */ + + if($sgbd->data_exists("cache/sources")){ + if(!@rename($base_dir."cache/sources", $base_dir."sml_source_cache")){ + return "impossible de renommer cache/sources en sml_source_cache"; + } + if(file_exists($base_dir."cache/.index")) @unlink($base_dir."cache/.index"); + @rmdir($base_dir."cache"); + } + + /* ---------------------------------------------------------------------- + source_status devient sml_classes + */ + + if($sgbd->data_exists("source_status")){ + if(!@rename($base_dir."source_status", $base_dir."sml_classes")){ + return "impossible de renommer source_status en sml_classes"; + } + } + + /* ---------------------------------------------------------------------- + nouvelle table sml_sources_invitations + */ + + if(!$sgbd->data_exists("sml_sources_invitations")){ + if(!$sgbd->create_data("sml_sources_invitations")){ + return "impossible de creer la table sml_sources_invitations"; + } + } + + return true; + } + + } diff --git a/app/out/default/views/sources/groupe/view.php b/app/out/default/views/sources/groupe/view.php index 180eb2a..e272710 100644 --- a/app/out/default/views/sources/groupe/view.php +++ b/app/out/default/views/sources/groupe/view.php @@ -49,7 +49,7 @@
-out["groupe"]["contact_form"]) : ?> +out["groupe"]["contact_form"]) && $this->out["groupe"]["contact_form"]) : ?>

Contact

$this->out["groupe"]["id"])) ?>">Envoyer un message à out["groupe"]["nom"]; ?>. diff --git a/app/out/default/views/sources/source/header.php b/app/out/default/views/sources/source/header.php index 31e1adf..1fbe626 100644 --- a/app/out/default/views/sources/source/header.php +++ b/app/out/default/views/sources/source/header.php @@ -29,8 +29,9 @@ $HAS_IMAGE = false; if($source["reference"]){ - if - ( $source["reference"]["image"] + if( + isset($source["reference"]["image"]) + && $source["reference"]["image"] && ($img_size = $data->img_size($source["reference"]["image"], 100, 100)) !== false ){ $HAS_IMAGE = true; -- 2.1.4