|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of Project Chaplin. |
| 4 | + * |
| 5 | + * Project Chaplin is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * Project Chaplin is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with Project Chaplin. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + * @package Project Chaplin |
| 19 | + * @author Dan Dart |
| 20 | + * @copyright 2012-2013 Project Chaplin |
| 21 | + * @license http://www.gnu.org/licenses/agpl-3.0.html GNU AGPL 3.0 |
| 22 | + * @version git |
| 23 | + * @link https://github.com/dandart/projectchaplin |
| 24 | +**/ |
| 25 | +class Admin_SetupController extends Zend_Controller_Action |
| 26 | +{ |
| 27 | + public function init() |
| 28 | + { |
| 29 | + parent::init(); |
| 30 | + if (file_exists(APPLICATION_PATH.'/../config/chaplin.ini')) { |
| 31 | + return $this->_redirect('/'); |
| 32 | + } |
| 33 | + $this->_helper->_layout->setLayout('plain'); |
| 34 | + } |
| 35 | + |
| 36 | + public function indexAction() |
| 37 | + { |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + public function sqltestAction() |
| 42 | + { |
| 43 | + $arrPost = $this->_request->getPost(); |
| 44 | + $strAdapter = isset($arrPost['adapter'])?$arrPost['adapter']:null; |
| 45 | + $arrParams = isset($arrPost['params'])?$arrPost['params']:array(); |
| 46 | + |
| 47 | + $this->_helper->layout()->disableLayout(); |
| 48 | + $this->_helper->viewRenderer->setNoRender(true); |
| 49 | + |
| 50 | + try { |
| 51 | + $adapter = Zend_Db::factory($strAdapter, $arrParams); |
| 52 | + // Make sure we get a PDO instance that tries to connect |
| 53 | + $adapter->prepare('SELECT'); |
| 54 | + echo 'DB Connect Success!'; |
| 55 | + } catch (Exception $e) { |
| 56 | + echo 'DB Connect failed! Reason: '.$e->getMessage(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public function amqptestAction() |
| 61 | + { |
| 62 | + $this->_helper->layout()->disableLayout(); |
| 63 | + $this->_helper->viewRenderer->setNoRender(true); |
| 64 | + |
| 65 | + try { |
| 66 | + $amqp = new Amqp\Connection($this->_request->getPost()); |
| 67 | + $amqp->connect(); |
| 68 | + echo 'AMQP connection success!'; |
| 69 | + } catch (Exception $e) { |
| 70 | + echo 'Sorry - the connection failed...'; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + public function smtptestAction() |
| 75 | + { |
| 76 | + $this->_helper->layout()->disableLayout(); |
| 77 | + $this->_helper->viewRenderer->setNoRender(true); |
| 78 | + $arrSmtp = $this->_request->getPost(); |
| 79 | + $transport = new Zend_Mail_Transport_Smtp( |
| 80 | + $arrSmtp['host'], |
| 81 | + $arrSmtp['options'] |
| 82 | + ); |
| 83 | + |
| 84 | + // No SMTP tests exist atm |
| 85 | + } |
| 86 | + |
| 87 | + public function writeAction() |
| 88 | + { |
| 89 | + $this->_helper->layout()->disableLayout(); |
| 90 | + $this->_helper->viewRenderer->setNoRender(true); |
| 91 | + $arrPost = array( |
| 92 | + 'default' => $this->_request->getPost(), |
| 93 | + 'production' => array(), |
| 94 | + 'staging' => array(), |
| 95 | + 'development' => array() |
| 96 | + ); |
| 97 | + |
| 98 | + $schemaSql = file_get_contents(APPLICATION_PATH . '/../sql/schema.sql'); |
| 99 | + |
| 100 | + $arrDefault = $arrPost['default']; |
| 101 | + |
| 102 | + if (!isset($arrDefault['sql'])) { |
| 103 | + echo 'No SQL settings exist.'; |
| 104 | + exit; |
| 105 | + } |
| 106 | + |
| 107 | + $arrSql = $arrDefault['sql']; |
| 108 | + |
| 109 | + $strAdapter = isset($arrSql['adapter'])?$arrSql['adapter']:null; |
| 110 | + if (is_null($strAdapter)) { |
| 111 | + echo 'Did you forget to choose an adapter?'; |
| 112 | + exit; |
| 113 | + } |
| 114 | + $arrParams = isset($arrSql['params'])?$arrSql['params']:array(); |
| 115 | + |
| 116 | + try { |
| 117 | + $adapter = Zend_Db::factory($strAdapter, $arrParams); |
| 118 | + $adapter->getConnection()->exec($schemaSql); |
| 119 | + } catch (Exception $e) { |
| 120 | + echo 'Error writing DB. Please refresh and try again.'; |
| 121 | + exit(); |
| 122 | + } |
| 123 | + |
| 124 | + $config = new Zend_Config($arrPost, true); |
| 125 | + $config->setExtend('production', 'default'); |
| 126 | + $config->setExtend('staging', 'production'); |
| 127 | + $config->setExtend('development', 'production'); |
| 128 | + |
| 129 | + $iniWriter = new Zend_Config_Writer_Ini(); |
| 130 | + $iniWriter->setConfig($config); |
| 131 | + try { |
| 132 | + $iniWriter->write(APPLICATION_PATH.'/../config/chaplin.ini'); |
| 133 | + echo 'File successfully written.'; |
| 134 | + } catch (Exception $e) { |
| 135 | + echo '; Could not write file. Please copy and insert the following into the file /config/chaplin.ini'.PHP_EOL; |
| 136 | + echo $iniWriter->render(); |
| 137 | + } |
| 138 | + } |
| 139 | +} |
0 commit comments