[$today], 'openingtime' => $open, 'closingtime' => $close ]]); Database::exec('UPDATE location SET openingtime = :ot WHERE locationid = 1', ['ot' => $json]); } public function testSetLocationOptionsCreatesOrDeletesSchedule(): void { // Initially, no schedule rows $row0 = Database::queryFirst('SELECT COUNT(*) AS c FROM reboot_scheduler'); $this->assertSame(0, (int)$row0['c']); // Enable WOL with small offset -> creates a schedule with next execution in future Scheduler::setLocationOptions(1, ['wol' => true, 'sd' => false, 'wol-offset' => 5, 'sd-offset' => 0, 'ra-mode' => Scheduler::RA_ALWAYS]); $row = Database::queryFirst('SELECT * FROM reboot_scheduler WHERE locationid = 1'); $this->assertNotFalse($row); $this->assertSame('WOL', $row['action']); $this->assertGreaterThan(time(), (int)$row['nextexecution']); $opts = json_decode($row['options'], true); $this->assertIsArray($opts); $this->assertTrue($opts['wol']); // Disable all (and RA_ALWAYS) -> deletes schedule Scheduler::setLocationOptions(1, ['wol' => false, 'sd' => false, 'wol-offset' => 0, 'sd-offset' => 0, 'ra-mode' => Scheduler::RA_ALWAYS]); $row2 = Database::queryFirst('SELECT * FROM reboot_scheduler WHERE locationid = 1'); $this->assertFalse($row2); } public function testUpdateScheduleRecursiveUpdatesChildrenWithoutOwnTimes(): void { // Give child (2) no opening times and write options Database::exec('UPDATE location SET openingtime = NULL WHERE locationid = 2'); // Assign options to child 2 Scheduler::setLocationOptions(2, ['wol' => true, 'sd' => false, 'wol-offset' => 0, 'sd-offset' => 0, 'ra-mode' => Scheduler::RA_ALWAYS]); // Now modify parent (1) opening time again -> should update child's schedule $today = date('l'); $json = json_encode([[ 'days' => [$today], 'openingtime' => '23:59', 'closingtime' => '23:59' ]]); Database::exec('UPDATE location SET openingtime = :ot WHERE locationid = 1', ['ot' => $json]); // Trigger recalculation by setting location options on parent (even if unchanged) Scheduler::setLocationOptions(1, ['wol' => true, 'sd' => false, 'wol-offset' => 0, 'sd-offset' => 0, 'ra-mode' => Scheduler::RA_ALWAYS]); $child = Database::queryFirst('SELECT * FROM reboot_scheduler WHERE locationid = 2'); $this->assertNotFalse($child); $this->assertGreaterThanOrEqual(0, (int)$child['nextexecution']); } }