summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/hooks/client-update.inc.php
blob: a8ffd555362ae3ff688024cf7f33904652072978 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

// Either poweron or user logged in
if ($type === '~poweron' || ($type === '~runstate' && $used === 1 && $old['state'] !== 'OCCUPIED')) {
	// Get all the clients that are managers for rooms this client is a tutor for.
	// Start in the machine table aliased tut, map $ip to client uuid, then look this
	// up in the location_roomplan table as tutoruuid, get the according managerip,
	// look this one up again in machine table aliased mgr to finally get the according
	// mac address of that manager. We need that for WOL.
	$managers = Database::queryAll('SELECT mgr.machineuuid, mgr.clientip, mgr.macaddr
					FROM machine tut
					INNER JOIN location_roomplan lr ON (tut.machineuuid = lr.tutoruuid)
					INNER JOIN machine mgr ON (lr.managerip = mgr.clientip)
					WHERE tut.clientip = :tutorip', ['tutorip' => $ip]);
	if (!empty($managers) && Module::isAvailable('rebootcontrol')) {
		// Create WOL job
		RebootControl::wakeMachines($managers);
	}
}