1616use Exception ;
1717use Pimcore \Bundle \StaticResolverBundle \Models \User \UserResolverInterface ;
1818use Pimcore \Bundle \StudioBackendBundle \Asset \ExecutionEngine \AutomationAction \Messenger \Messages \ExportDataCollectionMessage ;
19- use Pimcore \Bundle \StudioBackendBundle \Asset \Service \AssetServiceInterface ;
2019use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \AutomationAction \AbstractHandler ;
2120use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \Config ;
2221use Pimcore \Bundle \StudioBackendBundle \ExecutionEngine \Util \StepConfig ;
2827use Pimcore \Bundle \StudioBackendBundle \Mercure \Service \UserTopicServiceInterface ;
2928use Pimcore \Bundle \StudioBackendBundle \Util \Constant \ElementTypes ;
3029use Symfony \Component \Messenger \Attribute \AsMessageHandler ;
30+ use function count ;
3131
3232/**
3333 * @internal
@@ -44,7 +44,6 @@ public function __construct(
4444 private readonly UserResolverInterface $ userResolver ,
4545 private readonly UserTopicServiceInterface $ userTopicService ,
4646 private readonly GridServiceInterface $ gridService ,
47- private readonly AssetServiceInterface $ assetService
4847 ) {
4948 parent ::__construct ();
5049 }
@@ -70,70 +69,62 @@ public function __invoke(ExportDataCollectionMessage $message): void
7069 ));
7170 }
7271
73- $ jobAsset = $ this ->extractConfigFieldFromJobStepConfig ($ message , StepConfig::ELEMENT_TO_EXPORT ->value );
74-
75- $ asset = $ this ->assetService ->getAssetForUser ($ jobAsset ['id ' ], $ user );
76-
77- if ($ asset ->getType () === ElementTypes::TYPE_FOLDER ) {
78- $ this ->abort ($ this ->getAbortData (
79- Config::ELEMENT_FOLDER_COLLECTION_NOT_SUPPORTED ->value ,
80- [
81- 'folderId ' => $ asset ->getId (),
82- ]
83- ));
84-
85- return ;
86- }
87-
72+ $ assets = $ this ->extractConfigFieldFromJobStepConfig ($ message , StepConfig::ELEMENTS_TO_EXPORT ->value );
73+ $ totalAssets = count ($ assets );
8874 $ columns = $ this ->extractConfigFieldFromJobStepConfig ($ message , StepConfig::CONFIG_COLUMNS ->value );
8975
9076 $ columnsDefinitions = $ this ->columnConfigurationService ->getAvailableAssetColumnConfiguration ();
9177
92- $ columnCollection = $ this ->gridService ->getConfigurationForExport (
93- $ columns ,
94- $ columnsDefinitions
95- );
78+ $ columnCollection = $ this ->gridService ->getConfigurationForExport ($ columns , $ columnsDefinitions );
9679
97- try {
98- $ assetData = [
99- $ asset ->getId () => $ this ->gridService ->getGridValuesForElement (
80+ $ assetsData = [];
81+ foreach ($ assets as $ asset ) {
82+ try {
83+ $ assetsData [$ asset ['id ' ]] = $ this ->gridService ->getGridValuesForElement (
10084 $ columnCollection ,
10185 ElementTypes::TYPE_ASSET ,
102- $ asset ->getId (),
103- true ,
86+ $ asset ['id ' ],
10487 $ user
105- ),
106- ];
107-
108- $ this ->updateContextArrayValues ($ jobRun , StepConfig::GRID_EXPORT_DATA ->value , $ assetData );
109-
110- $ csvExportDataInfo = $ jobRun ->getContext ()[StepConfig::GRID_EXPORT_DATA_INFO ->value ] ?? null ;
88+ );
11189
112- if ($ csvExportDataInfo === null ) {
113- $ this ->updateContextArrayValues (
114- $ jobRun ,
115- StepConfig::GRID_EXPORT_DATA_INFO ->value ,
90+ } catch (Exception $ e ) {
91+ $ this ->abort ($ this ->getAbortData (
92+ Config::CSV_DATA_COLLECTION_FAILED_MESSAGE ->value ,
11693 [
117- 'type ' => ElementTypes::TYPE_ASSET ,
94+ 'id ' => $ asset ['id ' ],
95+ 'message ' => $ e ->getMessage (),
11896 ]
119- );
97+ )) ;
12098 }
12199
100+ $ this ->updateProgress (
101+ $ this ->publishService ,
102+ $ this ->userTopicService ,
103+ $ jobRun ,
104+ $ this ->getJobStep ($ message )->getName (),
105+ $ totalAssets ,
106+ $ totalAssets
107+ );
108+ }
109+
110+ try {
111+ if (!empty ($ assetsData )) {
112+ $ context = $ jobRun ->getContext ();
113+ if (isset ($ context [StepConfig::GRID_EXPORT_DATA ->value ])) {
114+ $ assetsData = array_merge (
115+ $ context [StepConfig::GRID_EXPORT_DATA ->value ],
116+ $ assetsData
117+ );
118+ }
119+ $ this ->updateJobRunContext ($ jobRun , StepConfig::GRID_EXPORT_DATA ->value , $ assetsData );
120+ }
122121 } catch (Exception $ e ) {
123122 $ this ->abort ($ this ->getAbortData (
124123 Config::CSV_DATA_COLLECTION_FAILED_MESSAGE ->value ,
125124 [
126- 'id ' => $ asset ->getId (),
127125 'message ' => $ e ->getMessage (),
128126 ]
129127 ));
130128 }
131-
132- $ this ->updateProgress (
133- $ this ->publishService ,
134- $ this ->userTopicService ,
135- $ jobRun ,
136- $ this ->getJobStep ($ message )->getName ()
137- );
138129 }
139130}
0 commit comments