66use Illuminate \Database \Eloquent \Model ;
77use Illuminate \Http \JsonResponse ;
88use Illuminate \Http \Request ;
9+ use ProcessMaker \Enums \ExporterMap ;
910use ProcessMaker \Exception \ExportModelNotFoundException ;
1011use ProcessMaker \Http \Controllers \Controller ;
1112use ProcessMaker \ImportExport \Exporter ;
12- use ProcessMaker \ImportExport \Exporters \ProcessExporter ;
13- use ProcessMaker \ImportExport \Exporters \ScreenExporter ;
14- use ProcessMaker \ImportExport \Exporters \ScriptExporter ;
15- use ProcessMaker \ImportExport \Exporters \TemplateExporter ;
1613use ProcessMaker \ImportExport \Options ;
17- use ProcessMaker \Models \Process ;
18- use ProcessMaker \Models \ProcessTemplates ;
19- use ProcessMaker \Models \Screen ;
20- use ProcessMaker \Models \Script ;
21- use ProcessMaker \PackageHelper ;
2214
2315class ExportController extends Controller
2416{
25- const DATA_SOURCE_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\Models\DataSource ' ;
26-
27- const DATA_SOURCE_EXPORTER_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\ImportExport\DataSourceExporter ' ;
28-
29- const DECISION_TABLE_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\Models\DecisionTable ' ;
30-
31- const DECISION_TABLE_EXPORTER_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\ImportExport\DecisionTableExporter ' ;
32-
33- protected array $ types = [
34- 'screen ' => [Screen::class, ScreenExporter::class],
35- 'process ' => [Process::class, ProcessExporter::class],
36- 'script ' => [Script::class, ScriptExporter::class],
37- 'process_templates ' => [ProcessTemplates::class, TemplateExporter::class],
38- ];
39-
40- public function __construct ()
41- {
42- if (PackageHelper::isPackageInstalled (self ::DATA_SOURCE_CLASS )) {
43- $ this ->types ['data_source ' ] = [self ::DATA_SOURCE_CLASS , self ::DATA_SOURCE_EXPORTER_CLASS ];
44- }
45- if (PackageHelper::isPackageInstalled (self ::DECISION_TABLE_CLASS )) {
46- $ this ->types ['decision_table ' ] = [self ::DECISION_TABLE_CLASS , self ::DECISION_TABLE_EXPORTER_CLASS ];
47- }
48- }
49-
5017 /**
5118 * Return only the manifest
5219 */
@@ -55,7 +22,7 @@ public function manifest(string $type, int $id): JsonResponse
5522 $ model = $ this ->getModel ($ type )->findOrFail ($ id );
5623 try {
5724 $ exporter = new Exporter (true );
58- $ exporter ->export ($ model , $ this -> types [ $ type][ 1 ] );
25+ $ exporter ->export ($ model , ExporterMap:: getExporterClass ( $ type) );
5926
6027 return response ()->json ($ exporter ->payload (true ), 200 );
6128 } catch (ExportModelNotFoundException $ error ) {
@@ -74,7 +41,7 @@ public function download(Request $request, string $type, int $id)
7441 $ password = (isset ($ post ['password ' ]) ? $ post ['password ' ] : null );
7542
7643 $ exporter = new Exporter ();
77- $ exporter ->export ($ model , $ this -> types [ $ type][ 1 ] , $ options );
44+ $ exporter ->export ($ model , ExporterMap:: getExporterClass ( $ type) , $ options );
7845
7946 $ payload = $ exporter ->payload ();
8047
@@ -111,9 +78,8 @@ function () use ($payload) {
11178
11279 public function getModel (string $ type ): Model
11380 {
114- if (isset ($ this ->types [$ type ])) {
115- $ modelClass = current ($ this ->types [$ type ]);
116-
81+ $ modelClass = ExporterMap::getModelClass ($ type );
82+ if ($ modelClass ) {
11783 return new $ modelClass ;
11884 }
11985 throw new Exception ("Type {$ type } not found " , 404 );
0 commit comments