Skip to content

Commit

Permalink
Merge branch 'master' into 6.x
Browse files Browse the repository at this point in the history
* master:
  [DashboardBundle] Deprecate remaining container usages in command
  • Loading branch information
acrobat committed May 30, 2021
2 parents c1e6f2c + 1a57739 commit 3a0f940
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions UPGRADE-5.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ DashboardBundle

* Passing a command classname for the "$command" argument in `Kunstmaan\DashboardBundle\Widget\DashboardWidget::__construct` is deprecated and will not be allowed 6.0. Pass a command name instead.
* Using the `kunstmaan_dashboard.widget.googleanalytics.command` parameter to modify the `kunstmaan_dashboard.widget.googleanalytics` service is deprecated and the parameter will be removed in 6.0. Use service decoration or a service alias instead.
* Not passing a value for the `$configHelper` or `$queryHelper` parameters in `Kunstmaan\DashboardBundle\Command\GoogleAnalyticsDataCollectCommand::__construct` is deprecated and the parameters will be required. Inject the required services instead.

GeneratorBundle
------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Kunstmaan\DashboardBundle\Entity\AnalyticsConfig;
use Kunstmaan\DashboardBundle\Entity\AnalyticsOverview;
use Kunstmaan\DashboardBundle\Entity\AnalyticsSegment;
use Kunstmaan\DashboardBundle\Helper\Google\Analytics\ConfigHelper;
use Kunstmaan\DashboardBundle\Helper\Google\Analytics\QueryHelper;
use Kunstmaan\DashboardBundle\Helper\Google\Analytics\ServiceHelper;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -33,12 +35,16 @@ class GoogleAnalyticsDataCollectCommand extends ContainerAwareCommand

/** @var ServiceHelper */
private $serviceHelper;
/** @var ConfigHelper */
private $configHelper;
/** @var QueryHelper */
private $queryHelper;

/**
* @param EntityManagerInterface|null $em
* @param ServiceHelper $serviceHelper
*/
public function __construct(/* EntityManagerInterface */ $em = null, ServiceHelper $serviceHelper = null)
public function __construct(/* EntityManagerInterface */ $em = null, ServiceHelper $serviceHelper = null, ConfigHelper $configHelper = null, QueryHelper $queryHelper = null)
{
parent::__construct();

Expand All @@ -50,8 +56,18 @@ public function __construct(/* EntityManagerInterface */ $em = null, ServiceHelp
return;
}

if (null === $configHelper) {
@trigger_error(sprintf('Not passing a value for the "$configHelper" parameter in "%s" is deprecated since KunstmaanDashboardBundle 5.9, the parameter will be required in KunstmaanDashboardBundle 6.0. Inject the required service instead.', __METHOD__), E_USER_DEPRECATED);
}

if (null === $queryHelper) {
@trigger_error(sprintf('Not passing a value for the "$queryHelper" parameter in "%s" is deprecated since KunstmaanDashboardBundle 5.9, the parameter will be required in KunstmaanDashboardBundle 6.0. Inject the required service instead.', __METHOD__), E_USER_DEPRECATED);
}

$this->em = $em;
$this->serviceHelper = $serviceHelper;
$this->configHelper = $configHelper;
$this->queryHelper = $queryHelper;
}

protected function configure()
Expand Down Expand Up @@ -95,11 +111,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->serviceHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.service');
}

if (null === $this->configHelper) {
$this->configHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.config');
}

if (null === $this->queryHelper) {
$this->queryHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.query');
}

$this->output = $output;

// check if token is set
$configHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.config');
if (!$configHelper->tokenIsSet()) {
if (!$this->configHelper->tokenIsSet()) {
$this->output->writeln('You haven\'t configured a Google account yet');

return 0;
Expand Down Expand Up @@ -260,16 +283,14 @@ private function getAllOverviews()
public function updateData($overviews)
{
// helpers
$queryHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.query');
$configHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.config');
$metrics = new MetricsCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
$chartData = new ChartDataCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
$goals = new GoalCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
$visitors = new UsersCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
$metrics = new MetricsCommandHelper($this->configHelper, $this->queryHelper, $this->output, $this->em);
$chartData = new ChartDataCommandHelper($this->configHelper, $this->queryHelper, $this->output, $this->em);
$goals = new GoalCommandHelper($this->configHelper, $this->queryHelper, $this->output, $this->em);
$visitors = new UsersCommandHelper($this->configHelper, $this->queryHelper, $this->output, $this->em);

// get data per overview
foreach ($overviews as $overview) {
$configHelper->init($overview->getConfig()->getId());
$this->configHelper->init($overview->getConfig()->getId());
/* @var AnalyticsOverview $overview */
$this->output->writeln('Fetching data for overview "<fg=green>' . $overview->getTitle() . '</fg=green>"');

Expand Down
6 changes: 5 additions & 1 deletion src/Kunstmaan/DashboardBundle/Resources/config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ services:
- { name: console.command }

Kunstmaan\DashboardBundle\Command\GoogleAnalyticsDataCollectCommand:
arguments: ['@doctrine.orm.entity_manager', '@kunstmaan_dashboard.helper.google.analytics.service']
arguments:
- '@doctrine.orm.entity_manager'
- '@kunstmaan_dashboard.helper.google.analytics.service'
- '@kunstmaan_dashboard.helper.google.analytics.config'
- '@kunstmaan_dashboard.helper.google.analytics.query'
tags:
- { name: console.command }

Expand Down

0 comments on commit 3a0f940

Please sign in to comment.