77use Exception ;
88use OpenApi \Attributes as OA ;
99use PhpList \Core \Domain \Subscription \Model \Dto \SubscriberImportOptions ;
10- use PhpList \Core \Domain \Subscription \Service \SubscriberCsvImportManager ;
10+ use PhpList \Core \Domain \Subscription \Service \SubscriberCsvImporter ;
1111use PhpList \Core \Security \Authentication ;
1212use PhpList \RestBundle \Common \Controller \BaseController ;
1313use PhpList \RestBundle \Common \Validator \RequestValidator ;
2020#[Route('/subscribers ' , name: 'subscriber_import_ ' )]
2121class SubscriberImportController extends BaseController
2222{
23- private SubscriberCsvImportManager $ importManager ;
23+ private SubscriberCsvImporter $ importManager ;
2424
2525 public function __construct (
2626 Authentication $ authentication ,
2727 RequestValidator $ validator ,
28- SubscriberCsvImportManager $ importManager
28+ SubscriberCsvImporter $ importManager
2929 ) {
3030 parent ::__construct ($ authentication , $ validator );
3131 $ this ->importManager = $ importManager ;
@@ -49,16 +49,16 @@ public function __construct(
4949 format: 'binary '
5050 ),
5151 new OA \Property (
52- property: 'request_confirmation ' ,
53- description: 'Whether to request confirmation from imported subscribers ' ,
54- type: 'boolean ' ,
55- default: false
52+ property: 'list_id ' ,
53+ description: 'List id to add imported subscribers to ' ,
54+ type: 'integer ' ,
55+ default: null
5656 ),
5757 new OA \Property (
58- property: 'html_email ' ,
59- description: 'Whether imported subscribers prefer HTML emails ' ,
58+ property: 'update_existing ' ,
59+ description: 'Weather to update existing subscribers or not ' ,
6060 type: 'boolean ' ,
61- default: true
61+ default: false
6262 )
6363 ],
6464 type: 'object '
@@ -111,17 +111,18 @@ public function importSubscribers(Request $request): JsonResponse
111111 $ file = $ request ->files ->get ('file ' );
112112
113113 if (!$ file ) {
114- return $ this ->json (['success ' => false , ' message ' => 'No file uploaded ' ], Response::HTTP_BAD_REQUEST );
114+ return $ this ->json (['message ' => 'No file uploaded ' ], Response::HTTP_BAD_REQUEST );
115115 }
116116
117117 if ($ file ->getClientMimeType () !== 'text/csv ' && $ file ->getClientOriginalExtension () !== 'csv ' ) {
118- return $ this ->json (['success ' => false , ' message ' => 'File must be a CSV ' ], Response::HTTP_BAD_REQUEST );
118+ return $ this ->json (['message ' => 'File must be a CSV ' ], Response::HTTP_BAD_REQUEST );
119119 }
120120
121121 try {
122- $ options = new SubscriberImportOptions ();
123-
124- $ stats = $ this ->importManager ->importFromCsv ($ file , $ options );
122+ $ stats = $ this ->importManager ->importFromCsv (
123+ $ file ,
124+ new SubscriberImportOptions ($ request ->getPayload ()->getBoolean ('update_existing ' ))
125+ );
125126
126127 return $ this ->json ([
127128 'imported ' => $ stats ['created ' ],
0 commit comments