PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php

https://bitbucket.org/pipehline/mautic-imachine
PHP | 111 lines | 74 code | 17 blank | 20 comment | 8 complexity | 1d4edcbf881e5fc0d62366a5e5e7a033 MD5 | raw file
  1. <?php
  2. /*
  3. * @copyright 2014 Mautic Contributors. All rights reserved
  4. * @author Mautic
  5. *
  6. * @link http://mautic.org
  7. *
  8. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  9. */
  10. namespace Mautic\PluginBundle\Command;
  11. use Mautic\PluginBundle\Integration\AbstractIntegration;
  12. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. /**
  17. * Class PushLeadActivityCommand.
  18. */
  19. class PushLeadActivityCommand extends ContainerAwareCommand
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. protected function configure()
  25. {
  26. $this
  27. ->setName('mautic:integration:pushleadactivity')
  28. ->setAliases(
  29. [
  30. 'mautic:integration:pushactivity',
  31. ]
  32. )
  33. ->setDescription('Push lead activity to integration.')
  34. ->addOption(
  35. '--integration',
  36. '-i',
  37. InputOption::VALUE_REQUIRED,
  38. 'Integration name. Integration must be enabled and authorised.',
  39. null
  40. )
  41. ->addOption('--start-date', '-d', InputOption::VALUE_REQUIRED, 'Set start date for updated values.')
  42. ->addOption(
  43. '--end-date',
  44. '-t',
  45. InputOption::VALUE_REQUIRED,
  46. 'Set end date for updated values.'
  47. )
  48. ->addOption(
  49. '--time-interval',
  50. '-a',
  51. InputOption::VALUE_OPTIONAL,
  52. 'Send time interval to check updates on Salesforce, it should be a correct php formatted time interval in the past eg:(-10 minutes)'
  53. )
  54. ->addOption('--force', '-f', InputOption::VALUE_NONE, 'Force execution even if another process is assumed running.');
  55. parent::configure();
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. protected function execute(InputInterface $input, OutputInterface $output)
  61. {
  62. $container = $this->getContainer();
  63. /** @var \Mautic\CoreBundle\Factory\MauticFactory $factory */
  64. $factory = $container->get('mautic.factory');
  65. $translator = $factory->getTranslator();
  66. $integration = $input->getOption('integration');
  67. $startDate = $input->getOption('start-date');
  68. $endDate = $input->getOption('end-date');
  69. $interval = $input->getOption('time-interval');
  70. if (!$interval) {
  71. $interval = '15 minutes';
  72. }
  73. if (!$startDate) {
  74. $startDate = date('c', strtotime('-'.$interval));
  75. }
  76. if (!$endDate) {
  77. $endDate = date('c');
  78. }
  79. if ($integration && $startDate && $endDate) {
  80. /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */
  81. $integrationHelper = $factory->getHelper('integration');
  82. /** @var AbstractIntegration $integrationObject */
  83. $integrationObject = $integrationHelper->getIntegrationObject($integration);
  84. if ($integrationObject !== null && method_exists($integrationObject, 'pushLeadActivity')) {
  85. $output->writeln('<info>'.$translator->trans('mautic.plugin.command.push.leads.activity', ['%integration%' => $integration]).'</info>');
  86. $params['start'] = $startDate;
  87. $params['end'] = $endDate;
  88. $processed = intval($integrationObject->pushLeadActivity($params));
  89. $output->writeln('<comment>'.$translator->trans('mautic.plugin.command.push.leads.events_executed', ['%events%' => $processed]).'</comment>'."\n");
  90. }
  91. }
  92. return 0;
  93. }
  94. }