コード例 #1
0
 protected function _refreshCache($options)
 {
     Kwf_Config_Web::reload();
 }
コード例 #2
0
 public static function setUp($configClass = 'Kwf_Config_Web')
 {
     error_reporting(E_ALL & ~E_STRICT);
     define('APP_PATH', getcwd());
     Kwf_Setup::$configClass = $configClass;
     if (PHP_SAPI == 'cli') {
         //don't use cached setup on cli so clear-cache will always work even if eg. paths change
         require_once dirname(__FILE__) . '/../Kwf/Util/Setup.php';
         Kwf_Util_Setup::minimalBootstrap();
         eval(substr(Kwf_Util_Setup::generateCode(), 5));
     } else {
         if (!@(include APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php')) {
             if (!file_exists(APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php')) {
                 require_once dirname(__FILE__) . '/../Kwf/Util/Setup.php';
                 Kwf_Util_Setup::minimalBootstrapAndGenerateFile();
             }
             include APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php';
         }
     }
     if (!defined('VKWF_PATH') && PHP_SAPI != 'cli' && self::getBaseUrl() === null) {
         //if server.baseUrl is not set try to auto detect it and generate config.local.ini accordingly
         //this code is not used if server.baseUrl is set to "" in vkwf
         if (!isset($_SERVER['PHP_SELF'])) {
             echo "Can't detect baseUrl, PHP_SELF is not set\n";
             exit(1);
         }
         $baseUrl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
         if (substr($baseUrl, -16) == '/kwf/maintenance') {
             $baseUrl = substr($baseUrl, 0, -16);
         }
         $cfg = "[production]\n";
         $cfg .= "server.domain = \"{$_SERVER['HTTP_HOST']}\"\n";
         $cfg .= "server.baseUrl = \"{$baseUrl}\"\n";
         $cfg .= "setupFinished = false\n";
         if (file_exists('config.local.ini') && filesize('config.local.ini') > 0) {
             echo "config.local.ini already exists but server.baseUrl is not set\n";
             exit(1);
         }
         if (!is_writable('.')) {
             echo "'" . getcwd() . "' is not writable, can't create config.local.ini\n";
             exit(1);
         }
         file_put_contents('config.local.ini', $cfg);
         Kwf_Config_Web::reload();
         Kwf_Config::deleteValueCache('server.domain');
         Kwf_Config::deleteValueCache('server.baseUrl');
         unlink('cache/setup' . self::CACHE_SETUP_VERSION . '.php');
         echo "<h1>" . Kwf_Config::getValue('application.name') . "</h1>\n";
         echo "<a href=\"{$baseUrl}/kwf/maintenance/setup\">[start setup]</a>\n";
         exit;
     }
     if (isset($_SERVER['REQUEST_URI']) && substr($_SERVER['REQUEST_URI'], 0, 5) == '/kwf/') {
         if (substr($_SERVER['REQUEST_URI'], 0, 9) == '/kwf/pma/' || $_SERVER['REQUEST_URI'] == '/kwf/pma') {
             Kwf_Util_Pma::dispatch();
         } else {
             if ($_SERVER['REQUEST_URI'] == '/kwf/check') {
                 $ok = true;
                 $msg = '';
                 if (Kwf_Setup::hasDb()) {
                     $date = Kwf_Registry::get('db')->query("SELECT NOW()")->fetchColumn();
                     if (!$date) {
                         $ok = false;
                         $msg .= 'mysql connection failed';
                     }
                 }
                 if (file_exists('instance_startup')) {
                     //can be used while starting up autoscaling instances
                     $ok = false;
                     $msg .= 'instance startup in progress';
                 }
                 if (!$ok) {
                     header("HTTP/1.0 500 Error");
                     echo "<h1>Check failed</h1>";
                     echo $msg;
                 } else {
                     echo "ok";
                 }
                 exit;
             }
         }
     }
     Kwf_Benchmark::checkpoint('setUp');
 }
コード例 #3
0
 public function jsonInstallAction()
 {
     $cfg = "[production]\n";
     $cfg .= "database.web.username = "******"\n";
     $cfg .= "database.web.password = "******"\n";
     $cfg .= "database.web.dbname = " . $this->_getParam('db_dbname') . "\n";
     $cfg .= "database.web.host = " . $this->_getParam('db_host') . "\n";
     $cfg .= "\n";
     $cfg .= "server.domain = " . $this->getRequest()->getHttpHost() . "\n";
     $cfg .= "server.baseUrl = \"" . $this->getRequest()->getBaseUrl() . "\"\n";
     $cfg .= "\n";
     $cfg .= "debug.error.log = " . (!$this->_getParam('display_errors') ? 'true' : 'false') . "\n";
     file_put_contents('config.local.ini', $cfg);
     file_put_contents('config_section', $this->_getParam('config_section'));
     //re-create config to load changed config.local.ini
     Kwf_Config::deleteValueCache('database');
     Kwf_Config_Web::reload();
     Zend_Registry::getInstance()->offsetUnset('db');
     Zend_Registry::getInstance()->offsetSet('dao', new Kwf_Dao());
     $updates = array();
     foreach (Kwf_Util_Update_Helper::getUpdateTags() as $tag) {
         $file = KWF_PATH . '/setup/' . $tag . '.sql';
         if (file_exists($file)) {
             $update = new Kwf_Update_Sql(0, null);
             $update->sql = file_get_contents($file);
             $updates[] = $update;
         }
     }
     $updates = array_merge($updates, Kwf_Util_Update_Helper::getUpdates());
     $updates[] = new Kwf_Update_Setup_InitialDb('setup/setup.sql');
     $updates[] = new Kwf_Update_Setup_InitialUploads('setup/uploads');
     $update = new Kwf_Update_Sql(0, null);
     $db = Kwf_Registry::get('db');
     mt_srand((double) microtime() * 1000000);
     $passwordSalt = substr(md5(uniqid(mt_rand(), true)), 0, 10);
     $update->sql = "TRUNCATE TABLE kwf_users;\n";
     $update->sql .= "INSERT INTO kwf_users SET\n            role='admin',\n            email=" . $db->quote($this->_getParam('admin_email')) . ",\n            password="******",\n            password_salt=" . $db->quote($passwordSalt) . ";\n";
     $updates[] = $update;
     $c = new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum'));
     $runner = new Kwf_Util_Update_Runner($updates);
     $progress = new Zend_ProgressBar($c, 0, $runner->getProgressSteps());
     $runner->setProgressBar($progress);
     if (!$runner->checkUpdatesSettings()) {
         throw new Kwf_Exception_Client("checkSettings failed, setup stopped");
     }
     $doneNames = $runner->executeUpdates(array('refreshCache' => false));
     $runner->writeExecutedUpdates($doneNames);
     $errors = $runner->getErrors();
     if ($errors) {
         $errMsg = count($errors) . " setup script(s) failed:\n";
         foreach ($errors as $error) {
             $errMsg .= $error['name'] . ": \n";
             $errMsg .= $error['message'] . "\n\n";
         }
         throw new Kwf_Exception_Client(nl2br($errMsg));
     }
 }