5 |
* @package openfoncier |
* @package openfoncier |
6 |
* @version SVN : $Id$ |
* @version SVN : $Id$ |
7 |
*/ |
*/ |
8 |
|
ini_set('max_execution_time', 86400); |
9 |
$time_start = microtime(true); |
$time_start = microtime(true); |
|
ob_start(); |
|
10 |
// |
// |
11 |
require_once "../obj/utils.class.php"; |
require_once "../obj/utils.class.php"; |
12 |
$f = new utils("nohtml", null, _("Calcul des dossiers d'autorisation en base")); |
$f = new utils("nohtml", null, _("Calcul des dossiers d'autorisation en base")); |
13 |
$f->db->autoCommit(false); |
ob_start(); |
14 |
$sql_da = "SELECT dossier_autorisation FROM ".DB_PREFIXE."dossier_autorisation"; |
// Initialisation session cURL |
15 |
$res_da = $f->db->query($sql_da); |
$curl = curl_init(); |
16 |
$f->addToLog("app/update_DA.php: db->query(\"".$sql_da."\");", VERBOSE_MODE); |
$url = 'http://localhost/openads/services/maintenance'; |
17 |
$f->isDatabaseError($res_da); |
// Url de la page à récupérer |
18 |
$count_da = 0; |
curl_setopt($curl, CURLOPT_URL, $url); |
19 |
$fp = fopen("err_update_da.csv", "w"); |
// Permet de récupérer le résultat au lieu de l'afficher |
20 |
require_once "../obj/dossier_autorisation.class.php"; |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
21 |
while($da_id = $res_da->fetchrow(DB_FETCHMODE_ASSOC)) { |
// Démarrer un nouveau cookie de session |
22 |
if(!preg_match('/^\w{2}013055\d{7}/', $da_id["dossier_autorisation"])) { |
curl_setopt($curl, CURLOPT_COOKIESESSION, true); |
23 |
echo "Format : ".$da_id["dossier_autorisation"]."<br/>"; |
|
24 |
fputcsv( |
curl_setopt($curl, CURLOPT_POST, true); |
25 |
$fp, |
|
26 |
array( |
$postfields = array( |
27 |
$da_id["dossier_autorisation"], |
'module' => 'maj_dt_reprise', |
28 |
'Format id', |
'data' => 0, |
29 |
'dossier no', |
); |
30 |
$da_id["dossier_autorisation"] |
|
31 |
), |
$sql_dt = "SELECT count(dossier) FROM ".DB_PREFIXE."dossier |
32 |
";" |
LEFT OUTER JOIN ".DB_PREFIXE."donnees_techniques ON dossier.dossier=donnees_techniques.dossier_instruction |
33 |
); |
WHERE donnees_techniques.donnees_techniques IS NULL"; |
34 |
|
$res_dt = $f->db->getone($sql_dt); |
35 |
|
$f->addToLog("app/update_DA.php: db->getone(\"".$sql_dt."\");", DEBUG_MODE); |
36 |
|
if($f->isDatabaseError($res_dt)){ |
37 |
|
$f->addToLog("app/update_DA.php: db->query(\"".$sql_dt."\");", DEBUG_MODE); |
38 |
|
die(); |
39 |
|
} |
40 |
|
$round = round($res_dt/1000)+1; |
41 |
|
$count_dt = 0; |
42 |
|
$data = "''"; |
43 |
|
gc_enable(); |
44 |
|
for($i=0; $i<= $round; $i++) { |
45 |
|
|
46 |
|
ob_start(); |
47 |
|
$postfields['data']=$data; |
48 |
|
$post = http_build_query($postfields); |
49 |
|
|
50 |
|
// Données passées en POST |
51 |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); |
52 |
|
|
53 |
|
// Retour de la session cURL |
54 |
|
$return = curl_exec($curl); |
55 |
|
// Decode du json et crée un objet |
56 |
|
$return = json_decode($return); |
57 |
|
|
58 |
|
if($return->http_code != 200) { |
59 |
|
echo $return->message."<br/>"; |
60 |
} |
} |
61 |
// echo $da_id["dossier_autorisation"]."<br/>"; |
|
62 |
$da = new dossier_autorisation($da_id["dossier_autorisation"], $f->db, false); |
$ret = explode("|", $return->message); |
63 |
if($da->majDossierAutorisation($fp) !== true) { |
$data.=$ret[1]; |
64 |
|
|
65 |
fputcsv( |
$count_dt += $ret[0]; |
66 |
$fp, |
echo "<br/>". str_replace("'", "DA sans DT : ",str_replace("', ","<br/>",$ret[1])); |
67 |
array( |
|
68 |
$da_id["dossier_autorisation"], |
echo $count_dt."/".$res_dt."<br/>"; |
69 |
'Format id', |
gc_collect_cycles(); |
70 |
'dossier no', |
$time_end = microtime(true); |
71 |
$da_id["dossier_autorisation"] |
$time = round($time_end - $time_start, 2); |
72 |
), |
echo $time." "._("secondes")."<br/>"; |
73 |
";" |
echo round(memory_get_usage()/1024)." ko<br/>"; |
74 |
|
$content = ob_get_clean(); |
75 |
|
file_put_contents('../tmp/update_da.log', str_replace("<br/>", "\n", $content), FILE_APPEND); |
76 |
|
|
77 |
|
} |
78 |
|
|
79 |
|
curl_close($curl); |
80 |
|
echo "Fin création DT manquantes<br/>"; |
81 |
|
|
82 |
|
$content = ob_get_clean(); |
83 |
|
file_put_contents('../tmp/update_da.log', str_replace("<br/>", "\n", $content), FILE_APPEND); |
84 |
|
ob_start(); |
85 |
|
$sql_date_depot = "UPDATE ".DB_PREFIXE."dossier_autorisation as da SET date_depot = d.date_depot |
86 |
|
FROM ".DB_PREFIXE."dossier as d WHERE da.dossier_autorisation=d.dossier_autorisation AND d.version=0"; |
87 |
|
$res_date_depot = $f->db->query($sql_date_depot); |
88 |
|
$f->addToLog("app/update_DA.php: db->query(\"".$sql_date_depot."\");", DEBUG_MODE); |
89 |
|
$f->isDatabaseError($res_date_depot); |
90 |
|
echo "Update date dépôt initiale<br/>"; |
91 |
|
$content = ob_get_clean(); |
92 |
|
file_put_contents('../tmp/update_da.log', str_replace("<br/>", "\n", $content), FILE_APPEND); |
93 |
|
// Initialisation session cURL |
94 |
|
$curl = curl_init(); |
95 |
|
$url = 'http://localhost/openads/services/maintenance'; |
96 |
|
// Url de la page à récupérer |
97 |
|
curl_setopt($curl, CURLOPT_URL, $url); |
98 |
|
// Permet de récupérer le résultat au lieu de l'afficher |
99 |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
100 |
|
// Démarrer un nouveau cookie de session |
101 |
|
curl_setopt($curl, CURLOPT_COOKIESESSION, true); |
102 |
|
|
103 |
|
curl_setopt($curl, CURLOPT_POST, true); |
104 |
|
|
105 |
|
$postfields = array( |
106 |
|
'module' => 'maj_da_reprise', |
107 |
|
'data' => array('offset' => 0), |
108 |
); |
); |
109 |
|
|
110 |
|
|
111 |
|
$sql_da = "SELECT count(*) FROM ".DB_PREFIXE."dossier_autorisation"; |
112 |
|
$res_da = $f->db->getone($sql_da); |
113 |
|
$f->addToLog("app/update_DA.php: db->query(\"".$sql_da."\");", DEBUG_MODE); |
114 |
|
$f->isDatabaseError($res_da); |
115 |
|
$round = round($res_da/1000)+1; |
116 |
|
$count_da = 0; |
117 |
|
gc_enable(); |
118 |
|
for($i=0; $i<= $round; $i++) { |
119 |
|
ob_start(); |
120 |
|
$postfields['data']['offset']=$i*1000; |
121 |
|
$post = http_build_query($postfields); |
122 |
|
// Données passées en POST |
123 |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); |
124 |
|
|
125 |
|
// Retour de la session cURL |
126 |
|
$return = curl_exec($curl); |
127 |
|
// Decode du json et crée un objet |
128 |
|
$return = json_decode($return); |
129 |
|
|
130 |
|
if($return->http_code != 200) { |
131 |
|
echo $return->message."<br/>"; |
132 |
} |
} |
133 |
if($count_da == 1) { |
|
134 |
$f->db->commit(); |
$ret = explode("|", $return->message); |
135 |
$f->db->autoCommit(false); |
$count_da = $count_da + $ret[0]; |
136 |
} |
echo "<br/>".$ret[1]; |
137 |
$count_da++; |
echo $count_da."/".$res_da."<br/>"; |
138 |
|
gc_collect_cycles(); |
139 |
|
$time_end = microtime(true); |
140 |
|
$time = round($time_end - $time_start, 2); |
141 |
|
echo $time." "._("secondes")."<br/>"; |
142 |
|
echo round(memory_get_usage()/1024)." ko<br/>"; |
143 |
|
$content = ob_get_clean(); |
144 |
|
file_put_contents('../tmp/update_da.log', str_replace("<br/>", "\n", $content), FILE_APPEND); |
145 |
} |
} |
146 |
|
|
147 |
|
curl_close($curl); |
148 |
$f->db->commit(); |
$f->db->commit(); |
149 |
$time_end = microtime(true); |
gc_disable(); |
|
$time = round($time_end - $time_start,2); |
|
|
echo $count_da." "._("dossier(s) traité(s) en")." ".$time." "._("secondes")."<br/>"; |
|
|
$content = ob_get_clean(); |
|
|
echo $content; |
|
|
file_put_contents('update_da.log', str_replace("<br/>","\n",$content)); |
|
|
fclose($fp); |
|
150 |
|
|
151 |
?> |
?> |