summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/statisticshooks.inc.php
blob: 6b9dfa217a9ac38435951a8098594afc1ca809b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

class StatisticsHooks
{

	private static $row = false;

	private static function getRow(string $machineuuid)
	{
		if (self::$row !== false)
			return;
		self::$row = Database::queryFirst('SELECT hostname, clientip, locationid FROM machine WHERE machineuuid = :machineuuid',
			['machineuuid' => $machineuuid]);
	}

	/**
	 * Hook for baseconfig.
	 * @return false|string Client name, or false if invalid
	 */
	public static function getBaseconfigName(string $machineuuid)
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return false;
		return self::$row['hostname'] ?: self::$row['clientip'];
	}

	/**
	 * Hook for baseconfig.
	 */
	public static function baseconfigLocationResolver(string $machineuuid): int
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return 0;
		return (int)self::$row['locationid'];
	}

	/**
	 * Hook to get inheritance tree for all config vars.
	 *
	 * @param string $machineuuid MachineUUID currently being edited
	 */
	public static function baseconfigInheritance(string $machineuuid): array
	{
		self::getRow($machineuuid);
		if (self::$row === false)
			return [];
		BaseConfig::prepareWithOverrides([
			'locationid' => self::$row['locationid'] ?? 0
		]);
		return ConfigHolder::getRecursiveConfig(true);
	}

}