function fraap_candidatures_upgrade($nom_meta_base_version, $version_cible)
{
    $current_version = "0.0";
    if (isset($GLOBALS['meta'][$nom_meta_base_version])) {
        $current_version = $GLOBALS['meta'][$nom_meta_base_version];
    }
    if ($current_version == "0.0") {
        creer_base();
        maj_tables('spip_auteurs');
        ecrire_meta($nom_meta_base_version, $current_version = $version_cible);
    }
    // ajout d'un statut publie par defaut
    /*	if (version_compare($current_version, '0.3', '<')) {
    		include_spip('base/abstract_sql');
    		sql_alter("TABLE spip_candidatures CHANGE statut statut VARCHAR(10) DEFAULT 'publie' NOT NULL");
    		ecrire_meta($nom_meta_base_version,$current_version="0.3");
    	}
    	// ajout du statut publié pour les enregistrements déjà présents
    	if (version_compare($current_version, '0.33', '<')) {
    		include_spip('base/abstract_sql');
    		$res = sql_select("statut", "spip_candidatures");
    		while ($row = sql_fetch($res)){
    			if(isset($row['statut'])) {
    				if (!sql_updateq("spip_candidatures",array('statut'=>'publie'))) spip_log('mise à jour colonne statut rencontre un probleme','journal');
    			}
    		}
    		ecrire_meta($nom_meta_base_version,$current_version="0.33");
    	}
    */
}
Beispiel #2
0
/**
 * Cree en base les champs extras demandes
 * @param $champs : objet ChampExtra ou tableau d'objets ChampExtra
 */
function creer_champs_extras($champs) {
	if (!is_array($champs)) 
		$champs = array($champs);
		
	// on recupere juste les differentes tables a mettre a jour
	$tables = array();
	foreach ($champs as $c){ 
		if ($table = table_objet_sql($c->table)) {
			$tables[$table] = $table;
		}
	}	
		
	// on met a jour les tables trouvees
	if ($tables) {	
		// recharger les tables principales et auxiliaires
		include_spip('base/serial');
		include_spip('base/auxiliaires');
		global $tables_principales, $tables_auxiliaires;
		base_serial($tables_principales);
		base_auxiliaires($tables_auxiliaires);		
		
		// executer la mise a jour
		include_spip('base/create');
		foreach($tables as $table) {
			maj_tables($table);
		}
	}
}
Beispiel #3
0
/**
 * Upgrade de la base
 * 
 * @param string $nom_meta_base_version
 * @param string $version_cible
 */
function bank_upgrade($nom_meta_base_version, $version_cible)
{
    $current_version = 0.0;
    if (!isset($GLOBALS['meta'][$nom_meta_base_version]) || ($current_version = $GLOBALS['meta'][$nom_meta_base_version]) != $version_cible) {
        include_spip('base/abstract_sql');
        if (spip_version_compare($current_version, "0.0.0", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            creer_base();
            echo "Paiement Install<br/>";
            ecrire_meta($nom_meta_base_version, $current_version = $version_cible, 'non');
        }
        if (spip_version_compare($current_version, "0.1.3", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            maj_tables(array('spip_transactions'));
            ecrire_meta($nom_meta_base_version, $current_version = "0.1.3", 'non');
        }
        if (spip_version_compare($current_version, "0.1.5", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            sql_alter("table spip_transactions change url_retour url_retour text DEFAULT '' NOT NULL");
            ecrire_meta($nom_meta_base_version, $current_version = "0.1.5", 'non');
        }
        if (spip_version_compare($current_version, "1.0.0", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            sql_alter("table spip_transactions change transaction_hash transaction_hash bigint(21) NOT NULL DEFAULT 0");
            ecrire_meta($nom_meta_base_version, $current_version = "1.0.0", 'non');
        }
        if (spip_version_compare($current_version, "1.0.1", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            sql_alter("table spip_transactions change finie finie tinyint(1) NOT NULL DEFAULT 0");
            sql_alter("table spip_transactions change tracking_id tracking_id bigint(21) NOT NULL DEFAULT 0");
            sql_alter("table spip_transactions change id_panier id_panier bigint(21) NOT NULL DEFAULT 0");
            sql_alter("table spip_transactions change id_facture id_facture bigint(21) NOT NULL DEFAULT 0");
            ecrire_meta($nom_meta_base_version, $current_version = "1.0.1", 'non');
        }
        if (spip_version_compare($current_version, "1.1.0", "<=")) {
            include_spip('base/create');
            include_spip('base/serial');
            sql_alter("table spip_transactions ADD contenu TEXT NOT NULL DEFAULT ''");
            ecrire_meta($nom_meta_base_version, $current_version = "1.1.0", 'non');
        }
        bank_presta_install();
    }
}
function vacarme_commande_upgrade($nom_meta_base_version, $version_cible)
{
    $current_version = 0.0;
    if (!isset($GLOBALS['meta'][$nom_meta_base_version]) || ($current_version = $GLOBALS['meta'][$nom_meta_base_version]) != $version_cible) {
        include_spip('base/vacarme_commande');
        if ($current_version == 0.0) {
            creer_base();
            maj_tables(array("spip_contacts", "spip_abonnements", "spip_contacts_abonnements", "spip_paniers_liens", "spip_commandes", "spip_commandes_details"));
            ecrire_meta($nom_meta_base_version, $current_version = $version_cible, 'non');
        }
        if (version_compare($current_version, "0.2", "<")) {
            maj_tables('spip_commandes');
            ecrire_meta($nom_meta_base_version, $current_version = "0.2");
        }
        if (version_compare($current_version, "0.3", "<")) {
            creer_base();
            // ajout de spip_commandes_transactions
            ecrire_meta($nom_meta_base_version, $current_version = "0.3");
        }
    }
}
Beispiel #5
0
	function agenda_verifier_base(){
		$version_base = $GLOBALS['agenda_base_version'];
		$current_version = 0.0;
		if (   (!isset($GLOBALS['meta']['agenda_base_version']) )
				|| (($current_version = $GLOBALS['meta']['agenda_base_version'])!=$version_base)){
			include_spip('base/agenda_evenements');
			if ($current_version==0.0){
				include_spip('base/create');
				include_spip('base/abstract_sql');
				creer_base();
				maj_tables('spip_rubriques'); 
				ecrire_meta('agenda_base_version',$current_version=$version_base,'non');
			}
			if (version_compare($current_version,"0.11","<")){
				sql_alter("TABLE spip_evenements ADD `horaire` ENUM('oui','non') DEFAULT 'oui' NOT NULL AFTER `lieu`");
				ecrire_meta('agenda_base_version',$current_version=0.11,'non');
			}
			if (version_compare($current_version,"0.12","<")){
				sql_alter("TABLE spip_evenements ADD `id_article` bigint(21) DEFAULT '0' NOT NULL AFTER `id_evenement`");
				sql_alter("TABLE spip_evenements ADD INDEX ( `id_article` )");
				$res = sql_select("*", "spip_evenements_articles");
				while ($row = sql_fetch($res)){
					$id_article = $row['id_article'];
					$id_evenement = $row['id_evenement'];
					sql_update("spip_evenements", "id_article=$id_article", "id_evenement=$id_evenement");
				}
				sql_drop_table("spip_evenements_articles");
				ecrire_meta('agenda_base_version',$current_version=0.12,'non');
			}
			if (version_compare($current_version,"0.13","<")){
				include_spip('base/create');
				include_spip('base/abstract_sql');
				creer_base();
				ecrire_meta('agenda_base_version',$current_version=0.13,'non');
			}
			if (version_compare($current_version,"0.18","<")){
				include_spip('base/create');
				include_spip('base/abstract_sql');
				creer_base();
				sql_update('spip_groupes_mots',array('tables_liees'=>"concat(tables_liees,'evenements,')"),"evenements='oui'");
				sql_alter("TABLE spip_groupes_mots DROP evenements");
				ecrire_meta('agenda_base_version',$current_version=0.18,'non');
			}
			if (version_compare($current_version,"0.20","<")){
				include_spip('base/abstract_sql');
				sql_alter("TABLE spip_rubriques ADD agenda tinyint(1) DEFAULT 0 NOT NULL");
				ecrire_meta('agenda_base_version',$current_version=0.20,'non');
			}
			if (version_compare($current_version,"0.21","<")){
				include_spip('base/abstract_sql');
				sql_alter("TABLE spip_evenements ADD adresse text NOT NULL");
				sql_alter("TABLE spip_evenements ADD inscription text NOT NULL");
				sql_alter("TABLE spip_evenements ADD places text NOT NULL");
				ecrire_meta('agenda_base_version',$current_version=0.21,'non');
			}
			if (version_compare($current_version,"0.22","<")){
				include_spip('base/abstract_sql');
				include_spip('base/create');
				include_spip('base/auxiliaires');
				maj_tables('spip_evenements_participants');
				ecrire_meta('agenda_base_version',$current_version=0.22,'non');
			}
			if (version_compare($current_version,"0.23","<")){
				include_spip('base/abstract_sql');
				sql_alter("TABLE spip_evenements CHANGE titre titre text NOT NULL DEFAULT ''");
				sql_alter("TABLE spip_evenements CHANGE descriptif descriptif text NOT NULL DEFAULT ''");
				sql_alter("TABLE spip_evenements CHANGE lieu lieu text NOT NULL DEFAULT ''");
				sql_alter("TABLE spip_evenements CHANGE adresse adresse text NOT NULL DEFAULT ''");
				ecrire_meta('agenda_base_version',$current_version=0.23,'non');
			}
		}
	}
Beispiel #6
0
/**
 * Cree en base les champs extras demandes
 * @param $champs : objet ChampExtra ou tableau d'objets ChampExtra
 */
function creer_champs_extras($champs) {
	if (!$champs) {
		return;
	}
	
	if (!is_array($champs)) 
		$champs = array($champs);
				
	// on recupere juste les differentes tables a mettre a jour
	$tables = array();
	foreach ($champs as $c){ 
		if ($table = $c->_table_sql) {
			$tables[$table] = $table;
		} else {
			// ici on est bien ennuye, vu qu'on ne pourra pas creer ce champ.
			extras_log("Aucune table trouvee pour le champs extras ; il ne pourra etre cree :", true);
			extras_log($c, true);
		}
	}	

	if (!$tables) {
		return false;
	}
	
	// on met a jour les tables trouvees
	// recharger les tables principales et auxiliaires
	include_spip('base/serial');
	include_spip('base/auxiliaires');
	global $tables_principales, $tables_auxiliaires;
	base_serial($tables_principales);
	base_auxiliaires($tables_auxiliaires);
	
	// inclure les champs extras declares ALORS que le pipeline
	// n'est pas encore actif : important lorsqu'on active
	// en meme temps CE2 et un plugin dependant
	// et non l'un apres l'autre
	if (!defined('_CHAMPS_EXTRAS_DECLARES')) {
		include_spip('base/cextras');
		$tables_principales = cextras_declarer_tables_principales($tables_principales);
	}

	// executer la mise a jour
	include_spip('base/create');
	maj_tables($tables);

	// pour chaque champ a creer, on verifie qu'il existe bien maintenant !
	$trouver_table = charger_fonction('trouver_table','base');
	$trouver_table(''); // recreer la description des tables.
	$retour = true;
	foreach ($champs as $c){
		if ($objet = $c->_objet) {
			$desc = $trouver_table($objet);
			if (!isset($desc['field'][$c->champ])) {
				extras_log("Le champ extra '" . $c->champ . "' sur $objet n'a pas ete cree :(", true);
				$retour = false;
			}
		} else {
			$retour = false;
		}
	}
	return $retour;
}
Beispiel #7
0
/**
 * Exécute une réparation de la base de données
 *
 * Crée les tables et les champs manquants.
 * Applique sur les tables un REPAIR en SQL (si le serveur SQL l'accepte).
 *
 * @return string
 *     Code HTML expliquant les actions réalisées
 **/
function admin_repair_tables()
{
    $repair = sql_repair('repair', null, 'continue');
    // recreer les tables manquantes eventuelles
    include_spip('base/create');
    creer_base();
    $connexion = $GLOBALS['connexions'][0];
    $prefixe = $connexion['prefixe'];
    $rows = array();
    if ($res1 = sql_showbase()) {
        while ($r = sql_fetch($res1)) {
            $rows[] = $r;
        }
        sql_free($res1);
    }
    $res = "";
    if (count($rows)) {
        while ($r = array_shift($rows)) {
            $tab = array_shift($r);
            $class = "";
            $m = "<strong>{$tab}</strong> ";
            spip_log("Repare {$tab}", _LOG_INFO_IMPORTANTE);
            // supprimer la meta avant de lancer la reparation
            // car le repair peut etre long ; on ne veut pas boucler
            effacer_meta('admin_repair');
            if ($repair) {
                $result_repair = sql_repair($tab);
                if (!$result_repair) {
                    return false;
                }
            }
            // essayer de maj la table (creation de champs manquants)
            maj_tables($tab);
            $count = sql_countsel($tab);
            if ($count > 1) {
                $m .= "(" . _T('texte_compte_elements', array('count' => $count)) . ")\n";
            } else {
                if ($count == 1) {
                    $m .= "(" . _T('texte_compte_element', array('count' => $count)) . ")\n";
                } else {
                    $m .= "(" . _T('texte_vide') . ")\n";
                }
            }
            if ($result_repair and $msg = join(" ", (is_resource($result_repair) or is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair) . ' ' and strpos($msg, ' OK ') === false) {
                $class = " class='notice'";
                $m .= "<br /><tt>" . spip_htmlentities($msg) . "</tt>\n";
            } else {
                $m .= " " . _T('texte_table_ok');
            }
            $res .= "<div{$class}>{$m}</div>";
        }
    }
    return $res;
}
function ecatalogue_upgrade($nom_meta_base_version, $version_cible)
{
    $current_version = "0.0";
    // If plugin is already installed, get it's base version
    if (isset($GLOBALS['meta'][$nom_meta_base_version])) {
        $current_version = $GLOBALS['meta'][$nom_meta_base_version];
        //spip_log('12:14 Version actuelle : '.$current_version,'ecatalogue');
    }
    // If plugin's base version is 0.0 (it is not installed) create database
    if ($current_version == "0.0") {
        // check if you already have an old database
        $r = mysql_query("SELECT `type` FROM `spip_ecatalogue_groupes` WHERE 0");
        if ($r) {
            sql_alter("TABLE spip_ecatalogue_groupes RENAME spip_ecatalogue_proprietes");
            sql_alter("TABLE spip_ecatalogue_proprietes CHANGE id_groupe id_propriete bigint(21) NOT NULL");
            sql_alter("TABLE spip_ecatalogue_options CHANGE id_groupe id_propriete bigint(21) NOT NULL");
        }
        creer_base();
        // Write new version to sql cache.
        //$current_version became latest, therefore all next version_compare checks won't be executed
        ecrire_meta($nom_meta_base_version, $current_version = $version_cible);
        //spip_log('Base de donnйes ecatalogue correctement peuplйe','ecatalogue');
    }
    // If plugin's base version is < 0.1, alter some tables
    if (version_compare($current_version, "0.1.0", "<")) {
        // Upgrade via sql_alter
        //sql_alter("TABLE spip_ecatalogue_products ADD COLUMN id_equipment bigint(21) NOT NULL");
        // Upgrade via maj_tables (it tells SPIP to refresh some tables)
        maj_tables('spip_ecatalogue_products');
        // Write new version to sql cache
        ecrire_meta($nom_meta_base_version, $current_version = "0.1");
    }
    if (version_compare($current_version, "0.2.0", "<")) {
        //maj_tables('spip_ecatalogue_articles_similars');
        creer_base();
        maj_tables('spip_ecatalogue_products');
        ecrire_meta($nom_meta_base_version, $current_version = "0.2");
    }
    if (version_compare($current_version, "0.3.0", "<")) {
        // Create tables that wasn't created yet
        creer_base();
        ecrire_meta($nom_meta_base_version, $current_version = "0.3");
    }
    if (version_compare($current_version, "0.4.0", "<")) {
        // Create tables that wasn't created yet
        //creer_base();
        maj_tables('spip_ecatalogue_products');
        ecrire_meta($nom_meta_base_version, $current_version = "0.4");
    }
    if (version_compare($current_version, "0.5.0", "<")) {
        // Create tables that wasn't created yet
        creer_base();
        ecrire_meta($nom_meta_base_version, $current_version = "0.5");
    }
    if (version_compare($current_version, "0.6.0", "<")) {
        maj_tables('spip_ecatalogue_products');
        ecrire_meta($nom_meta_base_version, $current_version = "0.6");
    }
    if (version_compare($current_version, "0.7.0", "<")) {
        maj_tables('spip_ecatalogue_composites_articles');
        ecrire_meta($nom_meta_base_version, $current_version = "0.7");
    }
    if (version_compare($current_version, "0.9.0", "<")) {
        maj_tables('spip_ecatalogue_options');
        ecrire_meta($nom_meta_base_version, $current_version = "0.9");
    }
    if (version_compare($current_version, "0.10.0", "<")) {
        // Create tables that wasn't created yet (spip_ecatalogue_proprietes,  spip_ecatalogue_rubriques_groupes)
        creer_base();
        // Update tables
        maj_tables('spip_ecatalogue_options');
        maj_tables('spip_ecatalogue_groupes');
        ecrire_meta($nom_meta_base_version, $current_version = "0.10");
    }
    if (version_compare($current_version, "0.11.0", "<")) {
        // Create tables that wasn't created yet (spip_ecatalogue_proprietes,  spip_ecatalogue_rubriques_groupes)
        //creer_base();
        $desc = description_table('spip_rubriques');
        // Update tables
        if (!array_key_exists('id_import', $desc['field'])) {
            sql_query('Alter table spip_rubriques add column id_import int null ');
        }
        ecrire_meta($nom_meta_base_version, $current_version = "0.11");
    }
    if (version_compare($current_version, "0.12.0", "<")) {
        creer_base();
        maj_tables('ecatalogue_prices');
        maj_tables('ecatalogue_prices_group');
        // Проверка на существование 1 группы цен
        $id_group = '';
        $r1 = sql_select('id_group', 'spip_ecatalogue_prices_group', array('id_group = 1', 'is_active = 1'));
        while ($res = sql_fetch($r1)) {
            $id_group = $res[1];
        }
        if (!$id_group) {
            sql_insert('spip_ecatalogue_prices_group', '(id_group,titre,is_active)', '(1,"Розница",1)');
        }
        // Запись в таблицу spip_ecatalogue_prices цен из таблицы spip_ecatalogue_products
        $r = sql_select('id_article,price', 'spip_ecatalogue_products', 'price<>""');
        while ($res = sql_fetch($r)) {
            $id_group = 1;
            $id_article = $res['id_article'];
            $price = $res['price'];
            // Проверка что такая цена уже есть в справочнике цен в 1 группе, тогда цену обновляем
            $id_tmp_art = '';
            $r2 = sql_select('id_article', 'spip_ecatalogue_prices', array('id_article = ' . $id_article, 'id_group = 1'));
            while ($res = sql_fetch($r2)) {
                $id_tmp_art = $res['id_article'];
            }
            if ($id_tmp_art) {
                // Обновляем цену
                sql_update('spip_ecatalogue_prices', array('price' => $price), array('id_article = ' . $id_article, 'id_group = 1'));
            } else {
                // Вставляем цену
                sql_insert('spip_ecatalogue_prices', '(id_article,id_group,price)', '(' . $id_article . ',1,' . $price . ')');
            }
        }
        ecrire_meta($nom_meta_base_version, $current_version = "0.12");
    }
    include_spip('base/ecatalogue_db_populate');
}