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] Deprecated service container usage in dashboard com… #2022

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions UPGRADE-5.1.md
Expand Up @@ -33,6 +33,18 @@ ConfigBundle

* Passing the `container` as the sixth argument in `Kunstmaan\ConfigBundle\Controller\ConfigController` is deprecated in and will be removed in 6.0.

DashboardBundle
---------------

* Injecting the container in the `DashboardCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upgrade log should be more like this, as the current message is not correct (the container is not injected in the commands, first argument is actually an optional command name)

`XXXXCommand::__construct()` now takes an instance of `XXXX` as the first argument. Not passing it is deprecated and will throw a `TypeError` in 6.0.

Same for the other upgrade notes

* Injecting the container in the `GoogleAnalyticsConfigFlushCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsConfigsListCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsDataCollectCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsDataFlushCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsOverviewsGenerateCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsOverviewsListCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.
* Injecting the container in the `GoogleAnalyticsSegmentsListCommand` is deprecated and will be removed in 6.0. Inject the required parameters instead.

FormBundle
-----------
* Added the optional `deletable_formsubmissions` config parameter, when set to true, form submissions can be deleted from the adminlist.
Expand Down
35 changes: 32 additions & 3 deletions src/Kunstmaan/DashboardBundle/Command/DashboardCommand.php
Expand Up @@ -7,23 +7,52 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Symfony CLI command to collect all the widget dashboard data using bin/console kuma:dashboard:collect
*
* @final since 5.1
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
*/
class DashboardCommand extends ContainerAwareCommand
{

private $widgetManager;

public function __construct(WidgetManager $widgetManager = null)
{
parent::__construct();

if (!$widgetManager instanceof WidgetManager) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);

$this->setName(null === $widgetManager ? 'kuma:dashboard:collect' : $widgetManager);

return;
}

$this->widgetManager = $widgetManager;
}

protected function configure()
{
$this
->setName('kuma:dashboard:collect')
->setDescription('Collect all the widget dashboard data');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var WidgetManager $widgetManager */
$widgetManager = $this->getContainer()->get('kunstmaan_dashboard.manager.widgets');
if (null === $this->widgetManager) {
$this->widgetManager = $this->getContainer()->get('kunstmaan_dashboard.manager.widgets');
}

/** @var DashboardWidget[] $widgets */
$widgets = $widgetManager->getWidgets();
$widgets = $this->widgetManager->getWidgets();
foreach ($widgets as $widget) {
/** @var DashboardWidget $widget */
$widget->getCommand()->execute($input, $output);
Expand Down
Expand Up @@ -5,10 +5,38 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;

/**
* @final since 5.1
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
*/
class GoogleAnalyticsConfigFlushCommand extends ContainerAwareCommand
{

/**
* @var EntityManager
*/
private $em;

/**
* @param EntityManagerInterface|null $em
*/
public function __construct(/* EntityManagerInterface */ $em = null)
{
parent::__construct();

if (!$em instanceof EntityManagerInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);

$this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:config:flush' : $em);

return;
}

$this->em = $em;
}

protected function configure()
{
$this
Expand All @@ -23,12 +51,20 @@ protected function configure()
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$configRepository = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
if (null === $this->em) {
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
}

$configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
$configId = $input->getOption('config');
$configs = array();
$configs = [];

try {
if ($configId) {
Expand All @@ -38,9 +74,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($configs as $config) {
$em->remove($config);
$this->em->remove($config);
}
$em->flush();
$this->em->flush();
$output->writeln('<fg=green>Config flushed</fg=green>');
} catch (\Exception $e) {
$output->writeln('<fg=red>'.$e->getMessage().'</fg=red>');
Expand Down
Expand Up @@ -4,12 +4,37 @@
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;

/**
* @final since 5.1
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
*/
class GoogleAnalyticsConfigsListCommand extends ContainerAwareCommand
{
/** @var EntityManager $em */
/**
* @var EntityManagerInterface
*/
private $em;

/**
* @param EntityManagerInterface|null $em
*/
public function __construct(/* EntityManagerInterface */ $em = null)
{
parent::__construct();

if (!$em instanceof EntityManagerInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);

$this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:config:list' : $em);

return;
}

$this->em = $em;
}

protected function configure()
{
$this
Expand All @@ -18,16 +43,15 @@ protected function configure()
}

/**
* Inits instance variables for global usage.
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
private function init()
{
$this->em = $this->getContainer()->get('doctrine')->getManager();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->init();
if (null === $this->em) {
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
}

$configs = $this->getconfigs();

Expand Down
Expand Up @@ -11,10 +11,16 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use Kunstmaan\DashboardBundle\Helper\Google\Analytics\ServiceHelper;

/**
* @final since 5.1
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
*/
class GoogleAnalyticsDataCollectCommand extends ContainerAwareCommand
{
/** @var EntityManager $em */
/** @var EntityManagerInterface $em */
private $em;

/** @var OutputInterface $output */
Expand All @@ -23,6 +29,29 @@ class GoogleAnalyticsDataCollectCommand extends ContainerAwareCommand
/** @var int $errors */
private $errors = 0;

/** @var ServiceHelper */
private $serviceHelper;

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

if (!$em instanceof EntityManagerInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);

$this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:data:collect' : $em);

return;
}

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

/**
* Configures the current command.
*/
Expand Down Expand Up @@ -55,21 +84,21 @@ protected function configure()
}

/**
* Inits instance variables for global usage.
*
* @param OutputInterface $output The output
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
private function init($output)
{
$this->output = $output;
$this->serviceHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.service');
$this->em = $this->getContainer()->get('doctrine')->getManager();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
// init
$this->init($output);
if (null === $this->em) {
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
}

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

$this->output = $output;

// check if token is set
$configHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.config');
Expand All @@ -90,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// get the overviews
try {
$overviews = array();
$overviews = [];

if ($overviewId) {
$overviews[] = $this->getSingleOverview($overviewId);
Expand Down
Expand Up @@ -5,9 +5,34 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;

/**
* @final since 5.1
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
*/
class GoogleAnalyticsDataFlushCommand extends ContainerAwareCommand
{
/** @var EntityManagerInterface */
private $em;

/**
* @param EntityManagerInterface|null $em
*/
public function __construct(/* EntityManagerInterface */ $em = null)
{
parent::__construct();

if (!$em instanceof EntityManagerInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);

$this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:data:flush' : $em);

return;
}

$this->em = $em;
}

protected function configure()
{
Expand All @@ -21,10 +46,18 @@ protected function configure()
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$configRepository = $em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
if (null === $this->em) {
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
}

$configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');

$configId = $input->getArgument('config') ? $input->getArgument('config') : false;
try {
Expand Down