diff options
Diffstat (limited to 'app/Console')
-rw-r--r-- | app/Console/BaseCommand.php | 35 | ||||
-rw-r--r-- | app/Console/PluginInstallCommand.php | 36 | ||||
-rw-r--r-- | app/Console/PluginUninstallCommand.php | 36 | ||||
-rw-r--r-- | app/Console/PluginUpgradeCommand.php | 55 | ||||
-rw-r--r-- | app/Console/ProjectDailyColumnStatsExportCommand.php | 2 | ||||
-rw-r--r-- | app/Console/ProjectDailyStatsCalculationCommand.php | 8 | ||||
-rw-r--r-- | app/Console/ResetPasswordCommand.php | 4 | ||||
-rw-r--r-- | app/Console/ResetTwoFactorCommand.php | 4 | ||||
-rw-r--r-- | app/Console/TaskOverdueNotificationCommand.php | 26 | ||||
-rw-r--r-- | app/Console/TaskTriggerCommand.php | 8 | ||||
-rw-r--r-- | app/Console/WorkerCommand.php | 28 |
11 files changed, 200 insertions, 42 deletions
diff --git a/app/Console/BaseCommand.php b/app/Console/BaseCommand.php index 4444ceba..50417071 100644 --- a/app/Console/BaseCommand.php +++ b/app/Console/BaseCommand.php @@ -11,22 +11,25 @@ use Symfony\Component\Console\Command\Command; * @package console * @author Frederic Guillot * - * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator - * @property \Kanboard\Export\SubtaskExport $subtaskExport - * @property \Kanboard\Export\TaskExport $taskExport - * @property \Kanboard\Export\TransitionExport $transitionExport - * @property \Kanboard\Model\Notification $notification - * @property \Kanboard\Model\Project $project - * @property \Kanboard\Model\ProjectPermission $projectPermission - * @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats - * @property \Kanboard\Model\ProjectDailyStats $projectDailyStats - * @property \Kanboard\Model\Task $task - * @property \Kanboard\Model\TaskFinder $taskFinder - * @property \Kanboard\Model\User $user - * @property \Kanboard\Model\UserNotification $userNotification - * @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter - * @property \Kanboard\Model\ProjectUserRole $projectUserRole - * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator + * @property \Kanboard\Export\SubtaskExport $subtaskExport + * @property \Kanboard\Export\TaskExport $taskExport + * @property \Kanboard\Export\TransitionExport $transitionExport + * @property \Kanboard\Model\NotificationModel $notificationModel + * @property \Kanboard\Model\ProjectModel $projectModel + * @property \Kanboard\Model\ProjectPermissionModel $projectPermissionModel + * @property \Kanboard\Model\ProjectDailyColumnStatsModel $projectDailyColumnStatsModel + * @property \Kanboard\Model\ProjectDailyStatsModel $projectDailyStatsModel + * @property \Kanboard\Model\TaskModel $taskModel + * @property \Kanboard\Model\TaskFinderModel $taskFinderModel + * @property \Kanboard\Model\UserModel $userModel + * @property \Kanboard\Model\UserNotificationModel $userNotificationModel + * @property \Kanboard\Model\UserNotificationFilterModel $userNotificationFilterModel + * @property \Kanboard\Model\ProjectUserRoleModel $projectUserRoleModel + * @property \Kanboard\Core\Plugin\Loader $pluginLoader + * @property \Kanboard\Core\Http\Client $httpClient + * @property \Kanboard\Core\Queue\QueueManager $queueManager + * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */ abstract class BaseCommand extends Command { diff --git a/app/Console/PluginInstallCommand.php b/app/Console/PluginInstallCommand.php new file mode 100644 index 00000000..a82f0069 --- /dev/null +++ b/app/Console/PluginInstallCommand.php @@ -0,0 +1,36 @@ +<?php + +namespace Kanboard\Console; + +use Kanboard\Core\Plugin\Installer; +use Kanboard\Core\Plugin\PluginInstallerException; +use LogicException; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class PluginInstallCommand extends BaseCommand +{ + protected function configure() + { + $this + ->setName('plugin:install') + ->setDescription('Install a plugin from a remote Zip archive') + ->addArgument('url', InputArgument::REQUIRED, 'Archive URL'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!Installer::isConfigured()) { + throw new LogicException('Kanboard is not configured to install plugins itself'); + } + + try { + $installer = new Installer($this->container); + $installer->install($input->getArgument('url')); + $output->writeln('<info>Plugin installed successfully</info>'); + } catch (PluginInstallerException $e) { + $output->writeln('<error>'.$e->getMessage().'</error>'); + } + } +} diff --git a/app/Console/PluginUninstallCommand.php b/app/Console/PluginUninstallCommand.php new file mode 100644 index 00000000..48722130 --- /dev/null +++ b/app/Console/PluginUninstallCommand.php @@ -0,0 +1,36 @@ +<?php + +namespace Kanboard\Console; + +use Kanboard\Core\Plugin\Installer; +use Kanboard\Core\Plugin\PluginInstallerException; +use LogicException; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class PluginUninstallCommand extends BaseCommand +{ + protected function configure() + { + $this + ->setName('plugin:uninstall') + ->setDescription('Remove a plugin') + ->addArgument('pluginId', InputArgument::REQUIRED, 'Plugin directory name'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!Installer::isConfigured()) { + throw new LogicException('Kanboard is not configured to install plugins itself'); + } + + try { + $installer = new Installer($this->container); + $installer->uninstall($input->getArgument('pluginId')); + $output->writeln('<info>Plugin removed successfully</info>'); + } catch (PluginInstallerException $e) { + $output->writeln('<error>'.$e->getMessage().'</error>'); + } + } +} diff --git a/app/Console/PluginUpgradeCommand.php b/app/Console/PluginUpgradeCommand.php new file mode 100644 index 00000000..6c66e917 --- /dev/null +++ b/app/Console/PluginUpgradeCommand.php @@ -0,0 +1,55 @@ +<?php + +namespace Kanboard\Console; + +use Kanboard\Core\Plugin\Base as BasePlugin; +use Kanboard\Core\Plugin\Directory; +use Kanboard\Core\Plugin\Installer; +use LogicException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class PluginUpgradeCommand extends BaseCommand +{ + protected function configure() + { + $this + ->setName('plugin:upgrade') + ->setDescription('Update all installed plugins') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!Installer::isConfigured()) { + throw new LogicException('Kanboard is not configured to install plugins itself'); + } + + $installer = new Installer($this->container); + $availablePlugins = Directory::getInstance($this->container)->getAvailablePlugins(); + + foreach ($this->pluginLoader->getPlugins() as $installedPlugin) { + $pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin); + + if ($pluginDetails === null) { + $output->writeln('<error>* Plugin not available in the directory: '.$installedPlugin->getPluginName().'</error>'); + } elseif ($pluginDetails['version'] > $installedPlugin->getPluginVersion()) { + $output->writeln('<comment>* Updating plugin: '.$installedPlugin->getPluginName().'</comment>'); + $installer->update($pluginDetails['download']); + } else { + $output->writeln('<info>* Plugin up to date: '.$installedPlugin->getPluginName().'</info>'); + } + } + } + + protected function getPluginDetails(array $availablePlugins, BasePlugin $installedPlugin) + { + foreach ($availablePlugins as $availablePlugin) { + if ($availablePlugin['title'] === $installedPlugin->getPluginName()) { + return $availablePlugin; + } + } + + return null; + } +} diff --git a/app/Console/ProjectDailyColumnStatsExportCommand.php b/app/Console/ProjectDailyColumnStatsExportCommand.php index ced1a374..1e8af727 100644 --- a/app/Console/ProjectDailyColumnStatsExportCommand.php +++ b/app/Console/ProjectDailyColumnStatsExportCommand.php @@ -21,7 +21,7 @@ class ProjectDailyColumnStatsExportCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { - $data = $this->projectDailyColumnStats->getAggregatedMetrics( + $data = $this->projectDailyColumnStatsModel->getAggregatedMetrics( $input->getArgument('project_id'), $input->getArgument('start_date'), $input->getArgument('end_date') diff --git a/app/Console/ProjectDailyStatsCalculationCommand.php b/app/Console/ProjectDailyStatsCalculationCommand.php index 5b898f02..8dde8a79 100644 --- a/app/Console/ProjectDailyStatsCalculationCommand.php +++ b/app/Console/ProjectDailyStatsCalculationCommand.php @@ -2,7 +2,7 @@ namespace Kanboard\Console; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -17,12 +17,12 @@ class ProjectDailyStatsCalculationCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { - $projects = $this->project->getAllByStatus(Project::ACTIVE); + $projects = $this->projectModel->getAllByStatus(ProjectModel::ACTIVE); foreach ($projects as $project) { $output->writeln('Run calculation for '.$project['name']); - $this->projectDailyColumnStats->updateTotals($project['id'], date('Y-m-d')); - $this->projectDailyStats->updateTotals($project['id'], date('Y-m-d')); + $this->projectDailyColumnStatsModel->updateTotals($project['id'], date('Y-m-d')); + $this->projectDailyStatsModel->updateTotals($project['id'], date('Y-m-d')); } } } diff --git a/app/Console/ResetPasswordCommand.php b/app/Console/ResetPasswordCommand.php index 93dc3761..b483f902 100644 --- a/app/Console/ResetPasswordCommand.php +++ b/app/Console/ResetPasswordCommand.php @@ -60,14 +60,14 @@ class ResetPasswordCommand extends BaseCommand private function resetPassword(OutputInterface $output, $username, $password) { - $userId = $this->user->getIdByUsername($username); + $userId = $this->userModel->getIdByUsername($username); if (empty($userId)) { $output->writeln('<error>User not found</error>'); return false; } - if (!$this->user->update(array('id' => $userId, 'password' => $password))) { + if (!$this->userModel->update(array('id' => $userId, 'password' => $password))) { $output->writeln('<error>Unable to update password</error>'); return false; } diff --git a/app/Console/ResetTwoFactorCommand.php b/app/Console/ResetTwoFactorCommand.php index 3bf01e81..a64206b6 100644 --- a/app/Console/ResetTwoFactorCommand.php +++ b/app/Console/ResetTwoFactorCommand.php @@ -19,14 +19,14 @@ class ResetTwoFactorCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); - $userId = $this->user->getIdByUsername($username); + $userId = $this->userModel->getIdByUsername($username); if (empty($userId)) { $output->writeln('<error>User not found</error>'); return false; } - if (!$this->user->update(array('id' => $userId, 'twofactor_activated' => 0, 'twofactor_secret' => ''))) { + if (!$this->userModel->update(array('id' => $userId, 'twofactor_activated' => 0, 'twofactor_secret' => ''))) { $output->writeln('<error>Unable to update user profile</error>'); return false; } diff --git a/app/Console/TaskOverdueNotificationCommand.php b/app/Console/TaskOverdueNotificationCommand.php index 7e8484c8..225a6a1a 100644 --- a/app/Console/TaskOverdueNotificationCommand.php +++ b/app/Console/TaskOverdueNotificationCommand.php @@ -2,7 +2,7 @@ namespace Kanboard\Console; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Kanboard\Core\Security\Role; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; @@ -65,10 +65,10 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendGroupOverdueTaskNotifications() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'owner_id') as $user_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($user_tasks[0]['project_id']); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($user_tasks[0]['project_id']); foreach ($users as $user) { $this->sendUserOverdueTaskNotifications($user, $user_tasks); @@ -85,14 +85,14 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendOverdueTaskNotificationsToManagers() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id); $managers = array(); foreach ($users as $user) { - $role = $this->projectUserRole->getUserRole($project_id, $user['id']); + $role = $this->projectUserRoleModel->getUserRole($project_id, $user['id']); if($role == Role::PROJECT_MANAGER) { $managers[] = $user; } @@ -113,10 +113,10 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendOverdueTaskNotifications() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id); foreach ($users as $user) { $this->sendUserOverdueTaskNotifications($user, $project_tasks); @@ -139,16 +139,16 @@ class TaskOverdueNotificationCommand extends BaseCommand $project_names = array(); foreach ($tasks as $task) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + if ($this->userNotificationFilterModel->shouldReceiveNotification($user, array('task' => $task))) { $user_tasks[] = $task; $project_names[$task['project_id']] = $task['project_name']; } } if (! empty($user_tasks)) { - $this->userNotification->sendUserNotification( + $this->userNotificationModel->sendUserNotification( $user, - Task::EVENT_OVERDUE, + TaskModel::EVENT_OVERDUE, array('tasks' => $user_tasks, 'project_name' => implode(", ", $project_names)) ); } @@ -163,9 +163,9 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendUserOverdueTaskNotificationsToManagers(array $manager, array $tasks) { - $this->userNotification->sendUserNotification( + $this->userNotificationModel->sendUserNotification( $manager, - Task::EVENT_OVERDUE, + TaskModel::EVENT_OVERDUE, array('tasks' => $tasks, 'project_name' => $tasks[0]['project_name']) ); } diff --git a/app/Console/TaskTriggerCommand.php b/app/Console/TaskTriggerCommand.php index 9e9554f9..a1f4dccf 100644 --- a/app/Console/TaskTriggerCommand.php +++ b/app/Console/TaskTriggerCommand.php @@ -4,7 +4,7 @@ namespace Kanboard\Console; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Kanboard\Event\TaskListEvent; class TaskTriggerCommand extends BaseCommand @@ -19,7 +19,7 @@ class TaskTriggerCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { foreach ($this->getProjectIds() as $project_id) { - $tasks = $this->taskFinder->getAll($project_id); + $tasks = $this->taskFinderModel->getAll($project_id); $nb_tasks = count($tasks); if ($nb_tasks > 0) { @@ -31,7 +31,7 @@ class TaskTriggerCommand extends BaseCommand private function getProjectIds() { - $listeners = $this->dispatcher->getListeners(Task::EVENT_DAILY_CRONJOB); + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_DAILY_CRONJOB); $project_ids = array(); foreach ($listeners as $listener) { @@ -46,6 +46,6 @@ class TaskTriggerCommand extends BaseCommand $event = new TaskListEvent(array('project_id' => $project_id)); $event->setTasks($tasks); - $this->dispatcher->dispatch(Task::EVENT_DAILY_CRONJOB, $event); + $this->dispatcher->dispatch(TaskModel::EVENT_DAILY_CRONJOB, $event); } } diff --git a/app/Console/WorkerCommand.php b/app/Console/WorkerCommand.php new file mode 100644 index 00000000..e332624b --- /dev/null +++ b/app/Console/WorkerCommand.php @@ -0,0 +1,28 @@ +<?php + +namespace Kanboard\Console; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Class WorkerCommand + * + * @package Kanboard\Console + * @author Frederic Guillot + */ +class WorkerCommand extends BaseCommand +{ + protected function configure() + { + $this + ->setName('worker') + ->setDescription('Execute queue worker') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->queueManager->listen(); + } +} |