2019-06-26 20:31:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\ApiBundle\Controller;
|
|
|
|
|
|
|
|
use JMS\Serializer\SerializationContext;
|
|
|
|
use JMS\Serializer\SerializerBuilder;
|
2022-11-06 12:00:41 +00:00
|
|
|
use Nelmio\ApiDocBundle\Annotation\Operation;
|
|
|
|
use Swagger\Annotations as SWG;
|
2019-06-26 20:31:47 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2022-11-23 11:44:55 +00:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2019-06-26 20:31:47 +00:00
|
|
|
|
|
|
|
class TaggingRuleRestController extends WallabagRestController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Export all tagging rules as a json file.
|
|
|
|
*
|
2022-11-06 12:00:41 +00:00
|
|
|
* @Operation(
|
|
|
|
* tags={"TaggingRule"},
|
|
|
|
* summary="Export all tagging rules as a json file.",
|
|
|
|
* @SWG\Response(
|
|
|
|
* response="200",
|
|
|
|
* description="Returned when successful"
|
|
|
|
* )
|
|
|
|
* )
|
2019-06-26 20:31:47 +00:00
|
|
|
*
|
2022-11-23 11:44:55 +00:00
|
|
|
* @Route("/api/taggingrule/export.{_format}", methods={"GET"}, name="api_get_taggingrule_export", defaults={"_format": "json"})
|
|
|
|
*
|
2019-06-26 20:31:47 +00:00
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function getTaggingruleExportAction()
|
|
|
|
{
|
|
|
|
$this->validateAuthentication();
|
|
|
|
|
|
|
|
$data = SerializerBuilder::create()->build()->serialize(
|
|
|
|
$this->getUser()->getConfig()->getTaggingRules(),
|
|
|
|
'json',
|
|
|
|
SerializationContext::create()->setGroups(['export_tagging_rule'])
|
|
|
|
);
|
|
|
|
|
|
|
|
return Response::create(
|
|
|
|
$data,
|
|
|
|
200,
|
|
|
|
[
|
|
|
|
'Content-type' => 'application/json',
|
|
|
|
'Content-Disposition' => 'attachment; filename="tagging_rules_' . $this->getUser()->getUsername() . '.json"',
|
|
|
|
'Content-Transfer-Encoding' => 'UTF-8',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|