| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 | <?phpclass Logfile{	public $Name;	public $Type = "Modell";	public $Filename;	public $Modified;	public $LastChangedDays;	public $Errors = array();	public $ErrorLevel = 5;	public $Sources = array();	public $Summary;	function __construct($filename)	{		$this->Filename = $filename;		$pathinfo = pathinfo($filename);		$this->Name = $pathinfo['filename'];		$this->Modified = str_replace(" ", "T", date("Y-m-d H:i:s", filemtime($filename)));		$this->LastChangedDays = $this->dateDiff($this->Modified, date("Y-m-d H:i:s"));		if (preg_match("/\.xml/", $this->Filename)) {			$this->Type = (stripos($this->Filename, "ver")  == false) ? "Portal" : "Versand";			$errors = json_decode(implode("",file($this->Filename)));			if (isset($errors->errors)) {				if (count($errors->errors) > 0) {					$this->ErrorLevel = 2;				}				$this->Errors = $errors->errors;				$this->Sources = $errors->sources;				$this->Summary = $errors->summary;			}		} else if (preg_match("/\.\D+\.log$/", $this->Filename)) {			$this->Errors = array(implode("\r\n", $this->Content()));			$this->Type = "Workflow";			$this->ErrorLevel = 3;		} else {			$this->transformerErrors();			$this->benchmark();			if ($this->ErrorLevel <= 2 && $this->Summary) {				$this->ErrorLevel = 3;			}			if (!$this->Summary) {				$this->ErrorLevel = 2;			}		}	}	function Content()	{		$content = file($this->Filename);		return array_map(array($this, 'formatMessage'), $content);	}	function Link() {		$link = $this->Name;		if (preg_match("/(.*)\.\d+$/", $link, $match)) {			$link = $match[1];		}		return "<a href=\"http://wiki.global-cube.de/{$link}\">{$this->Name}</a>";	}	private function webCreatorErrors()	{		foreach ($this->Content() as $line) {			if (preg_match("/^\w+/", $line) && !preg_match("/^(com|Source)/", $line)) {				$e = new WebCreatorError($line);				if ($e->Level < $this->ErrorLevel)					$this->ErrorLevel = $e->Level;				$this->Errors[] = $e;			}		}	}		private function copyAndReplaceErrors()	{		foreach ($this->Content() as $line) {			$e = new CopyAndReplaceError($line);			if ($e->Level < $this->ErrorLevel)				$this->ErrorLevel = $e->Level;			$this->Errors[] = $e;		}	}		private function transformerErrors()	{		foreach ($this->Content() as $line) {			if (preg_match("/\(TR\d*\)|DMS-E-GENERAL/", $line)) {				$e = new TransformerError($line);				if ($e->Level < $this->ErrorLevel)					$this->ErrorLevel = $e->Level;				$this->Errors[] = $e;			}		}	}	private function benchmark()	{		$current = null;		foreach ($this->Content() as $line) {			if (preg_match("/Verarbeitung von (\d*) Datens.+tzen der Datenquelle `(.*)` wird beendet/", $line, $match)) {				$current = new Source($match[2], $match[1]);			} else if ($current && preg_match("/DATENQUELLE GELESEN,\s*([\d:]+)/", $line, $match)) {				$current->Duration = $match[1];				$this->Sources[] = $current;				$current = null;			} else if (preg_match("/Durchgang \d+ wird ausgef.+hrt\. Es verbleiben (\d*) Zeilen und (\d*) Kategorien/", $line, $match)) {				$this->Summary = new Summary($match[1], $match[2]);			} else if ($this->Summary && preg_match("/ZEIT INSGESAMT \(CUBE ERSTELLEN\),\s*([\d:]+)/", $line, $match)) {				$this->Summary->Duration = $match[1];			}		}	}	private function dateDiff($d1, $d2)	{		$diff = round((strtotime($d2) - strtotime($d1)) / (24 * 60 * 60));		return $diff;	}		private function formatMessage($m)	{		$m = utf8_encode($m);		$m = str_replace("'", "`", $m);		$m = str_replace("\"", "`", $m);		$m = str_replace("ä", "ae", $m);		$m = str_replace("ö", "oe", $m);		$m = str_replace("ü", "ue", $m);		$m = str_replace("ß", "ss", $m);		$m = str_replace("Ä", "Ae", $m);		$m = str_replace("Ö", "Oe", $m);		$m = str_replace("Ü", "Ue", $m);		$m = str_replace("[->OK]", "", $m);		$m = str_replace("\r", "", $m);		$m = str_replace("\n", "", $m);		$m = str_replace("<", "", $m);		$m = str_replace(">", "", $m);		return $m;	}}class TransformerError{	public $Number;	public $Message;	public $Timestamp;	public $Level;	function __construct($line = 0)	{		if ($line) {			$cols = explode("\t", $line);			$this->Timestamp = $this->formatLogDate($cols[0]);			$this->Level = $cols[1];			if (preg_match("/\((TR\d*)\) (.*)/", $cols[3], $match)) {				$this->Number = $match[1];				if ($this->Number == "TR0220") {					$this->Level = 1;				}				$this->Message = $match[2];			} if (preg_match("/DMS-E-GENERAL (.*)/", $cols[3], $match)) {				$this->Number = "TR0109";				$this->Message = $cols[3];				$this->Level = 1;			}		}	}	private function formatLogDate($message)	{		$message = substr($message, 3);		$message = str_replace(" Jan ", ".01.", $message);		$message = str_replace(" Feb ", ".02.", $message);		$message = str_replace(" Mrz ", ".03.", $message);		$message = str_replace(" Apr ", ".04.", $message);		$message = str_replace(" Mai ", ".05.", $message);		$message = str_replace(" Jun ", ".06.", $message);		$message = str_replace(" Jul ", ".07.", $message);		$message = str_replace(" Aug ", ".08.", $message);		$message = str_replace(" Sep ", ".09.", $message);		$message = str_replace(" Okt ", ".10.", $message);		$message = str_replace(" Nov ", ".11.", $message);		$message = str_replace(" Dez ", ".12.", $message);		if (preg_match("/(\d{2}).(\d{2}).(\d{4})\s*([\d:]+)/", $message, $match)) {			return "{$match[3]}-{$match[2]}-{$match[1]}T{$match[4]}";		}		return "";	}}class WebCreatorError{	public $Number = "WC0000";	public $Message;	public $Timestamp;	public $Level = 2;	function __construct($line = 0)	{		if ($line) {			if (preg_match("/^Description: (.*)/", $line, $match)) {				$this->Message = $match[1];				if (preg_match("/Division durch Null/", $this->Message)) {					$this->Level = 4;					$this->Number = "WC0001";				}				if (preg_match("/Kategorieindex/", $this->Message)) {					$this->Level = 4;					$this->Number = "WC0002";				}							} else {				$this->Message = $line;			}		}	}}class CopyAndReplaceError{	public $Number = "CR0000";	public $Message;	public $Timestamp;	public $Level = 3;	function __construct($line = 0)	{		$this->Message = $line;	}}class WorkflowError{	public $Filename;	public $User;	public $Report;	public $ReportModified;	public $Layer;	public $MailTo;	public $Modified;		public function __toString() {		return $this->Report . ".ppr, " . $this->Layer . ": " . substr($this->Filename, -3) . " " . $this->Modified;	}}class Source{	public $Filename;	public $Report;	public $Layer;	public $Entities;	public $Duration;	function __construct($filename, $entities = 0)	{		$this->Filename = $filename;		$this->Entities = $entities;	}}class Summary{	public $Entities;	public $Categories;	public $Duration;	function __construct($entities, $categories = 0)	{		$this->Entities = $entities;		$this->Categories = $categories;	}}?>
 |