PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/mautic-master/mautic
PHP | 111 lines | 75 code | 18 blank | 18 comment | 8 complexity | 889eab002192dac6794bade60b3c4010 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Mautic
  4. * @copyright 2014 Mautic Contributors. All rights reserved.
  5. * @author Mautic
  6. * @link http://mautic.org
  7. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  8. */
  9. namespace Mautic\PluginBundle\Command;
  10. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. use Mautic\CoreBundle\Helper\DateTimeHelper;
  15. /**
  16. * Class PushLeadActivityCommand
  17. */
  18. class PushLeadActivityCommand extends ContainerAwareCommand
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function configure()
  24. {
  25. $this
  26. ->setName('mautic:integration:pushleadactivity')
  27. ->setAliases(
  28. array(
  29. 'mautic:integration:pushactivity',
  30. 'mautic:pushactivity:integration'
  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. $integrationObject = $integrationHelper->getIntegrationObject($integration);
  83. if ($integrationObject !== null && method_exists($integrationObject, 'pushLeadActivity')) {
  84. $output->writeln('<info>'.$translator->trans('mautic.plugin.command.push.leads.activity', array('%integration%' => $integration)).'</info>');
  85. $params['start']=$startDate;
  86. $params['end']=$endDate;
  87. $processed = intval($integrationObject->pushLeadActivity($params));
  88. $output->writeln('<comment>'.$translator->trans('mautic.plugin.command.push.leads.events_executed', array('%events%' => $processed)).'</comment>'."\n");
  89. }
  90. }
  91. return 0;
  92. }
  93. }