Example #1
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);
		}
	}
}
Example #2
0
/**
 * Lister les infos de toutes les tables sql declarées
 * 
 * Si un argument est fourni, on ne renvoie que les infos de cette table.
 * Elle est auto-declarée si inconnue jusqu'alors.
 *
 * @api
 * @param string $table_sql
 *   table_sql demandee explicitement
 * @param array $desc
 *   description connue de la table sql demandee
 * @return array|bool
 */
function lister_tables_objets_sql($table_sql = null, $desc = array())
{
    static $deja_la = false;
    static $infos_tables = null;
    static $md5 = null;
    static $plugin_hash = null;
    // prealablement recuperer les tables_principales
    if (is_null($infos_tables) or $plugin_hash !== _PLUGINS_HASH) {
        // pas de reentrance (cas base/serial)
        if ($deja_la) {
            spip_log("Re-entrance anormale sur lister_tables_objets_sql :" . var_export(debug_backtrace(), true), _LOG_CRITIQUE);
            return $table_sql === "::md5" ? $md5 : array();
        }
        $deja_la = true;
        $plugin_hash = _PLUGINS_HASH;
        // avant de lancer les pipelines
        // recuperer les declarations explicites ancienne mode
        // qui servent a completer declarer_tables_objets_sql
        base_serial($GLOBALS['tables_principales']);
        base_auxiliaires($GLOBALS['tables_auxiliaires']);
        $infos_tables = array('spip_articles' => array('page' => 'article', 'texte_retour' => 'icone_retour_article', 'texte_modifier' => 'icone_modifier_article', 'texte_creer' => 'icone_ecrire_article', 'texte_objets' => 'public:articles', 'texte_objet' => 'public:article', 'texte_signale_edition' => 'texte_travail_article', 'info_aucun_objet' => 'info_aucun_article', 'info_1_objet' => 'info_1_article', 'info_nb_objets' => 'info_nb_articles', 'texte_logo_objet' => 'logo_article', 'texte_langue_objet' => 'titre_langue_article', 'titre' => 'titre, lang', 'date' => 'date', 'principale' => 'oui', 'champs_editables' => array('surtitre', 'titre', 'soustitre', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps', 'virtuel'), 'champs_versionnes' => array('id_rubrique', 'surtitre', 'titre', 'soustitre', 'jointure_auteurs', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps'), 'field' => array("id_article" => "bigint(21) NOT NULL", "surtitre" => "text DEFAULT '' NOT NULL", "titre" => "text DEFAULT '' NOT NULL", "soustitre" => "text DEFAULT '' NOT NULL", "id_rubrique" => "bigint(21) DEFAULT '0' NOT NULL", "descriptif" => "text DEFAULT '' NOT NULL", "chapo" => "mediumtext DEFAULT '' NOT NULL", "texte" => "longtext DEFAULT '' NOT NULL", "ps" => "mediumtext DEFAULT '' NOT NULL", "date" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "statut" => "varchar(10) DEFAULT '0' NOT NULL", "id_secteur" => "bigint(21) DEFAULT '0' NOT NULL", "maj" => "TIMESTAMP", "export" => "VARCHAR(10) DEFAULT 'oui'", "date_redac" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "visites" => "integer DEFAULT '0' NOT NULL", "referers" => "integer DEFAULT '0' NOT NULL", "popularite" => "DOUBLE DEFAULT '0' NOT NULL", "accepter_forum" => "CHAR(3) DEFAULT '' NOT NULL", "date_modif" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "lang" => "VARCHAR(10) DEFAULT '' NOT NULL", "langue_choisie" => "VARCHAR(3) DEFAULT 'non'", "id_trad" => "bigint(21) DEFAULT '0' NOT NULL", "nom_site" => "tinytext DEFAULT '' NOT NULL", "url_site" => "VARCHAR(255) DEFAULT '' NOT NULL", "virtuel" => "VARCHAR(255) DEFAULT '' NOT NULL"), 'key' => array("PRIMARY KEY" => "id_article", "KEY id_rubrique" => "id_rubrique", "KEY id_secteur" => "id_secteur", "KEY id_trad" => "id_trad", "KEY lang" => "lang", "KEY statut" => "statut, date"), 'join' => array("id_article" => "id_article", "id_rubrique" => "id_rubrique"), 'rechercher_champs' => array('surtitre' => 5, 'titre' => 8, 'soustitre' => 5, 'chapo' => 3, 'texte' => 1, 'ps' => 1, 'nom_site' => 1, 'url_site' => 1, 'descriptif' => 4), 'rechercher_jointures' => array('auteur' => array('nom' => 10)), 'statut' => array(array('champ' => 'statut', 'publie' => 'publie', 'previsu' => 'publie,prop,prepa', 'post_date' => 'date', 'exception' => 'statut')), 'statut_titres' => array('prepa' => 'info_article_redaction', 'prop' => 'info_article_propose', 'publie' => 'info_article_publie', 'refuse' => 'info_article_refuse', 'poubelle' => 'info_article_supprime'), 'statut_textes_instituer' => array('prepa' => 'texte_statut_en_cours_redaction', 'prop' => 'texte_statut_propose_evaluation', 'publie' => 'texte_statut_publie', 'refuse' => 'texte_statut_refuse', 'poubelle' => 'texte_statut_poubelle'), 'texte_changer_statut' => 'texte_article_statut', 'aide_changer_statut' => 'artstatut', 'tables_jointures' => array('profondeur' => 'rubriques')), 'spip_auteurs' => array('page' => 'auteur', 'texte_retour' => 'icone_retour', 'texte_ajouter' => 'titre_ajouter_un_auteur', 'texte_modifier' => 'admin_modifier_auteur', 'texte_objets' => 'icone_auteurs', 'texte_objet' => 'public:auteur', 'info_aucun_objet' => 'info_aucun_auteur', 'info_1_objet' => 'info_1_auteur', 'info_nb_objets' => 'info_nb_auteurs', 'texte_logo_objet' => 'logo_auteur', 'texte_creer_associer' => 'creer_et_associer_un_auteur', 'titre' => "nom AS titre, '' AS lang", 'date' => 'date', 'principale' => 'oui', 'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'), 'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'), 'field' => array("id_auteur" => "bigint(21) NOT NULL", "nom" => "text DEFAULT '' NOT NULL", "bio" => "text DEFAULT '' NOT NULL", "email" => "tinytext DEFAULT '' NOT NULL", "nom_site" => "tinytext DEFAULT '' NOT NULL", "url_site" => "text DEFAULT '' NOT NULL", "login" => "VARCHAR(255) BINARY", "pass" => "tinytext DEFAULT '' NOT NULL", "low_sec" => "tinytext DEFAULT '' NOT NULL", "statut" => "varchar(255)  DEFAULT '0' NOT NULL", "webmestre" => "varchar(3)  DEFAULT 'non' NOT NULL", "maj" => "TIMESTAMP", "pgp" => "TEXT DEFAULT '' NOT NULL", "htpass" => "tinytext DEFAULT '' NOT NULL", "en_ligne" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "alea_actuel" => "tinytext", "alea_futur" => "tinytext", "prefs" => "tinytext", "cookie_oubli" => "tinytext", "source" => "VARCHAR(10) DEFAULT 'spip' NOT NULL", "lang" => "VARCHAR(10) DEFAULT '' NOT NULL"), 'key' => array("PRIMARY KEY" => "id_auteur", "KEY login" => "login", "KEY statut" => "statut", "KEY en_ligne" => "en_ligne"), 'join' => array("id_auteur" => "id_auteur", "login" => "login"), 'rechercher_champs' => array('nom' => 5, 'bio' => 1, 'email' => 1, 'nom_site' => 1, 'url_site' => 1, 'login' => 1), 'statut' => array(array('champ' => 'statut', 'publie' => '!5poubelle', 'previsu' => '!5poubelle', 'exception' => 'statut'), array('champ' => array(array('spip_auteurs_liens', 'id_auteur'), array('spip_articles', array('id_objet', 'id_article', 'objet', 'article')), 'statut'), 'publie' => 'publie', 'previsu' => '!', 'post_date' => 'date', 'exception' => array('statut', 'lien', 'tout'))), 'statut_images' => array('auteur-6forum-16.png', '0minirezo' => 'auteur-0minirezo-16.png', '1comite' => 'auteur-1comite-16.png', '6forum' => 'auteur-6forum-16.png', '5poubelle' => 'auteur-5poubelle-16.png', 'nouveau' => ''), 'statut_titres' => array('titre_image_visiteur', '0minirezo' => 'titre_image_administrateur', '1comite' => 'titre_image_redacteur_02', '6forum' => 'titre_image_visiteur', '5poubelle' => 'titre_image_auteur_supprime'), 'tables_jointures' => array()), 'spip_rubriques' => array('page' => 'rubrique', 'url_voir' => 'rubrique', 'url_edit' => 'rubrique_edit', 'texte_retour' => 'icone_retour', 'texte_objets' => 'public:rubriques', 'texte_objet' => 'public:rubrique', 'texte_modifier' => 'icone_modifier_rubrique', 'texte_creer' => 'icone_creer_rubrique', 'texte_ajouter' => 'titre_ajouter_une_rubrique', 'texte_creer_associer' => 'creer_et_associer_une_rubrique', 'info_aucun_objet' => 'info_aucun_rubrique', 'info_1_objet' => 'info_1_rubrique', 'info_nb_objets' => 'info_nb_rubriques', 'texte_logo_objet' => 'logo_rubrique', 'texte_langue_objet' => 'titre_langue_rubrique', 'titre' => 'titre, lang', 'date' => 'date', 'principale' => 'oui', 'champs_editables' => array('titre', 'texte', 'descriptif', 'extra'), 'champs_versionnes' => array('titre', 'descriptif', 'texte'), 'field' => array("id_rubrique" => "bigint(21) NOT NULL", "id_parent" => "bigint(21) DEFAULT '0' NOT NULL", "titre" => "text DEFAULT '' NOT NULL", "descriptif" => "text DEFAULT '' NOT NULL", "texte" => "longtext DEFAULT '' NOT NULL", "id_secteur" => "bigint(21) DEFAULT '0' NOT NULL", "maj" => "TIMESTAMP", "statut" => "varchar(10) DEFAULT '0' NOT NULL", "date" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "lang" => "VARCHAR(10) DEFAULT '' NOT NULL", "langue_choisie" => "VARCHAR(3) DEFAULT 'non'", "statut_tmp" => "varchar(10) DEFAULT '0' NOT NULL", "date_tmp" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", "profondeur" => "smallint(5) DEFAULT '0' NOT NULL"), 'key' => array("PRIMARY KEY" => "id_rubrique", "KEY lang" => "lang", "KEY id_parent" => "id_parent"), 'rechercher_champs' => array('titre' => 8, 'descriptif' => 5, 'texte' => 1), 'statut' => array(array('champ' => 'statut', 'publie' => 'publie', 'previsu' => '!', 'exception' => array('statut', 'tout'))), 'tables_jointures' => array()), array('tables_jointures' => array('id_auteur' => 'auteurs_liens')));
        // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
        // initialiser la signature
        $md5 = md5(serialize($infos_tables));
        $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
        $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
        $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
        // completer les informations manquantes ou implicites
        $all = array();
        foreach (array_keys($infos_tables) as $t) {
            // les cles numeriques servent a declarer
            // les proprietes applicables a tous les objets
            // on les mets de cote
            if (is_numeric($t)) {
                $all = array_merge_recursive($all, $infos_tables[$t]);
                unset($infos_tables[$t]);
            } else {
                $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
            }
        }
        // repercuter les proprietes generales communes a tous les objets
        foreach (array_keys($infos_tables) as $t) {
            foreach ($all as $i => $v) {
                if (in_array($i, array('tables_jointures', 'champs_versionnes'))) {
                    $add = $all[$i];
                    // eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
                    // pour les declarations generiques avec cles numeriques
                    if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) {
                        $doublons = array_intersect($infos_tables[$t][$i], $add);
                        foreach ($doublons as $d) {
                            if (is_numeric(array_search($d, $infos_tables[$t][$i])) and is_numeric($k = array_search($d, $add))) {
                                unset($add[$k]);
                            }
                        }
                    }
                    $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add);
                } else {
                    $infos_tables[$t][$i] = array_merge_recursive(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $all[$i]);
                }
            }
        }
        // completer les tables principales et auxiliaires
        // avec celles declarees uniquement dans declarer_table_objets_sql
        // pour assurer la compat en transition
        foreach ($infos_tables as $table => $infos) {
            $principale_ou_auxiliaire = $infos['principale'] ? 'tables_principales' : 'tables_auxiliaires';
            // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
            // qui a ete appelle avant
            $mem = isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array();
            // l'ajouter au tableau
            $GLOBALS[$principale_ou_auxiliaire][$table] = array();
            if (isset($infos['field']) and isset($infos['key'])) {
                foreach (array('field', 'key', 'join') as $k) {
                    if (isset($infos_tables[$table][$k])) {
                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] =& $infos_tables[$table][$k];
                    }
                }
            } else {
                // ici on ne renvoie que les declarations, donc RIEN
                // pour avoir la vrai description en base, il faut passer par trouver_table
                $GLOBALS[$principale_ou_auxiliaire][$table] = array();
            }
            if (count($mem)) {
                foreach (array_keys($mem) as $k) {
                    if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge($GLOBALS[$principale_ou_auxiliaire][$table][$k], $mem[$k]);
                    } else {
                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
                    }
                }
            }
        }
        // recuperer les interfaces (table_titre, table_date)
        // on ne le fait que dans un second temps pour que table_objet soit fonctionnel
        // dans le pipeline de declarer_tables_interfaces
        include_spip('public/interfaces');
        foreach (array_keys($infos_tables) as $t) {
            $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
        }
        $deja_la = false;
        // signature
        $md5 = md5(serialize($infos_tables));
    }
    if ($table_sql === "::md5") {
        return $md5;
    }
    if ($table_sql and !isset($infos_tables[$table_sql])) {
        #$desc = renseigner_table_objet_sql($table_sql,$desc);
        $desc = renseigner_table_objet_interfaces($table_sql, $desc);
        return $desc;
    }
    if ($table_sql) {
        return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array();
    }
    return $infos_tables;
}
Example #3
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;
}
Example #4
0
function import_tables($request, $archive) {
	global $import_ok, $abs_pos,  $affiche_progression_pourcent;

	// regarder si on est pas en train d'importer dans une copie des tables
	if (isset($GLOBALS['meta']['restauration_table_prefix'])) {
		$charger = charger_fonction('charger','maj/vieille_base');
		$charger($GLOBALS['meta']['vieille_version_installee']);
		$GLOBALS['serveur_vieille_base'] = 0;
		$prefix = $GLOBALS['connexions'][$GLOBALS['serveur_vieille_base']]['prefixe'];
		$GLOBALS['connexions'][$GLOBALS['serveur_vieille_base']]['prefixe'] = $GLOBALS['meta']['restauration_table_prefix'];
		// verifier qu'une table meta existe bien
		// sinon c'est une restauration anterieure echouee
		if (!sql_getfetsel('valeur','spip_meta','','','','0,1')){
				$GLOBALS['connexions'][$GLOBALS['serveur_vieille_base']]['prefixe'] = $prefix;
				return;
		}
		// recharger les metas
		lire_metas();
	}

	$abs_pos = (!isset($GLOBALS['meta']["restauration_status"])) ? 0 :
		$GLOBALS['meta']["restauration_status"];

	// au premier appel destruction des tables a restaurer
	// ou initialisation de la table des translations,
	// mais pas lors d'une reprise.

	if ($request['insertion']=='on') {
		include_spip('inc/import_insere');
		$request['init'] = (!$abs_pos) ? 'insere_1_init' : 'insere_1bis_init';
		$request['boucle'] = 'import_insere';
	} elseif ($request['insertion']=='passe2') {
		$request['init'] = 'insere_2_init';
		$request['boucle'] = 'import_translate';
	} else {
		$request['init'] = (!$abs_pos) ? 'import_init_tables' : 'import_table_choix';
		$request['boucle'] = 'import_replace';
	}

	if (strncmp(".gz", substr($archive,-3),3)==0) {
			$size = false;
			$taille = taille_en_octets($abs_pos);
			$file = gzopen($archive, 'rb');
			$gz = 'gzread';
	} else {
			$size = @filesize($archive);
			$taille = @floor(100 * $abs_pos / $size)." %";
			$file = fopen($archive, 'rb');
			$gz = 'fread';
	}

	
	if ($abs_pos==0) {
		list($tag, $atts, $charset) = import_debut($file, $gz);
		// improbable: fichier correct avant debut_admin et plus apres
		if (!$tag) return !($import_ok = true);
		$version_archive = import_init_meta($tag, $atts, $charset, $request);
	} else {
		$version_archive = $GLOBALS['meta']['restauration_version_archive'];
		$atts = unserialize($GLOBALS['meta']['restauration_attributs_archive']);
		spip_log("Reprise de l'importation interrompue en $abs_pos");
		$_fseek = ($gz=='gzread') ? 'gzseek' : 'fseek';
		$_fseek($file, $abs_pos);
	}
	
	// placer la connexion sql dans le bon charset

	if (isset($GLOBALS['meta']['restauration_charset_sql_connexion']))
		sql_set_charset($GLOBALS['meta']['restauration_charset_sql_connexion']);

	if (!defined('_DEBUG_IMPORT')) define('_DEBUG_IMPORT', false);
	if (_DEBUG_IMPORT)
		ecrire_fichier(_DIR_TMP."debug_import.log","#####".date('Y-m-d H:i:s')."\n",false,false);
	$fimport = import_charge_version($version_archive);

	if ($request['insertion'] !== 'passe2')
		import_affiche_javascript($taille);

	if (function_exists('ob_flush')) @ob_flush();
	flush();
	$oldtable ='';
	$cpt = 0;
	$pos = $abs_pos;

	// BOUCLE principale qui tourne en rond jusqu'a le fin du fichier
	while ($table = $fimport($file, $request, $gz, $atts)) {
	  // memoriser pour pouvoir reprendre en cas d'interrupt,
	  // mais pas d'ecriture sur fichier, ca ralentit trop
		ecrire_meta("restauration_status", "$abs_pos",'non');
		if ($oldtable != $table) {
			if (_DEBUG_IMPORT){
				ecrire_fichier(_DIR_TMP."debug_import.log","----\n".$GLOBALS['debug_import_avant']."\n<<<<\n$table\n>>>>\n".$GLOBALS['debug_import_apres']."\n----\n",false,false);
			}
			if ($oldtable) spip_log("$cpt entrees","import");
			spip_log("Analyse de $table (commence en $pos)","import");
			affiche_progression_javascript($abs_pos,$size,$table);
			$oldtable = $table;
			$cpt = 0;
			$pos = $abs_pos;
		}
		$cpt++;
	}
	spip_log("$cpt entrees","import");
	spip_log("fin de l'archive, statut: " .($import_ok ? 'ok' : 'alert'),"import");

	if (!$import_ok) 
	  return  _T('avis_archive_invalide') . ' ' .
	    _T('taille_octets', array('taille' => $pos)) ;

	if ($GLOBALS['spip_version_base'] != (str_replace(',','.',$GLOBALS['meta']['version_installee']))){
		// il FAUT recharger les bonnes desc serial/aux avant ...
		include_spip('base/serial');
		$GLOBALS['tables_principales']=array();
		base_serial($GLOBALS['tables_principales']);
		include_spip('base/auxiliaires');
		$GLOBALS['tables_auxiliaires']=array();
		base_auxiliaires($GLOBALS['tables_auxiliaires']);
		$GLOBALS['tables_jointures']=array();
		include_spip('public/interfaces');
		declarer_interfaces();
		include_spip('base/upgrade');
		maj_base(); // upgrade jusqu'a la version courante
	}
	// regarder si on est pas en train d'importer dans une copie des tables
	if (isset($GLOBALS['meta']['restauration_table_prefix_source'])){
		$prefixe_source = $GLOBALS['meta']['restauration_table_prefix_source'];
		
		$GLOBALS['connexions']['-1'] = $GLOBALS['connexions'][0];
		// rebasculer le serveur sur les bonnes tables pour finir proprement
		$GLOBALS['connexions'][0]['prefixe'] = $prefixe_source;
		// et relire les meta de la bonne base
		lire_metas();


		$tables_recopiees = isset($GLOBALS['meta']['restauration_recopie_tables'])?unserialize($GLOBALS['meta']['restauration_recopie_tables']):array();
		spip_log("charge tables_recopiees ".serialize($tables_recopiees),'dbdump');

		// recopier les tables l'une sur l'autre
		// il FAUT recharger les bonnes desc serial/aux avant ...
		include_spip('base/serial');
		$GLOBALS['tables_principales']=array();
		base_serial($GLOBALS['tables_principales']);
		include_spip('base/auxiliaires');
		$GLOBALS['tables_auxiliaires']=array();
		base_auxiliaires($GLOBALS['tables_auxiliaires']);
		$GLOBALS['tables_jointures']=array();
		include_spip('public/interfaces');
		declarer_interfaces();
		
		// puis relister les tables a importer
		// et les vider si besoin, au moment du premier passage ici
		// (et seulement si ce n'est pas une fusion, comment le dit-on ?)
		$initialisation_copie = (!isset($GLOBALS['meta']["restauration_status_copie"])) ? 0 :
			$GLOBALS['meta']["restauration_status_copie"];

		if (!$initialisation_copie) {
			// vide les tables qui le necessitent
			$tables = import_init_tables($request);
			ecrire_meta("restauration_status_copie", "ok",'non');
		}
		else
			// la liste des tables a recopier
			$tables = import_table_choix($request);
		#		var_dump($tables);die();
		spip_log("tables a copier :".implode(", ",$tables),'dbdump');
		if (in_array('spip_auteurs',$tables)){
			$tables = array_diff($tables,array('spip_auteurs'));
			$tables[] = 'spip_auteurs';
		}
		if (in_array('spip_meta',$tables)){
			$tables = array_diff($tables,array('spip_meta'));
			$tables[] = 'spip_meta';
		}
		sql_drop_table('spip_test','','-1');
		foreach ($tables as $table){
			if (sql_showtable($table,true,-1)){
				if (!isset($tables_recopiees[$table])) $tables_recopiees[$table] = 0;
				if ($tables_recopiees[$table]!==-1){
					affiche_progression_javascript(0,0,$table);
					while (true) {
						$n = intval($tables_recopiees[$table]);
						$res = sql_select('*',$table,'','','',"$n,400",'','-1');
						while ($row = sql_fetch($res,'-1')){
							array_walk($row,'sql_quote');
							sql_replace($table,$row);
							$tables_recopiees[$table]++;
						}
						if ($n == $tables_recopiees[$table])
							break;
						spip_log("recopie $table ".$tables_recopiees[$table],'dbdump');
						affiche_progression_javascript($tables_recopiees[$table],0,$table);
						ecrire_meta('restauration_recopie_tables',serialize($tables_recopiees));
					}
					sql_drop_table($table,'','-1');
					spip_log("drop $table",'dbdump');
					$tables_recopiees[$table]=-1;
					ecrire_meta('restauration_recopie_tables',serialize($tables_recopiees));
					spip_log("tables_recopiees ".serialize($tables_recopiees),'dbdump');
				}
			}
		}
	}

	// recharger les metas
	lire_metas();
	#die();
	return '' ;
}
Example #5
0
$tables_principales['spip_breves']   =
	array('field' => &$spip_breves, 'key' => &$spip_breves_key,'join' => &$spip_breves_join);
$tables_principales['spip_messages'] =
	array('field' => &$spip_messages, 'key' => &$spip_messages_key);
$tables_principales['spip_mots']     =
	array('field' => &$spip_mots, 'key' => &$spip_mots_key);
$tables_principales['spip_groupes_mots'] =
	array('field' => &$spip_groupes_mots, 'key' => &$spip_groupes_mots_key);
$tables_principales['spip_rubriques'] =
	array('field' => &$spip_rubriques, 'key' => &$spip_rubriques_key);
$tables_principales['spip_documents'] =
	array('field' => &$spip_documents,  'key' => &$spip_documents_key, 'join' => &$spip_documents_join);
$tables_principales['spip_types_documents']	=
	array('field' => &$spip_types_documents, 'key' => &$spip_types_documents_key);
$tables_principales['spip_syndic'] =
	array('field' => &$spip_syndic, 'key' => &$spip_syndic_key, 'join' => &$spip_syndic_join);
$tables_principales['spip_syndic_articles']	=
	array('field' => &$spip_syndic_articles, 'key' => &$spip_syndic_articles_key, 'join' => &$spip_syndic_articles_join);
$tables_principales['spip_forum'] =
	array('field' => &$spip_forum,	'key' => &$spip_forum_key, 'join' => &$spip_forum_join);
$tables_principales['spip_signatures'] =
	array('field' => &$spip_signatures, 'key' => &$spip_signatures_key, 'join' => &$spip_signatures_join);
	
	$tables_principales = pipeline('declarer_tables_principales',$tables_principales);
}

global $tables_principales;
base_serial($tables_principales);

?>