45 public $errors = array();
76 public $table_element =
"c_price_global_variable_updater";
96 public function create($user, $notrigger = 0)
103 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
104 $sql .=
"type, description, parameters, fk_variable, update_interval, next_update, last_status";
105 $sql .=
") VALUES (";
106 $sql .=
" ".((int) $this->
type).
",";
108 $sql .=
" ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
109 $sql .=
" ".((int) $this->fk_variable).
",";
110 $sql .=
" ".((int) $this->update_interval).
",";
111 $sql .=
" ".((int) $this->next_update).
",";
112 $sql .=
" ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
118 $resql = $this->db->query($sql);
120 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
124 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
139 foreach ($this->errors as $errmsg) {
141 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
143 $this->db->rollback();
160 $sql =
"SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status";
161 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
162 $sql .=
" WHERE rowid = ".((int) $id);
165 $resql = $this->db->query($sql);
167 $obj = $this->db->fetch_object($resql);
170 $this->
type = $obj->type;
172 $this->parameters = $obj->parameters;
173 $this->fk_variable = $obj->fk_variable;
174 $this->update_interval = $obj->update_interval;
175 $this->next_update = $obj->next_update;
176 $this->last_status = $obj->last_status;
183 $this->error =
"Error ".$this->db->lasterror();
195 public function update($user = 0, $notrigger = 0)
202 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
203 $sql .=
" type = ".((int) $this->
type).
",";
204 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
205 $sql .=
" parameters = ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
206 $sql .=
" fk_variable = ".((int) $this->fk_variable).
",";
207 $sql .=
" update_interval = ".((int) $this->update_interval).
",";
208 $sql .=
" next_update = ".((int) $this->next_update).
",";
209 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
210 $sql .=
" WHERE rowid = ".((int) $this->
id);
215 $resql = $this->db->query($sql);
217 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
236 foreach ($this->errors as $errmsg) {
237 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
238 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
240 $this->db->rollback();
256 public function delete($rowid, $user, $notrigger = 0)
277 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
278 $sql .=
" WHERE rowid = ".((int) $rowid);
281 $resql = $this->db->query($sql);
283 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
289 foreach ($this->errors as $errmsg) {
291 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
293 $this->db->rollback();
312 $this->parameters =
'';
313 $this->fk_variable = 0;
314 $this->update_interval = 0;
315 $this->next_update = 0;
316 $this->last_status =
'';
327 $last = $this->next_update - ($this->update_interval * 60);
329 return $langs->trans(
"Never");
331 $status = empty($this->last_status) ? $langs->trans(
"CorrectlyUpdated") : $this->last_status;
346 if (isset($this->parameters)) {
347 $this->parameters = trim($this->parameters);
349 $this->parameters =
"";
351 if (isset($this->last_status)) {
352 $this->last_status = trim($this->last_status);
356 if (empty($this->
type) || !is_numeric($this->
type) || !in_array($this->
type, $this->types)) {
359 if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) {
362 if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) {
363 $this->next_update = 0;
374 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
375 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
378 $resql = $this->db->query($sql);
382 while ($record = $this->db->fetch_array($resql)) {
384 $updater_obj->id = $record[
"rowid"];
385 $updater_obj->type = $record[
"type"];
386 $updater_obj->description = $record[
"description"];
387 $updater_obj->parameters = $record[
"parameters"];
388 $updater_obj->fk_variable = $record[
"fk_variable"];
389 $updater_obj->update_interval = $record[
"update_interval"];
390 $updater_obj->next_update = $record[
"next_update"];
391 $updater_obj->last_status = $record[
"last_status"];
392 $updater_obj->checkParameters();
393 $retarray[] = $updater_obj;
396 $this->db->free($resql);
399 $this->error = $this->db->error();
411 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
412 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
413 $sql .=
" WHERE next_update < ".dol_now();
416 $resql = $this->db->query($sql);
420 while ($record = $this->db->fetch_array($resql)) {
422 $updater_obj->id = $record[
"rowid"];
423 $updater_obj->type = $record[
"type"];
424 $updater_obj->description = $record[
"description"];
425 $updater_obj->parameters = $record[
"parameters"];
426 $updater_obj->fk_variable = $record[
"fk_variable"];
427 $updater_obj->update_interval = $record[
"update_interval"];
428 $updater_obj->next_update = $record[
"next_update"];
429 $updater_obj->last_status = $record[
"last_status"];
430 $updater_obj->checkParameters();
431 $retarray[] = $updater_obj;
434 $this->db->free($resql);
437 $this->error = $this->db->error();
449 global $langs, $user;
450 $langs->load(
"errors");
457 if ($this->fk_variable < 1) {
458 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
462 $res = $price_globals->fetch($this->fk_variable);
464 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
469 if ($this->
type == 0 || $this->
type == 1) {
471 $parameters = json_decode($this->parameters,
true);
472 if (!isset($parameters)) {
473 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater1", $this->parameters);
476 $url = $parameters[
'URL'];
478 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'URL');
481 $value = $parameters[
'VALUE'];
482 if (!isset($value)) {
483 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'VALUE');
487 if ($this->
type == 0) {
489 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
490 $tmpresult =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
491 $code = $tmpresult[
'http_code'];
492 $result = $tmpresult[
'content'];
494 if (!isset($result)) {
495 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0",
"empty response");
499 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0", $code.
' '.$tmpresult[
'curl_error_msg']);
504 $result = json_decode($result,
true);
505 } elseif ($this->
type == 1) {
506 $ns = $parameters[
'NS'];
508 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'NS');
511 $method = $parameters[
'METHOD'];
512 if (!isset($method)) {
513 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'METHOD');
516 $data = $parameters[
'DATA'];
518 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'DATA');
523 require_once NUSOAP_PATH.
'/nusoap.php';
524 $soap_client =
new nusoap_client($url);
525 $soap_client->soap_defencoding =
'UTF-8';
526 $soap_client->decodeUTF8(
false);
527 $result = $soap_client->call($method, $data, $ns,
'');
530 if ($result ===
false) {
531 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater4", $soap_client->error_str);
537 $value = explode(
',', $value);
538 foreach ($value as $key) {
539 $result = $result[$key];
541 if (!isset($result)) {
542 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater3");
547 $price_globals->value = $result;
548 $price_globals->update($user);
571 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
572 $sql .=
" next_update = ".$this->next_update;
573 $sql .=
" WHERE rowid = ".((int) $this->
id);
578 $resql = $this->db->query($sql);
580 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
585 foreach ($this->errors as $errmsg) {
587 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
589 $this->db->rollback();
611 $this->last_status = $last_status;
615 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
616 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
617 $sql .=
" WHERE rowid = ".((int) $this->
id);
622 $resql = $this->db->query($sql);
624 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
629 foreach ($this->errors as $errmsg) {
631 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
633 $this->db->rollback();
Class for accesing price global variables table.
Class for price global variable updaters table.
__construct($db)
Constructor.
$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_interval
Interval in mins.
update_status($last_status, $user=0, $notrigger=0)
Update last_status into database.
$next_update
Next update timestamp.
update($user=0, $notrigger=0)
Update object into database.
update_next_update($next_update, $user=0, $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.
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='', $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