summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/hooks/config-tgz.inc.php
blob: b732fd7a548e131bcb447e449d38d45c659621a8 (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
<?php

$res = Database::simpleQuery('SELECT h.hwname FROM statistic_hw h'
	. " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)"
	. " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array(
	'projector' => 'projector',
	'screen' => HardwareInfo::SCREEN,
));

if ($res !== false) { // CHeck this in case we're running on old DB during update
	$content = '';
	foreach ($res as $row) {
		$content .= $row['hwname'] . "=beamer\n";
	}

	if (!empty($content)) {
		$tmpfile = '/tmp/bwlp-' . md5($content) . '.tar';
		if (!is_file($tmpfile) || !is_readable($tmpfile) || filemtime($tmpfile) + 86400 < time()) {
			if (file_exists($tmpfile)) {
				unlink($tmpfile);
			}
			try {
				$a = new PharData($tmpfile);
				$a->addFromString("/opt/openslx/beamergui/beamer.conf", $content);
				$file = $tmpfile;
			} catch (Exception $e) {
				EventLog::failure('Could not include beamer.conf in config.tgz', (string)$e);
				unlink($tmpfile);
			}
		} elseif (is_file($tmpfile) && is_readable($tmpfile)) {
			$file = $tmpfile;
		}
	}
}