Explorar el Código

Implementacja możliwości przerwania badania

Mariusz Muszyński hace 7 años
padre
commit
156495bcc7
Se han modificado 1 ficheros con 36 adiciones y 0 borrados
  1. 36 0
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 36 - 0
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -473,6 +473,35 @@ function validate() {
 <?php
 	}
 
+	private function showPowiazania_progress() {
+?>
+<div class="container" style="margin-top:20px">
+  <legend>
+    Postęp generowania raportu nr <?=$this->powiazanie['ID']?>
+  </legend>
+  Panel w przygotowaniu
+<?php
+		$action = V::get('action', '', $_POST);
+		switch ($action) {
+			case "abort":
+				$powiazaniaDirLocation = self::getMainDirectory();
+				$tasksDirLocation = $powiazaniaDirLocation . "/.tasks";
+				$abortFile = "{$tasksDirLocation}/generatePowiazania-{$this->powiazanie['ID']}.abort";
+				touch($abortFile);
+?>
+  <h4>Zlecono przerwanie badania - odczekaj kilka minut</h4>
+<?php
+				break;
+			default:
+?>
+  <form method="post">
+    <button type="submit" name="action" value="abort">Przerwij badanie</button>
+  </form>
+</div>
+<?php
+		}
+	}
+
 	private function powiazania() {
 		try {
 			if (!$this->SOURCE) throw new Exception("Błąd danych");
@@ -486,6 +515,8 @@ function validate() {
 						case "NONE":
 							$this->initializePowiazania();
 							break;
+						case "IN_PROGRESS":
+							$this->showPowiazania_progress();
 						case "GENERATED":
 							$this->showPowiazania();
 							break;
@@ -3299,6 +3330,11 @@ class BiAuditPowiazania {
 		if (isset($args['reportsCreated'])) $this->progress['summary']['reportsCreated'] = round($this->progress['summary']['reportsCreated'] + $args['reportsCreated'], 2);
 		$this->progress['summary']['ts'] = $timestamp;
 		file_put_contents($this->progressFile, json_encode($this->progress));
+
+		if (file_exists("{$this->tasksDirLocation}/generatePowiazania-{$this->ID}.abort")) {
+			unlink("$this->tasksDirLocation}/generatePowiazania-{$this->ID}.abort");
+			self::throwException("Przerwano na żądanie użytkownika");
+		}
 	}
 
 	private static function throwException($message) {