Skip to content

Deprecate "messages" translation domain in favor of "HackzillaTicketBundle" (backport PR #123) #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading