47 public $errors = array();
86 public $update_interval;
99 public $table_element =
"c_price_global_variable_updater";
119 public function create($user, $notrigger = 0)
126 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
127 $sql .=
"type, description, parameters, fk_variable, update_interval, next_update, last_status";
128 $sql .=
") VALUES (";
129 $sql .=
" ".((int) $this->
type).
",";
131 $sql .=
" ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
132 $sql .=
" ".((int) $this->fk_variable).
",";
133 $sql .=
" ".((int) $this->update_interval).
",";
134 $sql .=
" ".((int) $this->next_update).
",";
135 $sql .=
" ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
141 $resql = $this->db->query($sql);
144 $this->errors[] =
"Error ".$this->db->lasterror();
148 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
156 //$result=$this->call_trigger('MYOBJECT_CREATE',$user);
157 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
165 foreach ($this->errors as $errmsg) {
167 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
169 $this->db->rollback();
186 $sql =
"SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status";
187 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
188 $sql .=
" WHERE rowid = ".((int) $id);
191 $resql = $this->db->query($sql);
193 $obj = $this->db->fetch_object($resql);
196 $this->
type = $obj->type;
198 $this->parameters = $obj->parameters;
199 $this->fk_variable = $obj->fk_variable;
200 $this->update_interval = $obj->update_interval;
201 $this->next_update = $obj->next_update;
202 $this->last_status = $obj->last_status;
209 $this->error =
"Error ".$this->db->lasterror();
221 public function update($user =
null, $notrigger = 0)
228 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
229 $sql .=
" type = ".((int) $this->
type).
",";
230 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
231 $sql .=
" parameters = ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
232 $sql .=
" fk_variable = ".((int) $this->fk_variable).
",";
233 $sql .=
" update_interval = ".((int) $this->update_interval).
",";
234 $sql .=
" next_update = ".((int) $this->next_update).
",";
235 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
236 $sql .=
" WHERE rowid = ".((int) $this->
id);
241 $resql = $this->db->query($sql);
244 $this->errors[] =
"Error ".$this->db->lasterror();
263 foreach ($this->errors as $errmsg) {
264 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
265 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
267 $this->db->rollback();
283 public function delete($rowid, $user, $notrigger = 0)
304 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
305 $sql .=
" WHERE rowid = ".((int) $rowid);
308 $resql = $this->db->query($sql);
311 $this->errors[] =
"Error ".$this->db->lasterror();
317 foreach ($this->errors as $errmsg) {
319 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
321 $this->db->rollback();
340 $this->parameters =
'';
341 $this->fk_variable = 0;
342 $this->update_interval = 0;
343 $this->next_update = 0;
344 $this->last_status =
'';
357 $last = $this->next_update - ($this->update_interval * 60);
359 return $langs->trans(
"Never");
361 $status = empty($this->last_status) ? $langs->trans(
"CorrectlyUpdated") : $this->last_status;
376 if (isset($this->parameters)) {
377 $this->parameters = trim($this->parameters);
379 $this->parameters =
"";
381 if (isset($this->last_status)) {
382 $this->last_status = trim($this->last_status);
386 if (empty($this->
type) || !is_numeric($this->
type) || !in_array($this->
type, $this->types)) {
389 if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) {
392 if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) {
393 $this->next_update = 0;
404 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
405 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
408 $resql = $this->db->query($sql);
412 while ($record = $this->db->fetch_array($resql)) {
414 $updater_obj->id = $record[
"rowid"];
415 $updater_obj->type = $record[
"type"];
416 $updater_obj->description = $record[
"description"];
417 $updater_obj->parameters = $record[
"parameters"];
418 $updater_obj->fk_variable = $record[
"fk_variable"];
419 $updater_obj->update_interval = $record[
"update_interval"];
420 $updater_obj->next_update = $record[
"next_update"];
421 $updater_obj->last_status = $record[
"last_status"];
422 $updater_obj->checkParameters();
423 $retarray[] = $updater_obj;
426 $this->db->free($resql);
429 $this->error = $this->db->error();
441 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
442 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
443 $sql .=
" WHERE next_update < ".dol_now();
446 $resql = $this->db->query($sql);
450 while ($record = $this->db->fetch_array($resql)) {
452 $updater_obj->id = $record[
"rowid"];
453 $updater_obj->type = $record[
"type"];
454 $updater_obj->description = $record[
"description"];
455 $updater_obj->parameters = $record[
"parameters"];
456 $updater_obj->fk_variable = $record[
"fk_variable"];
457 $updater_obj->update_interval = $record[
"update_interval"];
458 $updater_obj->next_update = $record[
"next_update"];
459 $updater_obj->last_status = $record[
"last_status"];
460 $updater_obj->checkParameters();
461 $retarray[] = $updater_obj;
464 $this->db->free($resql);
467 $this->error = $this->db->error();
479 global $langs, $user;
480 $langs->load(
"errors");
487 if ($this->fk_variable < 1) {
488 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
492 $res = $price_globals->fetch($this->fk_variable);
494 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
499 if ($this->
type == 0 || $this->
type == 1) {
501 $parameters = json_decode($this->parameters,
true);
502 if (!isset($parameters)) {
503 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater1", $this->parameters);
506 $url = $parameters[
'URL'];
508 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'URL');
511 $value = $parameters[
'VALUE'];
512 if (!isset($value)) {
513 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'VALUE');
517 if ($this->
type == 0) {
519 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
520 $tmpresult =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
521 $code = $tmpresult[
'http_code'];
522 $result = $tmpresult[
'content'];
524 if (!isset($result)) {
525 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0",
"empty response");
529 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0", $code.
' '.$tmpresult[
'curl_error_msg']);
534 $result = json_decode($result,
true);
535 } elseif ($this->
type == 1) {
536 $ns = $parameters[
'NS'];
538 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'NS');
541 $method = $parameters[
'METHOD'];
542 if (!isset($method)) {
543 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'METHOD');
546 $data = $parameters[
'DATA'];
548 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'DATA');
553 require_once NUSOAP_PATH.
'/nusoap.php';
554 $soap_client =
new nusoap_client($url);
555 $soap_client->soap_defencoding =
'UTF-8';
556 $soap_client->decodeUTF8(
false);
557 $result = $soap_client->call($method, $data, $ns,
'');
560 if ($result ===
false) {
561 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater4", $soap_client->error_str);
567 $value = explode(
',', $value);
568 foreach ($value as $key) {
569 $result = $result[$key];
571 if (!isset($result)) {
572 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater3");
577 $price_globals->value = $result;
578 $price_globals->update($user);
597 $this->next_update = $next_update;
601 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
602 $sql .=
" next_update = ".((int) $this->next_update);
603 $sql .=
" WHERE rowid = ".((int) $this->
id);
608 $resql = $this->db->query($sql);
611 $this->errors[] =
"Error ".$this->db->lasterror();
616 foreach ($this->errors as $errmsg) {
618 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
620 $this->db->rollback();
642 $this->last_status = $last_status;
646 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
647 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
648 $sql .=
" WHERE rowid = ".((int) $this->
id);
653 $resql = $this->db->query($sql);
656 $this->errors[] =
"Error ".$this->db->lasterror();
661 foreach ($this->errors as $errmsg) {
663 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
665 $this->db->rollback();
Class for accessing price global variables table.
Class for price global variable updaters table.
__construct($db)
Constructor.
update_status($last_status, $user=null, $notrigger=0)
Update last_status into database.
$update_min
Minimal update rate.
getLastUpdated()
Returns the last updated time in string html format, returns "never" if its less than 1.
checkParameters()
Checks if all parameters are in order.
update_next_update($next_update, $user=null, $notrigger=0)
Update next_update into database.
listUpdaters()
List all price global variables.
listPendingUpdaters()
List all updaters which need to be processed.
process()
Handles the processing of this updater.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
update($user=null, $notrigger=0)
Update object into database.
create($user, $notrigger=0)
Create object into database.
fetch($id)
Load object in memory from the database.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type