Subversion Repositories eFlore/Projets.eflore-projets

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
478 jpm 1
<?php
2
class Version1 {
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);
38
		$this->eflore->executerScripSql($contenuSql);
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);
61
		$this->eflore->executerScripSql($contenuSql);
62
	}
63
 
64
	public function supprimerTous() {
65
		$requete = "DROP TABLE IF EXISTS coste_meta, ".
66
				"	coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
67
				"	coste_v1_00 ";
68
		$this->bdd->requeter($requete);
69
	}
70
 
71
	public function nettoyerVersion1() {
72
		$requete = "DROP TABLE IF EXISTS coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
73
				"	coste_images_correspondance_bdnff, coste_index, coste_index_general";
74
		$this->bdd->requeter($requete);
75
	}
76
 
77
	public function creerVersion1() {
78
		$this->chargerStructureSqlVersion('0.00', '0_00');
79
		$this->chargerCosteImagesAuteurCorrespondanceBdnff();
80
		$this->chargerCosteCorrespondanceBdnff();
81
	}
82
 
83
	private function chargerCosteImagesAuteurCorrespondanceBdnff() {
84
		$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_auteur_correspondance_bdnff.tsv';
85
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
86
				"REPLACE INTO TABLE coste_images_auteur_correspondance_bdnff ".
87
				'CHARACTER SET utf8 '.
88
				'FIELDS '.
89
				"	TERMINATED BY '\t' ".
90
				"	ENCLOSED BY '\"' ".
91
				"	ESCAPED BY '\\\' ".
92
				'IGNORE 1 LINES ';
93
		$this->bdd->requeter($requete);
94
	}
95
 
96
	private function chargerCosteCorrespondanceBdnff() {
97
		$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_correspondance_bdnff.tsv';
98
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
99
				"REPLACE INTO TABLE coste_images_correspondance_bdnff ".
100
				'CHARACTER SET utf8 '.
101
				'FIELDS '.
102
				"	TERMINATED BY '\t' ".
103
				"	ENCLOSED BY '' ".
104
				"	ESCAPED BY '\\\' ".
105
				'IGNORE 1 LINES ';
106
		$this->bdd->requeter($requete);
107
	}
108
}
109
?>