X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConsole%2FGlobalCommunityBlock.php;h=59a5d9cfdc1ce99daa23eb813e940c62de14b5de;hb=46294d27ee65c6916ea3a5bd8e9ef7aee9cd16e4;hp=1516a8325cde4a1a10240e43deeee7077eaac36a;hpb=4d8d5ca6a58af9aa98cd7f6ca38da5176c621f0d;p=friendica.git diff --git a/src/Core/Console/GlobalCommunityBlock.php b/src/Core/Console/GlobalCommunityBlock.php index 1516a8325c..59a5d9cfdc 100644 --- a/src/Core/Console/GlobalCommunityBlock.php +++ b/src/Core/Console/GlobalCommunityBlock.php @@ -1,77 +1,75 @@ - - * @author Hypolite Petovan - */ -class GlobalCommunityBlock extends \Asika\SimpleConsole\Console -{ - protected $helpOptions = ['h', 'help', '?']; - - protected function getHelp() - { - $help = << [-h|--help|-?] [-v] - -Description - Blocks an account in such a way that no postings or comments this account writes are accepted to this node. - -Options - -h|--help|-? Show help information - -v Show more debug information. -HELP; - return $help; - } - - protected function doExecute() - { - if ($this->getOption('v')) { - $this->out('Class: ' . __CLASS__); - $this->out('Arguments: ' . var_export($this->args, true)); - $this->out('Options: ' . var_export($this->options, true)); - } - - if (count($this->args) == 0) { - $this->out($this->getHelp()); - return 0; - } - - if (count($this->args) > 1) { - throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); - } - - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); - } - - $contact_id = Contact::getIdForURL($this->getArgument(0)); - if (!$contact_id) { - throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl)); - } - if(Contact::block($contact_id)) { - $this->out(L10n::t('The contact has been blocked from the node')); - } else { - throw new \RuntimeException('The contact block failed.'); - } - - return 0; - } -} + + * @author Hypolite Petovan + */ +class GlobalCommunityBlock extends \Asika\SimpleConsole\Console +{ + protected $helpOptions = ['h', 'help', '?']; + + protected function getHelp() + { + $help = << [-h|--help|-?] [-v] + +Description + Blocks an account in such a way that no postings or comments this account writes are accepted to this node. + +Options + -h|--help|-? Show help information + -v Show more debug information. +HELP; + return $help; + } + + protected function doExecute() + { + $a = get_app(); + + if ($this->getOption('v')) { + $this->out('Class: ' . __CLASS__); + $this->out('Arguments: ' . var_export($this->args, true)); + $this->out('Options: ' . var_export($this->options, true)); + } + + if (count($this->args) == 0) { + $this->out($this->getHelp()); + return 0; + } + + if (count($this->args) > 1) { + throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); + } + + if ($a->isInstallMode()) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); + } + + $contact_id = Contact::getIdForURL($this->getArgument(0)); + if (!$contact_id) { + throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl)); + } + if(Contact::block($contact_id)) { + $this->out(L10n::t('The contact has been blocked from the node')); + } else { + throw new \RuntimeException('The contact block failed.'); + } + + return 0; + } +}