Example #1
0
 protected function _setup()
 {
     $this->_command_name = 'remove_scope';
     $this->_description = "Removes a scope";
     $this->addRequiredArgument('hostname', 'The hostname for the scope to remove');
     parent::_setup();
 }
Example #2
0
 /**
  * Log a message to the logger
  *
  * @param string $message The message to log
  * @param string $category [optional] The message category (default "main")
  * @param integer $level [optional] The loglevel
  */
 public static function log($message, $category = 'main', $level = 1)
 {
     if (!self::$_logging_enabled) {
         return false;
     }
     if (self::$_loglevel > $level) {
         return false;
     }
     if (self::$_cli_log_to_screen_in_debug_mode && Context::isCLI() && Context::isDebugMode() && class_exists('\\thebuggenie\\core\\framework\\cli\\Command')) {
         \thebuggenie\core\framework\cli\Command::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold');
         \thebuggenie\core\framework\cli\Command::cli_echo(" [{$category}] ", 'green', 'bold');
         \thebuggenie\core\framework\cli\Command::cli_echo("{$message}\n");
     }
     if (self::$_logonajaxcalls || Context::getRequest()->isAjaxCall()) {
         if (self::$_logfile !== null) {
             file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND);
         }
         $time_msg = Context::isDebugMode() ? ($load_time = Context::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms' : '';
         self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level);
         self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level);
     }
 }
Example #3
0
 protected function _setup()
 {
     $this->_command_name = 'create_scope';
     $this->_description = "Create a new scope";
     $this->addRequiredArgument('hostname', 'The default hostname for this scope');
     $this->addRequiredArgument('shortname', 'The short name for this scope');
     $this->addOptionalArgument('description', 'An optional description for this scope');
     $this->addOptionalArgument('enable_uploads', 'Whether uploads are enabled for this scope (yes/no)');
     $this->addOptionalArgument('upload_limit', 'The upload limit for this scope');
     $this->addOptionalArgument('projects', 'The number of available projects for this scope');
     $this->addOptionalArgument('users', 'The number of available users for this scope');
     $this->addOptionalArgument('teams', 'The number of available teams for this scope');
     $this->addOptionalArgument('workflows', 'The number of available workflows for this scope');
     foreach (framework\Context::getModules() as $module) {
         $module_name = $module->getName();
         if ($module_name == 'publish') {
             continue;
         }
         $this->addOptionalArgument("install_module_{$module_name}", "Install the {$module_name} module in this scope (yes/no)");
     }
     $this->addOptionalArgument('scope_admin', 'Add an admin user (username) to this scope');
     $this->addOptionalArgument('remove_admin', 'Remove admininistrator from this scope (yes/no)');
     parent::_setup();
 }
Example #4
0
 protected static function cliError($title, $exception)
 {
     cli\Command::cliError($title, $exception);
 }
Example #5
0
 public function loadArticles($namespace = '', $overwrite = true, $scope = null)
 {
     $scope = framework\Context::getScope()->getID();
     $namespace = mb_strtolower($namespace);
     $_path_handle = opendir(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS);
     while ($original_article_name = readdir($_path_handle)) {
         if (mb_strpos($original_article_name, '.') === false) {
             $article_name = mb_strtolower($original_article_name);
             $imported = false;
             $import = false;
             if ($namespace) {
                 if (mb_strpos(urldecode($article_name), "{$namespace}:") === 0 || mb_strpos(urldecode($article_name), "category:") === 0 && mb_strpos(urldecode($article_name), "{$namespace}:") === 9) {
                     $import = true;
                 }
             } else {
                 if (mb_strpos(urldecode($article_name), "category:help:") === 0) {
                     $name_test = mb_substr(urldecode($article_name), 14);
                 } elseif (mb_strpos(urldecode($article_name), "category:") === 0) {
                     $name_test = mb_substr(urldecode($article_name), 9);
                 } else {
                     $name_test = urldecode($article_name);
                 }
                 if (mb_strpos($name_test, ':') === false) {
                     $import = true;
                 }
             }
             if ($import) {
                 if (framework\Context::isCLI()) {
                     \thebuggenie\core\framework\cli\Command::cli_echo('Saving ' . urldecode($original_article_name) . "\n");
                 }
                 if ($overwrite) {
                     Articles::getTable()->deleteArticleByName(urldecode($original_article_name));
                 }
                 if (Articles::getTable()->getArticleByName(urldecode($original_article_name)) === null) {
                     $content = file_get_contents(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'fixtures' . DS . $original_article_name);
                     Article::createNew(urldecode($original_article_name), $content, $scope, array('overwrite' => $overwrite, 'noauthor' => true));
                     $imported = true;
                 }
                 framework\Event::createNew('publish', 'fixture_article_loaded', urldecode($original_article_name), array('imported' => $imported))->trigger();
             }
         }
     }
 }
Example #6
0
 protected function _setup()
 {
     $this->_command_name = 'list_scopes';
     $this->_description = "List available scopes";
     parent::_setup();
 }
Example #7
0
 public function do_execute()
 {
     $this->cliEcho("The Bug Genie CLI help\n", 'white', 'bold');
     if ($this->hasProvidedArgument(2)) {
         $module_command = explode(':', $this->getProvidedArgument(2));
         $module_name = count($module_command) == 2 ? $module_command[0] : 'main';
         $command = count($module_command) == 2 ? $module_command[1] : $module_command[0];
         $commands = self::getAvailableCommands();
         if (array_key_exists($module_name, $commands) && array_key_exists($command, $commands[$module_name])) {
             $this->cliEcho("\n");
             $class = $commands[$module_name][$command];
             $this->cliEcho("Usage: ", 'white', 'bold');
             $this->cliEcho(\thebuggenie\core\framework\cli\Command::getCommandLineName() . " ");
             if ($module_name != 'main') {
                 $this->cliEcho($module_name . ':', 'green', 'bold');
             }
             $this->cliEcho($class->getCommandName() . " ", 'green', 'bold');
             $hasArguments = false;
             foreach ($class->getRequiredArguments() as $argument => $description) {
                 $this->cliEcho($argument . ' ', 'magenta', 'bold');
                 $hasArguments = true;
             }
             foreach ($class->getOptionalArguments() as $argument => $description) {
                 $this->cliEcho('[' . $argument . '] ', 'magenta');
                 $hasArguments = true;
             }
             $this->cliEcho("\n");
             $this->cliEcho($class->getDescription(), 'white', 'bold');
             $this->cliEcho("\n\n");
             if ($hasArguments) {
                 $this->cliEcho("Argument descriptions:\n", 'white', 'bold');
                 foreach ($class->getRequiredArguments() as $argument => $description) {
                     $this->cliEcho("  {$argument}", 'magenta', 'bold');
                     if ($description != '') {
                         $this->cliEcho(" - {$description}");
                     } else {
                         $this->cliEcho(" - No description provided");
                     }
                     $this->cliEcho("\n");
                 }
                 foreach ($class->getOptionalArguments() as $argument => $description) {
                     $this->cliEcho("  [{$argument}]", 'magenta');
                     if ($description != '') {
                         $this->cliEcho(" - {$description}");
                     } else {
                         $this->cliEcho(" - No description provided");
                     }
                     $this->cliEcho("\n");
                 }
                 $this->cliEcho("\n");
                 $this->cliEcho("Parameters must be passed either in the order described above\nor in the following format:\n");
                 $this->cliEcho("--parameter_name=value", 'magenta');
                 $this->cliEcho("\n\n");
             }
         } else {
             $this->cliEcho("\n");
             $this->cliEcho("Unknown command\n", 'red', 'bold');
             $this->cliEcho("Type " . \thebuggenie\core\framework\cli\Command::getCommandLineName() . ' ', 'white', 'bold');
             $this->cliEcho('help', 'green', 'bold');
             $this->cliEcho(" for more information about the cli tool.\n\n");
         }
     } else {
         $this->cliEcho("Below is a list of available commands:\n");
         $this->cliEcho("Type ");
         $this->cliEcho(\thebuggenie\core\framework\cli\Command::getCommandLineName() . ' ', 'white', 'bold');
         $this->cliEcho('help', 'green', 'bold');
         $this->cliEcho(' command', 'magenta');
         $this->cliEcho(" for more information about a specific command.\n\n");
         $commands = $this->getAvailableCommands();
         foreach ($commands as $module_name => $module_commands) {
             if ($module_name != 'main' && count($module_commands) > 0) {
                 $this->cliEcho("\n{$module_name}:\n", 'green', 'bold');
             }
             ksort($module_commands, SORT_STRING);
             foreach ($module_commands as $command_name => $command) {
                 if ($module_name != 'main') {
                     $this->cliEcho("  ");
                 }
                 $this->cliEcho("{$command_name}", 'green', 'bold');
                 $this->cliEcho(" - {$command->getDescription()}\n");
             }
             if (count($commands) > 1 && $module_name == 'remote') {
                 $this->cliEcho("\nModule commands, use ");
                 $this->cliEcho("module_name:command_name", 'green');
                 $this->cliEcho(" to run:");
             }
         }
         $this->cliEcho("\n");
     }
 }