Преглед изворни кода

Poprawki z fid do BiAuditGenerate

Mariusz Muszyński пре 8 година
родитељ
комит
591662cff2
1 измењених фајлова са 48 додато и 26 уклоњено
  1. 48 26
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 48 - 26
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -272,21 +272,21 @@ function toggle(source) {
 				'files' => glob("{$dir}/relations*.pdf"),
 				'label' => 'Raporty PDF:<br/>&nbsp;',
 				'button' => 'Pokaż raport PDF',
-				'regex' => '/^relations_([[:digit:]]+)\.pdf$/',
+				'regex' => "/^relations(-{$this->powiazanie['ID']})?_([[:digit:]]+)\.pdf$/",
 				'parentDir' => false,
 			],
 			'html' => [
 				'files' => glob("{$dir}/html*/relations-{$this->powiazanie['ID']}*.html"),
 				'label' => 'Raporty HTML<br/>do przeglądania:',
 				'button' => 'Pokaż raport HTML',
-				'regex' => "/^relations-{$this->powiazanie['ID']}_([[:digit:]]+)\.html$/",
+				'regex' => "/^relations-({$this->powiazanie['ID']})_([[:digit:]]+)\.html$/",
 				'parentDir' => true,
 			],
 			'htmlZip' => [
 				'files' => glob("{$dir}/html*.zip"),
 				'label' => 'Raporty HTML<br/>do pobrania:',
 				'button' => 'Pobież raport HTML',
-				'regex' => '/^html_([[:digit:]]+)\.zip$/',
+				'regex' => "/^html(-{$this->powiazanie['ID']})?_([[:digit:]]+)\.zip$/",
 				'parentDir' => false,
 			],
 		];
@@ -302,7 +302,7 @@ function toggle(source) {
 			$hrefs = array_filter(array_map(function ($path) use ($url, $report) {
 				if (!is_file($path)) return false;
 				$file = basename($path);
-				if (preg_match($report['regex'], $file, $matches)) $i = " (" . ltrim($matches[1], '0') . ")";
+				if (preg_match($report['regex'], $file, $matches)) $i = " (" . ltrim($matches[2], '0') . ")";
 				else $i = '';
 				if ($report['parentDir']) $file = basename(dirname($path)) . "/" . $file;
 				return "<a href=\"{$url}/{$file}\" target=\"_blank\" class=\"btn btn-primary\">{$report['button']}{$i}</a>";
@@ -1187,10 +1187,10 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 							$generatePowiazaniaPdfFile = "{$generateFilesName}.pdf";
 							$generatePowiazaniaHtmlDir = "{$generateFilesName}.html";
 							$generatePowiazaniaHtmlZipFile = "{$generateFilesName}.zip";
-							$destXmlFile = "{$powiazanieDirLocation}/relations_{$partNo}.xml";
-							$destPdfFile = "{$powiazanieDirLocation}/relations_{$partNo}.pdf";
-							$destHtmlDir = "{$powiazanieDirLocation}/html_{$partNo}";
-                                        	        $destHtmlZipFile = "{$powiazanieDirLocation}/html_{$partNo}.zip";
+							$destXmlFile = "{$powiazanieDirLocation}/relations-{$row['ID']}_{$partNo}.xml";
+							$destPdfFile = "{$powiazanieDirLocation}/relations-{$row['ID']}_{$partNo}.pdf";
+							$destHtmlDir = "{$powiazanieDirLocation}/html-{$row['ID']}_{$partNo}";
+							$destHtmlZipFile = "{$powiazanieDirLocation}/html-{$row['ID']}_{$partNo}.zip";
 							if (file_exists($generatePowiazaniaXmlFile)) rename($generatePowiazaniaXmlFile, $destXmlFile);
 							if (file_exists($generatePowiazaniaPdfFile)) rename($generatePowiazaniaPdfFile, $destPdfFile);
 							if (file_exists($generatePowiazaniaHtmlDir)) {
@@ -1204,10 +1204,10 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
 						$generatePowiazaniaPdfFile = "{$generateFilesName}.pdf";
 						$generatePowiazaniaHtmlDir = "{$generateFilesName}.html";
 						$generatePowiazaniaHtmlZipFile = "{$generateFilesName}.zip";
-						$destXmlFile = "{$powiazanieDirLocation}/relations.xml";
-						$destPdfFile = "{$powiazanieDirLocation}/relations.pdf";
-						$destHtmlDir = "{$powiazanieDirLocation}/html";
-						$destHtmlZipFile = "{$powiazanieDirLocation}/html.zip";
+						$destXmlFile = "{$powiazanieDirLocation}/relations-{$row['ID']}.xml";
+						$destPdfFile = "{$powiazanieDirLocation}/relations-{$row['ID']}.pdf";
+						$destHtmlDir = "{$powiazanieDirLocation}/html-{$row['ID']}";
+						$destHtmlZipFile = "{$powiazanieDirLocation}/html-{$row['ID']}.zip";
 						if (file_exists($generatePowiazaniaXmlFile)) rename($generatePowiazaniaXmlFile, $destXmlFile);
 						if (file_exists($generatePowiazaniaPdfFile)) rename($generatePowiazaniaPdfFile, $destPdfFile);
 						if (file_exists($generatePowiazaniaHtmlDir)) {
@@ -2226,6 +2226,7 @@ class BiAuditPowiazania {
 	private $count, $i;
 	private $splittedResults = [];
 	private $maxResults = 1000000;
+	private $fidRow = [];
 
 	private static function generateJson($type, $data) {
 		return json_encode(['ts' => microtime(true), 'type' => $type, 'data' => $data]);
@@ -2412,7 +2413,7 @@ class BiAuditPowiazania {
 			return false;
 		}
 		$dataFile = "{$this->tasksDirLocation}/generatePowiazania-{$this->ID}.data";
-		$data = base64_encode(gzcompress(json_encode($this->results)));
+		$data = base64_encode(gzcompress(json_encode(['results' => $this->results, 'fidRow' => $this->fidRow])));
 		file_put_contents($dataFile, $data);
 		self::saveToLog("Zapisano wyliczone dane do pliku");
 		return true;
@@ -2431,7 +2432,10 @@ class BiAuditPowiazania {
 			self::saveToLog("Wystąpił błąd wczytywania wcześniej wyliczonych danych");
 			return false;
 		}
-		$this->results = $results;
+		if (isset($results['results'])) {
+			$this->results = $results['results'];
+			if (isset($results['fidRow'])) $this->fidRow = $results['fidRow'];
+		} else $this->results = $results;
 		self::saveToLog("Wczytano wcześniej wyliczone dane");
 
 		return true;
@@ -2492,8 +2496,9 @@ class BiAuditPowiazania {
 
 	private function generateItemsResults($resultsPart = null) {
 		self::saveToLog("Generuję dane na potrzeby utworzenia pliku XML ({$resultsPart})");
-		$xmlRoot2 = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA";
-		$xmlElements = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row";
+		$xmlTask = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA";
+		$xmlRow = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row";
+		$xmlObject = "BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object";
 
 		$this->items_results = [];
 		$items_kontrahenci = [];
@@ -2505,17 +2510,24 @@ class BiAuditPowiazania {
 		$refUmowyToKontrahenci = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_UMOWY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
 		$refKwRequestedToKwRequestedPerson = BiAuditRefTables::getRefTable('BI_audit_KW_requested', 'BI_audit_KW_requested_person', true);
 
+		$this->items_results[$resultsPart]['@attributes'] = ['xmlns:system_cache__dita' => 'http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/dita.xsd'];
+		$this->items_results[$resultsPart][$xmlTask]['@attributes'] = ['fid' => "{$xmlTask}.{$this->ID}"];
 		if ($resultsPart === null) $results = $this->results;
-		else $results = (!empty($this->splittedResults[$resultsPart])) ? $this->splittedResults[$resultsPart] : [];
+		else {
+			$results = (!empty($this->splittedResults[$resultsPart])) ? $this->splittedResults[$resultsPart] : [];
+			$this->items_results[$resultsPart][$xmlTask]['@attributes']['system_cache__dita:part'] = ($resultsPart + 1);
+		}
 
-		foreach ($results as $result) {
-			$item_results = [];
+		foreach ($results as $key => $result) {
+			if ($this->fidRow) $item_results = ['@attributes' => ['fid' => "{$xmlRow}.{$this->fidRow[$key]['fid']}"]];
 			foreach ($result as $ID => $rel) {
 				$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']}'";
 				$obj = DB::fetch(DB::query($query));
-				$item_result = [$row['REMOTE_TABLE'] => array_merge(['@attributes' => ['fid' => "{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}"]], (array) $obj)];
+				$item_result = [];
+				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)) {
 					$query = "select `note`.* from `BI_audit_operational_raport_note` `note` join `{$refTable}` `ref` on `note`.`ID` = `ref`.`PRIMARY_KEY` where `ref`.`REMOTE_PRIMARY_KEY` = '{$row['REMOTE_ID']}'";
@@ -2530,7 +2542,7 @@ class BiAuditPowiazania {
 				}
 
 				if ($rel) $item_result['relation_from'] = $this->relationName($rel);
-				$item_results['object'][] = $item_result;
+				$item_results[$xmlObject][] = $item_result;
 
 				if ($row['REMOTE_TABLE'] == "BI_audit_ENERGA_RUM_KONTRAHENCI" && (!in_array($row['REMOTE_ID'], $kontrahenci))) {
 					$kontrahenci[] = $row['REMOTE_ID'];
@@ -2566,26 +2578,31 @@ class BiAuditPowiazania {
 					}
 				}
 			}
-			$this->items_results[$resultsPart][$xmlRoot2][$xmlElements][] = $item_results;
+			$this->items_results[$resultsPart][$xmlTask][$xmlRow][] = $item_results;
 		}
-		$this->items_results[$resultsPart][$xmlRoot2]['BI_audit_ENERGA_RUM_KONTRAHENCI'] = $items_kontrahenci;
-		$this->items_results[$resultsPart][$xmlRoot2]['BI_audit_KW_requested_person'] = $items_kw_person;
+		$this->items_results[$resultsPart][$xmlTask]['BI_audit_ENERGA_RUM_KONTRAHENCI'] = $items_kontrahenci;
+		$this->items_results[$resultsPart][$xmlTask]['BI_audit_KW_requested_person'] = $items_kw_person;
 		self::saveToLog("Wygenerowano dane na potrzeby utworzenia pliku XML ({$resultsPart})");
 	}
 
-	private function saveToDb($result = null) {
+	private function saveToDb($result = null, $key = null) {
 		if ($result === null) {
 			self::saveToLog("Zapisuję wyliczone dane do bazy");
 			if (!$this->results) {
 				self::saveToLog("Brak wyliczonych danych - nie zapisaono niczego do bazy");
 				return null;
 			}
-			foreach ($this->results as $result) $this->saveToDb($result);
+			foreach ($this->results as $key => $result) $this->saveToDb($result, $key);
 			self::saveToLog("Zapisano wyliczone dane do bazy");
 		} else {
+			if ($key === null) {
+				end($this->results);
+				$key = key($this->results);
+			}
 			$refPowiazaniaToPowiazaniaRow = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', 'BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row', true);
 			$refPowiazaniaRowToPowiazaniaRowObject = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row', 'BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object', true);
 			$IdPowiazaniaRow = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row', []);
+			$fidObj = [];
 			DB::getPDO()->insert($refPowiazaniaToPowiazaniaRow, ['PRIMARY_KEY' => $this->ID, 'REMOTE_PRIMARY_KEY' => $IdPowiazaniaRow]);
 			foreach ($result as $ID => $rel) {
 				$query = "select REMOTE_TABLE, REMOTE_ID from BI_audit_ALL where ID = '{$ID}'";
@@ -2594,7 +2611,12 @@ class BiAuditPowiazania {
 				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']]);
+				$fidObj[$ID] = $idPowiazaniaRowObject;
 			}
+			$this->fidRow[$key] = [
+				'fid' => $IdPowiazaniaRow,
+				'obj' => $fidObj,
+			];
 		}
 	}