From f3a5d132ab8f96f7c58ee2df4f396716fbb332c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C3=B3jcik?= Date: Mon, 19 Feb 2024 10:06:37 +0100 Subject: [PATCH] Symfony4-compatibility only --- Builder/FormContractor.php | 12 ++++--- .../Source/PropelCollectionSourceIterator.php | 33 +++++++++++++++++++ Filter/AbstractDateFilter.php | 9 +++++ Filter/BooleanFilter.php | 5 +-- Filter/CallbackFilter.php | 3 +- Filter/ModelFilter.php | 3 +- Filter/NumberFilter.php | 2 +- Filter/StringFilter.php | 2 +- Model/ModelManager.php | 2 +- Tests/Admin/FieldDescriptionTest.php | 2 ++ Tests/Builder/ListBuilderTest.php | 2 +- Tests/Filter/BooleanFilterTest.php | 2 +- Tests/Filter/DateFilterTest.php | 3 +- Tests/Filter/DateRangeFilterTest.php | 4 ++- Tests/Filter/DateTimeFilterTest.php | 3 +- Tests/Filter/DateTimeRangeFilterTest.php | 4 ++- Tests/Fixtures/App/app/AppKernel.php | 5 ++- Tests/Fixtures/App/app/config/config.yml | 1 - Tests/Functional/ExportTest.php | 2 -- Tests/Model/ModelManagerTest.php | 2 +- composer.json | 26 +++++++-------- 21 files changed, 92 insertions(+), 35 deletions(-) create mode 100644 Exporter/Source/PropelCollectionSourceIterator.php diff --git a/Builder/FormContractor.php b/Builder/FormContractor.php index 69343ae..4cfa4d8 100644 --- a/Builder/FormContractor.php +++ b/Builder/FormContractor.php @@ -15,6 +15,10 @@ use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminBundle\Admin\FieldDescriptionInterface; use Sonata\AdminBundle\Builder\FormContractorInterface; +use Sonata\AdminBundle\Form\Type\AdminType; +use Sonata\AdminBundle\Form\Type\CollectionType; +use Sonata\AdminBundle\Form\Type\ModelListType; +use Sonata\AdminBundle\Form\Type\ModelType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormFactoryInterface; @@ -78,26 +82,26 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip 'sonata_field_description' => $fieldDescription, ); - if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') { + if ($type == ModelType::class || $type == ModelListType::class) { if ($fieldDescription->getOption('edit') == 'list') { throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle'); } $options['class'] = $fieldDescription->getTargetEntity(); $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); - } elseif ($type == 'sonata_type_admin') { + } elseif ($type == AdminType::class) { if (!$fieldDescription->getAssociationAdmin()) { throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity())); } $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); - } elseif ($type == 'sonata_type_collection') { + } elseif ($type == CollectionType::class) { if (!$fieldDescription->getAssociationAdmin()) { throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity())); } - $options['type'] = 'sonata_type_admin'; + $options['type'] = AdminType::class; $options['modifiable'] = true; $options['type_options'] = array( 'sonata_field_description' => $fieldDescription, diff --git a/Exporter/Source/PropelCollectionSourceIterator.php b/Exporter/Source/PropelCollectionSourceIterator.php new file mode 100644 index 0000000..0fa26d8 --- /dev/null +++ b/Exporter/Source/PropelCollectionSourceIterator.php @@ -0,0 +1,33 @@ + $fields Fields to export + */ + public function __construct(Collection $collection, array $fields, string $dateTimeFormat = 'r') + { + $this->collection = clone $collection; + + parent::__construct($fields, $dateTimeFormat); + } + + public function rewind(): void + { + if (null === $this->iterator) { + $this->iterator = $this->collection->getIterator(); + } + + $this->iterator->rewind(); + } +} + diff --git a/Filter/AbstractDateFilter.php b/Filter/AbstractDateFilter.php index f46c608..9ef08dc 100644 --- a/Filter/AbstractDateFilter.php +++ b/Filter/AbstractDateFilter.php @@ -14,6 +14,8 @@ use Propel\Runtime\ActiveQuery\ModelCriteria; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Form\Type\Filter\DateRangeType; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeType; use Sonata\AdminBundle\Form\Type\Filter\DateType; /** @@ -138,6 +140,13 @@ public function getRenderSettings() $name .= '_range'; } + $name = [ + 'sonata_type_filter_date' => DateType::class, + 'sonata_type_filter_datetime' => DateTimeType::class, + 'sonata_type_filter_date_range' => DateRangeType::class, + 'sonata_type_filter_datetime_range' => DateTimeRangeType::class, + ][$name]; + return array($name, array( 'field_type' => $this->getFieldType(), 'field_options' => $this->getFieldOptions(), diff --git a/Filter/BooleanFilter.php b/Filter/BooleanFilter.php index d1162fe..f8408a8 100644 --- a/Filter/BooleanFilter.php +++ b/Filter/BooleanFilter.php @@ -13,7 +13,8 @@ use Propel\Runtime\ActiveQuery\ModelCriteria; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; -use Sonata\CoreBundle\Form\Type\BooleanType; +use Sonata\AdminBundle\Form\Type\Filter\DefaultType; +use Sonata\Form\Type\BooleanType; /** * @author Kévin Gomez @@ -44,7 +45,7 @@ public function filter(ProxyQueryInterface $query, $alias, $field, $value) */ public function getRenderSettings() { - return array('sonata_type_filter_default', array( + return array(DefaultType::class, array( 'field_type' => $this->getFieldType(), 'field_options' => $this->getFieldOptions(), 'label' => $this->getLabel(), diff --git a/Filter/CallbackFilter.php b/Filter/CallbackFilter.php index 85742ea..87f37f9 100644 --- a/Filter/CallbackFilter.php +++ b/Filter/CallbackFilter.php @@ -14,6 +14,7 @@ use Propel\Runtime\ActiveQuery\ModelCriteria; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; +use Sonata\AdminBundle\Form\Type\Filter\DefaultType; class CallbackFilter extends AbstractFilter { @@ -55,7 +56,7 @@ public function getDefaultOptions() */ public function getRenderSettings() { - return array('sonata_type_filter_default', array( + return array(DefaultType::class, array( 'field_type' => $this->getFieldType(), 'field_options' => $this->getFieldOptions(), 'operator_type' => $this->getOption('operator_type'), diff --git a/Filter/ModelFilter.php b/Filter/ModelFilter.php index c0146f1..53f5765 100644 --- a/Filter/ModelFilter.php +++ b/Filter/ModelFilter.php @@ -15,6 +15,7 @@ use Propel\Runtime\Collection\ObjectCollection; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; +use Sonata\AdminBundle\Form\Type\Filter\DefaultType; /** * @author Toni Uebernickel @@ -63,7 +64,7 @@ protected function getCriteriaMap() */ public function getRenderSettings() { - return array('sonata_type_filter_default', array( + return array(DefaultType::class, array( 'operator_type' => 'sonata_type_equal', 'field_type' => 'model', 'field_options' => $this->getFieldOptions(), diff --git a/Filter/NumberFilter.php b/Filter/NumberFilter.php index d7e13fb..fc8ec8f 100644 --- a/Filter/NumberFilter.php +++ b/Filter/NumberFilter.php @@ -24,7 +24,7 @@ class NumberFilter extends AbstractFilter */ public function getRenderSettings() { - return array('sonata_type_filter_number', array( + return array(NumberType::class, array( 'field_type' => $this->getFieldType(), 'field_options' => $this->getFieldOptions(), 'label' => $this->getLabel(), diff --git a/Filter/StringFilter.php b/Filter/StringFilter.php index 71bddd2..60cb0a5 100644 --- a/Filter/StringFilter.php +++ b/Filter/StringFilter.php @@ -46,7 +46,7 @@ public function filter(ProxyQueryInterface $query, $alias, $field, $value) */ public function getRenderSettings() { - return array('sonata_type_filter_choice', array( + return array(ChoiceType::class, array( 'field_type' => $this->getFieldType(), 'field_options' => $this->getFieldOptions(), 'label' => $this->getLabel(), diff --git a/Model/ModelManager.php b/Model/ModelManager.php index 6e52833..93bd5ea 100644 --- a/Model/ModelManager.php +++ b/Model/ModelManager.php @@ -11,7 +11,7 @@ namespace Sonata\PropelAdminBundle\Model; -use Exporter\Source\PropelCollectionSourceIterator; +use Sonata\PropelAdminBundle\Exporter\Source\PropelCollectionSourceIterator; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveRecord\ActiveRecordInterface; use Propel\Runtime\Collection\ObjectCollection; diff --git a/Tests/Admin/FieldDescriptionTest.php b/Tests/Admin/FieldDescriptionTest.php index 5ba0623..230dee9 100644 --- a/Tests/Admin/FieldDescriptionTest.php +++ b/Tests/Admin/FieldDescriptionTest.php @@ -125,6 +125,7 @@ public function testGetValue(): void ->willReturn('myMethodValue'); $field = new FieldDescription(); + $field->setName('irrelevant'); $field->setOption('code', 'myMethod'); self::assertEquals('myMethodValue', $field->getValue($mockedObject)); @@ -140,6 +141,7 @@ public function testGetValueWhenCannotRetrieve(): void ->willReturn('myMethodValue'); $field = new FieldDescription(); + $field->setName('irrelevant'); self::assertEquals('myMethodValue', $field->getValue($mockedObject)); } diff --git a/Tests/Builder/ListBuilderTest.php b/Tests/Builder/ListBuilderTest.php index 2791374..ec5f32a 100644 --- a/Tests/Builder/ListBuilderTest.php +++ b/Tests/Builder/ListBuilderTest.php @@ -113,7 +113,7 @@ public function optionsProvider(): array array( $field, array('sortable' => true), - array('sortable' => true, 'sort_field_mapping' => null, 'sort_parent_association_mappings' => array()), + array('sortable' => true, 'sort_field_mapping' => array(), 'sort_parent_association_mappings' => array()), ), array( $field, diff --git a/Tests/Filter/BooleanFilterTest.php b/Tests/Filter/BooleanFilterTest.php index f65d872..9dd9f17 100644 --- a/Tests/Filter/BooleanFilterTest.php +++ b/Tests/Filter/BooleanFilterTest.php @@ -12,7 +12,7 @@ namespace Sonata\PropelAdminBundle\Tests\Filter; use Propel\Runtime\ActiveQuery\ModelCriteria; -use Sonata\CoreBundle\Form\Type\BooleanType; +use Sonata\Form\Type\BooleanType; use Sonata\PropelAdminBundle\Filter\BooleanFilter; /** diff --git a/Tests/Filter/DateFilterTest.php b/Tests/Filter/DateFilterTest.php index c60fb8a..77c4af0 100644 --- a/Tests/Filter/DateFilterTest.php +++ b/Tests/Filter/DateFilterTest.php @@ -11,6 +11,7 @@ namespace Sonata\PropelAdminBundle\Tests\Filter; +use Sonata\AdminBundle\Form\Type\Filter\DateType; use Sonata\PropelAdminBundle\Filter\DateFilter; /** @@ -28,6 +29,6 @@ protected function getFilterClass(): string public function testRenderSettingsHasRightName() { $settings = $this->filter->getRenderSettings(); - self::assertEquals('sonata_type_filter_date', $settings[0]); + self::assertEquals(DateType::class, $settings[0]); } } diff --git a/Tests/Filter/DateRangeFilterTest.php b/Tests/Filter/DateRangeFilterTest.php index a1e5b76..cef92e5 100644 --- a/Tests/Filter/DateRangeFilterTest.php +++ b/Tests/Filter/DateRangeFilterTest.php @@ -11,6 +11,8 @@ namespace Sonata\PropelAdminBundle\Tests\Filter; +use Sonata\AdminBundle\Form\Type\Filter\DateRangeType; + /** * DateRangeFilter tests. * @@ -26,6 +28,6 @@ protected function getFilterClass() public function testRenderSettingsHasRightName() { $settings = $this->filter->getRenderSettings(); - self::assertEquals('sonata_type_filter_date_range', $settings[0]); + self::assertEquals(DateRangeType::class, $settings[0]); } } diff --git a/Tests/Filter/DateTimeFilterTest.php b/Tests/Filter/DateTimeFilterTest.php index 1e95e13..0cf2a2d 100644 --- a/Tests/Filter/DateTimeFilterTest.php +++ b/Tests/Filter/DateTimeFilterTest.php @@ -11,6 +11,7 @@ namespace Sonata\PropelAdminBundle\Tests\Filter; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeType; use Sonata\PropelAdminBundle\Filter\DateTimeFilter; /** @@ -28,6 +29,6 @@ protected function getFilterClass(): string public function testRenderSettingsHasRightName() { $settings = $this->filter->getRenderSettings(); - self::assertEquals('sonata_type_filter_datetime', $settings[0]); + self::assertEquals(DateTimeType::class, $settings[0]); } } diff --git a/Tests/Filter/DateTimeRangeFilterTest.php b/Tests/Filter/DateTimeRangeFilterTest.php index fd35c09..3e9aae8 100644 --- a/Tests/Filter/DateTimeRangeFilterTest.php +++ b/Tests/Filter/DateTimeRangeFilterTest.php @@ -11,6 +11,8 @@ namespace Sonata\PropelAdminBundle\Tests\Filter; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType; + /** * DateTimeRangeFilter tests. * @@ -26,6 +28,6 @@ protected function getFilterClass() public function testRenderSettingsHasRightName() { $settings = $this->filter->getRenderSettings(); - self::assertEquals('sonata_type_filter_datetime_range', $settings[0]); + self::assertEquals(DateTimeRangeType::class, $settings[0]); } } diff --git a/Tests/Fixtures/App/app/AppKernel.php b/Tests/Fixtures/App/app/AppKernel.php index 95924e3..92a54c8 100644 --- a/Tests/Fixtures/App/app/AppKernel.php +++ b/Tests/Fixtures/App/app/AppKernel.php @@ -17,7 +17,10 @@ public function registerBundles() new Propel\Bundle\PropelBundle\PropelBundle(), - new Sonata\CoreBundle\SonataCoreBundle(), + new \Sonata\Twig\Bridge\Symfony\SonataTwigBundle(), + new \Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle(), + new \Sonata\Form\Bridge\Symfony\SonataFormBundle(), + new \Sonata\Exporter\Bridge\Symfony\SonataExporterBundle(), new Knp\Bundle\MenuBundle\KnpMenuBundle(), new Sonata\BlockBundle\SonataBlockBundle(), new Sonata\AdminBundle\SonataAdminBundle(), diff --git a/Tests/Fixtures/App/app/config/config.yml b/Tests/Fixtures/App/app/config/config.yml index 924958e..7fa8188 100644 --- a/Tests/Fixtures/App/app/config/config.yml +++ b/Tests/Fixtures/App/app/config/config.yml @@ -28,7 +28,6 @@ propel: charset: utf8 paths: -# phpDir: "%kernel.root_dir%/../src/Sonata/TestBundle/Model" sqlDir: '%kernel.cache_dir%/propel/sql/' schemaDir: '%kernel.root_dir%/../src/Sonata/TestBundle/Resources/config/' loaderScriptDir: '%kernel.cache_dir%/propel/generated-conf/' diff --git a/Tests/Functional/ExportTest.php b/Tests/Functional/ExportTest.php index 209f53e..916e986 100644 --- a/Tests/Functional/ExportTest.php +++ b/Tests/Functional/ExportTest.php @@ -59,8 +59,6 @@ public function testExportLinksWork(): void foreach ($this->expected_formats as $format) { $link = $crawler->selectLink($format)->link(); - $this->markTestIncomplete('sonata-project/exporter is having issues with autoloading PropelCollectionSourceIterator class'); - // as Sonata\AdminBundle\Export\Exporter writes directly to php://output // the exported data is displayed in the console ob_start(); diff --git a/Tests/Model/ModelManagerTest.php b/Tests/Model/ModelManagerTest.php index 6a5d61c..273961a 100644 --- a/Tests/Model/ModelManagerTest.php +++ b/Tests/Model/ModelManagerTest.php @@ -190,7 +190,7 @@ public function testGetDataSourceIterator(): void // // // and finally test it! // $collectionIterator = $manager->getDataSourceIterator($datagrid, $fields, $firstResult, $maxResults); -// self::assertInstanceOf('\Exporter\Source\PropelCollectionSourceIterator', $collectionIterator); +// self::assertInstanceOf('\Sonata\Exporter\Source\PropelCollectionSourceIterator', $collectionIterator); // self::assertSame(array( // array('title' => 'Super!'), // array('title' => 'Foo'), diff --git a/composer.json b/composer.json index 1775184..66dfe4b 100644 --- a/composer.json +++ b/composer.json @@ -13,25 +13,25 @@ ], "require": { "php": "^7.4 || ^8.0", + "doctrine/persistence": "^1.0", "propel/propel": "^2.0.0-beta1", - "sonata-project/admin-bundle": "~3.0", - "sonata-project/block-bundle": "~3.0", - "sonata-project/core-bundle": "3.17.2", - "sonata-project/exporter": "1.x-dev#7ea2008067c70b8caa70b9be72da40bea7104056", - "symfony/form": "^3.4 || ^4.0", - "symfony/framework-bundle": "^3.4 || ^4.0" + "sonata-project/admin-bundle": "^3.107.3", + "sonata-project/block-bundle": "^3.20", + "sonata-project/exporter": "^2", + "symfony/form": "^4.0", + "symfony/framework-bundle": "^4.0" }, "require-dev": { - "knplabs/knp-menu-bundle": ">=1.1.0,<3.0.0", + "knplabs/knp-menu-bundle": "^3", "phpunit/phpunit": "^9", "skyfox/propel-bundle": "~5.0.2@dev", - "symfony/browser-kit": "^3.4 || ^4.0", - "symfony/console": "^3.4 || ^4.0", - "symfony/css-selector": "^3.4 || ^4.0", - "symfony/phpunit-bridge": "^3.4 || ^4.0", + "symfony/browser-kit": "^4.0", + "symfony/console": "^4.0", + "symfony/css-selector": "^4.0", + "symfony/phpunit-bridge": "^4.0", "symfony/security-bundle": "^4.0", - "symfony/twig-bundle": "^3.4 || ^4.0", - "symfony/var-dumper": "^3.4 || ^4.0" + "symfony/twig-bundle": "^4.0", + "symfony/var-dumper": "^4.0" }, "conflict": { "doctrine/annotations": ">1"