Skip to content

Commit

Permalink
Merge pull request #83 from koillection/develop
Browse files Browse the repository at this point in the history
Add images export
  • Loading branch information
benjaminjonard authored Aug 10, 2018
2 parents f0886d5 + efccf5f commit 946cc80
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 18 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"doctrine/orm": "^2.6",
"friendsofsymfony/jsrouting-bundle": "^2.2",
"guzzlehttp/psr7": "^1.4",
"maennchen/zipstream-php": "^0.5.2",
"php-http/curl-client": "^1.7",
"ramsey/uuid-doctrine": "^1.4",
"roave/security-advisories": "dev-master",
Expand Down
70 changes: 56 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions src/Controller/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use ZipStream\ZipStream;

/**
* Class ToolsController
Expand Down Expand Up @@ -49,9 +52,9 @@ public function exportPrintableList() : Response
* @Route("/tools/export/csv", name="app_tools_export_csv")
* @Method({"GET"})
*
* @return Response
* @return CsvResponse
*/
public function exportCsv() : Response
public function exportCsv() : CsvResponse
{
$collections = $this->getDoctrine()->getRepository(Collection::class)->findAllWithItems();

Expand All @@ -69,10 +72,40 @@ public function exportCsv() : Response
* @Route("/tools/export/sql", name="app_tools_export_sql")
* @Method({"GET"})
*
* @return Response
* @param DatabaseDumper $databaseDumper
* @return FileResponse
* @throws \Doctrine\DBAL\DBALException
*/
public function exportSql(DatabaseDumper $databaseDumper) : Response
public function exportSql(DatabaseDumper $databaseDumper) : FileResponse
{
return new FileResponse($databaseDumper->dump(), (new \DateTime())->format('Ymd') . '-koillection-export.sql');
}

/**
* @Route("/tools/export/images", name="app_tools_export_images")
* @Method({"GET"})
*
* @return StreamedResponse
*/
public function exportImages() : StreamedResponse
{
$response = new StreamedResponse(function() {
$zipFilename = (new \DateTime())->format('Ymd') . '-koillection-export.zip';
$path = $this->getParameter('kernel.project_dir').'/public/uploads/'. $this->getUser()->getId();

$zip = new ZipStream($zipFilename);

$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$zip->addFileFromStream($file->getFilename(), fopen($file->getRealPath(), 'r'));
}
}

$zip->finish();
}) ;

return $response;
}

}
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
"ref": "c81bdcf4a9d4e7b1959071457f9608631865d381"
}
},
"maennchen/zipstream-php": {
"version": "v0.5.2"
},
"mailgun/mailgun-php": {
"version": "2.3",
"recipe": {
Expand Down
3 changes: 3 additions & 0 deletions templates/App/Tools/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<a href="{{ path('app_tools_export_sql') }}" class="btn waves-effect waves-light">
<i class="fa fa-database fa-fw"></i>{{ 'btn.export_sql'|trans }}
</a>
<a href="{{ path('app_tools_export_images') }}" class="btn waves-effect waves-light">
<i class="fa fa-archive fa-fw"></i>{{ 'btn.export_images'|trans }}
</a>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3886,5 +3886,11 @@
<target>SQL</target>
</segment>
</unit>
<unit id="Jd.jsk." name="btn.export_images">
<segment>
<source>btn.export_images</source>
<target>Images</target>
</segment>
</unit>
</file>
</xliff>
6 changes: 6 additions & 0 deletions translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3886,5 +3886,11 @@
<target>SQL</target>
</segment>
</unit>
<unit id="Jd.jsk." name="btn.export_images">
<segment>
<source>btn.export_images</source>
<target>Images</target>
</segment>
</unit>
</file>
</xliff>

0 comments on commit 946cc80

Please sign in to comment.