|
@@ -35,6 +35,14 @@ const P_TABLE_ID2 = [
|
|
|
'product_shop' => 'id_product',
|
|
|
];
|
|
|
|
|
|
+// Overloaded in each src/sync/model_name/common.inc.php
|
|
|
+//const MODEL_NAME;
|
|
|
+//const MODEL_ID;
|
|
|
+//const MAP_ID;
|
|
|
+//const D_TABLE_MAIN;
|
|
|
+//const P_TABLE_MAIN;
|
|
|
+//const P_TABLE_MAIN_ID;
|
|
|
+
|
|
|
// Général
|
|
|
const P_ID_LANG = 1;
|
|
|
const P_ID_SHOP = 1;
|
|
@@ -157,26 +165,14 @@ public static function _class($type, $sens)
|
|
|
try {
|
|
|
require_once(SYNC_PATH.'/'.$type.'/common.inc.php');
|
|
|
} catch(Throwable $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error("Could not load common sync class for type ".$type, $e);
|
|
|
- } catch(Exception $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error("Could not load common sync class for type ".$type, $e);
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($type, $sens)", "Could not load common sync class for type ".$type, NULL, $e);
|
|
|
}
|
|
|
|
|
|
// Load specific direction model class
|
|
|
try {
|
|
|
require_once(SYNC_PATH.'/'.$type.'/'.$sens.'.inc.php');
|
|
|
} catch(Throwable $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error("Could not load controller sync class for type ".$type.', sens '.$sens, $e);
|
|
|
- } catch(Exception $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error("Could not load controller sync class for type ".$type.', sens '.$sens, $e);
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($type, $sens)", "Could not load controller sync class for type ".$type.', sens '.$sens, NULL, $e);
|
|
|
}
|
|
|
|
|
|
return $classname = 'sync_'.$type.'_'.$sens;
|
|
@@ -192,13 +188,8 @@ public static function _action($type, $sens, $action, $otype, $oid)
|
|
|
$method = 'execute_'.$action;
|
|
|
$r = $controller->$method($otype, $oid);
|
|
|
} catch(Throwable $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error('Error executing controller '.$classname.'::'.$method.'('.$otype.','.$oid.')', $e);
|
|
|
- } catch(Exception $e) {
|
|
|
- if (DEBUG_AFF)
|
|
|
- var_dump($e);
|
|
|
- sync_error('Error executing controller '.$classname.'::'.$method.'('.$otype.','.$oid.')', $e);
|
|
|
+ $context = ['type'=>$type, 'sens'=>$sens, 'action'=>$action, 'otype'=>$otype, 'oid'=>$oid];
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($type, $sens, $action, $otype, $oid)", 'Error executing controller '.$classname.'::'.$method.'('.$otype.','.$oid.')', $context, $e);
|
|
|
}
|
|
|
|
|
|
if (!empty($r))
|
|
@@ -405,13 +396,13 @@ public static function _pd_map_fk($modelname, $tablename, $id)
|
|
|
|
|
|
// -- NOTIF Sync TS --
|
|
|
|
|
|
-public static function _notif_ts($type, $otype, $oid, $result=NULL)
|
|
|
+public static function _notif_ts($sens, $otype, $oid, $result=NULL)
|
|
|
{
|
|
|
$sql = 'UPDATE `_sync`
|
|
|
SET `sync_ts`=NOW(), `sync_result`='.($result==NULL ?'NULL' :'"'.$result.'"').'
|
|
|
WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$otype.'" AND `t_oid`="'.$oid.'" AND `action` IN ("create", "osync")
|
|
|
AND `sync_ts` IS NULL';
|
|
|
- return ($type=='p' ?DB::p_update($sql) :DB::d_update($sql));
|
|
|
+ return ($sens=='p' ?DB::p_update($sql) :DB::d_update($sql));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -463,26 +454,25 @@ public function pd_create($otype, $oid)
|
|
|
'p_tref'=>$otype,
|
|
|
'p_oid'=>$oid,
|
|
|
];
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'pd', 'action'=>'create', 'otype'=>$otype, 'oid'=>$oid];
|
|
|
|
|
|
// Récupère données source
|
|
|
$p_data = $this->p_data($otype, $oid);
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($p_data);
|
|
|
if (empty($p_data[$otype])) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : Source data does not exists");
|
|
|
- static::_notif_ts('p', $otype, $oid, 'nodata');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Construit nouvel objet
|
|
|
$d_data_map = $d_data_map_create = $this->pd_map_create($o, $p_data);
|
|
|
if (is_null($d_data_map)) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : map_create() : NULL");
|
|
|
- static::_notif_ts('p', $otype, $oid, 'nodatamap');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "map_create() : NULL", $context, NULL, 'nodatamap');
|
|
|
return;
|
|
|
}
|
|
|
elseif (empty($d_data_map)) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : map_create() : empty");
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "map_create() : empty", $context, NULL, 'nodatamap');
|
|
|
return;
|
|
|
}
|
|
|
$d_data_map_update = $this->pd_map_update($o, $p_data);
|
|
@@ -494,8 +484,15 @@ public function pd_create($otype, $oid)
|
|
|
echo '<p>CREATION OBJETS</p>';
|
|
|
|
|
|
// insert main row
|
|
|
- if (!($id = DB::d_insert_row($o['d_tref'], $d_data_map[$o['d_tref']]))) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : DB::d_insert_row : ".json_encode($d_data_map[$o['d_tref']]));
|
|
|
+ try {
|
|
|
+ $id = DB::d_insert_row($o['d_tref'], $d_data_map[$o['d_tref']]);
|
|
|
+ } catch(Throwable $e) {
|
|
|
+ if (DEBUG_AFF)
|
|
|
+ var_dump($e);
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "DB::d_insert_row() : ".json_encode($d_data_map[$o['d_tref']]), $context, $e);
|
|
|
+ }
|
|
|
+ if (empty($id)) {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "DB::d_insert_row() NO ID : ".json_encode($d_data_map[$o['d_tref']]), $context, NULL, 'db');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -503,7 +500,7 @@ public function pd_create($otype, $oid)
|
|
|
$o['d_oid'] = $id;
|
|
|
if (!($this->o_create($o))) {
|
|
|
// @todo : delete useless inserted data
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : o_create()");
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "o_create() returns false", $context, NULL, 'object');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -534,6 +531,8 @@ public function dp_create($otype, $oid)
|
|
|
'd_tref'=>$otype,
|
|
|
'd_oid'=>$oid,
|
|
|
];
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'dp', 'action'=>'create', 'otype'=>$otype, 'oid'=>$oid];
|
|
|
+
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($o);
|
|
|
|
|
@@ -542,21 +541,18 @@ public function dp_create($otype, $oid)
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($d_data);
|
|
|
if (empty($d_data[$otype])) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : Source data does not exists");
|
|
|
- static::_notif_ts('d', $otype, $oid, 'nodata');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Construit nouvel objet
|
|
|
$p_data_map = $p_data_map_create = $this->dp_map_create($o, $d_data);
|
|
|
if (is_null($p_data_map)) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : map_create() : NULL");
|
|
|
- static::_notif_ts('d', $otype, $oid, 'nodatamap');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "map_create() : NULL", $context, NULL, 'nodatamap');
|
|
|
return;
|
|
|
}
|
|
|
elseif (empty($p_data_map)) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : map_create() : empty");
|
|
|
- //static::_notif_ts('d', $otype, $oid, 'nodatamap');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "map_create() : empty", $context, NULL, 'nodatamap');
|
|
|
return;
|
|
|
}
|
|
|
$p_data_map_update = $this->dp_map_update($o, $d_data);
|
|
@@ -569,9 +565,17 @@ public function dp_create($otype, $oid)
|
|
|
if (DEBUG_AFF)
|
|
|
echo '<p>CREATION OBJETS</p>';
|
|
|
|
|
|
- // insert main row
|
|
|
- if (!($id = DB::p_insert_row($o['p_tref'], $p_data_map[$o['p_tref']]))) {
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : DB::d_insert_row() : ".json_encode($d_data_map[$o['p_tref']]));
|
|
|
+ try {
|
|
|
+ // insert main row
|
|
|
+ $id = DB::p_insert_row($o['p_tref'], $p_data_map[$o['p_tref']]);
|
|
|
+ } catch(Throwable $e) {
|
|
|
+ if (DEBUG_AFF)
|
|
|
+ var_dump($e);
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "DB::p_insert_row() : ".$o['p_tref']." -> ".json_encode($p_data_map[$o['p_tref']]), $context, $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isset($db) || empty($id)) {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "DB::p_insert_row() NO ID : ".$o['p_tref']." -> ".json_encode($p_data_map[$o['p_tref']]), $context, NULL, 'db');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -579,7 +583,7 @@ public function dp_create($otype, $oid)
|
|
|
$o['p_oid'] = $id;
|
|
|
if (!($this->o_create($o))) {
|
|
|
// @todo : delete useless inserted data
|
|
|
- sync_error("ERROR ".__METHOD__."($otype, $oid) : o_create()");
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "o_create() returns false", $context, NULL, 'object');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -608,14 +612,14 @@ public function pd_osync($o)
|
|
|
{
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($o);
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'pd', 'action'=>'osync', 'otype'=>$o['p_tref'], 'oid'=>$o['p_oid']];
|
|
|
|
|
|
// Récupère données source
|
|
|
$p_data = $this->p_data($o['p_tref'], $o['p_oid']);
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($p_data);
|
|
|
if (empty($p_data[$o['p_tref']])) {
|
|
|
- sync_error("ERROR ".__METHOD__."($o[p_tref], $o[p_oid]) : Source data does not exists");
|
|
|
- static::_notif_ts('p', $o['p_tref'], $o['p_oid'], 'nodata');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($o[p_tref], $o[p_oid])", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -635,7 +639,13 @@ public function pd_osync($o)
|
|
|
$d_data_map_create = $this->pd_map_create($o, $p_data);
|
|
|
|
|
|
// Update base
|
|
|
- static::d_update_row($o['d_tref'], ['rowid'=>$o['d_oid']], $d_data_map, $d_data_map_create, $d_data);
|
|
|
+ try {
|
|
|
+ static::d_update_row($o['d_tref'], ['rowid'=>$o['d_oid']], $d_data_map, $d_data_map_create, $d_data);
|
|
|
+ } catch(Throwable $e) {
|
|
|
+ if (DEBUG_AFF)
|
|
|
+ var_dump($e);
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."(".json_encode($o).")", "d_update_row() : ".json_encode($d_data_map), $context, $e);
|
|
|
+ }
|
|
|
|
|
|
// Update more
|
|
|
$this->pd_update_more($o, $d_data_map, $d_data_map_create, $d_data, $p_data);
|
|
@@ -657,14 +667,14 @@ public function dp_osync($o)
|
|
|
{
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($o);
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'dp', 'action'=>'osync', 'otype'=>$o['d_tref'], 'oid'=>$o['d_oid']];
|
|
|
|
|
|
// Récupère données source
|
|
|
$d_data = $this->d_data($o['d_tref'], $o['d_oid']);
|
|
|
if (DEBUG_AFF)
|
|
|
var_dump($d_data);
|
|
|
if (empty($d_data[static::D_TABLE_MAIN])) {
|
|
|
- sync_error("ERROR ".__METHOD__."($o[d_tref], $o[d_oid]) : Source data does not exists");
|
|
|
- static::_notif_ts('d', $o['d_tref'], $o['d_oid'], 'nodata');
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($o[d_tref], $o[d_oid])", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -714,26 +724,44 @@ public function dp_map_update(&$o, &$d_data, &$p_data=[])
|
|
|
public function pd_delete($otype, $oid)
|
|
|
{
|
|
|
$o = static::p_o_oid(static::MODEL_NAME, $otype, $oid);
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'pd', 'action'=>'delete', 'otype'=>$otype, 'oid'=>$oid];
|
|
|
if (!empty($o)) {
|
|
|
- DB::d_delete_row($o['d_tref'], ['rowid'=>$o['d_oid']]);
|
|
|
- //DB::p_delete_row($o['p_tref']], [static::P_TABLE_ID[$o['p_tref']]]=>$o['p_oid']]);
|
|
|
- $sql = 'DELETE FROM _objects WHERE id='.$o['id'];
|
|
|
- DB::o_delete($sql);
|
|
|
- return true;
|
|
|
+ if ($r=DB::d_delete_row($o['d_tref'], ['rowid'=>$o['d_oid']])) {
|
|
|
+ //DB::p_delete_row($o['p_tref']], [static::P_TABLE_ID[$o['p_tref']]]=>$o['p_oid']]);
|
|
|
+ $sql = 'DELETE FROM _objects WHERE id='.$o['id'];
|
|
|
+ DB::o_delete($sql);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data link does not exists", $context, NULL, 'nodata');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function dp_delete($otype, $oid)
|
|
|
{
|
|
|
$o = static::d_o_oid(static::MODEL_NAME, $otype, $oid);
|
|
|
+ $context = ['type'=>static::MODEL_NAME, 'sens'=>'dp', 'action'=>'delete', 'otype'=>$otype, 'oid'=>$oid];
|
|
|
if (!empty($o)) {
|
|
|
- if (empty(static::P_TABLE_ID[$o['p_tref']]))
|
|
|
+ if (empty(static::P_TABLE_ID[$o['p_tref']])) {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "No PK for table ".$o['p_tref'], $context);
|
|
|
return;
|
|
|
+ }
|
|
|
//DB::d_delete_row($o['d_tref']], ['rowid'=>$o['d_oid']]);
|
|
|
- DB::p_delete_row($o['p_tref'], [static::P_TABLE_ID[$o['p_tref']]=>$o['p_oid']]);
|
|
|
- $sql = 'DELETE FROM _objects WHERE id='.$o['id'];
|
|
|
- DB::o_delete($sql);
|
|
|
- return true;
|
|
|
+ if ($r=DB::p_delete_row($o['p_tref'], [static::P_TABLE_ID[$o['p_tref']]=>$o['p_oid']])) {
|
|
|
+ $sql = 'DELETE FROM _objects WHERE id='.$o['id'];
|
|
|
+ DB::o_delete($sql);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data does not exists", $context, NULL, 'nodata');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sync_error(__FILE__.':'.__LINE__.' : '.__METHOD__."($otype, $oid)", "Source data link does not exists", $context, NULL, 'nodata');
|
|
|
}
|
|
|
}
|
|
|
|