GithubHelp home page GithubHelp logo

sonata-project / exporter Goto Github PK

View Code? Open in Web Editor NEW
436.0 22.0 88.0 1.15 MB

Lightweight Exporter library

Home Page: https://docs.sonata-project.org/projects/exporter

License: MIT License

Makefile 1.31% PHP 98.69%
client csv data export php sonata symfony xls bundle symfony-bundle

exporter's Introduction

SonataExporter

Lightweight Exporter library

Latest Stable Version Latest Unstable Version Psalm Type Coverage License

Total Downloads Monthly Downloads Daily Downloads

Branch Github Actions Code Coverage Documentation
3.x Test Coverage Status Documentation Status
4.x Test Coverage Status Documentation Status

Documentation

Check out the documentation on the official website.

Support

For general support and questions, please use StackOverflow.

If you think you found a bug or you have a feature idea to propose, feel free to open an issue after looking at the contributing guide.

License

This package is available under the MIT license.

exporter's People

Contributors

bladrak avatar chalasr avatar chebba avatar core23 avatar eko avatar franmomu avatar greg0ire avatar gregbiv avatar jordisala1991 avatar k-phoen avatar kunicmarko20 avatar lctrs avatar lerouquin avatar makasim avatar mremi avatar oskarstark avatar parijke avatar petk avatar phansys avatar pkameisha avatar pokap avatar pulzarraider avatar rande avatar shulard avatar sonataci avatar soullivaneuh avatar tiagojsag avatar vincentlanglet avatar vincenttouzet avatar wharenn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

exporter's Issues

when order by relation filed export error

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'

root@vagrant-ubuntu-trusty:~/www/lion/current# composer show --latest 'sonata-project/*'
Do not run Composer as root/super user! See https://getcomposer.org/root for details
sonata-project/admin-bundle 3.19.0 3.23.0 The missing Symfony Admin Generator
sonata-project/block-bundle 3.3.2 3.3.2 Symfony SonataBlockBundle
sonata-project/cache 1.0.7 1.0.7 Cache library
sonata-project/core-bundle 3.4.0 3.4.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle 2.2.1 2.2.1 Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.1.5 3.1.6 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter 1.7.1 1.7.1 Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'

root@vagrant-ubuntu-trusty:~/www/lion/current# composer show --latest 'symfony/'
Do not run Composer as root/super user! See https://getcomposer.org/root for details
symfony/monolog-bundle v2.12.1 v3.1.0 Symfony MonologBundle
symfony/phpunit-bridge v3.3.2 v3.3.8 Symfony PHPUnit Bridge
symfony/polyfill-apcu v1.3.0 v1.5.0 Symfony polyfill backporting apcu_
functions to lower PHP versions
symfony/polyfill-intl-icu v1.3.0 v1.5.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.3.0 v1.5.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.3.0 v1.5.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.3.0 v1.5.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util v1.3.0 v1.5.0 Symfony utilities for portability of PHP codes
symfony/security-acl v3.0.0 v3.0.0 Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.6.2 v3.0.3 Symfony SwiftmailerBundle
symfony/symfony v3.3.2 v3.3.8 The Symfony PHP framework

PHP version

$ php -v
# Put the result here.

root@vagrant-ubuntu-trusty:/www/lion/current# php -v
PHP 7.0.19-1+deb.sury.org
trusty+2 (cli) (built: May 22 2017 13:29:59) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Subject

Steps to reproduce

Expected results

Actual results

the sql error
[2017-09-04 10:01:28] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred while executing 'SELECT DISTINCT t0_.id AS id_0, t0_.month_date AS month_date
1, t0.income AS income_2, t0_.from_normal AS from_normal_3, t0_.from_system AS from_system_4, t0_.from_protected_user AS from_protected_user_5, t0_.master_id AS master_id_6 FROM t_protected_user_master_
report t0_ LEFT JOIN t_master t1_ ON t0_.master_id = t1_.acc_id LEFT JOIN t_user t2_ ON t1_.acc_id = t2_.acc_id LEFT JOIN t_room t3_ ON t1_.room_id = t3_.room_id WHERE t0_.month_date LIKE '2017-08%' ORDER
BY t2_.acc_id ASC': SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'lion.t2_.acc_id' which is not in SELECT list; this is incompatible wit
h DISTINCT" at /data/www/lion/releases/20170828083035Z/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 115 {"exception":"[object] (Doctrine\DBAL\Exception\DriverException(cod
e: 0): An exception occurred while executing 'SELECT DISTINCT t0_.id AS id_0, t0_.month_date AS month_date_1, t0_.income AS income_2, t0_.from_normal AS from_normal_3, t0_.from_system AS from_system_4, t0
.from_protected_user AS from_protected_user_5, t0.master_id AS master_id_6 FROM t_protected_user_master_report t0_ LEFT JOIN t_master t1_ ON t0_.master_id = t1_.acc_id LEFT JOIN t_user t2_ ON t1_.acc_id
= t2_.acc_id LEFT JOIN t_room t3_ ON t1_.room_id = t3_.room_id WHERE t0_.month_date LIKE '2017-08%' ORDER BY t2_.acc_id ASC':\n\nSQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is n
ot in SELECT list, references column 'lion.t2_.acc_id' which is not in SELECT list; this is incompatible with DISTINCT at /data/www/lion/releases/20170828083035Z/vendor/doctrine/dbal/lib/Doctrine/DBAL/Dri
ver/AbstractMySQLDriver.php:115, Doctrine\DBAL\Driver\PDOException(code: HY000): SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'lion.t2_
.acc_id' which is not in SELECT list; this is incompatible with DISTINCT at /data/www/lion/releases/20170828083035Z/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:107, PDOException(code:
HY000): SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'lion.t2_.acc_id' which is not in SELECT list; this is incompatible with DISTINCT at
/data/www/lion/releases/20170828083035Z/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:105)"} []

[2.1] Lack of PropertyAccess throws an exception

Fatal error: Class 'Symfony\Component\PropertyAccess\PropertyAccess' not found in /(...)/vendor/sonata-project/exporter/lib/Exporter/Source/DoctrineORMQuerySourceIterator.php on line 57

This happens because PropertyAccess was only introduced in Sf2.2. I'll make a PR to add PropertyAccess to the required dependencies on master. However, for Sf2.1, installing PropertyAccess might not be a good idea, as it is only supported for Sf2.2+. I tried installing it and it seems to solve the problem, but I don't have enough knowledge of it to rule out any possible interference with other stuff in 2.1. Chaging SonataAdmin's dependencies to use exporter 1.2.3 on Sf 2.1 also solves the issue, which I'm guessing is a safer solution.

Translation

Bundle for exporting DateTime field returns the english name though not given the values :

sonata_intl:
     timezone:
         default: Europe / Warsaw

example:
string 'Mon, 09 Jul 2012 00:00:00 +0200' (length=31)

File DoctrineORMQuerySourceIterator.php line $value = $value->format('r');

Compatibilty with Doctrine DBAL 2.13 broken

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
# Put the result here.

sonata-project/block-bundle 3.23.3 4.8.0 Symfony SonataBlockBundle
sonata-project/cache 2.2.0 2.2.0 Cache library
sonata-project/classification-bundle 3.18.0 3.18.0 Symfony SonataClassificationBundle
sonata-project/datagrid-bundle 3.4.1 3.4.2 Symfony SonataDatagridBundle
sonata-project/doctrine-extensions 1.15.0 1.15.0 Doctrine2 behavioral extensions
sonata-project/exporter 2.9.0 2.9.0 Lightweight Exporter library
sonata-project/form-extensions 1.12.1 1.12.1 Symfony form extensions
sonata-project/media-bundle 3.36.0 3.36.0 Symfony SonataMediaBundle
sonata-project/twig-extensions 1.9.0 1.9.0 Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
# Put the result here.

symfony/asset v4.4.27 v5.3.4 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/browser-kit v4.4.27 v5.3.4 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmati...
symfony/cache v4.4.33 v5.3.10 Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts v2.4.0 v2.4.0 Generic abstractions related to caching
symfony/config v4.4.33 v5.3.10 Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console v4.4.33 v5.3.10 Eases the creation of beautiful and testable command line interfaces
symfony/css-selector v4.4.27 v5.3.4 Converts CSS selectors to XPath expressions
symfony/debug v4.4.31 v4.4.31 Provides tools to ease debugging PHP code
symfony/debug-bundle v4.4.27 v5.3.4 Provides a tight integration of the Symfony Debug component into the Symfony full-stack framework
symfony/dependency-injection v4.4.33 v5.3.10 Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts v2.4.0 v2.4.0 A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge v4.4.31 v5.3.8 Provides integration for Doctrine with various Symfony components
symfony/dom-crawler v4.4.30 v5.3.7 Eases DOM navigation for HTML and XML documents
symfony/dotenv v4.4.33 v5.3.10 Registers environment variables from a .env file
symfony/error-handler v4.4.30 v5.3.7 Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher v4.4.30 v5.3.7 Provides tools that allow your application components to communicate with each other by dispatching events and list...
symfony/event-dispatcher-contracts v1.1.9 v2.4.0 Generic abstractions related to dispatching event
symfony/expression-language v4.4.30 v5.3.7 Provides an engine that can compile and evaluate expressions
symfony/filesystem v4.4.27 v5.3.4 Provides basic utilities for the filesystem
symfony/finder v4.4.30 v5.3.7 Finds files and directories via an intuitive fluent interface
symfony/flex v1.17.2 v1.17.2 Composer plugin for Symfony
symfony/form v4.4.33 v5.3.10 Allows to easily create, process and reuse HTML forms
symfony/framework-bundle v4.4.31 v5.3.10 Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client v4.4.33 v5.3.10 Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts v2.4.0 v2.4.0 Generic abstractions related to HTTP clients
symfony/http-foundation v4.4.33 v5.3.10 Defines an object-oriented layer for the HTTP specification
symfony/http-kernel v4.4.33 v5.3.10 Provides a structured process for converting a Request into a Response
symfony/inflector v4.4.27 v5.3.4 Converts words between their singular and plural forms (English only)
Package symfony/inflector is abandoned, you should avoid using it. Use use EnglishInflector from the String component instead instead.
symfony/intl v4.4.31 v5.3.8 Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library
symfony/mailer v4.4.27 v5.3.9 Helps sending emails
symfony/maker-bundle v1.34.1 v1.34.1 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about wr...
symfony/mercure v0.4.1 v0.6.0 Symfony Mercure Component
symfony/mercure-bundle v0.2.6 v0.3.3 Symfony MercureBundle
symfony/mime v4.4.31 v5.3.8 Allows manipulating MIME messages
symfony/monolog-bridge v5.2.12 v5.3.7 Provides integration for Monolog with various Symfony components
symfony/monolog-bundle v3.7.1 v3.7.1 Symfony MonologBundle
symfony/options-resolver v4.4.30 v5.3.7 Provides an improved replacement for the array_replace PHP function
symfony/phpunit-bridge v5.3.10 v5.3.10 Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-apcu v1.23.0 v1.23.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-ctype v1.23.0 v1.23.0 Symfony polyfill for ctype functions
symfony/polyfill-iconv v1.23.0 v1.23.0 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-grapheme v1.23.1 v1.23.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu v1.23.0 v1.23.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn v1.23.0 v1.23.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.23.0 v1.23.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring v1.23.1 v1.23.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php72 v1.23.0 v1.23.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73 v1.23.0 v1.23.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80 v1.23.1 v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81 v1.23.0 v1.23.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process v4.4.30 v5.3.7 Executes commands in sub-processes
symfony/property-access v4.4.30 v5.3.8 Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info v4.4.31 v5.3.8 Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge v4.4.18 v5.3.4 Symfony ProxyManager Bridge
symfony/routing v4.4.30 v5.3.7 Maps an HTTP request to a set of configuration variables
symfony/security-bundle v4.4.27 v5.3.8 Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core v4.4.33 v5.3.10 Symfony Security Component - Core Library
symfony/security-csrf v4.4.27 v5.3.4 Symfony Security Component - CSRF Library
symfony/security-guard v4.4.27 v5.3.7 Symfony Security Component - Guard
symfony/security-http v4.4.30 v5.3.10 Symfony Security Component - HTTP Integration
symfony/serializer v4.4.33 v5.3.10 Handles serializing and deserializing data structures, including object graphs, into array structures or other form...
symfony/service-contracts v2.4.0 v2.4.0 Generic abstractions related to writing services
symfony/stopwatch v4.4.27 v5.3.4 Provides a way to profile code
symfony/string v5.3.10 v5.3.10 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unifi...
symfony/swiftmailer-bundle v3.5.2 v3.5.2 Symfony SwiftmailerBundle
symfony/templating v4.4.30 v5.3.7 Provides all the tools needed to build any kind of template system
symfony/translation v4.4.32 v5.3.10 Provides tools to internationalize your application
symfony/translation-contracts v2.4.0 v2.4.0 Generic abstractions related to translation
symfony/twig-bridge v4.4.27 v5.3.7 Provides integration for Twig with various Symfony components
symfony/twig-bundle v4.4.30 v5.3.10 Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator v4.4.33 v5.3.10 Provides tools to validate values
symfony/var-dumper v4.4.33 v5.3.10 Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter v4.4.31 v5.3.8 Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link v4.4.27 v5.3.4 Manages links between resources
symfony/web-profiler-bundle v4.4.31 v5.3.8 Provides a development tool that gives detailed information about the execution of any request
symfony/webpack-encore-bundle v1.12.0 v1.12.0 Integration with your Symfony app & Webpack Encore!
symfony/workflow v4.4.27 v5.3.4 Provides tools for managing a workflow or finite state machine
symfony/yaml v4.4.29 v5.3.6 Loads and dumps YAML files

PHP version

$ php -v
# Put the result here.

PHP 7.3.31-1+020210923.88+debian91.gbpac4058 (cli) (built: Sep 23 2021 22:05:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.31-1+020210923.88+debian91.gbpac4058, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

Subject

Minimal repository with the bug

Steps to reproduce

Performing an iteration with "DoctrineDBALConnectionSourceIterator

Actual results

In DoctrineDBALConnectionSourceIterator.php line 65:
                                                        
  [Error]                                               
  Call to a member function fetchAssociative() on bool  

In version 3 $statement->execute($this->parameters) return a Result, but it was a boolean in previous versions

https://github.com/doctrine/dbal/blob/2.13.x/lib/Doctrine/DBAL/Driver/Statement.php#L81-L95

[Bug] Actually use the escape parameter.

Subject

The construct method takes an escape character string, but never actually uses it when running fputcsv.

Steps to reproduce

Try using CsvWriter with a custom escape character.

Expected results

You'd expect that character to be used, since it's taken as a param.

Actual results

It uses the default escape character always.

Unable to register v2 Symfony bundle

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.45.1 3.45.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.14.0 3.14.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.15.0 3.15.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0  2.4.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.5  1.1.5  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.8.1  3.8.1  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.0.0  2.0.0  Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'
symfony/monolog-bundle     v3.3.1  v3.3.1  Symfony MonologBundle
symfony/phpunit-bridge     v3.4.21 v4.2.2  Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.10.0 v1.10.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-ctype     v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu  v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.10.0 v1.10.0 Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.1  v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.6.7  v3.2.5  Symfony SwiftmailerBundle
symfony/symfony            v3.4.21 v4.2.2  The Symfony PHP framework

PHP version

$ php -v
PHP 7.2.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec  7 2018 08:07:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Zend Server Z-Ray v9.2.0, Copyright (c) 2004-2017, by Zend Technologies
    with blackfire v1.23.1~linux-x64-non_zts72, https://blackfire.io, by Blackfire

Subject

Trying to register the v2 bundle on Sy3.4 at least fails miserably.
There is a note on support for different versions of symfony, but if v2 happens to be incompatible with <Sy4.0 at least update the damn documentation before including a version constraint like "^1.11.0 || ^2.0" that forces the update.

Steps to reproduce

Do something that installs the Exporter v2. I ran composer update on Sy3.4 (haven't tested on Sy4.0).
Try to register the exporter bundle ->
new Sonata\Exporter\Bridge\Symfony\Bundle\SonataExporterBundle()

Expected results

Seamless update.

Actual results

Various errors like
There is no extension able to load the configuration for "sonata_exporter"
OR
The service "sonata.admin.admin_exporter" has a dependency on a non-existent service "sonata.exporter.exporter".
...which boil down to not being able to register the bundle.

Sonata\Exporter\Handler uses deprecated interface SourceIteratorInterface

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version
sonata-project/admin-bundle              4.2.1  4.2.2  The missing Symfony Admin Generator
sonata-project/block-bundle              4.8.0  4.8.0  Symfony SonataBlockBundle
sonata-project/cache                     2.2.0  2.2.0  Cache library
sonata-project/datagrid-bundle           3.4.2  3.4.2  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.15.0 1.15.0 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.1.0  4.1.0  Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.9.0  2.9.1  Lightweight Exporter library
sonata-project/form-extensions           1.12.1 1.12.1 Symfony form extensions
sonata-project/twig-extensions           1.9.0  1.9.0  Sonata twig extensions

Subject

In #532 the SourceIteratorInterface interface has been deprecated, but the class Sonata\Exporter\Handler still expect an instance of SourceIteratorInterface.

So we don't have any way to fix the deprecation.

Exporter improvements

Currently, there are a few things that can be improved in exporter.
Here is the list I came up with:

  • Sources are not seekable
  • Handler is not stateless
  • Handler does not manage errors in the process
  • Handler does not manage cycles
  • There is currently no way to observe or interact with the services during an export
  • There is no db writer
  • XML source does not manage xpath

I will create a series of MR that will try to bring solutions to those issues.
I hope this will help you extend the scope and usages of the bundle.

DoctrineORMQuerySourceIterator only works if query has ORDER BY defined

I recently was creating my own export function, outside SonataAdminBundle, by I was getting a "File not found" error. After a while, and looking in some issues in SonataAdminBundle, I found out that the DoctrineORMQuerySourceIterator only works if ORDER BY is defined in the query. Like this:

$query = $em->createQuery(
            'SELECT c FROM PoPGerenciamentoBundle:Circuit c
            ORDER BY c.id ASC'
        );

Is this the normal behavior?

Move "private" methods and attributes to "protected".

Hi,

Is it possible to move "private" methods and attributes of this project to "protected" ?
It would allow to extend its php classes.

Thanks a lot.

Freepius

EDIT : I make a pull request. Sorry for duplicated issue.

DoctrineORMQuerySourceIterator is now final

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
# Put the result here.

sonata-project/admin-bundle              3.45.1 3.45.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.14.0 3.14.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.15.1 3.15.1 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0  2.4.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.5  1.1.5  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.8.1  3.8.1  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library
sonata-project/formatter-bundle          3.5.0  4.1.2  Symfony SonataFormatterBundle
sonata-project/media-bundle              3.18.1 3.18.1 Symfony SonataMediaBundle
sonata-project/user-bundle               4.2.3  4.2.3  Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
# Put the result here.
symfony/dependency-injection v4.2.2             v4.2.2             Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.2             v4.2.2             Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.2             v4.2.2             Symfony DomCrawler Component
symfony/dotenv               v4.2.2             v4.2.2             Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.2             v4.2.2             Symfony EventDispatcher Component
symfony/expression-language  v4.2.2             v4.2.2             Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.2             v4.2.2             Symfony Filesystem Component
symfony/finder               v4.2.2             v4.2.2             Symfony Finder Component
symfony/flex                 v1.1.8             v1.1.8             Composer plugin for Symfony
symfony/form                 v4.2.2             v4.2.2             Symfony Form Component
symfony/framework-bundle     v4.2.2             v4.2.2             Symfony FrameworkBundle
symfony/http-foundation      v4.2.2             v4.2.2             Symfony HttpFoundation Component
symfony/http-kernel          v4.2.2             v4.2.2             Symfony HttpKernel Component
symfony/inflector            v4.2.2             v4.2.2             Symfony Inflector Component
symfony/intl                 v4.2.2             v4.2.2             A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/lock                 v4.2.2             v4.2.2             Symfony Lock Component
symfony/lts                  dev-master c1affae dev-master c1affae Enforces Long Term Supported versions of Symfony components
symfony/maker-bundle         v1.11.3            v1.11.3            Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forge...
symfony/monolog-bridge       v4.2.2             v4.2.2             Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1             v3.3.1             Symfony MonologBundle
symfony/options-resolver     v4.2.2             v4.2.2             Symfony OptionsResolver Component
symfony/orm-pack             v1.0.6             v1.0.6             A pack for the Doctrine ORM
symfony/panther              v0.2.0             v0.2.0             A browser testing and web scraping library for PHP and Symfony.
symfony/phpunit-bridge       v4.2.2             v4.2.2             Symfony PHPUnit Bridge
symfony/polyfill-ctype       v1.10.0            v1.10.0            Symfony polyfill for ctype functions
symfony/polyfill-intl-icu    v1.10.0            v1.10.0            Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.10.0            v1.10.0            Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.10.0            v1.10.0            Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process              v4.2.2             v4.2.2             Symfony Process Component
symfony/profiler-pack        v1.0.4             v1.0.4             A pack for the Symfony web profiler
symfony/property-access      v4.2.2             v4.2.2             Symfony PropertyAccess Component
symfony/routing              v4.2.2             v4.2.2             Symfony Routing Component
symfony/security-acl         v3.0.1             v3.0.1             Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.2.2             v4.2.2             Symfony SecurityBundle
symfony/security-core        v4.2.2             v4.2.2             Symfony Security Component - Core Library
symfony/security-csrf        v4.2.2             v4.2.2             Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.2             v4.2.2             Symfony Security Component - Guard
symfony/security-http        v4.2.2             v4.2.2             Symfony Security Component - HTTP Integration
symfony/stopwatch            v4.2.2             v4.2.2             Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.5             v3.2.5             Symfony SwiftmailerBundle
symfony/templating           v4.2.2             v4.2.2             Symfony Templating Component
symfony/test-pack            v1.0.5             v1.0.5             A pack for functional and end-to-end testing within a Symfony app
symfony/translation          v4.2.2             v4.2.2             Symfony Translation Component
symfony/twig-bridge          v4.2.2             v4.2.2             Symfony Twig Bridge
symfony/twig-bundle          v4.2.2             v4.2.2             Symfony TwigBundle
symfony/validator            v4.2.2             v4.2.2             Symfony Validator Component
symfony/var-dumper           v4.2.2             v4.2.2             Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.2             v4.2.2             A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle  v4.2.2             v4.2.2             Symfony WebProfilerBundle
symfony/yaml                 v4.2.2             v4.2.2             Symfony Yaml Component

PHP version

$ php -v
# Put the result here.
PHP 7.2.3 (cli) (built: Mar 22 2018 22:03:09) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

Subject

I just updated to the latest Sonata\Export version and the Sonata\Exporter\Source\DoctrineORMQuerySourceIterator has all is method now final. I don't why this one specifically since all the other SourceIterator are not final.
I was extending it to support Doctrine\ORM\Query::HYDRATE_SCALAR but now I need to copy paste all the content of the class and do some adjustment instead of overiding 2 methods.

Issues with the deprecated arguments of the generate() method

I'm getting this deprecation message while upgrading a Symfony app to 2.8:

The hardcoded value you are using for the $referenceType argument of the 
Symfony\Component\Routing\Generator\UrlGenerator::generate method is
deprecated since version 2.8 and will not be supported anymore in 3.0. 
Use the constants defined in the UrlGeneratorInterface instead.

The problem is located here: https://github.com/sonata-project/exporter/blob/master/lib/Exporter/Source/SymfonySitemapSourceIterator.php#L50

Add an explanation of the withBom option utility

We currently have a withBom option adding some special chars at the beginning of the CSV file:

if (true === $this->withBom) {
fprintf($this->file, \chr(0xEF).\chr(0xBB).\chr(0xBF));
}

However, we don't know what is the goal of this option.

It would be great to have one explanation sentence on the documentation and/or a documentation links about it.

Provide autowiring for Exporter class

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'

sonata-project/exporter                  1.9.1  1.9.1  Lightweight Exporter library

PHP version

$ php -v

PHP 7.2.10 (cli) (built: Sep 15 2018 02:22:37) ( NTS )

Subject

Provide autowiring for sonata.exporter.exporter class

Cannot autowire argument $exporter of "AppBundle\Controller\LogController::exportAction()": it references class "Exporter\Exporter" but no such service exists. You should maybe alias this class to the existing "sonata.exporter.exporter" service.

Actual workaround

To temporary fix this I need to write this workaround inside Kernel.php

$aliases = ([
    \Exporter\Exporter::class => 'sonata.exporter.exporter',
]);

XMLExporter does not sanitize tags

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.13.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.0  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/cache-bundle              2.3.1  This bundle provides caching services
sonata-project/classification-bundle     3.3.0  Symfony SonataClassificationBundle
sonata-project/core-bundle               3.3.0  Symfony SonataCoreBundle
sonata-project/dashboard-bundle          0.1.0  Provides a Dashboard management through container and block services
sonata-project/datagrid-bundle           2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.3  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.1.10 Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1  Lightweight Exporter library
sonata-project/formatter-bundle          3.1.0  Symfony SonataFormatterBundle
sonata-project/google-authenticator      1.0.2  Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle               2.3.0  Symfony SonataIntlBundle
sonata-project/media-bundle              3.3.1  Symfony SonataMediaBundle
sonata-project/notification-bundle       3.1.0  Symfony SonataNotificationBundle
sonata-project/page-bundle               3.3.0  This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.1.0  Symfony SonataSeoBundle
sonata-project/user-bundle               3.2.1  Symfony SonataUserBundle

Symfony packages

$ composer show symfony/*
symfony/monolog-bundle     v2.8.0  Symfony MonologBundle
symfony/phpunit-bridge     v3.2.4  Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.1.0  Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.3.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55     v1.3.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.3.0  Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle    v2.3.0  Symfony SecurityBundle
symfony/swiftmailer-bundle v2.4.2  Symfony SwiftmailerBundle
symfony/symfony            v2.8.17 The Symfony PHP framework
symfony/var-dumper         v3.2.3  Symfony mechanism for exploring and dumping PHP variables

PHP version

$ php -v
PHP 7.0.19-1+deb.sury.org~xenial+1 (cli) (built: May 11 2017 14:06:14) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
    with Zend OPcache v7.0.19-1+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies

Subject

When using XMLExporter (in SonataAdmin in my case), I had to create a custom implementation of SourceIteratorInterface in order to export the fields I want (many levels of nested entities where involved).

I'm using translated messages as key in my Iterator and those messages sometimes contains spaces. The mainly used export is the CSV, so spaces are not really a problem in the header, but sometimes my users use the XML export and spaces in tags should not be present (they should be converted to underscores or maybe an other character).

Add BC way for namespace changes

The namespace will change with the next major release. We should find a way to inform the user, that the namespace will change.

Maybe we could use something like EasyAdmin is doing with the legacy folder

Make the writers configurable services

My client wants to open their CSV files with Microsoft Excel or LibreOffice, but Excel does not automatically detect that commas are in used and defaults to SSV (Semicolon-separated values).

I think a way to fix that would be to make the CsvWriter configurable services (and the other writers while we're at it).

An ugly workaround is to create another Exporter configured with semicolons, and overwrite the service definition, like this :

    sonata.admin.exporter: # ugly service id override
        class: MyProject\AppBundle\Admin\Export\Exporter

Optimizing export

For export large data need call flush() in StreamedResponse.
its allow clear buffer and not use extra memory.
Todo as feature of framework?

My solution:

# config/services.yml
services:
    app.export.writer.csv:
        class: App\Writer\FlushWriterDecorator
        decorates: sonata.exporter.writer.csv

    app.export.writer.json:
        class: App\Writer\FlushWriterDecorator
        decorates: sonata.exporter.writer.json

    app.export.writer.xml:
        class: App\Writer\FlushWriterDecorator
        decorates: sonata.exporter.writer.xml

    app.export.writer.xls:
        class: App\Writer\FlushWriterDecorator
        decorates: sonata.exporter.writer.xls
<?php
declare(strict_types=1);

namespace App\Writer;

use Sonata\Exporter\Writer\TypedWriterInterface;

class FlushWriterDecorator implements TypedWriterInterface
{
    private const FLUSH_EVERY = 1000;

    private int $position;
    private TypedWriterInterface $writer;

    public function __construct(TypedWriterInterface $writer)
    {
        $this->writer = $writer;
    }

    public function open(): void
    {
        $this->writer->open();

        $this->position = 0;
    }

    public function write(array $data): void
    {
        $this->writer->write($data);

        $this->position++;
        if (0 === ($this->position % self::FLUSH_EVERY)) {
            flush();
        }
    }

    public function close(): void
    {
        $this->writer->close();
    }

    public function getDefaultMimeType(): string
    {
        return $this->writer->getDefaultMimeType();
    }

    public function getFormat(): string
    {
        return $this->writer->getFormat();
    }
}

Replace Query::iterable with Query::toIterable

Feature Request

Query::iterable() is deprecated (doctrine/orm) in favor of Query::toIterable():

$this->iterator = $this->query->iterate();

The difference is that toIterable doesn't return an array, so:

$data = $this->getCurrentData($current[0]);

$current[0] won't be needed, just $current.

Also we're using IterableResult which is deprecated (and from doctrine/orm), I guess with \Iterator will be enough.

* @var IterableResult|null

Object of class DateTime could not be converted to string

Running this but of code I get an exception when Exporter finds a date in the array.

$source = new ArraySourceIterator($queryFilter->getArrayResult());
$writer = new CsvWriter("data.csv");
Handler::create($source, $writer)->export();

Catchable Fatal Error: Object of class DateTime could not be converted to string

$result = @fputcsv($this->file, $data, $this->delimiter, $this->enclosure);

And I have a question: how does the exporter handle entity relations?

Error when using custom query and fields with DoctrineORMQuerySourceIterator

We are extending Exporter features to make it work with our custom DTO object (not using an entity), and I met an error:

Notice: Undefined offset: 0 at .../vendor/sonata-project/exporter/src/Source/DoctrineORMQuerySourceIterator.php line 85

This is part of our admin class:

    public function getExportFields()
    {
        $datagrid = $this->getDatagrid();
        $columns = $datagrid->getColumns()->getElements();
        $fields = [];

        foreach ($columns as $column)
        {
            // Traduction du label => nom du champ
            $fields[$this->trans($column->getLabel())] = $column->getFieldName();
        }

        return $fields;
    }

    public function getDataSourceIterator()
    {
        return new DoctrineORMQuerySourceIterator($this->createQuery()->getQuery(), $this->getExportFields());
    }

As you can see it is pretty basic, just telling the Iterator to use the custom query of the class, and the list of fields from the datagrid.

This is a fix of the method.

    /**
     * {@inheritdoc}
     */
    public function current()
    {
        $current = $this->iterator->current();

        $data = [];

        foreach ($this->propertyPaths as $name => $propertyPath) {
            try {
                $data[$name] = $this->getValue($this->propertyAccessor->getValue(current($current), $propertyPath));
            } catch (UnexpectedTypeException $e) {
                //non existent object in path will be ignored
                $data[$name] = null;
            }
        }

        $this->query->getEntityManager()->getUnitOfWork()->detach(current($current));

        return $data;
    }

Where I replaced $current[0] with current($current) as sometimes the index changes from $current[0] to $current[1] etc.

Add support for DateInterval

Feature Request

When exporting DateInterval values in the DoctrineORMQuerySourceIterator class, no file can be downloaded.

Provide autowiring for Exporter class

Feature Request

Provide autowiring for sonata.exporter.exporter class

Cannot autowire argument $exporter of "AppBundle\Controller\LogController::exportAction()": it references class "Exporter\Exporter" but no such service exists. You should maybe alias this class to the existing "sonata.exporter.exporter" service.

I actually need to use this workaround inside Kernel.php

$aliases = ([
    \Exporter\Exporter::class => 'sonata.exporter.exporter',
]);

Encoding problems for CsvWriter

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/exporter'

name     : sonata-project/exporter
descrip. : Lightweight Exporter library
keywords : bundle, client, csv, data, export, symfony-bundle, xls
versions : * 2.7.0
latest   : 2.8.0
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://github.com/sonata-project/Exporter
source   : [git] https://mirrors.ekino.com/git/github.com/sonata-project/exporter.git 66a95588149bfe58bb6b854e0022dbfe45c8c025
dist     : [zip] https://mirrors.ekino.com/git/github.com/sonata-project/exporter/66a95588149bfe58bb6b854e0022dbfe45c8c025.zip 66a95588149bfe58bb6b854e0022dbfe45c8c025
path     : /var/www/html/skoda/laurin/vendor/sonata-project/exporter
names    : sonata-project/exporter

autoload
psr-4
Sonata\Exporter\ => src/
Sonata\Exporter\Bridge\Symfony\ => src/Bridge/Symfony/

requires
php ^7.3 || ^8.0

requires (dev)
doctrine/dbal ^2.5
doctrine/mongodb-odm ^2.0
doctrine/orm ^2.4.5
matthiasnoback/symfony-config-test ^4.2
matthiasnoback/symfony-dependency-injection-test ^4.0
propel/propel1 ^1.6
symfony/config ^4.4 || ^5.2
symfony/dependency-injection ^4.4 || ^5.2
symfony/http-foundation ^4.4 || ^5.2
symfony/http-kernel ^4.4 || ^5.2
symfony/phpunit-bridge ^5.2
symfony/property-access ^4.4 || ^5.2
symfony/routing ^4.4 || ^5.2

suggests
propel/propel1 To export propel collections
symfony/property-access To be able to export from database entities
symfony/routing To be able to export the routes of a Symfony app

conflicts
doctrine/mongodb-odm <2.0

Symfony packages

show

$ composer show --latest 'symfony/*'
N/A

PHP version

$ php -v

PHP 7.4.15 (cli) (built: Feb 18 2021 00:57:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
    with blackfire v1.61.0~linux-musl-x64-non_zts74, https://blackfire.io, by Blackfire

Subject

Handle the encoding problems for CsvWriter

Steps to reproduce

Export data that contains characters with accents like : "éàè etc..."

Make a distinction between writers and formatters

Feature Request

Right now the Writers are actually Formatters and Writers in one. It would be much nicer to have Formatters and Writers. For example:

Formatters

  • XmlFormatter
  • JsonFormatter
  • RSSFormatter

Writers

  • FileWriter
  • ResponseWriter
  • StreamedResponseWriter
  • FlysystemWriter

This way the exporter component can be used for more usecases

Provide autowiring for Exporter class

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'

sonata-project/exporter                  1.9.1  1.9.1  Lightweight Exporter library

PHP version

$ php -v

PHP 7.2.10 (cli) (built: Sep 15 2018 02:22:37) ( NTS )

Subject

Provide autowiring for sonata.exporter.exporter class.

Cannot autowire argument $exporter of "AppBundle\Controller\LogController::exportAction()": it references class "Exporter\Exporter" but no such service exists. You should maybe alias this class to the existing "sonata.exporter.exporter" service.

Actual workaround

To fix this I need actually to do this workaround

$aliases = ([
    \Exporter\Exporter::class => 'sonata.exporter.exporter',
]);

Prevent CSV and XLS injection in Writers

Feature Request

The export functionality of this bundle allows users to download data in a .csv or .xls file suitable for handling in spreadsheet applications like Microsoft Excel and OpenOffice Calc. The resulting spreadsheet's cells often contain input from untrusted sources such as survey responses, transaction details, and user-supplied content. This is inherently risky, because any cells starting with certain special characters will be interpreted by the spreadsheet software as formulas which can be used to execute payloads. These payloads can compromise a user's system by downloading and running malware as well as giving command line access to a compromised system.

If exported data cells were to contain payloads such as =cmd|' /C calc'!A0 in a CSV or XLS file generated by the this bundle, this payload becomes embedded within that file and will attempt to run upon being opened (mainly on Windows systems). The payload in this example will open the Windows calculator should a user open the file and accept two prompts (unfortunately many users would do this without questioning it).

See https://owasp.org/www-community/attacks/CSV_Injection for more.

Attempting to sanitize data for this specific purpose upon input would be cumbersome as it may come from various input sources. I suggest doing a simple regex filter within the Writer methods for both file formats. I currently have this implemented in another project that is using sonata-project/exporter:^1.11 by overriding the write(array $data) method in each Writer class - however in sonata-project/exporter:^2.0 these Writer classes are now marked as final - so I figure the best solution is to propose this as a security feature update to the Sonata Exporter bundle so we can all benefit from it.

Export with where clause

Hello,

I want to export an entity with a where clause in the SQL. I have this :

    $sqlQuery = $em->getRepository('AppBundle:Member')
                ->createQueryBuilder('m')
                ->where('m.association = :id')
               ->setParameter('id', $id)
                ->getQuery()
                ->getSQL(); 

But I have this error :

SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

If I remove the where clause, everything work fine.

What is the correct way for doing that ?

Thanks

Introducing PortPHP: Possible future cooperation

Hey everyone!

Sonata is pretty new to me and I can say I like what I see so far. During browsing the repositories I find this little library. It looks good...but there might be better options.

PortPHP is (going to be) a replacement for ddeboer/data-import. It does exactly the same as this library, but probably is a bit more powerful.

Take a look at it, I hope you might be able to use some things from it.

XlsWriter exports HTML

Clearly this is intended behavior but it seems counterintuitive that XlsWriter should output an html table rather than using something like PHP_Excel to output an actual xls file.

New release

Is it possible to release a new version? Projects relying on PropelCollectionSourceIterator can not depend on a stable version of this library, which can be problematic.

Add service definitions and Bundle

A Bundle directory should be created under src, containing optional integration with Symfony. This does not make this library a bundle, it makes it contain a bundle. Everything symfony related should go in this directory.

Check list :

  • create an exporter class (deprecating the one in core bundle)
  • create service definitions for the writers
  • create a bundle to load and configure the service definitions
  • create a compiler pass to inject new writers in the exporter

XLS Export - lack of support on Numbers app on OSX due to incorrect file format

Feature Request

When I download a list in XLS format, the file uses formatting with and other HTML tags. When I try to open it with Numbers app on OSX (macOS), it gives me wrong content.
sonata xls Numbers
Ms Excel can handle the format with but it shouts about incorrect format anyway.

The request is to add a better support for XLS files. @VincentLanglet has helped me a lot on Slack and has suggested to use https://packagist.org/packages/box/spout package, which supports XLSX format. Files may have .xls extension and Numbers still can open the format created by box/spout. Ms Excel can do that on Windows and OSX as well.

The Writer file that I use is following (it may be replaced in the repository, just change getFormat() method).

<?php

namespace Sonata\Exporter\Writer;

use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Sonata\Exporter\Writer\TypedWriterInterface;

class XlsWriter implements TypedWriterInterface
{
    /**
     * @var string
     */
    protected $filename;

    /**
     * @var bool
     */
    protected $showHeaders;

    /**
     * @var int
     */
    protected $position;

    /**
     * @var \Box\Spout\Writer\XLSX\Writer
     */
    protected $writer;

    /**
     * @throws \RuntimeException
     */
    public function __construct(string $filename, bool $showHeaders = true)
    {
        $this->filename = $filename;
        $this->showHeaders = $showHeaders;
        $this->position = 0;

        if (is_file($filename)) {
            throw new \RuntimeException(sprintf('The file %s already exist', $filename));
        }
    }

    /**
     * {@inheritdoc}
     */
    final public function getDefaultMimeType(): string
    {
        return 'application/vnd.ms-excel';
    }

    /**
     * {@inheritdoc}
     */
    final public function getFormat(): string
    {
        return 'xls-real';
    }

    /**
     * {@inheritdoc}
     */
    public function open()
    {
        $this->writer = WriterEntityFactory::createXLSXWriter();
        $this->writer->openToFile($this->filename);
    }

    /**
     * {@inheritdoc}
     */
    public function close()
    {
        $this->writer->close();
    }

    /**
     * {@inheritdoc}
     */
    public function write(array $data)
    {
        $this->init($data);

        $row = WriterEntityFactory::createRowFromArray(array_values($data));
        $this->writer->addRow($row);

        ++$this->position;
    }

    protected function init(array $data): void
    {
        if ($this->position > 0) {
            return;
        }

        if ($this->showHeaders) {
            $row = WriterEntityFactory::createRowFromArray(array_keys($data));
            $this->writer->addRow($row);
            ++$this->position;
        }
    }
}

Error when exporting MongoDb data with DoctrineODMQuerySourceIterator

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'  
sonata-project/admin-bundle                  3.88.0 3.89.1 The missing Symfony Admin Generator
sonata-project/block-bundle                  4.5.0  4.5.0  Symfony SonataBlockBundle
sonata-project/cache                         2.0.1  2.1.1  Cache library
sonata-project/doctrine-extensions           1.11.0 1.11.0 Doctrine2 behavioral extensions
sonata-project/doctrine-mongodb-admin-bundle 3.7.0  3.7.0  Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
sonata-project/doctrine-orm-admin-bundle     3.29.0 3.29.0 Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                      2.5.1  2.5.1  Lightweight Exporter library
sonata-project/form-extensions               1.9.0  1.9.0  Symfony form extensions
sonata-project/twig-extensions               1.5.1  1.5.1  Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
symfony/asset                      v4.4.8  v5.2.3  Symfony Asset Component
symfony/browser-kit                v4.4.8  v5.2.3  Symfony BrowserKit Component
symfony/cache                      v4.4.8  v5.2.3  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.0.1  v2.2.0  Generic abstractions related to caching
symfony/config                     v4.4.17 v5.2.3  Symfony Config Component
symfony/console                    v4.4.8  v5.2.3  Symfony Console Component
symfony/css-selector               v4.4.8  v5.2.3  Symfony CssSelector Component
symfony/debug                      v4.4.8  v4.4.19 Symfony Debug Component
symfony/debug-bundle               v4.4.8  v5.2.3  Symfony DebugBundle
symfony/debug-pack                 v1.0.8  v1.0.9  A debug pack for Symfony projects
symfony/dependency-injection       v4.4.17 v5.2.3  Symfony DependencyInjection Component
symfony/deprecation-contracts      v2.2.0  v2.2.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v4.4.8  v5.2.3  Symfony Doctrine Bridge
symfony/dom-crawler                v4.4.8  v5.2.3  Symfony DomCrawler Component
symfony/dotenv                     v4.4.8  v5.2.3  Registers environment variables from a .env file
symfony/error-handler              v4.4.8  v5.2.3  Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.8  v5.2.3  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.7  v2.2.0  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.8  v5.2.3  Symfony ExpressionLanguage Component
symfony/filesystem                 v4.4.17 v5.2.3  Symfony Filesystem Component
symfony/finder                     v4.4.8  v5.2.3  Symfony Finder Component
symfony/flex                       v1.9.5  v1.12.2 Composer plugin for Symfony
symfony/form                       v4.4.19 v5.2.3  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           v4.4.8  v5.2.3  Symfony FrameworkBundle
symfony/http-client                v4.4.8  v5.2.3  Symfony HttpClient component
symfony/http-client-contracts      v2.0.1  v2.3.1  Generic abstractions related to HTTP clients
symfony/http-foundation            v4.4.8  v5.2.3  Symfony HttpFoundation Component
symfony/http-kernel                v4.4.13 v5.2.3  Symfony HttpKernel Component
symfony/inflector                  v4.4.8  v5.2.3  Symfony Inflector Component
symfony/intl                       v4.4.8  v5.2.3  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/lock                       v4.4.8  v5.2.3  Symfony Lock Component
symfony/mailer                     v4.4.8  v5.2.3  Symfony Mailer Component
symfony/maker-bundle               v1.15.1 v1.29.1 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forge...
symfony/messenger                  v4.4.8  v5.2.3  Symfony Messenger Component
symfony/mime                       v4.4.13 v5.2.3  A library to manipulate MIME messages
symfony/monolog-bridge             v4.4.8  v5.2.3  Symfony Monolog Bridge
symfony/monolog-bundle             v3.5.0  v3.6.0  Symfony MonologBundle
symfony/options-resolver           v4.4.11 v5.2.3  Symfony OptionsResolver Component
symfony/orm-pack                   v1.0.8  v2.1.0  A pack for the Doctrine ORM
symfony/polyfill-ctype             v1.20.0 v1.22.1 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme     v1.15.0 v1.22.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.15.0 v1.22.1 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.15.0 v1.22.1 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.15.0 v1.22.1 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.15.0 v1.22.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.15.0 v1.22.1 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.15.0 v1.22.1 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.18.1 v1.22.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                    v4.4.8  v5.2.3  Symfony Process Component
symfony/profiler-pack              v1.0.4  v1.0.5  A pack for the Symfony web profiler
symfony/property-access            v4.4.8  v5.2.3  Symfony PropertyAccess Component
symfony/property-info              v4.4.11 v5.2.3  Symfony Property Info Component
symfony/psr-http-message-bridge    v1.3.0  v2.1.0  PSR HTTP message bridge
symfony/routing                    v4.4.8  v5.2.3  Symfony Routing Component
symfony/security-acl               v3.1.1  v3.1.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.8  v5.2.3  Symfony SecurityBundle
symfony/security-core              v4.4.8  v5.2.3  Symfony Security Component - Core Library
symfony/security-csrf              v4.4.8  v5.2.3  Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.8  v5.2.3  Symfony Security Component - Guard
symfony/security-http              v4.4.8  v5.2.3  Symfony Security Component - HTTP Integration
symfony/serializer                 v4.4.11 v5.2.3  Symfony Serializer Component
symfony/serializer-pack            v1.0.3  v1.0.4  A pack for the Symfony serializer
symfony/service-contracts          v2.2.0  v2.2.0  Generic abstractions related to writing services
symfony/stopwatch                  v4.4.8  v5.2.3  Symfony Stopwatch Component
symfony/string                     v5.2.3  v5.2.3  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters ...
symfony/templating                 v4.4.8  v5.2.3  Symfony Templating Component
symfony/translation                v4.4.8  v5.2.3  Symfony Translation Component
symfony/translation-contracts      v2.0.1  v2.3.0  Generic abstractions related to translation
symfony/twig-bridge                v4.4.8  v5.2.3  Symfony Twig Bridge
symfony/twig-bundle                v4.4.8  v5.2.3  Symfony TwigBundle
symfony/twig-pack                  v1.0.0  v1.0.1  A Twig pack for Symfony projects
symfony/validator                  v4.4.8  v5.2.3  Symfony Validator Component
symfony/var-dumper                 v4.4.8  v5.2.3  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v4.4.8  v5.2.3  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle        v4.4.8  v5.2.3  Symfony WebProfilerBundle
symfony/webpack-encore-bundle      v1.7.3  v1.11.1 Integration with your Symfony app & Webpack Encore!
symfony/workflow                   v4.4.8  v5.2.3  Symfony Workflow Component
symfony/yaml                       v4.4.8  v5.2.3  Symfony Yaml Component

PHP version

$ php -v
PHP 7.4.13 (cli) (built: Nov 30 2020 20:40:09) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

Subject

When exporting data from mongodb in Sonata Admin, the file got is filled by Symfony error. The DoctrineODMQuerySourceIterator got an object instead of an array.

Minimal repository with the bug

Steps to reproduce

In Sonata Admin, go to a list of mongodb records. Export the list (whatever the format).

Expected results

Data are exported in desired format.

Actual results

The file is available, but with a Symfony error in it.

Error:
Cannot use object of type App\Document\MyObject as array

  at /vendor/sonata-project/exporter/src/Source/DoctrineODMQuerySourceIterator.php:39
  at Sonata\Exporter\Source\DoctrineODMQuerySourceIterator->current()
     (//vendor/sonata-project/exporter/src/Handler.php:41)
  at Sonata\Exporter\Handler->export()
     (/vendor/sonata-project/exporter/src/Exporter.php:58)
  at Sonata\Exporter\Exporter::Sonata\Exporter\{closure}()
     (/vendor/symfony/http-foundation/StreamedResponse.php:112)
  at Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
     (/vendor/symfony/http-foundation/Response.php:381)
  at Symfony\Component\HttpFoundation\Response->send()
     (/vendor/symfony/http-kernel/EventListener/StreamedResponseListener.php:41)
  at Symfony\Component\HttpKernel\EventListener\StreamedResponseListener->onKernelResponse()
     (/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:126)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (/vendor/symfony/event-dispatcher/EventDispatcher.php:264)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch()
     (/vendor/symfony/event-dispatcher/EventDispatcher.php:239)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (/vendor/symfony/event-dispatcher/EventDispatcher.php:73)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:168)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (/vendor/symfony/http-kernel/HttpKernel.php:191)
  at Symfony\Component\HttpKernel\HttpKernel->filterResponse()
     (/vendor/symfony/http-kernel/HttpKernel.php:179)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (/vendor/symfony/http-kernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (/vendor/symfony/http-kernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (/public/index.php:25)        

Symfony 3.4 to flex upgrade issue :

In DefinitionErrorExceptionPass.php line 37:
Cannot autowire service "Abcd\ApplicationBundle\Exporter\Handler": argument "$source" of method "Exporter\Handler::__construct()" references interface "Exporter\Source\SourceIteratorInterface" but no such service exists. Did you create a class that implements this interface

Above issue not happened Symfony 3.4 . Once i upgraded Symfony flex that issue happen.Please Help me.

Environment : Local

Sonata packages

$ composer show --latest 'sonata-project/*'
# Put the result here.

Symfony packages

$ composer show --latest 'symfony/*'
# Put the result here.
sonata-project/admin-bundle              3.13.0 3.51.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.15.0 3.15.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/classification-bundle     3.6.1  3.8.1  Symfony SonataClassificationBundle
sonata-project/core-bundle               3.13.7 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.0  1.3.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.3  3.9.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1  2.0.1  Lightweight Exporter library
sonata-project/intl-bundle               2.6.0  2.6.0  Symfony SonataIntlBundle
sonata-project/media-bundle              3.20.1 3.20.1 Symfony SonataMediaBundle

#### PHP version

$ php -v

Put the result here.

PHP 7.3.4-1+ubuntu14.04.1
## Subject
I upgrade symfony 3.4 to flex, 

## Steps to reproduce

## Expected results

## Actual results

<!--
    If it's an error message or piece of code, use code block tags,
    and make sure you provide the whole stack trace(s),
    not just the first error message you can see.
    More details here: https://github.com/sonata-project/exporter/blob/2.x/CONTRIBUTING.md#issues
-->

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.