unserialize_task_params(); if (isset($tparameters)) { if (is_array($tparameters)) { foreach ($tparameters as $aparameters=>$aparametersv) { if (is_array($aparametersv)) { foreach ($aparametersv as $sparameters=>$sparametersv) { global ${$sparameters}; ${$sparameters} = $sparametersv; } } else { global ${$aparameters}; ${$aparameters} = $aparametersv; } } } } $this->id_source = $source_entrepot; if ($this->id_source) { $this->listen_commande(array(&$this,"traite_commande")); if($this->statut == WAITING) { $this->send_command(RUNNING); } if ($this->statut == RUNNING) { $rqt = "select id_connector, name from connectors_sources where source_id=".$this->id_source; $res = pmb_mysql_query($rqt); $path = pmb_mysql_result($res,0,"id_connector"); $name = pmb_mysql_result($res,0,"name"); for ($i=0; $iid_connector = $item["ID"]; $result = array(); $this->add_section_report($this->msg["report_sync"]." : ".$name); if (method_exists($this->proxy, "pmbesSync_doSync")) { if($form_radio == "all_notices") { $date_start = ''; $date_end = ''; } else if($form_radio == 'last_sync') { $date_start = $this->get_sync_last_date(); if($date_start && (isset($sync_empty) && $sync_empty) && !empty($sync_last_date)){ $date_start = $sync_last_date; } $date_end = ''; } else { $date_start = $form_from; $date_end = $form_until; } if(isset($sync_empty) && $sync_empty) { if (method_exists($this->proxy, "pmbesSync_emptySource")) { if($this->proxy->pmbesSync_emptySource($this->id_connector, $this->id_source)) { $this->add_content_report($this->msg['planificateur_sync_empty_success']); } else { $this->add_content_report($this->msg['planificateur_sync_empty_failed']); } } else { $this->add_function_rights_report("emptySource","pmbesSync"); } } $result[] = $this->proxy->pmbesSync_doSync($this->id_connector, $this->id_source, $auto_import, $this->id_tache, array(&$this, "listen_commande"), array(&$this, "traite_commande"), $auto_delete, $not_in_notices_externes, $date_start, $date_end); $this->update_param_sync_last_date(); if ($result) { foreach ($result as $lignes) { foreach ($lignes as $ligne) { if ($ligne != '') { $this->add_content_report($ligne); } } } } $this->update_progression(100); } else { $this->add_function_rights_report("doSync","pmbesSync"); } } } } } } else { $this->add_section_report($this->msg["report_sync"]." : ".$this->msg["report_sync_false"]); $this->add_content_report($this->msg["error_parameters"]); } } else { $this->add_rights_bad_user_report(); } } public function traite_commande($cmd,$message = '') { global $msg; switch ($cmd) { case STOP: $this->add_content_report($this->msg["planificateur_stop_sync"]); break; case ABORT: $requete="delete from source_sync where source_id=".$this->id_source; pmb_mysql_query($requete); $this->add_content_report($this->msg["planificateur_abort_sync"]); break; case FAIL : $requete="delete from source_sync where source_id=".$this->id_source; pmb_mysql_query($requete); $this->add_content_report($this->msg["planificateur_timeout_overtake"]); break; } parent::traite_commande($cmd, $message); } protected function get_sync_last_date() { $requete="select max(date_import) as sync_last_date from entrepot_source_".$this->id_source; $resultat=pmb_mysql_query($requete); if($resultat) { $sync_last_date = pmb_mysql_result($resultat, 0, 'sync_last_date'); if(!empty($sync_last_date)) { return substr($sync_last_date, 0, 10); } } return ''; } protected function update_param_sync_last_date() { $query = "select id_planificateur, param from planificateur, taches where id_planificateur=num_planificateur and id_tache=".$this->id_tache; $result = pmb_mysql_query($query); if($result && pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $params = unserialize($row->param); $params['sync_last_date'] = $this->get_sync_last_date(); pmb_mysql_query("UPDATE planificateur SET param = '".addslashes(serialize($params))."' WHERE id_planificateur = ".$row->id_planificateur); } } }