summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/sysconfig.inc.php
blob: 362ce1a96ea913d2dcb80aa26379f714b5026ff9 (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
<?php

class SysConfig
{

	/**
	 * @return array{array{configid: int, title: string, filepath: string, status: string, locs: string}}
	 */
	public static function getAll(): array
	{
		return Database::queryAll("SELECT c.configid, c.title, c.filepath, c.status, Group_Concat(cl.locationid) AS locs
				FROM configtgz c
				LEFT JOIN configtgz_location cl USING (configid) GROUP BY c.configid");
	}

	public static function archiveContentsFromTask($status, &$userGroupWarn = null) : array
	{
		// Sort files for better display
		$dirs = array();
		foreach ($status['data']['entries'] as $file) {
			if ($file['isdir']) continue;
			$dirs[dirname($file['name'])][] = $file;
			if ($file['userId'] > 0 || $file['groupId'] > 0) {
				$userGroupWarn = true;
			}
		}
		ksort($dirs);
		$list = array();
		foreach ($dirs as $dir => $files) {
			$list[] = array(
				'name' => $dir,
				'isdir' => true
			);
			sort($files);
			foreach ($files as $file) {
				$file['size'] = Util::readableFileSize($file['size']);
				$list[] = $file;
			}
		}
		return $list;
	}

}