Skip to content
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

[DashboardBundle] Deprecate remaining container usages in command #2877

Merged
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
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