protected function _installModule($module_name) { $this->cliEcho("Install module\n", 'green', 'bold'); try { if (!$module_name || !file_exists(THEBUGGENIE_MODULES_PATH . $module_name . DS . ucfirst($module_name) . '.php')) { throw new \Exception("Please provide a valid module name"); } elseif (\thebuggenie\core\framework\Context::isModuleLoaded($module_name)) { throw new \Exception("This module is already installed"); } else { $this->cliEcho("Installing {$module_name} ..."); \thebuggenie\core\entities\Module::installModule($module_name); $this->cliEcho(' ok!', 'green', 'bold'); $this->cliEcho("\n"); } } catch (\Exception $e) { $this->cliEcho($e->getMessage() . "\n", 'red'); } }
/** * Runs the action for the fourth step of the installation * where it loads fixtures and saves settings for url * * @param framework\Request $request The request object * * @return null */ public function runInstallStep4(framework\Request $request) { try { framework\Logging::log('Initializing language support'); framework\Context::reinitializeI18n('en_US'); framework\Logging::log('Loading fixtures for default scope'); $scope = new \thebuggenie\core\entities\Scope(); $scope->addHostname('*'); $scope->setName('The default scope'); $scope->setEnabled(true); framework\Context::setScope($scope); $scope->save(); framework\Settings::saveSetting('language', 'en_US', 'core', 1); \thebuggenie\core\entities\Module::installModule('publish'); \thebuggenie\core\entities\Module::installModule('agile'); \thebuggenie\core\entities\Module::installModule('mailing'); \thebuggenie\core\entities\Module::installModule('vcs_integration'); $this->htaccess_error = false; $this->htaccess_ok = (bool) $request['apache_autosetup']; if ($request['apache_autosetup']) { if (!is_writable(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/') || file_exists(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.htaccess') && !is_writable(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.htaccess')) { $this->htaccess_error = 'Permission denied when trying to save the [main folder]/' . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.htaccess'; } else { $content = str_replace('###PUT URL SUBDIRECTORY HERE###', $request['url_subdir'], file_get_contents(THEBUGGENIE_CORE_PATH . '/templates/htaccess.template')); file_put_contents(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.htaccess', $content); if (file_get_contents(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.htaccess') != $content) { $this->htaccess_error = true; } } if (!is_writable(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/') || file_exists(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.user.ini') && !is_writable(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.user.ini')) { $this->htaccess_error = 'Permission denied when trying to save the [main folder]/' . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.user.ini'; } else { $content = file_get_contents(THEBUGGENIE_CORE_PATH . '/templates/user.ini.template'); file_put_contents(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.user.ini', $content); if (file_get_contents(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . '/.user.ini') != $content) { $this->htaccess_error = true; } } } } catch (\Exception $e) { $this->error = $e->getMessage(); throw $e; } }
protected function _uninstall() { parent::_uninstall(); }
protected function _uninstall() { if (framework\Context::getScope()->getID() == 1) { Commits::getTable()->drop(); Files::getTable()->drop(); IssueLinks::getTable()->drop(); } parent::_uninstall(); }
public function do_execute() { if (file_exists(THEBUGGENIE_PATH . 'installed')) { $this->cliEcho("The Bug Genie seems to already be installed.\n", 'red', 'bold'); $this->cliEcho('Please remove the file '); $this->cliEcho(THEBUGGENIE_PATH . 'installed', 'white', 'bold'); $this->cliEcho(' and try again.'); $this->cliEcho("\n"); return; } $this->cliEcho("\nWelcome to the \"The Bug Genie\" installation wizard!\n", 'white', 'bold'); $this->cliEcho("This wizard will take you through the installation of The Bug Genie.\nRemember that you can also install The Bug Genie from your web-browser.\n"); $this->cliEcho("Simply point your web-browser to the The Bug Genie subdirectory on your web server,\nand the installation will start.\n\n"); $this->cliEcho("Press ENTER to continue with the installation: "); $this->pressEnterToContinue(); $this->cliEcho("\n"); $this->cliEcho("How to support future development\n", 'green', 'bold'); $this->cliEcho("Even though this software has been provided to you free of charge,\ndeveloping it would not have been possible without support from our users.\n"); $this->cliEcho("By making a donation, or buying a support contract you can help us continue development.\n\n"); $this->cliEcho("If this software is valuable to you - please consider supporting it.\n\n"); $this->cliEcho("More information about supporting The Bug Genie's development can be found here:\n"); $this->cliEcho("http://www.thebuggenie.com/support\n\n", 'blue', 'underline'); $this->cliEcho("Press ENTER to continue: "); $this->pressEnterToContinue(); $this->cliEcho("\n"); try { $this->cliEcho("License information\n", 'green', 'bold'); $this->cliEcho("This software is Open Source Initiative approved Open Source Software.\nOpen Source Initiative Approved is a trademark of the Open Source Initiative.\n\n"); $this->cliEcho("True to the the Open Source Definition, The Bug Genie is released\nunder the MPL 2.0. You can read the full license here:\n"); $this->cliEcho("http://opensource.org/licenses/MPL-2.0\n\n", 'blue', 'underline'); if ($this->getProvidedArgument('accept_license') != 'yes') { $this->cliEcho("Before you can continue the installation, you need to confirm that you \nagree to be bound by the terms in this license.\n\n"); $this->cliEcho("Do you agree to be bound by the terms in the MPL 2.0 license?\n(type \"yes\" to agree, anything else aborts the installation): "); if (!$this->askToAccept()) { throw new \Exception($this->cliEcho('You need to accept the license to continue', 'red', 'bold')); } } else { $this->cliEcho('You have accepted the license', 'yellow', 'bold'); $this->cliEcho("\n\n"); } $not_well = array(); if (!is_writable(\THEBUGGENIE_CONFIGURATION_PATH)) { $not_well[] = 'b2db_perm'; } if (!is_writable(THEBUGGENIE_PATH)) { $not_well[] = 'root'; } if (count($not_well) > 0) { $this->cliEcho("\n"); foreach ($not_well as $afail) { switch ($afail) { case 'b2db_perm': $this->cliEcho("Could not write to the B2DB directory\n", 'red', 'bold'); $this->cliEcho('The folder '); $this->cliEcho(\THEBUGGENIE_CONFIGURATION_PATH, 'white', 'bold'); $this->cliEcho(' folder needs to be writable'); break; case 'root': $this->cliEcho("Could not write to the main directory\n", 'red', 'bold'); $this->cliEcho('The top level folder must be writable during installation'); break; } } throw new \Exception("\n\nYou need to correct the above errors before the installation can continue."); } else { $this->cliEcho("Step 1 - database information\n"); if (file_exists($this->_b2db_config_file)) { $this->cliEcho("You seem to already have completed this step successfully.\n"); if ($this->getProvidedArgument('use_existing_db_info') == 'yes') { $this->cliEcho("\n"); $this->cliEcho("Using existing database information\n", 'yellow', 'bold'); $use_existing_db_info = true; } else { $this->cliEcho("Do you want to use the stored settings?\n", 'white', 'bold'); $this->cliEcho("\nType \"no\" to enter new settings, press ENTER to use existing: ", 'white', 'bold'); $use_existing_db_info = $this->askToDecline(); } $this->cliEcho("\n"); } else { $use_existing_db_info = false; } if (!$use_existing_db_info) { $this->cliEcho("The Bug Genie uses a database to store information. To be able to connect\nto your database, The Bug Genie needs some information, such as\ndatabase type, username, password, etc.\n\n"); $this->cliEcho("Please select what kind of database you are installing The Bug Genie on:\n"); $db_types = array(); foreach (\b2db\Core::getDBtypes() as $db_type => $db_desc) { $db_types[] = $db_type; $this->cliEcho(count($db_types) . ': ' . $db_desc . "\n", 'white', 'bold'); } do { $this->cliEcho('Enter the corresponding number for the database (1-' . count($db_types) . '): '); $db_selection = $this->getInput(); if (!isset($db_types[(int) $db_selection - 1])) { throw new \Exception($db_selection . ' is not a valid database type selection'); } $db_type = $db_types[(int) $db_selection - 1]; $this->cliEcho("Selected database type: "); $this->cliEcho($db_type . "\n\n"); $this->cliEcho("Please enter the database hostname: \n"); $this->cliEcho('Database hostname [localhost]: ', 'white', 'bold'); $db_hostname = $this->getInput(); $db_hostname = $db_hostname == '' ? 'localhost' : $db_hostname; $this->cliEcho("\nPlease enter the username The Bug Genie will use to connect to the database: \n"); $this->cliEcho('Database username: '******'white', 'bold'); $db_username = $this->getInput(); $this->cliEcho("Database password (press ENTER if blank): ", 'white', 'bold'); $db_password = $this->getInput(); $this->cliEcho("\nPlease enter the database The Bug Genie will use.\nIf it does not exist, The Bug Genie will create it for you.\n(the default database name is "); $this->cliEcho("thebuggenie_db", 'white', 'bold'); $this->cliEcho(" - press ENTER to use that):\n"); $this->cliEcho('Database name: ', 'white', 'bold'); $db_name = $this->getInput('thebuggenie_db'); $this->cliEcho("\n"); $this->cliEcho("The following settings will be used:\n"); $this->cliEcho("Database type: \t\t", 'white', 'bold'); $this->cliEcho($db_type . "\n"); $this->cliEcho("Database hostname: \t", 'white', 'bold'); $this->cliEcho($db_hostname . "\n"); $this->cliEcho("Database username: \t", 'white', 'bold'); $this->cliEcho($db_username . "\n"); $this->cliEcho("Database password: \t", 'white', 'bold'); $this->cliEcho($db_password . "\n"); $this->cliEcho("Database name: \t\t", 'white', 'bold'); $this->cliEcho($db_name . "\n"); $this->cliEcho("\nIf these settings are ok, press ENTER, or anything else to retry: "); $e_ok = $this->askToDecline(); } while (!$e_ok); try { \b2db\Core::setHost($db_hostname); \b2db\Core::setUname($db_username); \b2db\Core::setPasswd($db_password); \b2db\Core::setDBtype($db_type); \b2db\Core::setTablePrefix('tbg_'); \b2db\Core::doConnect(); \b2db\Core::createDatabase($db_name); \b2db\Core::setDBname($db_name); \b2db\Core::doConnect(); } catch (\Exception $e) { throw new \Exception("Could not connect to the database:\n" . $e->getMessage()); } \b2db\Core::setDBname($db_name); $this->cliEcho("\nSuccessfully connected to the database.\n", 'green'); $this->cliEcho("Press ENTER to continue ... "); $this->pressEnterToContinue(); $this->cliEcho("\n"); $this->cliEcho("Saving database connection information ... ", 'white', 'bold'); $this->cliEcho("\n"); \b2db\Core::saveConnectionParameters($this->_b2db_config_file); $this->cliEcho("Successfully saved database connection information.\n", 'green'); $this->cliEcho("\n"); } else { $b2db_config = \Spyc::YAMLLoad($this->_b2db_config_file); if (!array_key_exists("b2db", $b2db_config)) { throw new \Exception("Could not find database configuration in file " . $this->_b2db_config_file); } try { \b2db\Core::initialize($b2db_config["b2db"], \thebuggenie\core\framework\Context::getCache()); \b2db\Core::doConnect(); } catch (\Exception $e) { throw new \Exception("Could not connect to the database:\n" . $e->getMessage() . "\nPlease check your configuration file " . $this->_b2db_config_file); } $this->cliEcho("Successfully connected to the database.\n", 'green'); } $this->cliEcho("\nThe Bug Genie needs some server settings to function properly...\n\n"); do { $this->cliEcho("URL rewriting\n", 'cyan', 'bold'); $this->cliEcho("The Bug Genie uses a technique called \"url rewriting\" - which allows for pretty\nURLs such as ") . $this->cliEcho('/issue/1', 'white', 'bold') . $this->cliEcho(' instead of ') . $this->cliEcho("viewissue.php?issue_id=1\n", 'white', 'bold'); $this->cliEcho("Make sure you have read the URL_REWRITE document located in the root\nfolder, or at http://www.thebuggenie.com before you continue\n"); if (!$this->hasProvidedArgument('url_subdir')) { $this->cliEcho("Press ENTER to continue ... "); $this->pressEnterToContinue(); } $this->cliEcho("\n"); $this->cliEcho("The Bug Genie subdir\n", 'white', 'bold'); $this->cliEcho("This is the sub-path of the Web server where The Bug Genie will be located.\n"); if ($this->hasProvidedArgument('url_subdir')) { $this->cliEcho('The Bug Genie subdir: ', 'white', 'bold'); $url_subdir = $this->getProvidedArgument('url_subdir'); $this->cliEcho($url_subdir, 'yellow', 'bold'); $this->cliEcho("\n"); } else { $this->cliEcho('Start and end this with a forward slash', 'white', 'bold'); $this->cliEcho(". (ex: \"/thebuggenie/\")\nIf The Bug Genie is running at the root directory, just type \"/\" (without the quotes)\n\n"); $this->cliEcho('The Bug Genie subdir: ', 'white', 'bold'); $url_subdir = $this->getInput(); } $this->cliEcho("\n"); $this->cliEcho("The Bug Genie will now be accessible at\n"); $this->cliEcho("http://example.com" . $url_subdir, 'white', 'bold'); if ($this->hasProvidedArgument('url_subdir')) { $this->cliEcho("\n"); $this->cliEcho("Using existing values", 'yellow', 'bold'); $this->cliEcho("\n"); $e_ok = true; } else { $this->cliEcho("\nPress ENTER if ok, or \"no\" to try again: "); $e_ok = $this->askToDecline(); } $this->cliEcho("\n"); } while (!$e_ok); if ($this->getProvidedArgument('setup_htaccess') != 'yes') { $this->cliEcho("Setup can autoconfigure your .htaccess and .user.ini files (located in the thebuggenie/ subfolder), so you don't have to.\n"); $this->cliEcho('Would you like setup to auto-generate those files for you?'); $this->cliEcho("\nPress ENTER if ok, or \"no\" to not set up the .htaccess and .user.ini files: "); $htaccess_ok = $this->askToDecline(); } else { $this->cliEcho('Autoconfiguring .htaccess and .user.ini', 'yellow', 'bold'); $this->cliEcho("\n"); $htaccess_ok = true; } $this->cliEcho("\n"); if ($htaccess_ok) { if (!is_writable(THEBUGGENIE_PATH . 'thebuggenie/') || file_exists(THEBUGGENIE_PATH . 'thebuggenie/.htaccess') && !is_writable(THEBUGGENIE_PATH . 'thebuggenie/.htaccess')) { $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.htaccess\n", 'red', 'bold'); $this->cliEcho("You will have to set up the .htaccess file yourself. See the README file for more information.\n", 'white', 'bold'); $this->cliEcho('Please note: ', 'white', 'bold'); $this->cliEcho("The Bug Genie will not function properly until the .htaccess file is properly set up!\n"); } else { $content = str_replace('###PUT URL SUBDIRECTORY HERE###', $url_subdir, file_get_contents(THEBUGGENIE_CORE_PATH . 'templates/htaccess.template')); file_put_contents(THEBUGGENIE_PATH . 'thebuggenie/.htaccess', $content); if (file_get_contents(THEBUGGENIE_PATH . 'thebuggenie/.htaccess') != $content) { $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.htaccess\n", 'red', 'bold'); $this->cliEcho("You will have to set up the .htaccess file yourself. See the README file for more information.\n", 'white', 'bold'); $this->cliEcho('Please note: ', 'white', 'bold'); $this->cliEcho("The Bug Genie will not function properly until the .htaccess file is properly set up!\n"); } else { $this->cliEcho("The .htaccess file was successfully set up...\n", 'green', 'bold'); } } if (!is_writable(THEBUGGENIE_PATH . 'thebuggenie/') || file_exists(THEBUGGENIE_PATH . 'thebuggenie/.user.ini') && !is_writable(THEBUGGENIE_PATH . 'thebuggenie/.user.ini')) { $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.user.ini\n", 'red', 'bold'); $this->cliEcho("You will have to set up the .user.ini file yourself. See the README file for more information.\n", 'white', 'bold'); $this->cliEcho('Please note: ', 'white', 'bold'); $this->cliEcho("If you're using PHP-FPM, The Bug Genie might not function properly until the .user.ini file is properly set up\n"); } else { $content = file_get_contents(THEBUGGENIE_CORE_PATH . 'templates/htaccess.template'); file_put_contents(THEBUGGENIE_PATH . 'thebuggenie/.user.ini', $content); if (file_get_contents(THEBUGGENIE_PATH . 'thebuggenie/.user.ini') != $content) { $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.user.ini\n", 'red', 'bold'); $this->cliEcho("You will have to set up the .user.ini file yourself. See the README file for more information.\n", 'white', 'bold'); $this->cliEcho('Please note: ', 'white', 'bold'); $this->cliEcho("If you're using PHP-FPM, The Bug Genie might not function properly until the .user.ini file is properly set up\n"); } else { $this->cliEcho("The .user.ini file was successfully set up...\n", 'green', 'bold'); } } } else { $this->cliEcho("Skipping .htaccess and .user.ini auto-setup."); } if ($this->getProvidedArgument('setup_htaccess') != 'yes') { $this->cliEcho("Press ENTER to continue ... "); $this->pressEnterToContinue(); $this->cliEcho("\n"); } $this->cliEcho("\n"); $this->cliEcho("Creating tables ...\n", 'white', 'bold'); $b2db_entities_path = THEBUGGENIE_CORE_PATH . 'entities' . DS . 'tables' . DS; $tables_created = array(); foreach (scandir($b2db_entities_path) as $tablefile) { if (in_array($tablefile, array('.', '..'))) { continue; } if (($tablename = mb_substr($tablefile, 0, mb_strpos($tablefile, '.'))) != '') { $tablename = "\\thebuggenie\\core\\entities\\tables\\{$tablename}"; $reflection = new \ReflectionClass($tablename); $docblock = $reflection->getDocComment(); $annotationset = new \b2db\AnnotationSet($docblock); if ($annotationset->hasAnnotation('Table')) { \b2db\Core::getTable($tablename)->create(); \b2db\Core::getTable($tablename)->createIndexes(); $tables_created[] = $tablename; } } } $this->cliEcho("\n"); $this->cliEcho("All tables successfully created...\n\n", 'green', 'bold'); $this->cliEcho("Setting up initial scope... \n", 'white', 'bold'); \thebuggenie\core\framework\Context::reinitializeI18n('en_US'); $scope = new \thebuggenie\core\entities\Scope(); $scope->setName('The default scope'); $scope->addHostname('*'); $scope->setEnabled(); \thebuggenie\core\framework\Context::setScope($scope); $scope->save(); \thebuggenie\core\framework\Settings::saveSetting('language', 'en_US'); $this->cliEcho("Initial scope setup successfully... \n\n", 'green', 'bold'); $this->cliEcho("Setting up modules... \n", 'white', 'bold'); try { foreach (array('publish', 'mailing', 'vcs_integration') as $module) { $this->cliEcho("Installing {$module}... \n"); \thebuggenie\core\entities\Module::installModule($module); } $this->cliEcho("\n"); $this->cliEcho("All modules installed successfully...\n", 'green', 'bold'); $this->cliEcho("\n"); $this->cliEcho("Finishing installation... \n", 'white', 'bold'); $installed_string = \thebuggenie\core\framework\Settings::getMajorVer() . '.' . \thebuggenie\core\framework\Settings::getMinorVer() . ', installed ' . date('d.m.Y H:i'); if (file_exists(THEBUGGENIE_PATH . 'installed') && !is_writable(THEBUGGENIE_PATH . 'installed') || !file_exists(THEBUGGENIE_PATH . 'installed') && !is_writable(THEBUGGENIE_PATH)) { $this->cliEcho("\n"); $this->cliEcho("Could not create the 'installed' file.\n", 'red', 'bold'); $this->cliEcho("Please create the file "); $this->cliEcho(THEBUGGENIE_PATH . "installed\n", 'white', 'bold'); $this->cliEcho("with the following line inside:\n"); $this->cliEcho($installed_string, 'blue', 'bold'); $this->cliEcho("\n"); $this->cliEcho("This can be done by running the following command when installation has finished:\n"); $this->cliEcho('echo "' . $installed_string . '" > ' . THEBUGGENIE_PATH . 'installed', 'white', 'bold'); $this->cliEcho("\n"); $this->cliEcho("Press ENTER to continue ... "); $this->pressEnterToContinue(); $this->cliEcho("\n"); $this->cliEcho("\n"); } else { file_put_contents(THEBUGGENIE_PATH . 'installed', $installed_string); } $this->cliEcho("The installation was completed successfully!\n", 'green', 'bold'); $this->cliEcho("\nTo use The Bug Genie, access http://example.com" . $url_subdir . "index.php with a web-browser.\n"); $this->cliEcho("The default username is ") . $this->cliEcho('Administrator') . $this->cliEcho(' and the password is ') . $this->cliEcho('admin'); $this->cliEcho("\n\nFor support, please visit ") . $this->cliEcho('http://www.thebuggenie.com/', 'blue', 'underline'); $this->cliEcho("\n"); } catch (\Exception $e) { throw new \Exception("Could not install the {$module} module:\n" . $e->getMessage()); } } } catch (\Exception $e) { $this->cliEcho("\n\nThe installation was interrupted\n", 'red'); $this->cliEcho($e->getMessage() . "\n"); } $this->cliEcho("\n"); }
/** * Loads and initializes all modules */ public static function loadModules() { Logging::log('Loading modules'); if (self::isInstallmode()) { return; } if (self::isUpgrademode()) { self::$_modules = Module::getB2DBTable()->getAllNames(); return; } Logging::log('getting modules from database'); self::$_modules = Module::getB2DBTable()->getAll(); Logging::log('done (setting up module objects)'); Logging::log('initializing modules'); if (!empty(self::$_modules)) { foreach (self::$_modules as $module) { $module->initialize(); } Logging::log('done (initializing modules)'); } else { Logging::log('no modules found'); } Logging::log('...done (loading modules)'); }
public function getTabKey() { return framework\Context::isProjectContext() ? parent::getTabKey() : 'wiki'; }
public function runScope(framework\Request $request) { $this->scope = new entities\Scope($request['id']); $modules = tables\Modules::getTable()->getModulesForScope($this->scope->getID()); $this->modules = $modules; $this->scope_save_error = framework\Context::getMessageAndClear('scope_save_error'); if ($request->isPost()) { try { if ($request['scope_action'] == 'delete') { if (!$this->scope->isDefault()) { $this->scope->delete(); framework\Context::setMessage('scope_deleted', true); $this->forward(make_url('configure_scopes')); } else { $this->scope_save_error = $this->getI18n()->__('You cannot delete the default scope'); } } else { if (!$request['name']) { throw new \Exception($this->getI18n()->__('Please specify a scope name')); } $this->scope->setName($request['name']); $this->scope->setDescription($request['description']); $this->scope->setCustomWorkflowsEnabled((bool) $request['custom_workflows_enabled']); $this->scope->setMaxWorkflowsLimit((int) $request['workflow_limit']); $this->scope->setUploadsEnabled((bool) $request['file_uploads_enabled']); $this->scope->setMaxUploadLimit((int) $request['upload_limit']); $this->scope->setMaxProjects((int) $request['project_limit']); $this->scope->setMaxUsers((int) $request['user_limit']); $this->scope->setMaxTeams((int) $request['team_limit']); $this->scope->save(); $enabled_modules = $request['module_enabled']; $prev_scope = framework\Context::getScope(); foreach ($enabled_modules as $module => $enabled) { if (!framework\Context::getModule($module)->isCore() && !$enabled && array_key_exists($module, $modules)) { $module = tables\Modules::getTable()->getModuleForScope($module, $this->scope->getID()); $module->uninstall($this->scope->getID()); } elseif (!framework\Context::getModule($module)->isCore() && $enabled && !array_key_exists($module, $modules)) { framework\Context::setScope($this->scope); entities\Module::installModule($module); framework\Context::setScope($prev_scope); } } framework\Context::setMessage('scope_saved', true); $this->forward(make_url('configure_scopes')); } } catch (\Exception $e) { framework\Context::setMessage('scope_save_error', $e->getMessage()); } } }
public function do_execute() { $hostname = $this->getProvidedArgument('hostname'); $this->cliEcho('Checking scope availability ...'); if (tables\ScopeHostnames::getTable()->getScopeIDForHostname($hostname) === null) { $this->cliEcho("available!\n"); $this->cliEcho("Creating scope ..."); $scope = new entities\Scope(); $scope->addHostname($hostname); $scope->setName($this->getProvidedArgument('shortname')); $uploads_enabled = $this->getProvidedArgument('enable_uploads', 'yes') == 'yes'; $scope->setUploadsEnabled((bool) $uploads_enabled); $scope->setMaxUploadLimit($this->getProvidedArgument('upload_limit', 0)); $scope->setMaxProjects($this->getProvidedArgument('projects', 0)); $scope->setMaxUsers($this->getProvidedArgument('users', 0)); $scope->setMaxTeams($this->getProvidedArgument('teams', 0)); $scope->setMaxWorkflowsLimit($this->getProvidedArgument('workflows', 0)); $scope->setEnabled(); $this->cliEcho("."); $scope->save(); $this->cliEcho(".done!\n"); $admin_user = $this->getProvidedArgument('scope_admin'); if ($admin_user) { $user = entities\User::getByUsername($admin_user); if ($user instanceof entities\User) { $this->cliEcho("Adding user {$admin_user} to scope\n"); $admin_group_id = (int) framework\Settings::get(framework\Settings::SETTING_ADMIN_GROUP, 'core', $scope->getID()); tables\UserScopes::getTable()->addUserToScope($user->getID(), $scope->getID(), $admin_group_id, true); } else { $this->cliEcho("Could not add user {$admin_user} to scope (username not found)\n"); } } if ($this->getProvidedArgument('remove_admin', 'no') == 'yes') { $this->cliEcho("Removing administrator user from scope\n"); tables\UserScopes::getTable()->removeUserFromScope(1, $scope->getID()); } foreach (framework\Context::getModules() as $module) { $module_name = $module->getName(); if ($module_name == 'publish') { continue; } if ($this->getProvidedArgument("install_module_{$module_name}", "no") == 'yes') { $this->cliEcho("Installing module {$module_name}\n"); entities\Module::installModule($module_name, $scope); } } } else { $this->cliEcho("not available\n", 'red'); } $this->cliEcho("\n"); }
public function runUserdata(framework\Request $request) { if ($this->getUser()->isGuest()) { return $this->renderJSON(array()); } else { $data = array(); if ($request->isPost()) { switch ($request['say']) { case 'install-module': try { entities\Module::downloadModule($request['module_key']); $module = entities\Module::installModule($request['module_key']); $data['installed'] = true; $data['module_key'] = $request['module_key']; $data['module'] = $this->getComponentHTML('configuration/modulebox', array('module' => $module)); } catch (framework\exceptions\ModuleDownloadException $e) { $this->getResponse()->setHttpStatus(400); switch ($e->getCode()) { case framework\exceptions\ModuleDownloadException::JSON_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to retrieve the module data'))); break; case framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('The module could not be downloaded'))); break; } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to install the module'))); } break; case 'install-theme': try { entities\Module::downloadTheme($request['theme_key']); $data['installed'] = true; $data['theme_key'] = $request['theme_key']; $themes = framework\Context::getThemes(); $data['theme'] = $this->getComponentHTML('configuration/theme', array('theme' => $themes[$request['theme_key']])); } catch (framework\exceptions\ModuleDownloadException $e) { $this->getResponse()->setHttpStatus(400); switch ($e->getCode()) { case framework\exceptions\ModuleDownloadException::JSON_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to retrieve the module data'))); break; case framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND: return $this->renderJSON(array('message' => $this->getI18n()->__('The module could not be downloaded'))); break; } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('message' => $this->getI18n()->__('An error occured when trying to install the module'))); } break; case 'notificationstatus': $notification = tables\Notifications::getTable()->selectById($request['notification_id']); $data['notification_id'] = $request['notification_id']; $data['is_read'] = 1; if ($notification instanceof entities\Notification) { $notification->setIsRead(!$notification->isRead()); $notification->save(); $data['is_read'] = (int) $notification->isRead(); $this->getUser()->markNotificationGroupedNotificationsRead($notification); } break; case 'notificationsread': $this->getUser()->markAllNotificationsRead(); $data['all'] = 'read'; break; } } else { switch ($request['say']) { case 'get_module_updates': $addons_param = array(); foreach ($request['addons'] as $addon) { $addons_param[] = 'addons[]=' . $addon; } try { $client = new \Net_Http_Client(); $client->get('http://www.thebuggenie.com/addons.json?' . join('&', $addons_param)); $addons_json = json_decode($client->getBody(), true); } catch (\Exception $e) { } return $this->renderJSON($addons_json); break; case 'getsearchcounts': $counts_json = array(); foreach ($request['search_ids'] as $search_id) { if (is_numeric($search_id)) { $search = tables\SavedSearches::getTable()->selectById($search_id); } else { $predefined_id = str_replace('predefined_', '', $search_id); $search = \thebuggenie\core\entities\SavedSearch::getPredefinedSearchObject($predefined_id); } if ($search instanceof entities\SavedSearch) { $counts_json[$search_id] = $search->getTotalNumberOfIssues(); } } return $this->renderJSON($counts_json); break; case 'get_theme_updates': $addons_param = array(); foreach ($request['addons'] as $addon) { $addons_param[] = 'themes[]=' . $addon; } try { $client = new \Net_Http_Client(); $client->get('http://www.thebuggenie.com/themes.json?' . join('&', $addons_param)); $addons_json = json_decode($client->getBody(), true); } catch (\Exception $e) { } return $this->renderJSON($addons_json); break; case 'verify_module_update_file': $filename = THEBUGGENIE_CACHE_PATH . $request['module_key'] . '.zip'; $exists = file_exists($filename) && dirname($filename) . DS == THEBUGGENIE_CACHE_PATH; return $this->renderJSON(array('verified' => (int) $exists)); break; case 'get_modules': return $this->renderComponent('configuration/onlinemodules'); break; case 'get_themes': return $this->renderComponent('configuration/onlinethemes'); break; case 'get_mentionables': switch ($request['target_type']) { case 'issue': $target = entities\Issue::getB2DBTable()->selectById($request['target_id']); break; case 'article': $target = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->selectById($request['target_id']); break; case 'project': $target = tables\Projects::getTable()->selectById($request['target_id']); break; } $mentionables = array(); if (isset($target) && $target instanceof \thebuggenie\core\helpers\MentionableProvider) { foreach ($target->getMentionableUsers() as $user) { if ($user->isOpenIdLocked()) { continue; } $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL()); } } foreach ($this->getUser()->getFriends() as $user) { if ($user->isOpenIdLocked()) { continue; } $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL()); } foreach ($this->getUser()->getTeams() as $team) { foreach ($team->getMembers() as $user) { if ($user->isOpenIdLocked()) { continue; } $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL()); } } foreach ($this->getUser()->getClients() as $client) { foreach ($client->getMembers() as $user) { if ($user->isOpenIdLocked()) { continue; } $mentionables[$user->getID()] = array('username' => $user->getUsername(), 'name' => $user->getName(), 'image' => $user->getAvatarURL()); } } $data['mentionables'] = array_values($mentionables); break; default: $data['unread_notifications_count'] = $this->getUser()->getNumberOfUnreadNotifications(); $data['unread_notifications'] = array(); foreach ($this->getUser()->getUnreadNotifications() as $unread_notification) { $data['unread_notifications'][] = $unread_notification->getID(); } $data['poll_interval'] = framework\Settings::getNotificationPollInterval(); } } return $this->renderJSON($data); } }
protected function _postSave($is_new) { tables\ScopeHostnames::getTable()->saveScopeHostnames($this->getHostnames(), $this->getID()); // Load fixtures for this scope if it's a new scope if ($is_new) { if (!$this->isDefault()) { $prev_scope = framework\Context::getScope(); framework\Context::setScope($this); } $this->loadFixtures(); if (!$this->isDefault()) { Module::installModule('publish', $this); framework\Context::setScope($prev_scope); framework\Context::clearPermissionsCache(); } } }