|
@@ -3123,11 +3123,13 @@ SQL;
|
|
|
if ($onlyBase && (!$tableConf['base'])) continue;
|
|
if ($onlyBase && (!$tableConf['base'])) continue;
|
|
|
foreach ($refTableConf['refTablesTo'] as $refTableTo) {
|
|
foreach ($refTableConf['refTablesTo'] as $refTableTo) {
|
|
|
$refTable = BiAuditRefTables::getRefTable($refTableFrom, $refTableTo, true);
|
|
$refTable = BiAuditRefTables::getRefTable($refTableFrom, $refTableTo, true);
|
|
|
|
|
+ $queries[] = "delete from `aref` using `BI_audit_ALL_ref` as `aref` join `BI_audit_ALL` as `all1` on `aref`.`ID1` = `all1`.`ID` and `all1`.`REMOTE_TABLE` = '{$refTableFrom}' join `BI_audit_ALL` as `all2` on `aref`.`ID2` = `all2`.`ID` and `all2`.`REMOTE_TABLE` = '{$refTableTo}' join `{$refTable}` as `ref` on `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `all2`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL_ref_RELATIONS` `rel` on `all1`.`REMOTE_TABLE` = `rel`.`RELATION` and `aref`.`RELATION_ID` = `rel`.`ID`";
|
|
|
$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `PARAMS`, `RELATION_ID`, `BASE`) select `all1`.`ID`, `all2`.`ID`, `ref`.`REMOTE_TYPENAME`, `rel`.`ID`, {$refTableConf['base']} from `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` join `BI_audit_ALL_ref_RELATIONS` `rel` on `all1`.`REMOTE_TABLE` = `rel`.`RELATION`";
|
|
$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `PARAMS`, `RELATION_ID`, `BASE`) select `all1`.`ID`, `all2`.`ID`, `ref`.`REMOTE_TYPENAME`, `rel`.`ID`, {$refTableConf['base']} from `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` join `BI_audit_ALL_ref_RELATIONS` `rel` on `all1`.`REMOTE_TABLE` = `rel`.`RELATION`";
|
|
|
if (!in_array($refTableFrom, $sourceTables)) {
|
|
if (!in_array($refTableFrom, $sourceTables)) {
|
|
|
$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `PARAMS`, `RELATION_ID`, `BASE`) select `all2`.`ID`, `all1`.`ID`, `ref`.`REMOTE_TYPENAME`, `rel`.`ID`, {$refTableConf['base']} from `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` join `BI_audit_ALL_ref_RELATIONS` `rel` on `all2`.`REMOTE_TABLE` = `rel`.`RELATION`";
|
|
$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `PARAMS`, `RELATION_ID`, `BASE`) select `all2`.`ID`, `all1`.`ID`, `ref`.`REMOTE_TYPENAME`, `rel`.`ID`, {$refTableConf['base']} from `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` join `BI_audit_ALL_ref_RELATIONS` `rel` on `all2`.`REMOTE_TABLE` = `rel`.`RELATION`";
|
|
|
}
|
|
}
|
|
|
if ($backRefTable = BiAuditRefTables::getRefTable($refTableTo, $refTableFrom, false)) {
|
|
if ($backRefTable = BiAuditRefTables::getRefTable($refTableTo, $refTableFrom, false)) {
|
|
|
|
|
+ $queries[] = "delete from `backRef` using `{$backRefTable}` as `backRef` join `{$refTable}` as `ref` on `backRef`.`PRIMARY_KEY` = `ref`.`REMOTE_PRIMARY_KEY` and `backRef`.`REMOTE_PRIMARY_KEY` = `ref`.`PRIMARY_KEY` and `backRef`.`TRANSACTION_ID` = '-1' and `ref`.`A_STATUS` = 'WAITING'";
|
|
|
$queries[] = "insert into `{$backRefTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`, `REMOTE_TYPENAME`, `TRANSACTION_ID`, `A_STATUS`) select `REMOTE_PRIMARY_KEY`, `PRIMARY_KEY`, `REMOTE_TYPENAME`, '-1', 'NORMAL' from `{$refTable}` where `A_STATUS` = 'WAITING'";
|
|
$queries[] = "insert into `{$backRefTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`, `REMOTE_TYPENAME`, `TRANSACTION_ID`, `A_STATUS`) select `REMOTE_PRIMARY_KEY`, `PRIMARY_KEY`, `REMOTE_TYPENAME`, '-1', 'NORMAL' from `{$refTable}` where `A_STATUS` = 'WAITING'";
|
|
|
}
|
|
}
|
|
|
$queries[] = "update `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` set `ref`.`A_STATUS` = 'NORMAL'";
|
|
$queries[] = "update `BI_audit_ALL` as `all1` join `{$refTable}` as `ref` on `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all1`.`REMOTE_ID` = `ref`.`PRIMARY_KEY` and `ref`.`A_STATUS` = 'WAITING' join `BI_audit_ALL` as `all2` on `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref`.`REMOTE_PRIMARY_KEY` = `all2`.`REMOTE_ID` set `ref`.`A_STATUS` = 'NORMAL'";
|