Example #1
0
 /**
  * @covers \thebuggenie\core\framework\Context::isInstallmode
  * @covers \thebuggenie\core\framework\Context::checkInstallMode
  */
 public function testInstallMode()
 {
     $installed_file = THEBUGGENIE_PATH . 'installed';
     if (file_exists($installed_file)) {
         unlink($installed_file);
     }
     \thebuggenie\core\framework\Context::checkInstallMode();
     $this->assertTrue(\thebuggenie\core\framework\Context::isInstallmode());
     file_put_contents($installed_file, \thebuggenie\core\framework\Settings::getMajorVer() . "." . \thebuggenie\core\framework\Settings::getMinorVer() . "." . \thebuggenie\core\framework\Settings::getRevision() . ", installed today");
     \thebuggenie\core\framework\Context::checkInstallMode();
     $this->assertFalse(\thebuggenie\core\framework\Context::isInstallmode());
 }
Example #2
0
 public function hasCachedAnnotationListeners()
 {
     if ($this->has_cached_annotation_listeners === null) {
         if (Context::isInstallmode()) {
             $this->has_cached_annotation_listeners = false;
         } else {
             $this->has_cached_annotation_listeners = Context::getCache()->has(Cache::KEY_ANNOTATION_LISTENERS_CACHE);
             if ($this->has_cached_annotation_listeners) {
                 Logging::log('Annotation listeners are cached', 'routing');
             } else {
                 Logging::log('Annotation listeners are not cached', 'routing');
             }
         }
     }
     return $this->has_cached_annotation_listeners;
 }
Example #3
0
 public function do_execute()
 {
     if (\thebuggenie\core\framework\Context::isInstallmode()) {
         $this->cliEcho("The Bug Genie is not installed\n", 'red');
     } else {
         $this->cliEcho("Finding files to remove\n", 'white', 'bold');
         $files = Files::getTable()->getUnattachedFiles();
         $this->cliEcho("Found " . count($files) . " files\n", 'white');
         foreach ($files as $file_id) {
             $file = Files::getTable()->selectById($file_id);
             $this->cliEcho('Deleting file ' . $file_id . "\n");
             $file->delete();
         }
         $this->cliEcho("All " . count($files) . " files removed successfully!\n\n", 'white', 'bold');
     }
 }
Example #4
0
 public function do_execute()
 {
     if (\thebuggenie\core\framework\Context::isInstallmode()) {
         $this->cliEcho("The Bug Genie is not installed\n", 'red');
     } else {
         $this->cliEcho("Finding times to fix\n", 'white', 'bold');
         $issuetimes = \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->getAllSpentTimesForFixing();
         $error_issues = array();
         foreach ($issuetimes as $issue_id => $times) {
             if (count($times) > 1) {
                 $this->cliEcho("Fixing times spent for issue ID {$issue_id}, " . count($times) . " entries\n");
                 $prev_times = \thebuggenie\core\entities\common\Timeable::getZeroedUnitsWithPoints();
                 foreach ($times as $k => $row) {
                     if ($row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_POINTS] < $prev_times['points'] || $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_HOURS] < $prev_times['minutes'] || $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_HOURS] < $prev_times['hours'] || $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_DAYS] < $prev_times['days'] || $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_WEEKS] < $prev_times['weeks'] || $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_MONTHS] < $prev_times['months']) {
                         $error_issues[] = $issue_id;
                     } else {
                         \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->fixRow($row, $prev_times);
                         $prev_times['points'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_POINTS];
                         $prev_times['minutes'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_MINUTES];
                         $prev_times['hours'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_HOURS];
                         $prev_times['days'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_DAYS];
                         $prev_times['weeks'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_WEEKS];
                         $prev_times['months'] += $row[\thebuggenie\core\entities\tables\IssueSpentTimes::SPENT_MONTHS];
                     }
                 }
             }
         }
         foreach (\thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->getAllSpentTimesForFixing() as $issue_id => $times) {
             foreach ($times as $row) {
                 \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->fixHours($row);
             }
             \thebuggenie\core\entities\tables\Issues::getTable()->fixHours($issue_id);
         }
         if (count($error_issues) > 0) {
             $this->cliEcho("\n");
             $this->cliEcho("All spent times have been attempted fixed, but there were some issues that could not be fixed automatically!\n");
             $this->cliEcho("This happens if there has been adjustments in time spent, lowering the value for spent points, minutes, hours, days, weeks or months.\n\n");
             $this->cliEcho("You should fix the issues manually (issue ids corresponding to issue_ids in the timesspent table): ");
             $this->cliEcho(join(', ', $error_issues) . "\n\n");
             $this->cliEcho("Spent times fixed!\n\n", 'green');
         } else {
             $this->cliEcho("All spent times fixed successfully!\n\n", 'green');
         }
         $this->cliEcho("IMPORTANT: Don't run this task again!\n", 'white', 'bold');
     }
 }
Example #5
0
 public static function get($name, $module = 'core', $scope = null, $uid = 0)
 {
     if (Context::isInstallmode() && !Context::getScope() instanceof Scope) {
         return null;
     }
     if ($scope instanceof Scope) {
         $scope = $scope->getID();
     }
     if (!Context::getScope() instanceof Scope) {
         throw new \Exception('The Bug Genie is not installed correctly');
     }
     if ($scope != Context::getScope()->getID() && $scope !== null) {
         $setting = self::_loadSetting($name, $module, $scope);
         return $setting[$uid];
     }
     if (self::$_settings === null) {
         self::loadSettings();
     }
     if ($uid > 0 && !array_key_exists($uid, self::$_loadedsettings)) {
         self::loadSettings($uid);
     }
     if (!is_array(self::$_settings) || !array_key_exists($module, self::$_settings)) {
         return null;
     }
     if (!array_key_exists($name, self::$_settings[$module])) {
         return null;
         //self::$_settings[$name] = self::_loadSetting($name, $module, Context::getScope()->getID());
     }
     if ($uid !== 0 && array_key_exists($uid, self::$_settings[$module][$name])) {
         return self::$_settings[$module][$name][$uid];
     } else {
         if (!array_key_exists($uid, self::$_settings[$module][$name])) {
             return null;
         }
         return self::$_settings[$module][$name][$uid];
     }
 }
Example #6
0
 /**
  * Pre-save function to check for conflicting usernames and to make
  * sure some properties are set
  *
  * @param boolean $is_new Whether this is a new user object
  */
 protected function _preSave($is_new)
 {
     parent::_preSave($is_new);
     if (!framework\Context::isInstallmode() && !framework\Context::isUpgrademode()) {
         $compare_user = self::getByUsername($this->getUsername());
         if ($compare_user instanceof User && $compare_user->getID() && $compare_user->getID() != $this->getID()) {
             throw new \Exception(framework\Context::getI18n()->__('This username already exists'));
         }
     }
     if ($is_new) {
         // In case the postsave event isn't processed we automatically enable the user
         // since we can't be sure that an activation email has been sent out
         $this->setEnabled();
         $this->setActivated();
     }
     if (!$this->_realname) {
         $this->_realname = $this->_username;
     }
     if (!$this->_buddyname) {
         $this->_buddyname = $this->_username;
     }
     if (is_object($this->_timezone)) {
         $this->_timezone = $this->_timezone->getName();
     }
     if ($is_new && $this->_joined === 0) {
         $this->_joined = NOW;
     }
     if ($is_new && $this->_group_id === null) {
         $this->setGroup(framework\Settings::getDefaultGroup());
     }
     if ($this->_deleted) {
         try {
             if ($this->getGroup() instanceof \thebuggenie\core\entities\Group) {
                 $this->getGroup()->removeMember($this);
             }
         } catch (\Exception $e) {
         }
         $this->_group_id = null;
         $this->_buddyname = $this->_username;
         $this->_username = '';
         if (!$is_new) {
             tables\TeamMembers::getTable()->clearTeamsByUserID($this->getID());
             tables\ClientMembers::getTable()->clearClientsByUserID($this->getID());
             tables\UserScopes::getTable()->clearUserScopes($this->getID());
         }
     }
 }
Example #7
0
 public function do_execute()
 {
     if (\thebuggenie\core\framework\Context::isInstallmode()) {
         $this->cliEcho("Create module\n", 'white', 'bold');
         $this->cliEcho("The Bug Genie is not installed\n", 'red');
     } else {
         $module_key = mb_strtolower($this->getProvidedArgument('module_name'));
         $module_name = ucfirst($module_key);
         $module_description = "Autogenerated module {$module_name}";
         $this->cliEcho("Initializing empty module ");
         $this->cliEcho("{$module_key}\n", 'white', 'bold');
         $this->cliEcho("Checking that the module doesn't exist ... ");
         if (file_exists(THEBUGGENIE_MODULES_PATH . $module_key)) {
             $this->cliEcho("fail\n", 'red');
             $this->cliEcho("A module with this name already exists\n", 'red');
             return false;
         } else {
             $this->cliEcho("OK\n", 'green', 'bold');
         }
         $this->cliEcho("Checking for conflicting classnames ... ");
         if (class_exists($module_name)) {
             $this->cliEcho("fail\n", 'red');
             $this->cliEcho("A class with this name already exists\n", 'red');
             return false;
         } else {
             $this->cliEcho("OK\n", 'green', 'bold');
         }
         $this->cliEcho("Checking that the module path is writable ... ");
         if (!is_writable(THEBUGGENIE_MODULES_PATH)) {
             $this->cliEcho("fail\n", 'red');
             $this->cliEcho("Module path isn't writable\n\n", 'red');
             $this->cliEcho("Please make sure that the following path is writable: \n");
             $this->cliEcho(THEBUGGENIE_MODULES_PATH, 'cyan');
             return false;
         } else {
             $this->cliEcho("OK\n", 'green', 'bold');
         }
         $this->cliEcho("\nCreating module directory structure ... \n", 'white', 'bold');
         $this_module_path = THEBUGGENIE_MODULES_PATH . $module_key . DS;
         mkdir(THEBUGGENIE_MODULES_PATH . $module_key);
         $this->cliEcho('modules' . DS . "{$module_key}\n");
         mkdir($this_module_path . 'controllers');
         $this->cliEcho('modules' . DS . $module_key . DS . "controllers\n");
         mkdir($this_module_path . 'configuration');
         $this->cliEcho('modules' . DS . $module_key . DS . "configuration\n");
         mkdir($this_module_path . 'entities');
         $this->cliEcho('modules' . DS . $module_key . DS . "entities\n");
         mkdir($this_module_path . 'cli');
         $this->cliEcho('modules' . DS . $module_key . DS . "cli\n");
         mkdir($this_module_path . 'templates');
         $this->cliEcho('modules' . DS . $module_key . DS . "templates\n");
         $this->cliEcho("... ", 'white', 'bold');
         $this->cliEcho("OK\n", 'green', 'bold');
         $this->cliEcho("\nCreating module files ... \n", 'white', 'bold');
         $module_class_template = file_get_contents(THEBUGGENIE_INTERNAL_MODULES_PATH . "main" . DS . "fixtures" . DS . "emptymoduleclass");
         $module_class_content = str_replace(array('module_key', 'module_name', 'module_description'), array($module_key, $module_name, $module_description), $module_class_template);
         file_put_contents($this_module_path . $module_name . ".php", $module_class_content);
         $this->cliEcho("modules" . DS . $module_key . DS . $module_name . ".php\n");
         $module_actions_class_template = file_get_contents(THEBUGGENIE_INTERNAL_MODULES_PATH . "main" . DS . "fixtures" . DS . "emptymoduleactionsclass");
         $module_actions_class_content = str_replace(array('module_key', 'module_name', 'module_description'), array($module_key, $module_name, $module_description), $module_actions_class_template);
         file_put_contents($this_module_path . DS . "controllers" . DS . "Main.php", $module_actions_class_content);
         $this->cliEcho("modules" . DS . $module_key . DS . "Main.php\n");
         $module_actioncomponents_class_template = file_get_contents(THEBUGGENIE_INTERNAL_MODULES_PATH . "main" . DS . "fixtures" . DS . "emptymoduleactioncomponentsclass");
         $module_actioncomponents_class_content = str_replace(array('module_key', 'module_name', 'module_description'), array($module_key, $module_name, $module_description), $module_actioncomponents_class_template);
         file_put_contents($this_module_path . "Components.php", $module_actioncomponents_class_content);
         $this->cliEcho("modules" . DS . $module_key . DS . "Components.php\n");
         file_put_contents($this_module_path . "templates" . DS . "index.html.php", "{$module_name} frontpage");
         $this->cliEcho("modules" . DS . $module_key . DS . "templates" . DS . "index.html.php\n");
         $this->cliEcho("... ", 'white', 'bold');
         $this->cliEcho("OK\n\n", 'green', 'bold');
         $this->cliEcho("The module was created successfully!\n", 'green');
     }
 }
Example #8
0
 public function getCharset()
 {
     if (Context::isInstallmode()) {
         return $this->_charset;
     }
     return Settings::get('charset') != '' ? Settings::get('charset') : $this->_charset;
 }
Example #9
0
 public function do_execute()
 {
     if (\thebuggenie\core\framework\Context::isInstallmode()) {
         $this->cliEcho("Manage modules\n", 'white', 'bold');
         $this->cliEcho("The Bug Genie is not installed\n", 'red');
     } else {
         switch ($this->getProvidedArgument('action')) {
             case 'list_installed':
                 $this->_listInstalled();
                 break;
             case 'list_available':
                 $this->_listAvailable();
                 break;
             case 'install':
                 $this->_installModule($this->getProvidedArgument('module_name'));
                 break;
             case 'uninstall':
                 $this->_uninstallModule($this->getProvidedArgument('module_name'));
                 break;
             default:
                 $this->cliEcho("Unknown action\n", 'red');
         }
     }
 }