console.php 8.25 KB
Newer Older
amette's avatar
amette committed
1
#!/usr/bin/php
2
<?php
3
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
4 5 6 7 8 9 10
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

use Symfony\Component\Console\Input\ArgvInput;

11
define('TIKI_CONSOLE', 1);
12 13 14 15 16 17 18 19 20
declare(ticks = 1); // how often to check for signals

if (function_exists('pcntl_signal')) {
	$exit = function () {
		error_reporting(0); // Disable error reporting, misleading backtrace on kill
		exit;
	};

	pcntl_signal(SIGTERM, $exit);
changi67's avatar
changi67 committed
21
	pcntl_signal(SIGHUP, $exit);
22 23 24 25
	pcntl_signal(SIGINT, $exit);
}


26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
if (isset($_SERVER['REQUEST_METHOD'])) {
	die('Only available through command-line.');
}

require_once 'tiki-filter-base.php';
require_once 'lib/init/initlib.php';
include_once('lib/init/tra.php');
require_once('lib/setup/tikisetup.class.php');
require_once 'lib/setup/twversion.class.php';

$input = new ArgvInput;

if (false !== $site = $input->getParameterOption(array('--site'))) {
	$_SERVER['TIKI_VIRTUAL'] = $site;
}

$local_php = TikiInit::getCredentialsFile();

44 45 46 47
if (! is_readable($local_php)) {
	die("Credentials file local.php not found. See http://doc.tiki.org/Installation for more information.\n");
}

48 49
$console = new Tiki\Command\Application;

50
$console->add(new Tiki\Command\ConfigureCommand);
51
if (is_file($local_php) || TikiInit::getEnvironmentCredentials()) {
52
	require_once 'db/tiki-db.php';
53 54
	$console->add(new Tiki\Command\InstallCommand);
	$console->add(new Tiki\Command\UpdateCommand);
55 56
	$console->add(new Tiki\Command\MultiTikiListCommand);
	$console->add(new Tiki\Command\MultiTikiMoveCommand);
57 58 59
} else {
	$console->add(new Tiki\Command\UnavailableCommand('database:install'));
	$console->add(new Tiki\Command\UnavailableCommand('database:update'));
60 61
	$console->add(new Tiki\Command\UnavailableCommand('multitiki:list'));
	$console->add(new Tiki\Command\UnavailableCommand('multitiki:move'));
62
}
63

64
$installer = $installer = new Installer;
65
$isInstalled = $installer->isInstalled();
66

67
if ($isInstalled) {
68
	$bypass_siteclose_check = true;
69 70 71 72 73
	try {
		require_once 'tiki-setup.php';
	} catch (Exception $e) {
		$console->renderException($e, new \Symfony\Component\Console\Output\ConsoleOutput());
	}
74 75 76 77 78 79 80 81 82 83 84

	if (! $asUser = $input->getParameterOption(array('--as-user'))) {
		$asUser = 'admin';
	}

	if (TikiLib::lib('user')->user_exists($asUser)) {
		$permissionContext = new Perms_Context($asUser);
	}
}

if ($isInstalled) {
85
	$console->add(new Tiki\Command\CacheClearCommand);
86
	$console->add(new Tiki\Command\LessCompileCommand);
87
	$console->add(new Tiki\Command\BackupDBCommand);
88
	$console->add(new Tiki\Command\BackupFilesCommand);
89
	$console->add(new Tiki\Command\ProfileBaselineCommand);
90
} else {
drsassafras's avatar
drsassafras committed
91 92 93 94 95
	$console->add(new Tiki\Command\UnavailableCommand('cache:clear'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('less:compile'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('database:backup'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('backup:files'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('profile:baseline'))->ignoreValidationErrors();
96 97
}

98
if ($isInstalled && ! $installer->requiresUpdate()) {
99 100
	$console->add(new Tiki\Command\AddonInstallCommand);
	$console->add(new Tiki\Command\AddonRemoveCommand);
101
	$console->add(new Tiki\Command\AddonUpgradeCommand);
102
	$console->add(new Tiki\Command\DailyReportSendCommand);
103
	$console->add(new Tiki\Command\GoalCheckCommand);
104
	$console->add(new Tiki\Command\FilesBatchuploadCommand);
105
	$console->add(new Tiki\Command\FilesCopyCommand);
106
	$console->add(new Tiki\Command\FilesDeleteoldCommand);
107
	$console->add(new Tiki\Command\FilesMoveCommand);
108 109 110
	$console->add(new Tiki\Command\IndexRebuildCommand);
	$console->add(new Tiki\Command\IndexOptimizeCommand);
	$console->add(new Tiki\Command\IndexCatchUpCommand);
drsassafras's avatar
drsassafras committed
111
	$console->add(new Tiki\Command\ListExecuteCommand);
112
	$console->add(new Tiki\Command\MailInPollCommand);
113
    $console->add(new Tiki\Command\MailQueueSendCommand);
114
	$console->add(new Tiki\Command\NotificationDigestCommand);
115 116
	$console->add(new Tiki\Command\ProfileForgetCommand);
	$console->add(new Tiki\Command\ProfileInstallCommand);
117
	$console->add(new Tiki\Command\ProfileExport\Init);
118
	$console->add(new Tiki\Command\RecommendationBatchCommand);
119
	$console->add(new Tiki\Command\RefreshRssCommand);
drsassafras's avatar
drsassafras committed
120
	$console->add(new Tiki\Command\RssClearCacheCommand);
121
	$console->add(new Tiki\Command\TrackerImportCommand);
122
	$console->add(new Tiki\Command\TrackerClearCommand);
123
} else {
drsassafras's avatar
drsassafras committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
	$console->add(new Tiki\Command\UnavailableCommand('addon:install'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('addon:remove'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('addon:upgrade'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('daily-report:send'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('goal:check'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('files:batchupload'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('files:deleteold'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('index:rebuild'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('index:optimize'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('index:catch-up'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('list:execute'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('mail-in:poll'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('mail-queue:send'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('notification:digest'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('profile:forget'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('profile:apply'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('profile:export:init'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('recommendation:batch'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('rss:refresh'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('rss:clear'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('tracker:import'))->ignoreValidationErrors();
	$console->add(new Tiki\Command\UnavailableCommand('tracker:clear'))->ignoreValidationErrors();
146 147 148
}

if (file_exists('profiles/info.ini')) {
149 150
	$console->add(new Tiki\Command\ProfileExport\ActivityRuleSet);
	$console->add(new Tiki\Command\ProfileExport\ActivityStreamRule);
151
	$console->add(new Tiki\Command\ProfileExport\Article);
152 153
	$console->add(new Tiki\Command\ProfileExport\ArticleTopic);
	$console->add(new Tiki\Command\ProfileExport\ArticleType);
154
	$console->add(new Tiki\Command\ProfileExport\AllModules);
155
	$console->add(new Tiki\Command\ProfileExport\Category);
156
	$console->add(new Tiki\Command\ProfileExport\FileGallery);
157
	$console->add(new Tiki\Command\ProfileExport\Forum);
158 159
	$console->add(new Tiki\Command\ProfileExport\Goal);
	$console->add(new Tiki\Command\ProfileExport\GoalSet);
160
	$console->add(new Tiki\Command\ProfileExport\Group);
161
	$console->add(new Tiki\Command\ProfileExport\IncludeProfile);
162
	$console->add(new Tiki\Command\ProfileExport\Menu);
163
	$console->add(new Tiki\Command\ProfileExport\Module);
164
	$console->add(new Tiki\Command\ProfileExport\Preference);
165 166
	$console->add(new Tiki\Command\ProfileExport\RatingConfig);
	$console->add(new Tiki\Command\ProfileExport\RatingConfigSet);
167
	$console->add(new Tiki\Command\ProfileExport\RecentChanges);
168
	$console->add(new Tiki\Command\ProfileExport\Rss);
169 170 171 172
	$console->add(new Tiki\Command\ProfileExport\Tracker);
	$console->add(new Tiki\Command\ProfileExport\TrackerField);
	$console->add(new Tiki\Command\ProfileExport\WikiPage);

173
	$console->add(new Tiki\Command\ProfileExport\Finalize);
174 175
}

amette's avatar
amette committed
176 177 178
if (is_file('db/redact/local.php') && ($site == 'redact') ) {
	$console->add(new Tiki\Command\RedactDBCommand);
} else {
drsassafras's avatar
drsassafras committed
179
	$console->add(new Tiki\Command\UnavailableCommand('database:redact'))->ignoreValidationErrors();
amette's avatar
amette committed
180 181
}

182
$console->run();