1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class Tiki_Profile_InstallHandler_DataChannel extends Tiki_Profile_InstallHandler
9{
10	function getData()
11	{
12		if ($this->data) {
13			return $this->data;
14		}
15
16		$defaults = [
17			'domain' => 'tiki://local',
18			'groups' => [ 'Admins' ],
19		];
20
21		$data = array_merge($defaults, $this->obj->getData());
22
23		return $this->data = $data;
24	}
25
26	function canInstall()
27	{
28		$data = $this->getData();
29		if (! isset($data['name'], $data['profile'])) {
30			return false;
31		}
32		if (! is_array($data['groups'])) {
33			return false;
34		}
35		if (! is_string($data['domain'])) {
36			return false;
37		}
38
39		return true;
40	}
41
42	function _install()
43	{
44		global $tikilib, $prefs;
45		$channels = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']);
46
47		$data = $this->getData();
48
49		$this->replaceReferences($data);
50
51		$channels->addChannel($data['name'], $data['domain'], $data['profile'], $data['groups']);
52		$tikilib->set_preference('profile_channels', $channels->getConfiguration());
53
54		return $data['name'];
55	}
56}
57