fix(remotepc): properly evaluate negative and positive calendar rules
parent
6d63ca00df
commit
e8f5fe12d3
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## [1.11.1] - 2026-10-02
|
||||
|
||||
### Fixed
|
||||
- **RemotePC Calendars**: Rediseñada por completo la lógica de evaluación en `RemoteCalendar::isAvailable()`. Se ha solucionado un error grave donde las reglas de calendario (especialmente las negativas) se ignoraban de forma silente al depender del orden y salir prematuramente del bucle con valores positivos. Ahora, las reglas negativas bloquean inmediatamente la disponibilidad, y las positivas exigen cumplimiento estricto, respetando casos de calendarios con solo reglas negativas.
|
||||
|
||||
## [1.11.0] - 2026-10-02
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -88,29 +88,39 @@ class RemoteCalendar extends AbstractEntity
|
|||
{
|
||||
$now = new \DateTime();
|
||||
|
||||
$hasPositiveRules = false;
|
||||
$matchesPositiveRule = false;
|
||||
|
||||
foreach ($this->getRules() as $rule) {
|
||||
if ($rule->isRemoteAvailable()) {
|
||||
if (!$rule->isRemoteAvailable()) {
|
||||
// Negative rule: If we are currently inside it, immediately return false
|
||||
$dayOfWeek = (int) $now->format('w');
|
||||
$adjustedDayOfWeek = ($dayOfWeek + 6) % 7;
|
||||
|
||||
if (in_array($adjustedDayOfWeek, $rule->getBusyWeekdays() ?? [])) {
|
||||
$currentTime = $now->format('H:i');
|
||||
if ($currentTime >= $rule->getBusyFromHour() && $currentTime <= $rule->getBusyToHour()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Positive rule: Record that we have them, and check if we match any
|
||||
$hasPositiveRules = true;
|
||||
|
||||
$fromDate = $rule->getAvailableFromDate();
|
||||
$toDate = $rule->getAvailableToDate();
|
||||
|
||||
if ($fromDate && $toDate && $fromDate <= $now && $now <= $toDate) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$dayOfWeek = (int) $now->format('w');
|
||||
$adjustedDayOfWeek = ($dayOfWeek + 6) % 7;
|
||||
|
||||
if (!in_array($adjustedDayOfWeek, $rule->getBusyWeekdays())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentTime = $now->format('H:i');
|
||||
if (!($currentTime >= $rule->getBusyFromHour() && $currentTime <= $rule->getBusyToHour())) {
|
||||
return true;
|
||||
$matchesPositiveRule = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// If there are positive rules defined, we MUST match at least one
|
||||
if ($hasPositiveRules && !$matchesPositiveRule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue