public function indexAction() { if (Kwf_Setup::getBaseUrl() === null || !Kwf_Config::getValue('server.domain')) { throw new Kwf_Exception_Client("Before running setup please set server.domain and server.baseUrl in config.local.ini"); } if (file_exists('update')) { //for pre 3.3 webs, update file got replaced by kwf_update table throw new Kwf_Exception_Client("Application seems to be set up already. (update file exists)"); } try { Kwf_Registry::get('db'); } catch (Exception $e) { throw new Kwf_Exception_Client("Connection to database failed: " . $e->getMessage()); } if (!Kwf_Registry::get('db')) { throw new Kwf_Exception_Client("Database not configured: create a config.local.ini containing database connection."); } try { Kwf_Registry::get('db')->query("SELECT 1"); } catch (Exception $e) { throw new Kwf_Exception_Client("Connection to database failed: " . $e->getMessage()); } try { $tables = Kwf_Registry::get('db')->fetchCol("SHOW TABLES"); } catch (Exception $e) { throw new Kwf_Exception_Client("Fetching Tables failed: " . $e->getMessage()); } if (in_array('kwf_update', $tables) || in_array('kwf_updates', $tables)) { echo "Application seems to be set up already. (kwf_updates table exists)\n"; echo "Executing update...\n"; $this->forward('index', 'update'); return; } if ($tables) { throw new Kwf_Exception_Client("Database not empty, incomplete kwf installation or other application already exists in this database."); } $updates = array(); if (file_exists('setup/initial/dump.sql')) { $updates[] = new Kwf_Update_Setup_InitialDb('setup/initial/dump.sql'); if (file_exists('setup/initial/uploads')) { $updates[] = new Kwf_Update_Setup_InitialUploads('setup/initial/uploads'); } } else { 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'); } $c = new Zend_ProgressBar_Adapter_Console(); $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT)); $c->setTextWidth(50); $runner = new Kwf_Util_Update_Runner($updates); $progress = new Zend_ProgressBar($c, 0, $runner->getProgressSteps()); $runner->setProgressBar($progress); if (!$runner->checkUpdatesSettings()) { echo "\ncheckSettings failed, setup stopped\n"; exit; } $doneNames = $runner->executeUpdates(); $runner->writeExecutedUpdates($doneNames); $runner->executePostMaintenanceBootstrapUpdates(); $errors = $runner->getErrors(); if ($errors) { echo "\n\n================\n"; echo count($errors) . " setup script(s) failed:\n"; foreach ($errors as $error) { echo $error['name'] . ": \n"; echo $error['message'] . "\n\n"; } } else { echo "\n\nSetup finished.\nThank you for using Koala Framework.\n"; } exit; }
public function indexAction() { Kwf_Util_MemoryLimit::set(512); Kwf_Events_ModelObserver::getInstance()->disable(); //try to update old-style db config if (file_exists('config.db.ini')) { $db = file_get_contents('config.db.ini'); if (file_exists('config.local.ini')) { $c = file_get_contents('config.local.ini'); } else { $c = "[production]\n"; } $c .= "\n"; $db = str_replace("[database]\n", '', $db); foreach (explode("\n", trim($db)) as $line) { if (trim($line)) { $c .= "database." . $line . "\n"; } } file_put_contents('config.local.ini', $c); unlink('config.db.ini'); } if ($this->_getParam('rev')) { throw new Kwf_Exception("rev parameter is not supported anymore"); } if ($this->_getParam('class')) { throw new Kwf_Exception("class parameter is not supported anymore"); } $skipClearCache = $this->_getParam('skip-clear-cache'); $excludeClearCacheType = $this->_getParam('exclude-clear-cache-type'); $doneNames = Kwf_Util_Update_Helper::getExecutedUpdatesNames(); if ($this->_getParam('name')) { $updates = Kwf_Util_Update_Helper::getUpdates(); foreach ($updates as $k => $u) { $n = $u->getUniqueName(); $n = substr($n, strrpos($n, '_') + 1); if ($n != $this->_getParam('name')) { unset($updates[$k]); } } } else { if (!$skipClearCache) { $excludeTypes = $excludeClearCacheType; if ($excludeTypes) { $excludeTypes .= ','; } $excludeTypes .= 'componentView,componentUrl'; //never clear before updating (table structure might have changed) Kwf_Util_ClearCache::getInstance()->clearCache(array('types' => 'all', 'output' => true, 'refresh' => false, 'excludeTypes' => $excludeTypes)); } echo "Looking for update-scripts..."; $updates = Kwf_Util_Update_Helper::getUpdates(); foreach ($updates as $k => $u) { if (in_array($u->getUniqueName(), $doneNames) || $u->getLegacyName() && in_array($u->getLegacyName(), $doneNames)) { unset($updates[$k]); } } echo " found " . count($updates) . "\n\n"; } if (!$this->_getParam('debug')) { Kwf_Util_Maintenance::writeMaintenanceBootstrap(); } $c = new Zend_ProgressBar_Adapter_Console(); $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT)); $c->setTextWidth(50); $runner = new Kwf_Util_Update_Runner($updates); $progress = new Zend_ProgressBar($c, 0, $runner->getProgressSteps()); $runner->setProgressBar($progress); $runner->setVerbose(true); $runner->setEnableDebug($this->_getParam('debug')); $runner->setSkipClearCache($skipClearCache); $runner->setExcludeClearCacheTypes($excludeClearCacheType); $checkUpdatesSettings = $runner->checkUpdatesSettings(); if (!$checkUpdatesSettings) { echo "\ncheckSettings failed, update stopped\n"; } else { $executedUpdates = $runner->executeUpdates(); echo "\n[32mupdate finished[0m\n"; $runner->writeExecutedUpdates($executedUpdates); } if (!$this->_getParam('debug')) { Kwf_Util_Maintenance::restoreMaintenanceBootstrap(); } if ($checkUpdatesSettings) { $runner->executePostMaintenanceBootstrapUpdates(); echo "\n[32mpost maintenance bootstrap update finished[0m\n"; } $errors = $runner->getErrors(); if ($errors) { echo "\n\n" . str_repeat('=', 16) . "\n"; echo count($errors) . " update script(s) failed:\n"; foreach ($errors as $error) { echo $error['name'] . ": \n"; echo $error['message'] . "\n\n"; } exit(1); } else { echo "\n" . count($updates) . " update script(s) successfully executed.\n"; exit(0); } }