Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 676 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
478 jpm 1
<?php
479 jpm 2
class Versions {
478 jpm 3
 
4
	private $conteneur = null;
5
	private $eflore = null;
6
	private $bdd = null;
7
 
8
	public function __construct(Conteneur $conteneur) {
9
		$this->conteneur = $conteneur;
10
		$this->eflore = $conteneur->getEfloreCommun();
11
		$this->bdd = $conteneur->getBdd();
12
	}
13
 
14
	public function chargerTous() {
15
		$this->chargerStructureSql();
16
		$this->chargerVersions();
17
	}
18
 
19
	public function chargerStructureSql() {
20
		$this->eflore->chargerStructureSql();
21
	}
22
 
23
	public function chargerVersions() {
24
		$versions = explode(',', Config::get('versions'));
25
		$versionsDonnees = explode(',', Config::get('versionsDonnees'));
26
		foreach ($versions as $id => $version) {
27
			$versionDonnees = $versionsDonnees[$id];
28
			$this->chargerStructureSqlVersion($versionDonnees, $version);
29
			$this->chargerIndexVersion($versionDonnees, $version);
30
			$this->chargerDumpWikiniVersion($versionDonnees, $version);
31
		}
32
	}
33
 
34
	private function chargerStructureSqlVersion($versionDonnees, $version) {
35
		$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
36
		$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $version);
37
		$contenuSql = $this->eflore->recupererContenu($fichierSql);
676 jpm 38
		$this->eflore->executerScriptSql($contenuSql);
478 jpm 39
	}
40
 
41
	private function chargerIndexVersion($versionDonnees, $version) {
42
		$fichierTsvTpl = Config::get('chemins.costeTpl');
43
		$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $version);
44
		$tableTpl = Config::get('tables.costeTpl');
45
		$table = sprintf($tableTpl, $version);
46
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
47
				"REPLACE INTO TABLE $table ".
48
				'CHARACTER SET utf8 '.
49
				'FIELDS '.
50
				"	TERMINATED BY '\t' ".
51
				"	ENCLOSED BY '' ".
52
				"	ESCAPED BY '\\\' ".
53
				'IGNORE 1 LINES ';
54
		$this->bdd->requeter($requete);
55
	}
56
 
57
	private function chargerDumpWikiniVersion($versionDonnees, $version) {
58
		$fichierWikiTpl = Config::get('chemins.costeWikiniTpl');
59
		$fichierDump = sprintf($fichierWikiTpl, $versionDonnees, $version);
60
		$contenuSql = $this->eflore->recupererContenu($fichierDump);
683 jpm 61
		$this->eflore->executerScriptSql($contenuSql);
478 jpm 62
	}
63
 
64
	public function supprimerTous() {
65
		$requete = "DROP TABLE IF EXISTS coste_meta, ".
484 jpm 66
				"	coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
67
				"	coste_images_correspondance_bdnff, coste_index, coste_index_general, ".
478 jpm 68
				"	coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
479 jpm 69
				"	coste_v1_00, coste_v2_00 ";
478 jpm 70
		$this->bdd->requeter($requete);
71
	}
72
}
73
?>