protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::EDITION, Core::getTable('TBGEditionsTable'), TBGEditionsTable::ID);
     parent::_addForeignKeyColumn(self::COMPONENT, Core::getTable('TBGComponentsTable'), TBGComponentsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function addArticleHistory($article_name, $old_content, $new_content, $user_id, $reason = null)
 {
     if (!Core::isTransactionActive()) {
         $transaction = Core::startTransaction();
     }
     $crit = $this->getCriteria();
     $crit->addInsert(self::ARTICLE_NAME, $article_name);
     $crit->addInsert(self::AUTHOR, $user_id);
     $revision_number = $this->_getNextRevisionNumberForArticle($article_name);
     $crit->addInsert(self::REVISION, $revision_number);
     if (!($revision_number == 1 && $old_content == $new_content)) {
         $crit->addInsert(self::OLD_CONTENT, $old_content);
     } else {
         $crit->addInsert(self::OLD_CONTENT, '');
     }
     $crit->addInsert(self::NEW_CONTENT, $new_content);
     if ($reason !== null) {
         $crit->addInsert(self::REASON, $reason);
     }
     $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID());
     $crit->addInsert(self::DATE, NOW);
     $res = $this->doInsert($crit);
     if (isset($transaction)) {
         $transaction->commitAndEnd();
     }
     return $revision_number;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, TBGIssuesTable::getTable(), TBGIssuesTable::ID);
     parent::_addForeignKeyColumn(self::CUSTOMFIELDS_ID, Core::getTable('TBGCustomFieldsTable'), TBGCustomFieldsTable::ID);
     parent::_addText(self::OPTION_VALUE, false);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addBoolean(self::CONFIRMED);
     parent::_addForeignKeyColumn(self::BUILD, Core::getTable('TBGBuildsTable'), TBGBuildsTable::ID);
     parent::_addForeignKeyColumn(self::ISSUE, TBGIssuesTable::getTable(), TBGIssuesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::STATUS, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::VALUE, 200);
     parent::_addVarchar(self::OPERATOR, 40);
     parent::_addVarchar(self::FILTER_KEY, 100);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::SEARCH_ID, Core::getTable('TBGSavedSearchesTable'), TBGSavedSearchesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::MODULE_NAME, 50);
     parent::_addBoolean(self::ALLOWED);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::GID, TBGGroupsTable::getTable(), TBGGroupsTable::ID);
     parent::_addForeignKeyColumn(self::TID, Core::getTable('TBGTeamsTable'), TBGTeamsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::MODULE_NAME, 50);
     parent::_addInteger(self::NOTIFY_TYPE, 5);
     parent::_addInteger(self::TARGET_ID, 10);
     parent::_addVarchar(self::TITLE, 100);
     parent::_addText(self::CONTENTS, false);
     parent::_addInteger(self::STATUS, 5);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::GID, TBGGroupsTable::getTable(), TBGGroupsTable::ID);
     parent::_addForeignKeyColumn(self::TID, Core::getTable('TBGTeamsTable'), TBGTeamsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function saveSearch($saved_search_name, $saved_search_description, $saved_search_public, $filters, $groupby, $grouporder, $ipp, $templatename, $template_parameter, $project_id, $saved_search_id = null)
 {
     $crit = $this->getCriteria();
     if ($saved_search_id !== null) {
         $crit->addUpdate(self::NAME, $saved_search_name);
         $crit->addUpdate(self::DESCRIPTION, $saved_search_description);
         $crit->addUpdate(self::TEMPLATE_NAME, $templatename);
         $crit->addUpdate(self::TEMPLATE_PARAMETER, $template_parameter);
         $crit->addUpdate(self::GROUPBY, $groupby);
         $crit->addUpdate(self::GROUPORDER, $grouporder);
         $crit->addUpdate(self::ISSUES_PER_PAGE, $ipp);
         $crit->addUpdate(self::APPLIES_TO_PROJECT, $project_id);
         if (TBGContext::getUser()->canCreatePublicSearches()) {
             $crit->addUpdate(self::IS_PUBLIC, $saved_search_public);
             $crit->addUpdate(self::UID, (bool) $saved_search_public ? 0 : TBGContext::getUser()->getID());
         } else {
             $crit->addUpdate(self::IS_PUBLIC, false);
             $crit->addWhere(self::UID, TBGContext::getUser()->getID());
         }
         $crit->addUpdate(self::SCOPE, TBGContext::getScope()->getID());
         $this->doUpdateById($crit, $saved_search_id);
     } else {
         $crit->addInsert(self::NAME, $saved_search_name);
         $crit->addInsert(self::DESCRIPTION, $saved_search_description);
         $crit->addInsert(self::TEMPLATE_NAME, $templatename);
         $crit->addInsert(self::TEMPLATE_PARAMETER, $template_parameter);
         $crit->addInsert(self::GROUPBY, $groupby);
         $crit->addInsert(self::GROUPORDER, $grouporder);
         $crit->addInsert(self::ISSUES_PER_PAGE, $ipp);
         $crit->addInsert(self::APPLIES_TO_PROJECT, $project_id);
         if (TBGContext::getUser()->canCreatePublicSearches()) {
             $crit->addInsert(self::IS_PUBLIC, $saved_search_public);
             $crit->addInsert(self::UID, (bool) $saved_search_public ? 0 : TBGContext::getUser()->getID());
         } else {
             $crit->addInsert(self::IS_PUBLIC, false);
             $crit->addInsert(self::UID, TBGContext::getUser()->getID());
         }
         $crit->addInsert(self::SCOPE, TBGContext::getScope()->getID());
         $saved_search_id = $this->doInsert($crit)->getInsertID();
     }
     Core::getTable('TBGSavedSearchFiltersTable')->deleteBySearchID($saved_search_id);
     Core::getTable('TBGSavedSearchFiltersTable')->saveFiltersForSavedSearch($saved_search_id, $filters);
     return $saved_search_id;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::UNAME, 50);
     parent::_addVarchar(self::PASSWORD, 100);
     parent::_addVarchar(self::BUDDYNAME, 50);
     parent::_addVarchar(self::REALNAME, 100);
     parent::_addVarchar(self::EMAIL, 200);
     parent::_addForeignKeyColumn(self::USERSTATE, Core::getTable('TBGUserStateTable'), TBGUserStateTable::ID);
     parent::_addBoolean(self::CUSTOMSTATE);
     parent::_addVarchar(self::HOMEPAGE, 250, '');
     parent::_addVarchar(self::LANGUAGE, 100, '');
     parent::_addInteger(self::LASTSEEN, 10);
     parent::_addInteger(self::QUOTA);
     parent::_addBoolean(self::ACTIVATED);
     parent::_addBoolean(self::ENABLED);
     parent::_addBoolean(self::DELETED);
     parent::_addVarchar(self::AVATAR, 30, '');
     parent::_addBoolean(self::USE_GRAVATAR, true);
     parent::_addBoolean(self::PRIVATE_EMAIL);
     parent::_addBoolean(self::OPENID_LOCKED);
     parent::_addInteger(self::JOINED, 10);
 }
Exemple #10
0
 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");
 }
 private static function _loadSetting($name, $module = 'core', $scope = 0)
 {
     $crit = new \b2db\Criteria();
     $crit->addWhere(TBGSettingsTable::NAME, $name);
     $crit->addWhere(TBGSettingsTable::MODULE, $module);
     if ($scope == 0) {
         throw new Exception('The Bug Genie has not been correctly installed. Please check that the default scope exists');
     }
     $crit->addWhere(TBGSettingsTable::SCOPE, $scope);
     $res = \b2db\Core::getTable('TBGSettingsTable')->doSelect($crit);
     if ($res) {
         $retarr = array();
         while ($row = $res->getNextRow()) {
             $retarr[$row->get(TBGSettingsTable::UID)] = $row->get(TBGSettingsTable::VALUE);
         }
         return $retarr;
     } else {
         return null;
     }
 }
Exemple #12
0
 protected static function generateDebugInfo()
 {
     $tbg_summary = array();
     $load_time = self::getLoadtime();
     if (\b2db\Core::isInitialized()) {
         $tbg_summary['db']['queries'] = \b2db\Core::getSQLHits();
         $tbg_summary['db']['timing'] = \b2db\Core::getSQLTiming();
         $tbg_summary['db']['objectpopulation'] = \b2db\Core::getObjectPopulationHits();
         $tbg_summary['db']['objecttiming'] = \b2db\Core::getObjectPopulationTiming();
         $tbg_summary['db']['objectcount'] = \b2db\Core::getObjectPopulationCount();
     }
     $tbg_summary['load_time'] = $load_time >= 1 ? round($load_time, 2) . 's' : round($load_time * 1000, 1) . 'ms';
     $tbg_summary['scope'] = array();
     $scope = self::getScope();
     $tbg_summary['scope']['id'] = $scope instanceof Scope ? $scope->getID() : 'unknown';
     $tbg_summary['scope']['hostnames'] = $scope instanceof Scope && \b2db\Core::isConnected() ? implode(', ', $scope->getHostnames()) : 'unknown';
     $tbg_summary['settings'] = Settings::getAll();
     $tbg_summary['memory'] = memory_get_usage();
     $tbg_summary['partials'] = self::getVisitedPartials();
     $tbg_summary['log'] = Logging::getEntries();
     $tbg_summary['routing'] = array('name' => self::getRouting()->getCurrentRouteName(), 'module' => self::getRouting()->getCurrentRouteModule(), 'action' => self::getRouting()->getCurrentRouteAction());
     if (isset($_SESSION)) {
         if (!array_key_exists('___DEBUGINFO___', $_SESSION)) {
             $_SESSION['___DEBUGINFO___'] = array();
         }
         $_SESSION['___DEBUGINFO___'][self::$debug_id] = $tbg_summary;
         while (count($_SESSION['___DEBUGINFO___']) > 25) {
             array_shift($_SESSION['___DEBUGINFO___']);
         }
     }
 }
Exemple #13
0
 /**
  * Configuration import page
  *
  * @param framework\Request $request
  */
 public function runIndex(framework\Request $request)
 {
     if ($request->isPost()) {
         if ($request['import_sample_data']) {
             $transaction = \b2db\Core::startTransaction();
             $users = array();
             $user1 = new entities\User();
             $user1->setUsername('john');
             $user1->setPassword('john');
             $user1->setBuddyname('John');
             $user1->setRealname('John');
             $user1->setActivated();
             $user1->setEnabled();
             $user1->save();
             $users[] = $user1;
             $user2 = new entities\User();
             $user2->setUsername('jane');
             $user2->setPassword('jane');
             $user2->setBuddyname('Jane');
             $user2->setRealname('Jane');
             $user2->setActivated();
             $user2->setEnabled();
             $user2->save();
             $users[] = $user2;
             $user3 = new entities\User();
             $user3->setUsername('jackdaniels');
             $user3->setPassword('jackdaniels');
             $user3->setBuddyname('Jack');
             $user3->setRealname('Jack Daniels');
             $user3->setActivated();
             $user3->setEnabled();
             $user3->save();
             $users[] = $user3;
             $project1 = new entities\Project();
             $project1->setName('Sample project 1');
             $project1->setOwner($users[rand(0, 2)]);
             $project1->setLeader($users[rand(0, 2)]);
             $project1->setQaResponsible($users[rand(0, 2)]);
             $project1->setDescription('This is a sample project that is awesome. Try it out!');
             $project1->setHomepage('http://www.google.com');
             $project1->save();
             $project2 = new entities\Project();
             $project2->setName('Sample project 2');
             $project2->setOwner($users[rand(0, 2)]);
             $project2->setLeader($users[rand(0, 2)]);
             $project2->setQaResponsible($users[rand(0, 2)]);
             $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!');
             $project2->setHomepage('http://www.bing.com');
             $project2->save();
             foreach (array($project1, $project2) as $project) {
                 for ($cc = 1; $cc <= 5; $cc++) {
                     $milestone = new entities\Milestone();
                     $milestone->setName("Milestone {$cc}");
                     $milestone->setProject($project);
                     $milestone->setType(entities\Milestone::TYPE_REGULAR);
                     if ((bool) rand(0, 1)) {
                         $milestone->setScheduledDate(NOW + 100000 * (20 * $cc));
                     }
                     $milestone->save();
                 }
             }
             $p1_milestones = $project1->getMilestones();
             $p2_milestones = $project2->getMilestones();
             $issues = array();
             $priorities = entities\Priority::getAll();
             $categories = entities\Category::getAll();
             $severities = entities\Severity::getAll();
             $statuses = entities\Status::getAll();
             $reproducabilities = entities\Reproducability::getAll();
             $lorem_ipsum = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('LoremIpsum');
             $lorem_words = explode(' ', $lorem_ipsum->getContent());
             foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) {
                 $issuetype = entities\Issuetype::getByKeyish($issuetype);
                 for ($cc = 1; $cc <= 10; $cc++) {
                     $issue1 = new entities\Issue();
                     $issue1->setProject($project1);
                     $issue1->setPostedBy($users[rand(0, 2)]);
                     $issue1->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue1->setTitle(ucfirst($title_string));
                     $issue1->setDescription($description_string);
                     $issue1->setIssuetype($issuetype);
                     $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]);
                     $issue1->setPriority($priorities[array_rand($priorities)]);
                     $issue1->setCategory($categories[array_rand($categories)]);
                     $issue1->setSeverity($severities[array_rand($severities)]);
                     $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue1->setPercentCompleted(rand(0, 100));
                     $issue1->save();
                     $issue1->setStatus($statuses[array_rand($statuses)]);
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue1->save();
                     $issues[] = $issue1;
                     $issue2 = new entities\Issue();
                     $issue2->setProject($project2);
                     $issue2->setPostedBy($users[rand(0, 2)]);
                     $issue2->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue2->setTitle(ucfirst($title_string));
                     $issue2->setDescription($description_string);
                     $issue2->setIssuetype($issuetype);
                     $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]);
                     $issue2->setPriority($priorities[array_rand($priorities)]);
                     $issue2->setCategory($categories[array_rand($categories)]);
                     $issue2->setSeverity($severities[array_rand($severities)]);
                     $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue2->setPercentCompleted(rand(0, 100));
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue2->save();
                     $issue2->setStatus($statuses[array_rand($statuses)]);
                     $issue2->save();
                     $issues[] = $issue2;
                 }
             }
             $rand_issues_to_close = rand(8, 40);
             $resolutions = entities\Resolution::getAll();
             for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) {
                 $issue = array_slice($issues, array_rand($issues), 1);
                 $issue = $issue[0];
                 $issue->setResolution($resolutions[array_rand($resolutions)]);
                 $issue->close();
                 $issue->save();
             }
             $this->imported_data = true;
             $roles = entities\Role::getAll();
             foreach (array($project1, $project2) as $project) {
                 foreach ($users as $user) {
                     $project->addAssignee($user, $roles[array_rand($roles)]);
                 }
             }
             $transaction->commitAndEnd();
         }
     }
     $project1 = entities\Project::getByKey('sampleproject1');
     $project2 = entities\Project::getByKey('sampleproject2');
     $this->canimport = !$project1 instanceof entities\Project && !$project2 instanceof entities\Project;
 }
 public static function findClients($details)
 {
     $crit = new \b2db\Criteria();
     $crit->addWhere(TBGClientsTable::NAME, "%{$details}%", \b2db\Criteria::DB_LIKE);
     $clients = array();
     if ($res = \b2db\Core::getTable('TBGClientsTable')->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $clients[$row->get(TBGClientsTable::ID)] = TBGContext::factory()->TBGClient($row->get(TBGClientsTable::ID), $row);
         }
     }
     return $clients;
 }
Exemple #15
0
 /**
  * Makes sure adding a user happens without errors
  * 
  * @link http://issues.thebuggenie.com/thebuggenie/issues/2494
  *
  * @covers thebuggenie\core\modules\configuration\Actions::runAddUser
  * @dataProvider addUserRequestProvider
  */
 public function testRunAddUser($username, $buddyname, $email, $password, $group_id)
 {
     \b2db\Core::resetMocks();
     $scope = $this->getMockBuilder('thebuggenie\\core\\entities\\Scope')->setMethods(array('hasUsersAvailable'))->getMock();
     $scope->method('hasUsersAvailable')->willReturn(true);
     \thebuggenie\core\framework\Context::setScope($scope);
     $request = new \thebuggenie\core\framework\Request();
     $request->setParameter('username', $username);
     $request->setParameter('buddyname', $buddyname);
     $request->setParameter('email', $email);
     $request->setParameter('password', $password);
     $request->setParameter('password_repeat', $password);
     $request->setParameter('group_id', $group_id);
     $usertablestub = $this->getMockBuilder('b2db\\Table')->setMethods(array('isUsernameAvailable'))->getMock();
     $userscopestablestub = $this->getMockBuilder('b2db\\Table')->getMock();
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\tables\\UserScopes', $userscopestablestub);
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\User', $usertablestub);
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\tables\\Users', $usertablestub);
     $usertablestub->method('isUsernameAvailable')->will($this->returnValue(true));
     // Expect action to verify that username is available
     $usertablestub->expects($this->once())->method('isUsernameAvailable')->with($username);
     $userscopestablestub->expects($this->once())->method('countUsers');
     $this->object->runAddUser($request);
     $userobject = \b2db\Core::getTable('thebuggenie\\core\\entities\\tables\\Users')->getLastMockObject();
     // Expect action to set correct user properties
     $this->assertEquals($userobject->getUsername(), $username);
     $this->assertEquals($userobject->getBuddyname(), $buddyname);
     $this->assertEquals($userobject->getRealname(), $username);
     $this->assertEquals($userobject->getEmail(), $email);
 }
Exemple #16
0
    ?>
</span>&nbsp;&nbsp;<span class="csp-dbg-log-msg"><?php 
    echo $entry['message'];
    ?>
</span><br />
						<?php 
}
?>
						</div>
					</div>
					<div id="csp-dbg-row-<?php 
echo $cspdbgrow;
?>
-content-tab-5-panel" class="csp-dbg-tab-panel" style="display: none;">
<?php 
if (\b2db\Core::isConnected()) {
    ?>
						<p><i>This list shows all the SQL queries that have been made, and how long each took.</i></p>
						<?php 
    $i = 0;
    ?>
						<?php 
    foreach ($dbgqueries as $entry) {
        ?>
							<?php 
        $i++;
        ?>
							<div class="csp-dbg-query-title">
								<span class="csp-dbg-query-title-id">Query <?php 
        echo $i;
        ?>
Exemple #17
0
 /**
  * Register a new SQL call (debug only)
  *
  * @param Statement $statement
  * @param mixed $pretime
  */
 public static function sqlHit(Statement $statement, $pretime)
 {
     if (!Core::isDebugMode()) {
         return;
     }
     $time = Core::getDebugTime() - $pretime;
     $sql = $statement->printSQL();
     $values = $statement->getCriteria() instanceof Criteria ? $statement->getCriteria()->getValues() : array();
     $trace = self::getRelevantDebugBacktraceElement();
     self::$_sqlhits[] = array('sql' => $sql, 'values' => implode(', ', $values), 'time' => $time, 'filename' => $trace['file'], 'line' => $trace['line'], 'function' => $trace['function'], 'class' => isset($trace['class']) ? $trace['class'] : 'unknown', 'type' => isset($trace['type']) ? $trace['type'] : 'unknown', 'arguments' => $trace['args']);
     self::$_sqltiming += $time;
 }
Exemple #18
0
 public final function install($scope)
 {
     try {
         framework\Context::clearRoutingCache();
         framework\Context::clearPermissionsCache();
         $this->_install($scope);
         $b2db_classpath = THEBUGGENIE_MODULES_PATH . $this->_name . DS . 'entities' . DS . 'tables';
         if ($scope == framework\Settings::getDefaultScopeID() && is_dir($b2db_classpath)) {
             $b2db_classpath_handle = opendir($b2db_classpath);
             while ($table_class_file = readdir($b2db_classpath_handle)) {
                 if (($tablename = mb_substr($table_class_file, 0, mb_strpos($table_class_file, '.'))) != '') {
                     \b2db\Core::getTable("\\thebuggenie\\modules\\" . $this->_name . "\\entities\\tables\\" . $tablename)->create();
                 }
             }
         }
         $this->_loadFixtures($scope);
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * Removes an existing component from the edition
  *
  * @param TBGComponent|integer $c_id
  */
 public function removeComponent($c_id)
 {
     if ($c_id instanceof TBGComponent) {
         $c_id = $c_id->getID();
     }
     \b2db\Core::getTable('TBGEditionComponentsTable')->removeEditionComponent($this->getID(), $c_id);
 }
Exemple #20
0
 public function runDetachFile(TBGrequest $request)
 {
     try {
         switch ($request['mode']) {
             case 'issue':
                 $issue = TBGContext::factory()->TBGIssue($request['issue_id']);
                 if ($issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) {
                     \b2db\Core::getTable('TBGIssueFilesTable')->removeByIssueIDAndFileID($issue->getID(), (int) $request['file_id']);
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
             case 'article':
                 $article = TBGWikiArticle::getByName($request['article_name']);
                 if ($article instanceof TBGWikiArticle && $article->canEdit() && (int) $request->getParameter('file_id', 0)) {
                     $article->removeFile(TBGContext::factory()->TBGFile((int) $request['file_id']));
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
         }
     } catch (Exception $e) {
         throw $e;
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Invalid mode')));
 }
 public function getByUserIDAndGroupableMinutes($user_id, $minutes = 0)
 {
     if ($minutes <= 0 || !is_numeric($minutes)) {
         return $this->getByUserID($user_id);
     }
     $notification_type_issue_updated_col = \thebuggenie\core\entities\Notification::TYPE_ISSUE_UPDATED;
     $seconds = $minutes * 60;
     list($target_id_col, $notification_type_col, $module_name_col, $is_read_col, $created_at_col, $triggered_by_user_id_col, $user_id_col, $scope_col, $id_col) = $this->getAliasColumns();
     $sql = 'SELECT ';
     $sql_selects = array();
     foreach ($this->getAliasColumns() as $column) {
         $sql_selects[] = $column . ' AS ' . str_replace('.', '_', $column);
     }
     $sql .= join(', ', $sql_selects);
     $sql .= ", (CASE WHEN {$notification_type_col} = '{$notification_type_issue_updated_col}' THEN 1 ELSE {$id_col} END) as {$this->b2db_alias}_custom_group_by";
     $sql .= ' FROM ' . Core::getTablePrefix() . $this->getB2DBName() . ' ' . $this->getB2DBAlias();
     $sql .= " WHERE {$user_id_col} = {$user_id} AND {$triggered_by_user_id_col} != {$user_id}";
     $sql .= " GROUP BY {$this->b2db_alias}_custom_group_by, {$created_at_col} DIV {$seconds}, {$triggered_by_user_id_col}";
     $sql .= " ORDER BY {$id_col} DESC";
     $crit = $this->getCriteria();
     $crit->sql = $sql;
     $crit->action = 'select';
     $statement = \b2db\Statement::getPreparedStatement($crit);
     $resultset = $statement->performQuery();
     return $this->_populateFromResultset($resultset->count() ? $resultset : null);
 }
Exemple #22
0
        echo $entry['message'];
        ?>
</div>
				<?php 
    }
    ?>
			<?php 
}
?>
			<?php 
if (class_exists("\\b2db\\Core") && TBGContext::isDebugMode() && (!isset($exception) || !$exception instanceof TBGComposerException)) {
    ?>
				<h3>SQL queries:</h3>
					<ol>
					<?php 
    foreach (\b2db\Core::getSQLHits() as $details) {
        ?>
						<li>
							<span class="faded_out dark small"><b>[<?php 
        echo $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
        ?>
]</b></span>
							from <b><?php 
        echo $details['filename'];
        ?>
, line <?php 
        echo $details['line'];
        ?>
</b>:<br>
							<span style="font-size: 12px;"><?php 
        echo $details['sql'];
 public function hasLinkedWorkflowStep()
 {
     return (bool) \b2db\Core::getTable('TBGWorkflowStepsTable')->countByStatusID($this->getID());
 }
Exemple #24
0
 /**
  * Add or delete an issue field option
  *
  * @param TBGRequest $request
  */
 public function runConfigureIssuefieldsAction(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     $this->forward403unless($this->access_level == TBGSettings::ACCESS_FULL);
     $types = TBGDatatype::getTypes();
     switch ($request['mode']) {
         case 'saveorder':
             $itemtype = $request['type'];
             if (array_key_exists($itemtype, $types)) {
                 TBGListTypesTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $itemtype);
             } else {
                 $customtype = TBGCustomDatatype::getByKey($request['type']);
                 TBGCustomFieldOptionsTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $customtype->getID());
             }
             return $this->renderJSON('ok');
             break;
         case 'add':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $type_name = $types[$request['type']];
                     $item = new $type_name();
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     $item->save();
                 } else {
                     $customtype = TBGCustomDatatype::getByKey($request['type']);
                     $item = $customtype->createNewOption($request['name'], $request['value'], $request['itemdata']);
                 }
                 return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was added'), 'content' => $this->getTemplateHTML('issuefield', array('item' => $item, 'access_level' => $this->access_level, 'type' => $request['type']))));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
         case 'edit':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $labname = $types[$request['type']];
                     $item = TBGContext::factory()->{$labname}($request['id']);
                 } else {
                     $customtype = TBGCustomDatatype::getByKey($request['type']);
                     $item = TBGContext::factory()->TBGCustomDatatypeOption($request['id']);
                 }
                 if ($item instanceof TBGDatatypeBase) {
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     if (!$item->isBuiltin()) {
                         $item->setValue($request['value']);
                     }
                     $item->save();
                     return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was updated')));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid id')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
         case 'delete':
             if ($request->hasParameter('id')) {
                 if (array_key_exists($request['type'], $types)) {
                     $classname = 'TBG' . ucfirst($request['type']);
                     $item = TBGContext::factory()->{$classname}($request['id'])->delete();
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 } else {
                     \b2db\Core::getTable('TBGCustomFieldOptionsTable')->doDeleteById($request['id']);
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $i18n->__('Invalid id or type')));
             break;
     }
 }
Exemple #25
0
 protected function _upgradeFrom3dot2(framework\Request $request)
 {
     set_time_limit(0);
     \thebuggenie\core\entities\tables\Milestones::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGMilestone::getB2DBTable());
     \thebuggenie\core\entities\tables\Projects::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGProjectsTable::getTable());
     \thebuggenie\core\entities\tables\Log::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGLogTable::getTable());
     \thebuggenie\core\entities\tables\Users::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGUsersTable::getTable());
     \thebuggenie\core\entities\tables\Issues::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssuesTable::getTable());
     \thebuggenie\core\entities\tables\Workflows::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGWorkflowsTable::getTable());
     \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssueSpentTimesTable::getTable());
     \thebuggenie\core\entities\tables\Comments::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGCommentsTable::getTable());
     \thebuggenie\core\entities\tables\SavedSearches::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSavedSearchesTable::getTable());
     \thebuggenie\core\entities\tables\Settings::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSettingsTable::getTable());
     \thebuggenie\core\entities\tables\Notifications::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGNotificationsTable::getTable());
     \thebuggenie\core\entities\tables\Permissions::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGPermissionsTable::getTable());
     \thebuggenie\core\entities\Dashboard::getB2DBTable()->create();
     \thebuggenie\core\entities\DashboardView::getB2DBTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGDashboardViewsTable::getTable());
     \thebuggenie\core\entities\ApplicationPassword::getB2DBTable()->create();
     \thebuggenie\core\entities\NotificationSetting::getB2DBTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manual_password'];
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 if ($field == 'username' && trim($user->getUsername())) {
                     $user->setPassword(trim($user->getUsername()));
                     $user->save();
                 } elseif ($field == 'email' && trim($user->getEmail())) {
                     $user->setPassword(trim($user->getEmail()));
                     $user->save();
                 }
             }
             break;
     }
     $adminuser = \thebuggenie\core\entities\User::getB2DBTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     framework\Settings::saveSetting(framework\Settings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->selectById((int) $scope_id);
         if ($scope instanceof \thebuggenie\core\entities\Scope) {
             $epic = new \thebuggenie\core\entities\Issuetype();
             $epic->setName('Epic');
             $epic->setIcon('epic');
             $epic->setDescription('Issue type suited for entering epics');
             $epic->setScope($scope_id);
             $epic->save();
             framework\Settings::saveSetting('issuetype_epic', $epic->getID(), 'core', $scope_id);
             foreach (\thebuggenie\core\entities\tables\Workflows::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new \thebuggenie\core\entities\WorkflowTransition();
                 $steps = $workflow->getSteps();
                 $step = array_shift($steps);
                 $step->setLinkedStatusID((int) $status_id);
                 $step->save();
                 $transition->setOutgoingStep($step);
                 $transition->setName('Issue created');
                 $transition->setWorkflow($workflow);
                 $transition->setScope($scope);
                 $transition->setDescription('This is the initial transition for issues using this workflow');
                 $transition->save();
                 $workflow->setInitialTransition($transition);
                 $workflow->save();
             }
             \thebuggenie\core\entities\ActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     framework\Context::finishUpgrading();
     foreach (framework\Context::getModules() as $module) {
         $module->upgrade();
     }
     $this->upgrade_complete = true;
 }
Exemple #26
0
 protected function _upgradeFrom3dot2(TBGRequest $request)
 {
     set_time_limit(0);
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.2');
     foreach (array('publish', 'mailing') as $module) {
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes');
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes' . DS . 'B2DB');
     }
     TBGMilestonesTable::getTable()->upgrade(TBGMilestonesTable3dot2::getTable());
     TBGArticlesTable::getTable()->upgrade(TBGArticlesTable3dot2::getTable());
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot2::getTable());
     TBGLogTable::getTable()->upgrade(TBGLogTable3dot2::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot2::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot2::getTable());
     TBGWorkflowsTable::getTable()->upgrade(TBGWorkflowsTable3dot2::getTable());
     TBGIncomingEmailAccountTable::getTable()->upgrade(TBGIncomingEmailAccountTable3dot2::getTable());
     TBGIssueSpentTimesTable::getTable()->upgrade(TBGIssueSpentTimesTable3dot2::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot2::getTable());
     TBGSavedSearchesTable::getTable()->upgrade(TBGSavedSearchesTable3dot2::getTable());
     TBGSettingsTable::getTable()->upgrade(TBGSettingsTable3dot2::getTable());
     TBGNotificationsTable::getTable()->upgrade(TBGNotificationsTable3dot2::getTable());
     TBGPermissionsTable::getTable()->upgrade(TBGPermissionsTable3dot2::getTable());
     TBGUserArticlesTable::getTable()->create();
     TBGApplicationPasswordsTable::getTable()->create();
     TBGUserNotificationSettingsTable::getTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manul_password'];
             foreach (TBGUsersTable::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (TBGUsersTable::getTable()->selectAll() as $user) {
                 if ($field == 'username' && trim($user->getUsername())) {
                     $user->setPassword(trim($user->getUsername()));
                     $user->save();
                 } elseif ($field == 'email' && trim($user->getEmail())) {
                     $user->setPassword(trim($user->getEmail()));
                     $user->save();
                 }
             }
             break;
     }
     $adminuser = TBGUsersTable::getTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     TBGSettings::saveSetting(TBGSettings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = TBGScopesTable::getTable()->selectById((int) $scope_id);
         if ($scope instanceof TBGScope) {
             foreach (TBGWorkflowsTable::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new TBGWorkflowTransition();
                 $steps = $workflow->getSteps();
                 $step = array_shift($steps);
                 $step->setLinkedStatusID((int) $status_id);
                 $step->save();
                 $transition->setOutgoingStep($step);
                 $transition->setName('Issue created');
                 $transition->setWorkflow($workflow);
                 $transition->setScope($scope);
                 $transition->setDescription('This is the initial transition for issues using this workflow');
                 $transition->save();
                 $workflow->setInitialTransition($transition);
                 $workflow->save();
             }
             TBGActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     TBGContext::finishUpgrading();
     TBGContext::getModule('mailing')->upgradeFrom3dot2();
     $this->upgrade_complete = true;
 }
Exemple #27
0
 public static function cliError($title, $exception)
 {
     $trace_elements = null;
     if ($exception instanceof \Exception) {
         if ($exception instanceof \thebuggenie\core\framework\exceptions\ActionNotFoundException) {
             self::cli_echo("Could not find the specified action\n", 'white', 'bold');
         } elseif ($exception instanceof \thebuggenie\core\framework\exceptions\TemplateNotFoundException) {
             self::cli_echo("Could not find the template file for the specified action\n", 'white', 'bold');
         } elseif ($exception instanceof \b2db\Exception) {
             self::cli_echo("An exception was thrown in the B2DB framework\n", 'white', 'bold');
         } else {
             self::cli_echo("An unhandled exception occurred:\n", 'white', 'bold');
         }
         echo self::cli_echo($exception->getMessage(), 'red', 'bold') . "\n";
         echo "\n";
         self::cli_echo('Stack trace') . ":\n";
         $trace_elements = $exception->getTrace();
     } else {
         if ($exception['code'] == 8) {
             self::cli_echo('The following notice has stopped further execution:', 'white', 'bold');
         } else {
             self::cli_echo('The following error occured:', 'white', 'bold');
         }
         echo "\n";
         echo "\n";
         self::cli_echo($title, 'red', 'bold');
         echo "\n";
         self::cli_echo("occured in\n");
         self::cli_echo($exception['file'] . ', line ' . $exception['line'], 'blue', 'bold');
         echo "\n";
         echo "\n";
         self::cli_echo("Backtrace:\n", 'white', 'bold');
         $trace_elements = debug_backtrace();
     }
     foreach ($trace_elements as $trace_element) {
         if (array_key_exists('class', $trace_element)) {
             if (array_key_exists('class', $trace_element) && $trace_element['class'] == 'thebuggenie\\core\\framework\\Context' && array_key_exists('function', $trace_element) && in_array($trace_element['function'], array('errorHandler', 'cliError'))) {
                 continue;
             }
             self::cli_echo($trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()');
         } elseif (array_key_exists('function', $trace_element)) {
             self::cli_echo($trace_element['function'] . '()');
         } else {
             self::cli_echo('unknown function');
         }
         echo "\n";
         if (array_key_exists('file', $trace_element)) {
             self::cli_echo($trace_element['file'] . ', line ' . $trace_element['line'], 'blue', 'bold');
         } else {
             self::cli_echo('unknown file', 'red', 'bold');
         }
         echo "\n";
     }
     if (class_exists('\\b2db\\Core')) {
         echo "\n";
         $sqlhits = \b2db\Core::getSQLHits();
         if (count($sqlhits)) {
             self::cli_echo("SQL queries:\n", 'white', 'bold');
             try {
                 $cc = 1;
                 foreach ($sqlhits as $details) {
                     self::cli_echo("(" . $cc++ . ") [");
                     $str = $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
                     self::cli_echo($str);
                     self::cli_echo("] from ");
                     self::cli_echo($details['filename'], 'blue');
                     self::cli_echo(", line ");
                     self::cli_echo($details['line'], 'white', 'bold');
                     self::cli_echo(":\n");
                     self::cli_echo("{$details['sql']}\n");
                 }
                 echo "\n";
             } catch (\Exception $e) {
                 self::cli_echo("Could not generate query list (there may be no database connection)", "red", "bold");
             }
         }
     }
     echo "\n";
 }
 /**
  * Delete a custom type by id
  *
  * @param integer $id
  */
 protected function _preDelete()
 {
     TBGCustomFieldOptionsTable::getTable()->deleteCustomFieldOptions($this->getID());
     \b2db\Core::getTable('TBGIssueFieldsTable')->deleteByIssueFieldKey($this->getKey());
 }
                <i><a href="http://www.php.net/manual/en/pdo.construct.php" target="_blank">What is a DSN?</a></i>
            </dd>
        </dl>
        <dl class="install_list" style="<?php 
if ($selected_connection_detail != 'custom') {
    echo 'display: none;';
}
?>
" id="custom_info">
            <dt>
                <label for="db_type">Database type</label>
            </dt>
            <dd>
                <select name="db_type" id="db_type">
                <?php 
foreach (\b2db\Core::getDBtypes() as $db_type => $db_desc) {
    ?>
                    <?php 
    if (extension_loaded("pdo_{$db_type}")) {
        ?>
                        <option value="<?php 
        echo $db_type;
        ?>
"<?php 
        if (isset($b2db_dbtype) && $b2db_dbtype == $db_type) {
            ?>
 selected<?php 
        }
        ?>
><?php 
        echo $db_desc;
Exemple #30
0
 /**
  * Return an array of issues that has changes pending
  * 
  * @param int $number number of issues to be retrieved
  * 
  * @return array
  */
 public function getIssues($number = null)
 {
     $retval = array();
     if ($res = \b2db\Core::getTable('TBGIssuesTable')->getIssuesPostedByUser($this->getID(), $number)) {
         while ($row = $res->getNextRow()) {
             $issue = TBGContext::factory()->TBGIssue($row->get(TBGIssuesTable::ID), $row);
             $retval[$issue->getID()] = $issue;
         }
     }
     return $retval;
 }