@@ -24,7 +24,10 @@ public function configs(){
2424 $ product = Product::find (App::getFromRequest ('id ' ));
2525 if (App::getFromRequest ('action ' ) == 'save ' ) {
2626 $ this ->ensureCustomFields ($ product );
27- $ this ->createGlobalConfigurableOptions ($ product );
27+ $ this ->createLinuxCloudInitConfigurableOptions ($ product );
28+ $ this ->createLinuxNativeConfigurableOptions ($ product );
29+ $ this ->createWindowsNativeConfigurableOptions ($ product );
30+ $ this ->createBackupLocationConfigurableOptions ($ product );
2831 $ this ->createCustomConfigurableOptions ($ product );
2932 } // Save End
3033
@@ -39,10 +42,10 @@ private function createCustomConfigurableOptions($product)
3942 {
4043 $ currencyId = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->id ;
4144 $ currencyCode = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->code ;
42- $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - Custom Plans ' )->first ()->id ;
45+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - custom plans ' )->first ()->id ;
4346
4447 if (!$ groupId ){
45- $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - Custom Plans ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
48+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - custom plans ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
4649 $ groupIdLinks = Capsule::table ('tblproductconfiglinks ' )->where ('gid ' , $ groupId )->where ('pid ' , $ product ->id )->first ()->gid ;
4750 if (!$ groupIdLinks ){
4851 Capsule::table ('tblproductconfiglinks ' )->insert (['gid ' => $ groupId , 'pid ' => $ product ->id ]);
@@ -53,22 +56,67 @@ private function createCustomConfigurableOptions($product)
5356 }
5457 }
5558
56- private function createGlobalConfigurableOptions ($ product )
59+ private function createLinuxCloudInitConfigurableOptions ($ product )
5760 {
58- $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud Global ' )->first ()->id ;
61+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - Linux (cloud-init template) ' )->first ()->id ;
5962 $ currencyId = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->id ;
6063 $ currencyCode = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->code ;
61- if (!$ groupId ){
62- $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud Global ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
64+ if (!$ groupId ) {
65+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - Linux (cloud-init template) ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
6366 $ groupIdLinks = Capsule::table ('tblproductconfiglinks ' )->where ('gid ' , $ groupId )->where ('pid ' , $ product ->id )->first ()->gid ;
64- if (!$ groupIdLinks ){
67+ if (!$ groupIdLinks ) {
6568 Capsule::table ('tblproductconfiglinks ' )->insert (['gid ' => $ groupId , 'pid ' => $ product ->id ]);
6669 }
67- $ pomTemplates = $ this ->getTemplateIds ();
68- $ zones = $ this ->getZoneLocation ();
69- $ this ->createLocationFields ($ groupId , $ zones , $ currencyId );
70- $ this ->createTemplateFields ($ groupId , $ pomTemplates , $ currencyId , $ currencyCode );
71- $ this ->createBackupFields ($ groupId , $ this ->getBackups ());
70+ $ pomTemplates = $ this ->getTemplateIds ("cloudinit " );
71+ $ this ->createTemplateFields ($ groupId , $ pomTemplates , $ currencyId , $ currencyCode );
72+ }
73+ }
74+
75+ private function createLinuxNativeConfigurableOptions ($ product )
76+ {
77+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - Linux (native template) ' )->first ()->id ;
78+ $ currencyId = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->id ;
79+ $ currencyCode = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->code ;
80+ if (!$ groupId ) {
81+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - Linux (native template) ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
82+ $ groupIdLinks = Capsule::table ('tblproductconfiglinks ' )->where ('gid ' , $ groupId )->where ('pid ' , $ product ->id )->first ()->gid ;
83+ if (!$ groupIdLinks ) {
84+ Capsule::table ('tblproductconfiglinks ' )->insert (['gid ' => $ groupId , 'pid ' => $ product ->id ]);
85+ }
86+ $ pomTemplates = $ this ->getTemplateIds ("nativelinux " );
87+ $ this ->createTemplateFields ($ groupId , $ pomTemplates , $ currencyId , $ currencyCode );
88+ }
89+ }
90+
91+ private function createWindowsNativeConfigurableOptions ($ product )
92+ {
93+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - Windows (native template) ' )->first ()->id ;
94+ $ currencyId = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->id ;
95+ $ currencyCode = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->code ;
96+ if (!$ groupId ) {
97+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - Windows (native template) ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
98+ $ groupIdLinks = Capsule::table ('tblproductconfiglinks ' )->where ('gid ' , $ groupId )->where ('pid ' , $ product ->id )->first ()->gid ;
99+ if (!$ groupIdLinks ) {
100+ Capsule::table ('tblproductconfiglinks ' )->insert (['gid ' => $ groupId , 'pid ' => $ product ->id ]);
101+ }
102+ $ pomTemplates = $ this ->getTemplateIds ("nativewindows " );
103+ $ this ->createTemplateFields ($ groupId , $ pomTemplates , $ currencyId , $ currencyCode );
104+ }
105+ }
106+
107+ private function createBackupLocationConfigurableOptions ($ product )
108+ {
109+ $ currencyId = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->id ;
110+ $ currencyCode = Capsule::table ('tblcurrencies ' )->where ('default ' , '1 ' )->first ()->code ;
111+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->where ('name ' , 'Configurable options for UpCloud - backup and location ' )->first ()->id ;
112+ if (!$ groupId ) {
113+ $ groupId = Capsule::table ('tblproductconfiggroups ' )->insertGetId (['name ' => 'Configurable options for UpCloud - backup and location ' , 'description ' => 'Auto generated by upCloudVps module ' ]);
114+ $ groupIdLinks = Capsule::table ('tblproductconfiglinks ' )->where ('gid ' , $ groupId )->where ('pid ' , $ product ->id )->first ()->gid ;
115+ if (!$ groupIdLinks ) {
116+ Capsule::table ('tblproductconfiglinks ' )->insert (['gid ' => $ groupId , 'pid ' => $ product ->id ]);
117+ }
118+ $ this ->createBackupFields ($ groupId , $ this ->getBackups ());
119+ $ this ->createLocationFields ($ groupId , $ this ->getZoneLocation (), $ currencyId );
72120 }
73121 }
74122
@@ -213,16 +261,28 @@ private function getZoneLocation()
213261 return $ zoneLocation ;
214262 }
215263
216- private function getTemplateIds ()
264+ private function getTemplateIds ($ vmtype = null )
217265 {
218- $ templates = $ this ->manager ->GetTemplate ()['response ' ]['storages ' ]['storage ' ];
219- $ templateIds = [];
266+ $ templates = $ this ->manager ->GetTemplate ()['response ' ]['storages ' ]['storage ' ];
267+ $ templateIds = [];
220268
269+ if (!$ vmtype ) {
270+ foreach ($ templates as $ template ) {
271+ $ templateIds [$ template ['uuid ' ]] = $ template ['title ' ];
272+ }
273+ } else {
221274 foreach ($ templates as $ template ) {
275+ if (
276+ ($ template ['template_type ' ] == "native " &&
277+ (($ vmtype == 'nativewindows ' && preg_match ('/Windows/ ' , $ template ['title ' ])) ||
278+ ($ vmtype == 'nativelinux ' && !preg_match ('/Windows/ ' , $ template ['title ' ])))) ||
279+ $ template ['template_type ' ] == "cloud-init " && $ vmtype == 'cloudinit '
280+ ) {
222281 $ templateIds [$ template ['uuid ' ]] = $ template ['title ' ];
282+ }
223283 }
224-
225- return $ templateIds ;
284+ }
285+ return $ templateIds ;
226286 }
227287
228288 private function getVmplans ()
0 commit comments