correction de bugs
This commit is contained in:
		
							
								
								
									
										128
									
								
								events.php
									
									
									
									
									
								
							
							
						
						
									
										128
									
								
								events.php
									
									
									
									
									
								
							| @@ -12,38 +12,44 @@ function checkEvents() | ||||
| 	$oldLevel = $logLevel; | ||||
| 	//$logLevel = DEBUG; | ||||
| 	$exception = false; | ||||
| 	/*if ($events === null) | ||||
| 	if ($events === null) | ||||
| 	{ | ||||
| 		$events = array(); | ||||
| 	}*/ | ||||
| 	} | ||||
| 	//var_dump($events); | ||||
| 	$now = now(); | ||||
| 	foreach ($events as $key => &$event) | ||||
| 	if (!empty($events)) | ||||
| 	{ | ||||
|  | ||||
| 		if($event->dateTimeEvent < $now) | ||||
| 		foreach ($events as $key => &$event) | ||||
| 		{ | ||||
| 			if (is_callable($event->function)) | ||||
|  | ||||
| 			if($event->dateTimeEvent < $now) | ||||
| 			{ | ||||
| 				logger(DEBUG, _("executing function") . $event->function[1], __FILE__ . ":" . __LINE__); | ||||
| 				$event->function($event); | ||||
| 			}elseif (is_object($event->device)) | ||||
| 			{ | ||||
| 				logger(DEBUG, sprintf(_("sending command set %s => %s  for %s"), $event->param ,bool2string($event->value), $event->device->friendlyName), __FILE__ . ":" . __LINE__); | ||||
| 				publish(mktopic($event->device), array($event->param => $event->value), "set"); | ||||
| 				if ($event->method !== null)	$event->device->properties[$event->param]["method"] = $event->method; | ||||
| 			}else | ||||
| 			{ | ||||
| 				logger(ERROR, _("Event is malformed") . $key, __FILE__ . ":" . __LINE__); | ||||
| 				logger(DEBUG, _("Executing event") . $key, __FILE__ . ":" . __LINE__); | ||||
| 				if (is_callable($event->function)) | ||||
| 				{ | ||||
| 					logger(DEBUG, _("executing function") . $event->function[1], __FILE__ . ":" . __LINE__); | ||||
| 					$event->function($event); | ||||
| 				}elseif (is_object($event->device)) | ||||
| 				{ | ||||
| 					logger(DEBUG, sprintf(_("sending command set %s => %s  for %s"), $event->param ,bool2string($event->value), $event->device->friendlyName), __FILE__ . ":" . __LINE__); | ||||
| 					publish(mktopic($event->device), array($event->param => $event->value), "set"); | ||||
| 					if ($event->method !== null)	$event->device->properties[$event->param]["method"] = $event->method; | ||||
| 				}else | ||||
| 				{ | ||||
| 					logger(ERROR, _("Event is malformed") . $key, __FILE__ . ":" . __LINE__); | ||||
| 				} | ||||
|  | ||||
| 				$event->published = $now; | ||||
| 				if (!empty($event->recurrence)) | ||||
| 				{ | ||||
| 					nextOccurence($event, $key); | ||||
| 				}else | ||||
| 				{ | ||||
| 					logger(DEBUG, _("Unsetting event") . $key, __FILE__ . ":" . __LINE__); | ||||
| 					unset($events[$key]); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			$event->published = $now; | ||||
| 		} | ||||
| 		if (!empty($event->recurrence)) | ||||
| 		{ | ||||
| 			nextOccurence($event, $key, $now); | ||||
| 		}else | ||||
| 		{ | ||||
| 			unset($events[$key]); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -125,7 +131,7 @@ function nextDate(&$event) | ||||
| 	$event->dateTimeEvent->setTime(intval($hour), intval($minutes), intval($seconds)); | ||||
| } | ||||
|  | ||||
| function exceptionsTest(&$event, $now) | ||||
| function exceptionsTest(&$event, $date) | ||||
| { | ||||
| 	$exception = false; | ||||
|  | ||||
| @@ -146,10 +152,10 @@ function exceptionsTest(&$event, $now) | ||||
| 	return $exception; | ||||
| } | ||||
|  | ||||
| function nextOccurence(&$event, $eventKey, $now) | ||||
| function nextOccurence(&$event, $eventKey) | ||||
| { | ||||
| 	$n = 0; | ||||
| 	logger(DEBUG, _("Calculating next occurence"), __FILE__ . ":" . __LINE__); | ||||
| 	logger(DEBUG, _("Calculating next occurence of event #") . $event->key, __FILE__ . ":" . __LINE__); | ||||
| 	do | ||||
| 	{ | ||||
| 		if ($event->isInterval === true) | ||||
| @@ -164,7 +170,7 @@ function nextOccurence(&$event, $eventKey, $now) | ||||
| 			logger(ERROR, _("infinite loop"), __FILE__ . ":" . __LINE__); | ||||
| 			return 1; | ||||
| 		} | ||||
| 	}while (exceptionsTest($event, $now) === true);			// loop until the date is not comprise in exceptions dates | ||||
| 	}while (exceptionsTest($event, $event->dateTimeEvent) === true);			// loop until the date is not comprise in exceptions dates | ||||
| } | ||||
|  | ||||
| // datetime format : "yyyy-mm-dd hh:mm:ss" | ||||
| @@ -173,7 +179,8 @@ function setOneshotEvent(device &$deviceObject, string $datetime, $property, $va | ||||
| { | ||||
| 	global $events; | ||||
| 	$events[] = new event; | ||||
| 	$key = key($events); | ||||
| 	$key = array_key_last($events); | ||||
| 	$events[$key]->key = $key; | ||||
| 	$events[$key]->dateTimeEvent = new dateTime($datetime); | ||||
| 	$events[$key]->ieeeAddress = $deviceObject->ieeeAddress; | ||||
| 	$events[$key]->topic = $deviceObject->topic; | ||||
| @@ -186,30 +193,41 @@ function setOneshotEvent(device &$deviceObject, string $datetime, $property, $va | ||||
|  | ||||
| // startDatetime and stopDatetime format : "yyyy-mm-dd hh:mm:ss" | ||||
|  | ||||
| function setRecurrentEvent($function, $ieeeAddress, string $property, $value, bool $isInterval, string $startDatetime, string $stopDatetime, int $hours, int $minutes, int $seconds, int $days, int $weeks, int $months, int $years, int $method = null) | ||||
| function setRecurrentEvent(string $id, $function, string $ieeeAddress, string $property, $value, int $method=0 , string $startDatetime,  string $stopDatetime, bool $isInterval, int $hours=0, int $minutes=0, int $seconds=0, int $days=0, int $weeks=0, int $months=0, int $years=0) | ||||
| { | ||||
| 	global $events, $indexDevices; | ||||
| 	$string =""; | ||||
| 	$stringTemp = ""; | ||||
|  | ||||
| 	logger(INFO, _("Setting recurrent event"), __FILE__ . ":" . __LINE__); | ||||
|  | ||||
| 	$string = "P"; | ||||
| 	if (!empty($years))		$string .= $years . "Y"; | ||||
| 	if (!empty($months))	$string .= $months . "M"; | ||||
| 	if (!empty($week))		$string .= $week . "W"; | ||||
| 	if (!empty($days))		$string .= $days . "D"; | ||||
| 	$string .= "T"; | ||||
| 	if (!empty($hours))  $string .= $hours . "H"; | ||||
| 	if (!empty($minutes))  $string .= $minutes . "M"; | ||||
| 	if (!empty($seconds))  $string .= $seconds . "S"; | ||||
| 	if (!empty($years))		$stringTemp .= $years . "Y"; | ||||
| 	if (!empty($months))	$stringTemp .= $months . "M"; | ||||
| 	if (!empty($week))		$stringTemp .= $week . "W"; | ||||
| 	if (!empty($days))		$stringTemp .= $days . "D"; | ||||
| 	if (!empty($stringTemp))	$string = "P" . $stringTemp; | ||||
| 	$stringTemp = ""; | ||||
| 	if (!empty($hours))  $stringTemp .= $hours . "H"; | ||||
| 	if (!empty($minutes))  $stringTemp .= $minutes . "M"; | ||||
| 	if (!empty($seconds))  $stringTemp .= $seconds . "S"; | ||||
| 	if (!empty($stringTemp))	$string .= "T" . $stringTemp; | ||||
|  | ||||
| 	logger(DEBUG, _("reccurrent event string : ") . $string, __FILE__ . ":" . __LINE__); | ||||
|  | ||||
|  | ||||
| 	$key = searchEventByID($id); | ||||
| 	if($key !== false) | ||||
| 	{ | ||||
| 		deleteEvent($key); | ||||
| 	} | ||||
| 	$event = new event; | ||||
|  | ||||
| 	$event->id = $id; | ||||
| 	//  pb in  recurrent event in case of date and not interval | ||||
| 	if ($isInterval === true) | ||||
| 	{ | ||||
| 		if (($event->dateTimeEvent->add($event->recurrence)) === false) | ||||
| 		{ | ||||
| 			logger(ERROR, _("Error in event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__); | ||||
| 			logger(ERROR, _("Error in event recurrence. event: ") . $id , __FILE__ . ":" . __LINE__); | ||||
| 			return true; | ||||
| 		} | ||||
| 		$event->recurrence = new DateInterval($string); | ||||
| @@ -226,14 +244,16 @@ function setRecurrentEvent($function, $ieeeAddress, string $property, $value, bo | ||||
| 	}else | ||||
| 	{ | ||||
| 		$event->startDatetime = now(); | ||||
| 		logger(DEBUG, _("Datetime is ") . $event->startDatetime->format("Y-m-d H:i:s"), __FILE__ . ":" . __LINE__); | ||||
| 	} | ||||
|  | ||||
| 	if (!empty($stopDatetime)) | ||||
| 	{ | ||||
| 		$event->stopDatetime		= new datetime($stopDatetime); | ||||
| 		$event->stopDatetime = new datetime($stopDatetime); | ||||
| 	} | ||||
|  | ||||
| 	$event->dateTimeEvent = $event->startDatetime; | ||||
|  | ||||
| 	if (!empty($ieeeAddress)) | ||||
| 	{ | ||||
| 		$event->ieee_address		= $ieeeAddress; | ||||
| @@ -245,10 +265,14 @@ function setRecurrentEvent($function, $ieeeAddress, string $property, $value, bo | ||||
|  | ||||
| 	if ($method !== null)	$event->method = $method; | ||||
| 	$events[] = $event; | ||||
| 	return false; | ||||
| 	$r = key($events); | ||||
| 	$events[$r]->key = $r; | ||||
| 	$events[$r]->dateTimeEvent = nextOccurence($events[$r], $r); | ||||
|  | ||||
| 	return $r; | ||||
| } | ||||
|  | ||||
| function setDelay(device &$deviceObject, float $delay, string $unit, string $property, $value, $function, bool $replace=false, int $method = null) | ||||
| function setDelay(device &$deviceObject, float $delay, string $unit, string $property, $value, $function, bool $replace=false, int $method=null) | ||||
| { | ||||
| 	global $events, $logLevel; | ||||
| 	$oldLevel = $logLevel; | ||||
| @@ -336,6 +360,20 @@ function searchEvent(device $deviceObject, string $property, $value, $function=n | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| function searchEventByID($id) | ||||
| { | ||||
| 	global $events; | ||||
| 	logger(DEBUG, sprintf(_("searching event by ID %s"), $id), __FILE__ . ":" . __LINE__); | ||||
| 	foreach($events as $key => $event) | ||||
| 	{ | ||||
| 		if ($event->id == $id) | ||||
| 		{ | ||||
| 			return $key; | ||||
| 		} | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| // warning delete event does not manage method of the device (IDLE, ) | ||||
| function deleteEvent(int $eventKey) | ||||
| { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user