Bläddra i källkod

Deprecate exporter class and service

The class was already marked as deprecated, but only in its phpdoc.
Let's schedule its deletion.
Grégoire Paris 8 år sedan
förälder
incheckning
52eab4bab1

+ 6 - 1
Controller/CRUDController.php

@@ -819,7 +819,12 @@ class CRUDController extends Controller
             $format
         );
 
-        return $this->get('sonata.admin.exporter')->getResponse(
+        // NEXT_MAJOR : require sonata-project/exporter ^1.6 and remove this
+        $exporter = $this->has('sonata.exporter.exporter') ?
+            $this->get('sonata.exporter.exporter') :
+            $this->get('sonata.admin.exporter');
+
+        return $exporter->getResponse(
             $format,
             $filename,
             $this->admin->getDataSourceIterator()

+ 7 - 0
DependencyInjection/SonataAdminExtension.php

@@ -60,6 +60,13 @@ class SonataAdminExtension extends Extension implements PrependExtensionInterfac
         $loader->load('block.xml');
         $loader->load('menu.xml');
 
+        if (method_exists('Symfony\Component\DependencyInjection\Definition', 'setDeprecated')) {
+            // NEXT_MAJOR : remove this block
+            $container->getDefinition('sonata.admin.exporter')->setDeprecated(
+                'The service "%service_id%" is deprecated in favor of the "sonata.exporter.exporter" service'
+            );
+        }
+
         // TODO: Go back on xml configuration when bumping requirements to SF 2.6+
         $sidebarMenu = $container->getDefinition('sonata.admin.sidebar_menu');
         if (method_exists($sidebarMenu, 'setFactory')) {

+ 6 - 0
Export/Exporter.php

@@ -13,6 +13,12 @@ namespace Sonata\AdminBundle\Export;
 
 use Sonata\CoreBundle\Exporter\Exporter as BaseExporter;
 
+@trigger_error(
+    'The '.__NAMESPACE__.'\Exporter class is deprecated since version 3.x and will be removed in 4.0.'.
+    ' Use Exporter\Exporter instead',
+    E_USER_DEPRECATED
+);
+
 /**
  * NEXT_MAJOR: remove this class.
  *

+ 1 - 0
Resources/config/core.xml

@@ -53,6 +53,7 @@
         <service id="sonata.admin.audit.manager" class="Sonata\AdminBundle\Model\AuditManager">
             <argument type="service" id="service_container"/>
         </service>
+        <!-- NEXT_MAJOR : remove this service -->
         <service id="sonata.admin.exporter" class="Sonata\AdminBundle\Export\Exporter"/>
         <service id="sonata.admin.search.handler" class="Sonata\AdminBundle\Search\SearchHandler">
             <argument type="service" id="sonata.admin.pool"/>

+ 2 - 0
Tests/Controller/CRUDControllerTest.php

@@ -42,6 +42,8 @@ use Symfony\Component\Security\Csrf\CsrfToken;
  * Test for CRUDController.
  *
  * @author Andrej Hudec <pulzarraider@gmail.com>
+ *
+ * @group legacy
  */
 class CRUDControllerTest extends PHPUnit_Framework_TestCase
 {

+ 2 - 0
Tests/Export/ExporterTest.php

@@ -16,6 +16,8 @@ use Sonata\AdminBundle\Export\Exporter;
 use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
 
 /**
+ * NEXT_MAJOR: remove this class.
+ *
  * @group legacy
  */
 class ExporterTest extends PHPUnit_Framework_TestCase

+ 6 - 0
UPGRADE-3.x.md

@@ -65,6 +65,12 @@ All files under the ``Tests`` directory are now correctly handled as internal te
 You can't extend them anymore, because they are only loaded when running internal tests.
 More information can be found in the [composer docs](https://getcomposer.org/doc/04-schema.md#autoload-dev).
 
+### Exporter service and class
+
+The `sonata.admin.exporter` is deprecated in favor of the `sonata.exporter.exporter` service.
+To make this service available, you have to install `sonata-project.exporter` ^1.7
+and enable the bundle as described in the documentation.
+
 UPGRADE FROM 3.2 to 3.3
 =======================