22
33namespace Sugarcrm \REST \Endpoint ;
44
5- class ModuleLoader extends SugarBean
6- {
7- public const ACTION_INSTALL = 'install ' ;
8-
9- public const ACTION_UNINSTALL = 'uninstall ' ;
5+ use MRussell \REST \Endpoint \CollectionEndpoint ;
106
11- public const ACTION_ENABLE = 'enable ' ;
7+ class ModuleLoader extends CollectionEndpoint
8+ {
9+ public const URL_ARG_FILTER = 'filter ' ;
1210
13- public const ACTION_DISABLE = 'disable ' ;
11+ public const FILTER_STAGED = 'staged ' ;
1412
15- public const ACTION_INSTALL_STATUS = 'installation-status ' ;
13+ public const FILTER_INSTALLED = 'installed ' ;
1614
1715 protected static array $ _DEFAULT_PROPERTIES = [
18- self ::PROPERTY_URL => 'Administration/packages/$id/$:action ' ,
19- self ::PROPERTY_AUTH => true ,
16+ self ::PROPERTY_URL => 'Administration/packages/$:filter ' ,
17+ self ::PROPERTY_RESPONSE_PROP => 'packages ' ,
18+ self ::PROPERTY_HTTP_METHOD => 'GET ' ,
19+ self ::PROPERTY_AUTH => true
2020 ];
2121
22- protected static array $ _DEFAULT_SUGAR_BEAN_ACTIONS = [
23- self ::ACTION_INSTALL => 'GET ' ,
24- self ::ACTION_UNINSTALL => 'GET ' ,
25- self ::ACTION_ENABLE => 'GET ' ,
26- self ::ACTION_DISABLE => 'GET ' ,
27- self ::ACTION_INSTALL_STATUS => 'GET ' ,
28- ];
22+ protected string $ _modelInterface = MLPackage::class;
23+
24+ protected string $ _filter = '' ;
25+
26+ public function setUrlArgs (array $ args ): static
27+ {
28+ if (!empty ($ args [0 ])) {
29+ $ this ->_filter = $ args [0 ];
30+ unset($ args [0 ]);
31+ }
32+ if (!empty ($ args [self ::URL_ARG_FILTER ])) {
33+ $ this ->_filter = $ args [self ::URL_ARG_FILTER ];
34+ unset($ args [self ::URL_ARG_FILTER ]);
35+ }
36+ return parent ::setUrlArgs ($ args );
37+ }
38+
39+ protected function configureURL (array $ urlArgs ): string
40+ {
41+ if (!empty ($ this ->_filter )) {
42+ $ urlArgs [self ::URL_ARG_FILTER ] = $ this ->_filter ;
43+ }
44+ return parent ::configureURL ($ urlArgs );
45+ }
46+
47+ public function execute (array $ options = []): static
48+ {
49+ parent ::execute ($ options );
50+ $ this ->_filter = '' ;
51+ return $ this ;
52+ }
53+
54+ public function staged (): static
55+ {
56+ $ this ->_filter = self ::FILTER_STAGED ;
57+ return $ this ->execute ();
58+ }
59+
60+ public function installed (): static
61+ {
62+ $ this ->_filter = self ::FILTER_INSTALLED ;
63+ return $ this ->execute ();
64+ }
2965
30- /**
31- * Setup the query params passed during File Uploads
32- */
33- protected function configureFileUploadQueryParams (): array
66+ public function newPackage (): MLPackage
3467 {
35- return [] ;
68+ return $ this -> generateEndpoint (MLPackage::class) ;
3669 }
3770}
0 commit comments