Skip to content

Commit

Permalink
minor #158 Deprecate "messages" translation domain in favor of "Hackz…
Browse files Browse the repository at this point in the history
…illaTicketBundle" (backport PR #123) (phansys)

This PR was merged into the 3.x branch.

Discussion
----------

|Q            |A  |
|---          |---|
|Branch       |3.x|
|Bug fix?     |no |
|New feature? |no |
|BC breaks?   |no |
|Deprecations?|yes|
|Tests pass?  |yes|
|Fixed tickets|n/a|
|License      |MIT|
|Doc PR       |n/a|

This is a backport from PR #123.

Commits
-------

8754ed5 Backport PR #123
  • Loading branch information
phansys committed Jul 3, 2020
2 parents daac81c + 8754ed5 commit 33c3fca
Show file tree
Hide file tree
Showing 19 changed files with 1,633 additions and 75 deletions.
4 changes: 3 additions & 1 deletion Command/AutoClosingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$translator = $this->getContainer()->get('translator');
$translator->setLocale($locale);

$translationDomain = $this->getContainer()->getParameter('hackzilla_ticket.translation_domain');

$username = $input->getArgument('username');

$resolved_tickets = $ticketRepository->getResolvedTicketOlderThan($input->getOption('age'));

foreach ($resolved_tickets as $ticket) {
$message = $ticket_manager->createMessage()
->setMessage(
$translator->trans('MESSAGE_STATUS_CHANGED', ['%status%' => $translator->trans('STATUS_CLOSED')])
$translator->trans('MESSAGE_STATUS_CHANGED', ['%status%' => $translator->trans('STATUS_CLOSED', [], $translationDomain)], $translationDomain)
)
->setStatus(TicketMessage::STATUS_CLOSED)
->setPriority($ticket->getPriority())
Expand Down
4 changes: 3 additions & 1 deletion Controller/TicketAttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function downloadAction($ticketMessageId)
$ticketMessage = $ticketManager->getMessageById($ticketMessageId);

if (!$ticketMessage || !$ticketMessage instanceof TicketMessageWithAttachment) {
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
}

// check permissions
Expand Down
43 changes: 28 additions & 15 deletions Controller/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function indexAction(Request $request)
$userManager = $this->getUserManager();
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');

$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN'));
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN', [], $translationDomain));
$ticketPriority = $request->get('priority', null);

$query = $ticketManager->getTicketListQuery(
Expand All @@ -48,9 +50,10 @@ public function indexAction(Request $request)
return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['index'],
[
'pagination' => $pagination,
'ticketState' => $ticketState,
'ticketPriority' => $ticketPriority,
'pagination' => $pagination,
'ticketState' => $ticketState,
'ticketPriority' => $ticketPriority,
'translationDomain' => $translationDomain,
]
);
}
Expand Down Expand Up @@ -81,11 +84,14 @@ public function createAction(Request $request)
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
}

$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['new'],
[
'entity' => $ticket,
'form' => $form->createView(),
'entity' => $ticket,
'form' => $form->createView(),
'translationDomain' => $translationDomain,
]
);
}
Expand All @@ -100,11 +106,14 @@ public function newAction()

$form = $this->createForm(TicketType::class, $entity);

$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['new'],
[
'entity' => $entity,
'form' => $form->createView(),
'entity' => $entity,
'form' => $form->createView(),
'translationDomain' => $translationDomain,
]
);
}
Expand All @@ -128,7 +137,9 @@ public function showAction($ticketId)
$currentUser = $this->getUserManager()->getCurrentUser();
$this->getUserManager()->hasPermission($currentUser, $ticket);

$data = ['ticket' => $ticket];
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

$data = ['ticket' => $ticket, 'translationDomain' => $translationDomain];

$message = $ticketManager->createMessage($ticket);

Expand Down Expand Up @@ -156,8 +167,10 @@ public function replyAction(Request $request, $ticketId)
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
$ticket = $ticketManager->getTicketById($ticketId);

$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

if (!$ticket) {
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
}

$user = $this->getUserManager()->getCurrentUser();
Expand All @@ -176,7 +189,7 @@ public function replyAction(Request $request, $ticketId)
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
}

$data = ['ticket' => $ticket, 'form' => $form->createView()];
$data = ['ticket' => $ticket, 'form' => $form->createView(), 'translationDomain' => $translationDomain];

if ($user && $this->get('hackzilla_ticket.user_manager')->hasRole($user, TicketRole::ADMIN)) {
$data['delete_form'] = $this->createDeleteForm($ticket->getId())->createView();
Expand Down Expand Up @@ -212,7 +225,9 @@ public function deleteAction(Request $request, $ticketId)
$ticket = $ticketManager->getTicketById($ticketId);

if (!$ticket) {
throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY'));
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], $translationDomain));
}

$ticketManager->deleteTicket($ticket);
Expand Down Expand Up @@ -264,8 +279,6 @@ private function createMessageForm(TicketMessageInterface $message)
*/
private function getUserManager()
{
$userManager = $this->get('hackzilla_ticket.user_manager');

return $userManager;
return $this->get('hackzilla_ticket.user_manager');
}
}
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->enumNode('translation_domain')
->values(['HackzillaTicketBundle', 'messages'])
->defaultValue('messages')
->end()
->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
->scalarNode('ticket_class')->cannotBeEmpty()->defaultValue('Hackzilla\Bundle\TicketBundle\Entity\Ticket')->end()
->scalarNode('message_class')->cannotBeEmpty()->defaultValue('Hackzilla\Bundle\TicketBundle\Entity\TicketMessage')->end()
Expand Down
20 changes: 20 additions & 0 deletions DependencyInjection/HackzillaTicketExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,30 @@ public function load(array $configs, ContainerBuilder $container)
if (!isset($bundles['VichUploaderBundle'])) {
$container->removeDefinition('hackzilla_ticket.file_upload_subscriber');
}

$this->setTranslationDomain($config, $container);
}

public static function bundleDirectory()
{
return realpath(__DIR__.'/..');
}

private function setTranslationDomain(array $config, ContainerBuilder $container)
{
$translationDomain = $config['translation_domain'];

if ('HackzillaTicketBundle' !== $translationDomain) {
@trigger_error(
'Omitting the option "hackzilla_ticket.translation_domain" or using other value than "HackzillaTicketBundle" is deprecated since hackzilla/ticket-bundle 3.3.'
.' This option will be removed in version 4.0 and the only supported translation domain will be "HackzillaTicketBundle".',
E_USER_DEPRECATED
);
}

$container->setParameter('hackzilla_ticket.translation_domain', $translationDomain);

$definition = $container->getDefinition('hackzilla_ticket.ticket_manager');
$definition->addMethodCall('setTranslationDomain', [$translationDomain]);
}
}
25 changes: 23 additions & 2 deletions Manager/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class TicketManager implements TicketManagerInterface
{
private $translator;

/**
* NEXT_MAJOR: Remove this property and replace its usages with "HackzillaTicketBundle".
*
* @var string
*/
private $translationDomain = 'messages';

private $objectManager;

private $ticketRepository;
Expand Down Expand Up @@ -61,6 +68,20 @@ public function setTranslator(TranslatorInterface $translator)
return $this;
}

/**
* NEXT_MAJOR: Remove this method.
*
* @param string $translationDomain
*
* @return $this
*/
public function setTranslationDomain($translationDomain)
{
$this->translationDomain = $translationDomain;

return $this;
}

/**
* Create a new instance of Ticket entity.
*
Expand Down Expand Up @@ -279,7 +300,7 @@ public function getTicketStatus($statusStr)
$statuses = [];

foreach (TicketMessageInterface::STATUSES as $id => $value) {
$statuses[$id] = $this->translator->trans($value);
$statuses[$id] = $this->translator->trans($value, [], $this->translationDomain);
}
}

Expand All @@ -301,7 +322,7 @@ public function getTicketPriority($priorityStr)
$priorities = [];

foreach (TicketMessageInterface::PRIORITIES as $id => $value) {
$priorities[$id] = $this->translator->trans($value);
$priorities[$id] = $this->translator->trans($value, [], $this->translationDomain);
}
}

Expand Down

0 comments on commit 33c3fca

Please sign in to comment.