aboutsummaryrefslogtreecommitdiffstats
path: root/util/nconfig.php
blob: a7cf350d0afd1d5ffa455b4d62c0443164b6bd0b (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
#!/usr/bin/env php
<?php

/**
* switch off channel email notifications utility
* This is a preliminary solution using the existing functions from include/channel.php. 
* More options would be nice.
**/

if(! file_exists('include/cli_startup.php')) {
    echo 'Run from the top level $Projectname web directory, as util/nconfig <args>' . PHP_EOL;
    exit(1);
}

require_once('include/cli_startup.php');
require_once('include/channel.php');

cli_startup();


	if($argc != 2) {
		echo 'Usage: util/nconfig channel_id|channel_address off' . PHP_EOL;
		exit(1);
	}

	if(ctype_digit($argv[1])) {
		$c = channelx_by_n($argv[1]);
	}
	else {
		$c = channelx_by_nick($argv[1]);
	}

	if(! $c) {
		echo t('Source channel not found.');
		exit(1);
	}

	switch ($argv[2]) {
		case 'off':
			$result = notifications_off($c['channel_id']);
			break;
		default:
			echo 'Only on or off in lower cases are allowed' . PHP_EOL;
			exit(1);
	}

	if($result['success'] == false) {
		echo $result['message'];
		exit(1);
	}

	exit(0);