I have backend on SonataAdminBundle 2.4.*@dev version.
Before update version and symfony core from 2.7 to 2.8 my code worked.
Explain: I have an list of subscribers that have a flag isNew for separate export of new or old users. By default is 1, on export need to change it to 0 if in list exist new users.
But now it doesn't work. Because if filter of grid is set by this field isNew and export, in DB field is changed before, and later
return $this->get('sonata.admin.exporter')->getResponse(
$format,
$filename,
$this->admin->getDataSourceIterator()
);
getDataSourceIterator take data from DB not from result. So there is no more new users and file is empty.
How to update data after export, have any idea?
UPDATE:
Export function:
/**
* Export data to specified format.
*
* @param Request $request
*
* @return Response
*
* @throws AccessDeniedException If access is not granted
* @throws \RuntimeException If the export format is invalid
*/
public function exportAction(Request $request = null)
{
$request = $this->resolveRequest($request);
$this->admin->checkAccess('export');
$format = $request->get('format');
$allowedExportFormats = (array) $this->admin->getExportFormats();
if (!in_array($format, $allowedExportFormats)) {
throw new \RuntimeException(
sprintf(
'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
$format,
$this->admin->getClass(),
implode(', ', $allowedExportFormats)
)
);
}
$filename = sprintf(
'export_%s_%s.%s',
strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
//my code to update field isNew of subscribers
$this->get('cfw.subscription')->processExportEmails($controller->admin->getFilterParameters());
return $this->get('sonata.admin.exporter')->getResponse(
$format,
$filename,
$this->admin->getDataSourceIterator()
);
}