1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: abstract class Horde_Core_Bundle
14: {
15: 16: 17:
18: protected $_cli;
19:
20: 21: 22:
23: protected $_config;
24:
25: 26: 27: 28: 29:
30: protected $_pearconf;
31:
32: 33: 34:
35: public function __construct(Horde_Core_Cli $cli, $pearconf = null)
36: {
37: $this->_cli = $cli;
38: $this->_pearconf = $pearconf;
39: }
40:
41: 42: 43:
44: public function init()
45: {
46:
47: if ((file_exists(HORDE_BASE . '/config/conf.php') &&
48: !is_writable(HORDE_BASE . '/config/conf.php')) ||
49: !is_writable(HORDE_BASE . '/config')) {
50: $this->_cli->message(Horde_Util::realPath(HORDE_BASE . '/config/conf.php') . ' is not writable.', 'cli.error');
51: }
52:
53:
54: if (!file_exists(HORDE_BASE . '/config/conf.php')) {
55: copy(HORDE_BASE . '/config/conf.php.dist', HORDE_BASE . '/config/conf.php');
56: }
57:
58:
59: $umask = umask();
60: Horde_Registry::appInit('horde', array('nocompress' => true, 'authentication' => 'none'));
61: $this->_config = new Horde_Config();
62: umask($umask);
63: }
64:
65: 66: 67:
68: public function configDb()
69: {
70: $this->_cli->writeln();
71: $this->_cli->writeln($this->_cli->bold('Configuring database settings'));
72: $this->_cli->writeln();
73:
74: $sql_config = $this->_config->configSQL('');
75: $vars = new Horde_Variables();
76: new Horde_Config_Form($vars, 'horde', true);
77: $this->_cli->question(
78: $vars,
79: 'sql',
80: 'phptype',
81: $sql_config['switch']['custom']['fields']['phptype']);
82:
83: $this->writeConfig($vars);
84: }
85:
86: 87: 88: 89: 90:
91: public function migrateDb()
92: {
93: $this->_cli->writeln();
94: echo 'Creating and updating database tables...';
95:
96: $migration = new Horde_Core_Db_Migration(null, $this->_pearconf);
97:
98:
99: for ($i = 0; $i < 2; $i++) {
100: $error = null;
101: foreach ($migration->apps as $app) {
102: $migrator = $migration->getMigrator($app);
103: if ($migrator->getTargetVersion() <= $migrator->getCurrentVersion()) {
104: continue;
105: }
106: try {
107: $migrator->up();
108: } catch (Exception $error) {
109: if ($i) {
110: throw $error;
111: }
112: }
113: }
114: if (!$error) {
115: break;
116: }
117: }
118:
119: $this->_cli->writeln($this->_cli->green(' done.'));
120: }
121:
122: 123: 124: 125:
126: public function configAuth()
127: {
128: $vars = new Horde_Variables();
129: new Horde_Config_Form($vars, 'horde', true);
130: $this->_cli->writeln();
131: $this->_cli->writeln($this->_cli->bold('Configuring administrator settings'));
132: $admin_user = $this->_configAuth($vars);
133: $vars->auth__admins = $admin_user;
134: $this->writeConfig($vars);
135: }
136:
137: 138: 139:
140: abstract protected function _configAuth(Horde_Variables $vars);
141:
142: 143: 144: 145: 146:
147: public function writeConfig(Horde_Variables $vars)
148: {
149: $this->_cli->writeln();
150: echo 'Writing main configuration file...';
151:
152: $php_config = $this->_config->generatePHPConfig($vars, $GLOBALS['conf']);
153: $configFile = $this->_config->configFile();
154: $fp = fopen($configFile, 'w');
155: if (!$fp) {
156: throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile));
157: }
158: fwrite($fp, $php_config);
159: fclose($fp);
160:
161:
162: include $configFile;
163: $GLOBALS['conf'] = $conf;
164:
165: $this->_cli->writeln($this->_cli->green(' done.'));
166: }
167:
168: 169: 170: 171: 172:
173: public function writeAllConfigs()
174: {
175: foreach ($GLOBALS['registry']->listAllApps() as $app) {
176: if ($app == 'horde' ||
177: !file_exists($GLOBALS['registry']->get('fileroot', $app) . '/config/conf.xml')) {
178: continue;
179: }
180: $config = new Horde_Config($app);
181: $configFile = $config->configFile();
182: if (!$config->writePHPConfig(new Horde_Variables())) {
183: throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile));
184: }
185: }
186: }
187: }
188: