aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Import_progress.php
blob: 06498f6497bbebb60ff67c75a32d97b528dc2fe9 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Zotlabs\Module;

use Zotlabs\Lib\PConfig;
use Zotlabs\Daemon\Master;

class Import_progress extends \Zotlabs\Web\Controller {

	function post() {

		if(! local_channel())
			return;

	}

	function get() {

		if(! local_channel()) {
			return;
		}

		nav_set_selected('Channel Import');

		// items
		$c = PConfig::Get(local_channel(), 'import', 'content_progress');

		if (!$c) {
			$cprogress = 'waiting to start...';
		}
		else {

			$total_cpages = floor(intval($c['items_total']) / intval($c['items_page']));
			if(!$total_cpages) {
				$total_cpages = 1; // because of floor
			}

			$cpage = $c['last_page'] + 1; // because page count start at 0

			$cprogress = intval(floor((intval($cpage) * 100) / $total_cpages));

			if(argv(1) === 'resume_itemsync' && $cprogress < 100) {
				Master::Summon($c['next_cmd']);
				goaway('/import_progress');
			}
		}

		$cprogress_str = ((intval($cprogress)) ? $cprogress . '%' : $cprogress);

		// files
		$f = PConfig::Get(local_channel(), 'import', 'files_progress');

		if (!$f) {
			$fprogress = 'waiting to start...';
		}
		else {
			$total_fpages = floor(intval($f['files_total']) / intval($f['files_page']));
			if(!$total_fpages) {
				$total_fpages = 1;
			}

			$fpage = $f['last_page'] + 1;

			$fprogress = intval(floor((intval($fpage) * 100) / $total_fpages));

			if(argv(1) === 'resume_filesync' && $fprogress < 100) {
				Master::Summon($f['next_cmd']);
				goaway('/import_progress');
			}

		}

		$fprogress_str = ((intval($fprogress)) ? $fprogress . '%' : $fprogress);

		if(is_ajax()) {
			$ret = [
				'cprogress' => $cprogress,
				'fprogress' => $fprogress
			];

			json_return_and_die($ret);
		}

		$o = replace_macros(get_markup_template("import_progress.tpl"), [
			'$cprogress_str' => $cprogress_str,
			'$cprogress' => intval($cprogress),
			'$fprogress_str' => $fprogress_str,
			'$fprogress' => intval($fprogress),
		]);

		return $o;
	}

}