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
8namespace Tiki\Command\ProfileExport;
9
10use Symfony\Component\Console\Input\InputArgument;
11use Symfony\Component\Console\Input\InputInterface;
12use Symfony\Component\Console\Input\InputOption;
13use Symfony\Component\Console\Output\OutputInterface;
14
15class Preference extends ObjectWriter
16{
17	protected function configure()
18	{
19		$this
20			->setName('profile:export:preference')
21			->setDescription('Include a preference within the profile definition')
22			->addOption(
23				'all',
24				null,
25				InputOption::VALUE_NONE,
26				'Export all preferences'
27			)
28			->addArgument(
29				'name',
30				InputArgument::OPTIONAL,
31				'Preference name'
32			);
33	}
34
35	protected function execute(InputInterface $input, OutputInterface $output)
36	{
37		$preference = $input->getArgument('name');
38		$all = $input->getOption('all');
39
40		if (! $all && empty($preference)) {
41			$output->writeln('<error>' . tra('Not enough arguments (missing: "name" or "--all" options)') . '</error>');
42			return false;
43		}
44
45		$writer = $this->getProfileWriter($input);
46
47		$prefslib = \TikiLib::lib('prefs');
48		$result = $prefslib->exportPreference($writer, $preference, $all);
49
50		if ($result) {
51			$writer->save();
52		} else {
53			$output->writeln("Preference not found: $preference");
54		}
55	}
56}
57