/[openfoncier]/branches/3.14.x/app/update_da.php
ViewVC logotype

Contents of /branches/3.14.x/app/update_da.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3343 - (show annotations)
Thu Mar 19 17:34:18 2015 UTC (9 years, 10 months ago) by vpihour
File size: 4942 byte(s)
Ajout de la branche

1 <?php
2 /**
3 * Ce script permet de mettre à jour l'ensemble des DA en fonction de leurs DI
4 *
5 * @package openfoncier
6 * @version SVN : $Id$
7 */
8 ini_set('max_execution_time', 86400);
9 $time_start = microtime(true);
10 //
11 require_once "../obj/utils.class.php";
12 $f = new utils("nohtml", null, _("Calcul des dossiers d'autorisation en base"));
13 ob_start();
14 // Initialisation session cURL
15 $curl = curl_init();
16 $url = 'http://localhost/openads/services/maintenance';
17 // Url de la page à récupérer
18 curl_setopt($curl, CURLOPT_URL, $url);
19 // Permet de récupérer le résultat au lieu de l'afficher
20 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
21 // Démarrer un nouveau cookie de session
22 curl_setopt($curl, CURLOPT_COOKIESESSION, true);
23
24 curl_setopt($curl, CURLOPT_POST, true);
25
26 $postfields = array(
27 'module' => 'maj_dt_reprise',
28 'data' => 0,
29 );
30
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
62 $ret = explode("|", $return->message);
63 $data.=$ret[1];
64
65 $count_dt += $ret[0];
66 echo "<br/>". str_replace("'", "DA sans DT : ",str_replace("', ","<br/>",$ret[1]));
67
68 echo $count_dt."/".$res_dt."<br/>";
69 gc_collect_cycles();
70 $time_end = microtime(true);
71 $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
134 $ret = explode("|", $return->message);
135 $count_da = $count_da + $ret[0];
136 echo "<br/>".$ret[1];
137 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();
149 gc_disable();
150
151 ?>

Properties

Name Value
svn:keywords Id

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26