Skip to content

Commit

Permalink
Merge pull request #382 from itk-dev/feature/drush-commands
Browse files Browse the repository at this point in the history
639: Updated custom Drush commands
  • Loading branch information
rimi-itk committed Jan 31, 2024
2 parents c812edf + 28d3b1c commit b61ebc5
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 135 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

* [PR-382](https://github.com/itk-dev/hoeringsportal/pull/382)
Updated custom Drush commands to work with Drush 12.

## [4.0.0] - 2024-01-24

* [PR-375](https://github.com/itk-dev/hoeringsportal/pull/375)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

namespace Drupal\hoeringsportal_citizen_proposal\Commands;
namespace Drupal\hoeringsportal_citizen_proposal\Drush\Commands;

use Drupal\hoeringsportal_citizen_proposal\Helper\Helper;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands as BaseDrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Custom drush commands for citizen proposal.
*/
class DrushCommands extends BaseDrushCommands {
final class DrushCommands extends BaseDrushCommands {

/**
* Constructor for the citizen proposal commands class.
Expand All @@ -19,27 +21,28 @@ public function __construct(
parent::__construct();
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get(Helper::class),
);
}

/**
* A drush command for finishing a specific proposal.
*
* @param int $proposalId
* A node id to finish.
*
* @command hoeringsportal-citizen-proposal:finish-proposal
*
* @aliases hcp-fp
*/
#[CLI\Command(name: 'hoeringsportal-citizen-proposal:finish-proposal')]
#[CLI\Argument(name: 'proposalId', description: 'The proposal (node) id to finish')]
public function finishProposal(int $proposalId): void {
$this->helper->finishProposal($proposalId);
}

/**
* A drush command for finishing all overdue proposals.
*
* @command hoeringsportal-citizen-proposal:finish-overdue-proposals
*
* @aliases hcp-fop
*/
#[CLI\Command(name: 'hoeringsportal-citizen-proposal:finish-overdue-proposals')]
public function finishOverdueProposals(): void {
$overdueProposals = $this->helper->findOverdueProposals();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

namespace Drupal\hoeringsportal_citizen_proposal\Commands;
namespace Drupal\hoeringsportal_citizen_proposal\Drush\Commands;

use Drupal\entity_events\EntityEventType;
use Drupal\hoeringsportal_citizen_proposal\Helper\Helper;
use Drupal\hoeringsportal_citizen_proposal\Helper\MailHelper;
use Drupal\symfony_mailer\AddressInterface;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands as BaseDrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Test mail commands for citizen proposal.
*/
class TestMailCommand extends BaseDrushCommands {
final class TestMailCommand extends BaseDrushCommands {

/**
* Constructor for the citizen proposal commands class.
Expand All @@ -23,18 +25,23 @@ public function __construct(
parent::__construct();
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get(Helper::class),
$container->get(MailHelper::class)
);
}

/**
* Send mail command.
*
* @param int $proposalId
* The proposal (node) id.
* @param string $event
* The event; "create" or "update".
* @param string $recipient
* The mail recipient.
*
* @command hoeringsportal-citizen-proposal:test-mail:send
*/
#[CLI\Command(name: 'hoeringsportal-citizen-proposal:test-mail:send')]
#[CLI\Argument(name: 'proposalId', description: 'The proposal (node) id.')]
#[CLI\Argument(name: 'event', description: 'The event; "create" or "update".', suggestedValues: ['create', 'update'])]
#[CLI\Argument(name: 'recipient', description: 'The mail recipient.')]
public function send(int $proposalId, string $event, string $recipient): void {
$proposal = $this->helper->loadCitizenProposal($proposalId);
// Overwrite the proposal author.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

namespace Drupal\hoeringsportal_citizen_proposal_archiving\Commands;
namespace Drupal\hoeringsportal_citizen_proposal_archiving\Drush\Commands;

use Drupal\hoeringsportal_citizen_proposal\Helper\Helper as CitizenProposalHelper;
use Drupal\hoeringsportal_citizen_proposal_archiving\Helper\Helper;
use Drupal\hoeringsportal_citizen_proposal_archiving\Renderer\Renderer;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Drush commands.
*/
class Commands extends DrushCommands {
final class Commands extends DrushCommands {

/**
* Constructor.
Expand All @@ -23,6 +24,17 @@ public function __construct(
) {
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get(Helper::class),
$container->get(CitizenProposalHelper::class),
$container->get(Renderer::class)
);
}

/**
* Render node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ services:
class: Drupal\hoeringsportal_data\Helper\LocalplanItemHelper
arguments: ['@hoeringsportal_data.plandata']

hoeringsportal_data.commands:
class: Drupal\hoeringsportal_data\Commands\DrushCommands
arguments: ['@hoeringsportal_data.hearing_helper']
tags:
- { name: drush.command }

hoeringsportal_data.geojson_helper:
class: Drupal\hoeringsportal_data\Helper\GeoJsonHelper
arguments:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
<?php

namespace Drupal\hoeringsportal_data\Commands;
namespace Drupal\hoeringsportal_data\Drush\Commands;

use Drupal\hoeringsportal_data\Helper\HearingHelper;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands as BaseDrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Custom drush commands from hoeringsportal_deskpro.
* Custom drush commands for hoeringsportal_data.
*/
class DrushCommands extends BaseDrushCommands {
/**
* Deskpro helper.
*
* @var \Drupal\hoeringsportal_data\Helper\HearingHelper
*/
private $helper;
final class DrushCommands extends BaseDrushCommands {

/**
* Constructor.
*/
public function __construct(HearingHelper $helper) {
public function __construct(
private readonly HearingHelper $helper
) {
parent::__construct();
$this->helper = $helper;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('hoeringsportal_data.hearing_helper'),
);
}

/**
Expand All @@ -31,6 +37,7 @@ public function __construct(HearingHelper $helper) {
* @usage hoeringsportal:data:hearing-state-update
* Update state for all hearings.
*/
#[CLI\Command(name: 'hoeringsportal:data:hearing-state-update')]
public function updateHearingState() {
$hearings = $this->helper->loadHearings();

Expand All @@ -50,6 +57,7 @@ public function updateHearingState() {
* @usage hoeringsportal:data:hearing-state-show
* SHow state for all hearings.
*/
#[CLI\Command(name: 'hoeringsportal:data:hearing-state-show')]
public function showHearingState() {
$hearings = $this->helper->loadHearings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,3 @@ services:
arguments: ['@hoeringsportal_deskpro.deskpro', '@hoeringsportal_deskpro.helper']
tags:
- { name: twig.extension }

hoeringsportal_deskpro.commands:
class: Drupal\hoeringsportal_deskpro\Commands\DrushCommands
arguments: ['@entity_type.manager', '@hoeringsportal_deskpro.helper']
tags:
- { name: drush.command }
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

namespace Drupal\hoeringsportal_deskpro\Commands;
namespace Drupal\hoeringsportal_deskpro\Drush\Commands;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\hoeringsportal_deskpro\Service\HearingHelper;
use Drupal\node\Entity\Node;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands as BaseDrushCommands;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Custom drush commands from hoeringsportal_deskpro.
*/
class DrushCommands extends BaseDrushCommands {
final class DrushCommands extends BaseDrushCommands {
/**
* Entity type manager.
*
Expand All @@ -35,23 +37,24 @@ public function __construct(EntityTypeManagerInterface $entityTypeManager, Heari
$this->helper = $helper;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('hoeringsportal_deskpro.helper'),
);
}

/**
* Synchronizes hearing ticket data with Deskpro.
*
* @param int $hearingId
* Hearing id.
* @param string $ticketIds
* Comma-separated list of ticket ids.
* @param array $options
* The options.
*
* @option enqueue
* Enqueue the synchronization.
*
* @command hoeringsportal:deskpro:synchronize-hearing-ticket
* @usage hoeringsportal:deskpro:synchronize-hearing-ticket 123 456
* Refreshes Deskpro data for ticket 456 on hearing 123.
*/
#[CLI\Command(name: 'hoeringsportal:deskpro:synchronize-hearing-ticket')]
#[CLI\Argument(name: 'hearingId', description: 'Hearing (node) id.')]
#[CLI\Argument(name: 'ticketIds', description: 'Comma-separated list of ticket ids.')]
#[CLI\Option(name: 'enqueue', description: 'Enqueue the synchronization.')]
#[CLI\Usage(name: 'hoeringsportal:deskpro:synchronize-hearing-ticket 123 456', description: 'Refreshes Deskpro data for ticket 456 on hearing 123.')]
public function synchronizeHearingTicket(int $hearingId, string $ticketIds, array $options = [
'enqueue' => FALSE,
]) {
Expand Down Expand Up @@ -88,14 +91,10 @@ static function (int $id) {

/**
* Synchronizes hearing tickets data with Deskpro.
*
* @param string|null $ids
* Comma-list of hearing ids.
*
* @command hoeringsportal:deskpro:synchronize-hearing-tickets
* @usage hoeringsportal:deskpro:synchronize-hearing-tickets 42,87
* Refreshes Deskpro data for hearings with ids 42 and 87.
*/
#[CLI\Command(name: 'hoeringsportal:deskpro:synchronize-hearing-tickets')]
#[CLI\Argument(name: 'ids', description: 'Comma-separated list of hearing ids.')]
#[CLI\Usage(name: 'hoeringsportal:deskpro:synchronize-hearing-tickets 42,87', description: 'Refreshes Deskpro data for hearings with ids 42 and 87.')]
public function synchronizeHearingTickets($ids) {
$ids = preg_split('/\s*,\s*/', $ids, -1, PREG_SPLIT_NO_EMPTY);

Expand Down Expand Up @@ -127,14 +126,10 @@ public function synchronizeHearingTickets($ids) {

/**
* Shows information on data synchronization endpoint.
*
* @param int $hearingId
* Hearing id.
* @param int $ticketId
* Ticket id.
*
* @command hoeringsportal:deskpro:synchronize-endpoint
*/
#[CLI\Command(name: 'hoeringsportal:deskpro:synchronize-endpoint')]
#[CLI\Argument(name: 'hearingId', description: 'Hearing (node) id.')]
#[CLI\Argument(name: 'ticketId', description: 'Ticket id.')]
public function synchronizeEndpoint(int $hearingId, int $ticketId) {
$url = $this->helper->getTicketSynchronizationUrl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,3 @@ services:
hoeringsportal_public_meeting.public_meeting_helper:
class: Drupal\hoeringsportal_public_meeting\Helper\PublicMeetingHelper
arguments: ['@entity_type.manager']

hoeringsportal_public_meeting.commands:
class: Drupal\hoeringsportal_public_meeting\Commands\DrushCommands
arguments:
- '@hoeringsportal_public_meeting.public_meeting_helper'
- '@datetime.time'
- '@state'
tags:
- { name: drush.command }
Loading

0 comments on commit b61ebc5

Please sign in to comment.