Bladeren bron

Implementacja dat relacji przy odświeżaniu cache (pozostało jeszcze zaimplementować w raportach)

Mariusz Muszyński 7 jaren geleden
bovenliggende
commit
c11728c806
1 gewijzigde bestanden met toevoegingen van 30 en 13 verwijderingen
  1. 30 13
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 30 - 13
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -2825,7 +2825,7 @@ SQL;
 		foreach ($tables as $table => $tableConf) {
 			DB::getPDO()->query("update `{$table}` set `{$tableConf['fieldsTeryt']['nrDomu']}` = null where trim(`{$tableConf['fieldsTeryt']['nrDomu']}`) = ''");
 			DB::getPDO()->query("update `{$table}` set `{$tableConf['fieldsTeryt']['nrLokalu']}` = null where trim(`{$tableConf['fieldsTeryt']['nrLokalu']}`) = ''");
-			$where = ($full && ($forceAll || (!$tableConf['base']))) ? "" : "where `TERYT_SYM` is null and `cached` = 0";
+			$where = ($full && ($forceAll || (!$tableConf['base']))) ? "" : "where `cached` = 0";
 			$query = "select * from `{$table}` {$where}";
 			$refTable = BiAuditRefTables::getRefTable($table, 'TERYT_adresy', true);
 
@@ -2846,7 +2846,7 @@ SQL;
 			while ($adres = $adresy->fetch()) {
 				DB::getPDO()->query("delete from `{$refTable}` where `PRIMARY_KEY` = '{$adres['ID']}'");
 
-				if (!($forceAll and $adres['TERYT_SYM'])) {
+				if ($full || (!$adres['TERYT_SYM'])) {
 					$search = [];
 					foreach ($tableConf['fields'] as $field => $param) if (!empty($adres[$param])) $search[$field] = $adres[$param];
 					try {
@@ -3084,7 +3084,7 @@ SQL;
 					if ($refTable = BiAuditRefTables::getRefTable($refTableFrom, $refTableTo, false)) {
 						$queries[] = "delete from `{$refTable}` where `TRANSACTION_ID` = '-1'";
 						$queries[] = "optimize table `{$refTable}`";
-						$queries[] = "insert into `{$refTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`, `TRANSACTION_ID`, `A_STATUS`) select `all1`.`REMOTE_ID`, `all2`.`REMOTE_ID`, '-1', 'NORMAL' from `BI_audit_ALL` as `all1` join `BI_audit_ALL_ref` as `ref` on `all1`.`ID` = `ref`.`ID1` join `BI_audit_ALL` as `all2` on `ref`.`ID2` = `all2`.`ID` left join `${refTable}` as `ref2` on `all1`.`REMOTE_ID` = `ref2`.`PRIMARY_KEY` and `all2`.`REMOTE_ID` = `ref2`.`REMOTE_PRIMARY_KEY` where `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref2`.`PRIMARY_KEY` is null";
+						$queries[] = "insert into `{$refTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`, `REMOTE_TYPENAME`, `TRANSACTION_ID`, `A_STATUS`) select `all1`.`REMOTE_ID`, `all2`.`REMOTE_ID`, `ref`.`PARAMS`, '-1', 'NORMAL' from `BI_audit_ALL` as `all1` join `BI_audit_ALL_ref` as `ref` on `all1`.`ID` = `ref`.`ID1` join `BI_audit_ALL` as `all2` on `ref`.`ID2` = `all2`.`ID` left join `${refTable}` as `ref2` on `all1`.`REMOTE_ID` = `ref2`.`PRIMARY_KEY` and `all2`.`REMOTE_ID` = `ref2`.`REMOTE_PRIMARY_KEY` where `all1`.`REMOTE_TABLE` = '{$refTableFrom}' and `all2`.`REMOTE_TABLE` = '{$refTableTo}' and `ref2`.`PRIMARY_KEY` is null";
 					}
 				}
 			}
@@ -3121,12 +3121,12 @@ SQL;
 			if ($onlyBase && (!$tableConf['base'])) continue;
 			foreach ($refTableConf['refTablesTo'] as $refTableTo) {
 				$refTable = BiAuditRefTables::getRefTable($refTableFrom, $refTableTo, true);
-				$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `RELATION_ID`, `BASE`) select `all1`.`ID`, `all2`.`ID`, `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)) {
-					$queries[] = "insert into `BI_audit_ALL_ref` (`ID1`, `ID2`, `RELATION_ID`, `BASE`) select `all2`.`ID`, `all1`.`ID`, `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)) {
-					$queries[] = "insert into `{$backRefTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`, `TRANSACTION_ID`, `A_STATUS`) select `REMOTE_PRIMARY_KEY`, `PRIMARY_KEY`, '-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'";
 			}
@@ -3651,12 +3651,12 @@ class BiAuditPowiazania {
 			$result = $resultSrc;
 			$this->endNodes = array_map('reset', $resultDest);
 			$this->reverseSearch = false;
-			$this->query = "select ref.ID2 as ID, RELATION_ID from BI_audit_ALL_ref ref where ref.ID1";
+			$this->query = "select ref.ID2 as ID, ref.RELATION_ID, ref.PARAMS from BI_audit_ALL_ref ref where ref.ID1";
 		} else {
 			$result = $resultDest;
 			$this->endNodes = array_map('reset', $resultSrc);
 			$this->reverseSearch = true;
-			$this->query = "select ref.ID1 as ID, RELATION_ID from BI_audit_ALL_ref ref where ref.ID2";
+			$this->query = "select ref.ID1 as ID, ref.RELATION_ID, ref.PARAMS from BI_audit_ALL_ref ref where ref.ID2";
 			self::saveToLog("Docelowych obiektów jest mniej, niż początkowych - włączono mechanizm odwrotnego przeszukiwania");
 		}
 
@@ -3737,7 +3737,7 @@ class BiAuditPowiazania {
 		return 10;
 	}
 
-	public function findPowiazania($ID, $weight = 0, $progress = 0, $steps = 1, $relation = "") {
+	public function findPowiazania($ID, $weight = 0, $progress = 0, $steps = 1, $relation = "", $relationDateRange = "") {
 		$this->step++;
 
 		if ($this->maxDepth > $this->minDepth) {
@@ -3768,7 +3768,7 @@ class BiAuditPowiazania {
 
 		if (isset($this->path[$ID])) return false;
 
-		$this->path[$ID] = $relation;
+		$this->path[$ID] = [$relation, $relationDateRange];
 		if (!$relation) $relation = 0;
 
 		if (in_array($ID, $this->endNodes)) {
@@ -3796,7 +3796,7 @@ class BiAuditPowiazania {
 		$count = count($nodes);
 		$weight += self::weightCalc($count);
 		if ($weight <= $this->maxDepth) {
-			foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], $weight, ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID']);
+			foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], $weight, ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID'], $node['PARAMS']);
 		}
 
 		array_pop($this->path);
@@ -3956,6 +3956,10 @@ class BiAuditPowiazania {
 		foreach ($results as $key => $result) {
 			if ($this->fidRow) $item_results = ['@attributes' => ['fid' => "{$xmlRow}.{$this->fidRow[$key]['fid']}"]];
 			foreach ($result as $ID => $rel) {
+				if (is_array($rel)) {
+					$relDateRange = $rel[1];
+					$rel =$rel[0];
+				} else $relDateRange = '';
 				$query = "select REMOTE_TABLE, REMOTE_ID from BI_audit_ALL where ID = '{$ID}'";
 				$row = DB::getPDO()->fetchFirst($query);
 				$query = "select * from `{$row['REMOTE_TABLE']}` where ID = '{$row['REMOTE_ID']}'";
@@ -3995,7 +3999,16 @@ class BiAuditPowiazania {
 					}
 				}
 
-				if ($rel) $item_result['relation_from'] = $this->relationName($rel);
+				if ($rel) {
+					$item_result['relation_from'] = $this->relationName($rel);
+					if ($relDateRange) $item_result['relation_dateRange'] = $relDateRange;
+					// TODO
+//					<relation_dateRangeElements>
+//						<relation_dateRange from="2010-01-01" to="2011-01-01"/>
+//						<relation_dateRange from="2012-01-01" to="2013-01-01"/>
+//						<relation_dateRange from="2014-01-01" [?to=""?]/>
+//					</relation_dateRangeElements>
+				}
 				$item_results[$xmlObject][] = $item_result;
 
 				if ($row['REMOTE_TABLE'] == "BI_audit_ENERGA_RUM_KONTRAHENCI" && (!in_array($row['REMOTE_ID'], $kontrahenci))) {
@@ -4076,9 +4089,13 @@ class BiAuditPowiazania {
 			$fidObj = [];
 			DB::getPDO()->insert($refPowiazaniaToPowiazaniaRow, ['PRIMARY_KEY' => $this->ID, 'REMOTE_PRIMARY_KEY' => $IdPowiazaniaRow]);
 			foreach ($result as $ID => $rel) {
+				if (is_array($rel)) {
+					$relDateRange = $rel[1];
+					$rel = $rel[0];
+				} else $relDateRange = '';
 				$query = "select REMOTE_TABLE, REMOTE_ID from BI_audit_ALL where ID = '{$ID}'";
 				$object = DB::getPDO()->fetchFirst($query);
-				$idPowiazaniaRowObject = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object', ['relation_from' => $this->relationName($rel)]);
+				$idPowiazaniaRowObject = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object', ['relation_from' => $this->relationName($rel), 'dateRange' => $dateRange]);
 				DB::getPDO()->insert($refPowiazaniaRowToPowiazaniaRowObject, ['PRIMARY_KEY' => $IdPowiazaniaRow, 'REMOTE_PRIMARY_KEY' => $idPowiazaniaRowObject]);
 				$ref = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object', $object['REMOTE_TABLE'], true);
 				DB::getPDO()->insert($ref, ['PRIMARY_KEY' => $idPowiazaniaRowObject, 'REMOTE_PRIMARY_KEY' => $object['REMOTE_ID']]);