Add ProfileAdd subconsole
This commit is contained in:
parent
f9b9557415
commit
63b10c37f5
|
@ -23,6 +23,7 @@ class Console extends \Asika\SimpleConsole\Console
|
|||
protected $routes = [
|
||||
'directory-add' => \Friendica\Directory\Routes\Console\DirectoryAdd::class,
|
||||
'directory-poll' => \Friendica\Directory\Routes\Console\DirectoryPoll::class,
|
||||
'profile-add' => \Friendica\Directory\Routes\Console\ProfileAdd::class,
|
||||
'profile-hide' => \Friendica\Directory\Routes\Console\ProfileHide::class,
|
||||
'profile-poll' => \Friendica\Directory\Routes\Console\ProfilePoll::class,
|
||||
'server-hide' => \Friendica\Directory\Routes\Console\ServerHide::class,
|
||||
|
|
86
src/classes/Controllers/Console/ProfileAdd.php
Normal file
86
src/classes/Controllers/Console/ProfileAdd.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Controllers\Console;
|
||||
|
||||
use Friendica\Directory\Models\ProfilePollQueue;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class ProfileAdd extends \Asika\SimpleConsole\Console
|
||||
{
|
||||
/**
|
||||
* @var ProfilePollQueue
|
||||
*/
|
||||
protected $profilePollQueueModel;
|
||||
|
||||
protected $helpOptions = ['h', 'help', '?'];
|
||||
|
||||
public function __construct(
|
||||
ProfilePollQueue $profilePollQueueModel,
|
||||
?array $argv = null
|
||||
)
|
||||
{
|
||||
parent::__construct($argv);
|
||||
|
||||
$this->profilePollQueueModel = $profilePollQueueModel;
|
||||
}
|
||||
|
||||
protected function getHelp()
|
||||
{
|
||||
$help = <<<HELP
|
||||
console profile-add - Adds provided profile to queue
|
||||
Usage
|
||||
bin/console profile-add <profile_url> [-h|--help|-?] [-v]
|
||||
|
||||
Description
|
||||
Adds provided profile to queue
|
||||
|
||||
Options
|
||||
-h|--help|-? Show help information
|
||||
-v Show more debug information.
|
||||
HELP;
|
||||
return $help;
|
||||
}
|
||||
|
||||
protected function doExecute()
|
||||
{
|
||||
if (count($this->args) == 0) {
|
||||
$this->out($this->getHelp());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (count($this->args) > 1) {
|
||||
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
||||
}
|
||||
|
||||
$profile_url = $this->getArgument(0);
|
||||
|
||||
$result = $this->profilePollQueueModel->add($profile_url);
|
||||
|
||||
switch($result) {
|
||||
case 0: {
|
||||
$this->out('Successfully added the profile to the queue.');
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
case ProfilePollQueue::EMPTY_URL: {
|
||||
throw new \RuntimeException('Unable to add profile with empty URL');
|
||||
}
|
||||
case ProfilePollQueue::MISSING_HOST: {
|
||||
throw new \RuntimeException('Unable to add profile URL with a missing host');
|
||||
}
|
||||
case ProfilePollQueue::PRIVATE_HOST: {
|
||||
throw new \RuntimeException('Unable to add profile with a private URL');
|
||||
}
|
||||
case ProfilePollQueue::ALREADY_EXISTS: {
|
||||
$this->out('Profile already existing in the queue.');
|
||||
return 0;
|
||||
}
|
||||
default: {
|
||||
throw new \RuntimeException('Unable to add profile to the queue');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
src/classes/Routes/Console/ProfileAdd.php
Normal file
17
src/classes/Routes/Console/ProfileAdd.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Routes\Console;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class ProfileAdd extends BaseRoute
|
||||
{
|
||||
public function __invoke(array $args)
|
||||
{
|
||||
return (new \Friendica\Directory\Controllers\Console\ProfileAdd(
|
||||
$this->container->get('\Friendica\Directory\Models\ProfilePollQueue'),
|
||||
$args
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue