Browse Source

Poprawki do BiAudit

Mariusz Muszyński 8 years ago
parent
commit
3309e620db
1 changed files with 21 additions and 15 deletions
  1. 21 15
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 21 - 15
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -1949,6 +1949,8 @@ SQL;
 		];
 
 		try {
+			$BiAuditPowiazania = new BiAuditPowiazania($ID, $tasksDirLocation);
+
 			$query = "select count(*) from `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` where `FILE_STATUS` = 'IN_PROGRESS' and `BI_analiza_reloadCache` = 'Part' and ID != ${ID}";
 			$sqlArr = [
 				'BI_analiza_reloadCache' => 'Part',
@@ -1966,7 +1968,7 @@ SQL;
 			} while ($activeReloadingCache);
 			
 			BiAuditPowiazania::saveToLog("Uruchamiam częściowe odświeżenie cache");
-			$this->doReloadCache();
+//			$this->doReloadCache();
 			BiAuditPowiazania::saveToLog("Odświeżono częściowo cache");
 
 			$sqlArr = [
@@ -1975,7 +1977,7 @@ SQL;
 			];
 			DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', "ID", $ID, $sqlArr);
 
-			$BiAuditPowiazania = new BiAuditPowiazania($ID, $tasksDirLocation);
+			$BiAuditPowiazania->run();
 			if (!$BiAuditPowiazania->powiazaniaFound()) throw new Exception("Nie znaleziono żadnych powiązań");
 			//file_put_contents($xmlFile, $BiAuditPowiazania->asXml());
 
@@ -2184,11 +2186,12 @@ class BiAuditPowiazania {
 	private $progressFile;
 	private $progress = [
 		'summary' => [
-			'count' => null,
+			'count' => 0,
 			'message' => 'Inicjacja',
 			'ts' => null,
 			'step' => 'initialize',
-			'created' => 0,
+			'reportsCount' => 0,
+			'reportsCreated' => 0,
 		],
 		'details' => [],
 	];
@@ -2248,14 +2251,16 @@ class BiAuditPowiazania {
 	public function __construct($ID = 0, $tasksDirLocation = null) {
 		if (!$ID) self::throwException("Wrong ID parameter");
 		if (!$tasksDirLocation) self::throwException("Wrong directory of tasks location");
+		$this->ID = $ID;
 		$this->tasksDirLocation = $tasksDirLocation;
-
+		$this->progressFile = "{$this->tasksDirLocation}/generatePowiazania-{$this->ID}.progress";
 		$this->saveProgress();
+	}
 
-		$query = "select BI_analiza_minDepth, BI_analiza_maxDepth, BI_analiza_onlyTargets from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = '{$ID}' and FILE_STATUS = 'IN_PROGRESS' and BI_analiza_reloadCache not in ('Full')";
+	public function run() {
+		$query = "select BI_analiza_minDepth, BI_analiza_maxDepth, BI_analiza_onlyTargets from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = '{$this->ID}' and FILE_STATUS = 'IN_PROGRESS' and BI_analiza_reloadCache not in ('Full')";
 		$result = DB::getPDO()->fetchAll($query);
 		if (!$result) self::throwException("Błąd danych");
-		$this->ID = $ID;
 
 		if ($this->loadResults()) {
 			$this->splitResults();
@@ -2282,7 +2287,6 @@ class BiAuditPowiazania {
 
 		self::saveToLog("Rozpoczynam wyszukiwanie powiązań");
 
-		$this->progressFile = "{$this->tasksDirLocation}/generatePowiazania-{$this->ID}.progress";
 		$refPowiazaniaToPracownicy = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', 'BI_audit_ENERGA_PRACOWNICY', true);
 		$query = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refPowiazaniaToPracownicy}` `ref`
 			on `all`.`REMOTE_TABLE` = 'BI_audit_ENERGA_PRACOWNICY' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}' order by `all`.`ID` asc";
@@ -2449,10 +2453,7 @@ class BiAuditPowiazania {
 					$_keys = array_keys($this->results[$resultKey]);
 					$countByDest[end($_keys)][] = $resultKey;
 				}
-				foreach ($countByDest as $resultKeys2) {
-					while (count($resultKeys2) > $MAX) $resultsKeys[] = array_splice($resultKeys2, 0, $MAX);
-					$resultsKeys[] = $resultKeys2;
-				}
+				foreach ($countByDest as $resultKeys2) $resultsKeys = array_merge($resultsKeys, array_chunk($resultKeys2, $MAX));
 			} else $resultsKeys[] = $resultKeys;
 		}
 
@@ -2463,9 +2464,12 @@ class BiAuditPowiazania {
 				if (count($resultKeys) + count($next) <= $MAX) {
 					$resultKeys = array_merge($resultKeys, $next);
 					unset($resultsKeys[key($resultsKeys)]);
-				} else next($resultsKeys);
+				} else break; //next($resultsKeys);
 			}
-			$results[] = array_map(function ($resultKey) {return $this->results[$resultKey];}, $resultKeys);
+			$_results = [];
+			foreach ($resultKeys as $key) $_results[$key] = $this->results[$key];
+			$results[] = $_results;
+//			$results[] = array_map(function ($resultKey) {return $this->results[$resultKey];}, $resultKeys);
 		}
 
 		$this->splittedResults = $results;
@@ -2507,7 +2511,9 @@ class BiAuditPowiazania {
 				$query = "select * from `{$row['REMOTE_TABLE']}` where ID = '{$row['REMOTE_ID']}'";
 				$obj = DB::fetch(DB::query($query));
 				$item_result = [];
-				if ($this->fidRow) $item_result['@attributes'] = ['fid' => "{$xmlObject}.{$this->fidRow[$key]['obj'][$ID]}"];
+				if ($this->fidRow) {
+					$item_result['@attributes'] = ['fid' => "{$xmlObject}.{$this->fidRow[$key]['obj'][$ID]}"];
+				}
 				$item_result[$row['REMOTE_TABLE']] = array_merge(['@attributes' => ['fid' => "{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}"]], (array) $obj);
 
 				if ($refTable = BiAuditRefTables::getRefTable('BI_audit_operational_raport_note', $row['REMOTE_TABLE'], false)) {