-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed Issue #44 #65
base: main
Are you sure you want to change the base?
Fixed Issue #44 #65
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,12 @@ public function configs(){ | |
$product = Product::find(App::getFromRequest('id')); | ||
if (App::getFromRequest('action') == 'save') { | ||
$this->ensureCustomFields($product); | ||
$this->createGlobalConfigurableOptions($product); | ||
$this->createWindowsConfigurableOptions($product); | ||
$this->createLinuxConfigurableOptions($product); | ||
$this->createCloudConfigurableOptions($product); | ||
$this->createCustomConfigurableOptions($product); | ||
} // Save End | ||
$this->createBackupLocationConfigurableOptions($product); | ||
} | ||
|
||
return [ | ||
'Default Location' => ['Type' => 'dropdown', 'Options' => $this->getZoneLocation()], | ||
|
@@ -53,22 +56,68 @@ private function createCustomConfigurableOptions($product) | |
} | ||
} | ||
|
||
private function createGlobalConfigurableOptions($product) | ||
private function createBackupLocationConfigurableOptions($product) | ||
{ | ||
$currencyId = Capsule::table('tblcurrencies')->where('default', '1')->first()->id; | ||
$currencyCode = Capsule::table('tblcurrencies')->where('default', '1')->first()->code; | ||
$groupId = Capsule::table('tblproductconfiggroups')->where('name', 'Configurable options for UpCloud - Backup and Location')->first()->id; | ||
|
||
if(!$groupId){ | ||
$groupId = Capsule::table('tblproductconfiggroups')->insertGetId(['name' => 'Configurable options for UpCloud - Backup and Location', 'description' => 'Auto generated by upCloudVps module']); | ||
$groupIdLinks = Capsule::table('tblproductconfiglinks')->where('gid', $groupId)->where('pid', $product->id)->first()->gid; | ||
if(!$groupIdLinks){ | ||
Capsule::table('tblproductconfiglinks')->insert(['gid' => $groupId, 'pid' => $product->id]); | ||
} | ||
$this->createBackupFields($groupId, $this->getBackups()); | ||
$this->createLocationFields($groupId, $this->getZoneLocation(), $currencyId); | ||
} | ||
} | ||
|
||
private function createWindowsConfigurableOptions($product) | ||
{ | ||
$groupId = Capsule::table('tblproductconfiggroups')->where('name', 'Configurable options for UpCloud Native Windows')->first()->id; | ||
$currencyId = Capsule::table('tblcurrencies')->where('default', '1')->first()->id; | ||
$currencyCode = Capsule::table('tblcurrencies')->where('default', '1')->first()->code; | ||
if(!$groupId){ | ||
$groupId = Capsule::table('tblproductconfiggroups')->insertGetId(['name' => 'Configurable options for UpCloud Native Windows', 'description' => 'Auto generated by upCloudVps module']); | ||
$groupIdLinks = Capsule::table('tblproductconfiglinks')->where('gid', $groupId)->where('pid', $product->id)->first()->gid; | ||
if(!$groupIdLinks){ | ||
Capsule::table('tblproductconfiglinks')->insert(['gid' => $groupId, 'pid' => $product->id]); | ||
} | ||
$pomTemplates = $this->getTemplateIds("nativewindows"); | ||
$this->createTemplateFields($groupId, $pomTemplates, $currencyId, $currencyCode); | ||
} | ||
} | ||
|
||
private function createLinuxConfigurableOptions($product) | ||
{ | ||
$groupId = Capsule::table('tblproductconfiggroups')->where('name', 'Configurable options for UpCloud Native Linux')->first()->id; | ||
$currencyId = Capsule::table('tblcurrencies')->where('default', '1')->first()->id; | ||
$currencyCode = Capsule::table('tblcurrencies')->where('default', '1')->first()->code; | ||
if(!$groupId){ | ||
$groupId = Capsule::table('tblproductconfiggroups')->insertGetId(['name' => 'Configurable options for UpCloud Native Linux', 'description' => 'Auto generated by upCloudVps module']); | ||
$groupIdLinks = Capsule::table('tblproductconfiglinks')->where('gid', $groupId)->where('pid', $product->id)->first()->gid; | ||
if(!$groupIdLinks){ | ||
Capsule::table('tblproductconfiglinks')->insert(['gid' => $groupId, 'pid' => $product->id]); | ||
} | ||
$pomTemplates = $this->getTemplateIds("nativelinux"); | ||
$this->createTemplateFields($groupId, $pomTemplates, $currencyId, $currencyCode); | ||
} | ||
} | ||
|
||
private function createCloudConfigurableOptions($product) | ||
{ | ||
$groupId = Capsule::table('tblproductconfiggroups')->where('name', 'Configurable options for UpCloud Global')->first()->id; | ||
$groupId = Capsule::table('tblproductconfiggroups')->where('name', 'Configurable options for UpCloud Cloud Linux')->first()->id; | ||
$currencyId = Capsule::table('tblcurrencies')->where('default', '1')->first()->id; | ||
$currencyCode = Capsule::table('tblcurrencies')->where('default', '1')->first()->code; | ||
if(!$groupId){ | ||
$groupId = Capsule::table('tblproductconfiggroups')->insertGetId(['name' => 'Configurable options for UpCloud Global', 'description' => 'Auto generated by upCloudVps module']); | ||
$groupId = Capsule::table('tblproductconfiggroups')->insertGetId(['name' => 'Configurable options for UpCloud Cloud Linux', 'description' => 'Auto generated by upCloudVps module']); | ||
$groupIdLinks = Capsule::table('tblproductconfiglinks')->where('gid', $groupId)->where('pid', $product->id)->first()->gid; | ||
if(!$groupIdLinks){ | ||
Capsule::table('tblproductconfiglinks')->insert(['gid' => $groupId, 'pid' => $product->id]); | ||
} | ||
$pomTemplates = $this->getTemplateIds(); | ||
$zones = $this->getZoneLocation(); | ||
$this->createLocationFields($groupId, $zones, $currencyId); | ||
$this->createTemplateFields($groupId, $pomTemplates, $currencyId, $currencyCode); | ||
$this->createBackupFields($groupId, $this->getBackups()); | ||
$pomTemplates = $this->getTemplateIds("cloudinit"); | ||
$this->createTemplateFields($groupId, $pomTemplates, $currencyId, $currencyCode); | ||
} | ||
} | ||
|
||
|
@@ -85,19 +134,17 @@ private function createBackupFields($groupId, $backup){ | |
private function createRAMFields($groupId, $currencyId, $currencyCode){ | ||
$mems = array(); | ||
for ($i = 4; $i <= 64; $i += 1) { | ||
$mems["$i"] = "$i Gigabyte (GB)"; | ||
$mems["$i"] = "$i Gigabyte [GB]"; | ||
Comment on lines
-88
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder what is the rationale for this change, and its relation to #44? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was creating some conflicts so added [] brackets |
||
} | ||
$optionId = Capsule::table('tblproductconfigoptions')->where('gid', $groupId)->where('optionname', 'ram|Memory (RAM)')->first()->id; | ||
if(!$optionId){ | ||
$optionId = Capsule::table('tblproductconfigoptions')->insertGetId(['gid' => $groupId, 'optionname' => 'ram|Memory (RAM)', 'optiontype' => 1]); | ||
foreach ($mems as $mem => $mvals) { | ||
Capsule::table('tblproductconfigoptionssub')->updateOrInsert(['optionname' => $mem.'|'.$mvals], ['configid' => $optionId]); | ||
} | ||
foreach (Capsule::table('tblproductconfigoptionssub')->where('configid', $optionId)->get() as $id) { | ||
$parts = explode("|", $id->optionname); | ||
$fprice = $parts[0] * "2"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $id->id, 'monthly' => $monthlys['convertedAmount'] ],['currency' => $currencyId]); | ||
$relId = Capsule::table('tblproductconfigoptionssub')->where('optionname', $mem.'|'.$mvals)->where('configid', $optionId)->first()->id; | ||
$fprice = $mem * "2"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $relId, 'monthly' => $monthlys['convertedAmount'] ],['currency' => $currencyId]); | ||
Comment on lines
-95
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I read this correctly, or how it is related to issue #44. Could we clarify the purpose of this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think that I made any changes createRAMFields function, please check again. |
||
} | ||
} | ||
} | ||
|
@@ -112,12 +159,10 @@ private function createCPUFields($groupId, $currencyId, $currencyCode){ | |
$optionId = Capsule::table('tblproductconfigoptions')->insertGetId(['gid' => $groupId, 'optionname' => 'vcpu|vCPU', 'optiontype' => 1]); | ||
foreach ($cpus as $cpu => $cvals) { | ||
Capsule::table('tblproductconfigoptionssub')->updateOrInsert(['optionname' => $cpu.'|'.$cvals], ['configid' => $optionId]); | ||
} | ||
foreach (Capsule::table('tblproductconfigoptionssub')->where('configid', $optionId)->get() as $id) { | ||
$parts = explode("|", $id->optionname); | ||
$fprice = $parts[0] * "6"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $id->id, 'monthly' => $monthlys['convertedAmount'] ],['currency' => $currencyId]); | ||
$relId = Capsule::table('tblproductconfigoptionssub')->where('optionname', $cpu.'|'.$cvals)->where('configid', $optionId)->first()->id; | ||
$fprice = $cpu * "6"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $relId, 'monthly' => $monthlys['convertedAmount'] ],['currency' => $currencyId]); | ||
Comment on lines
-115
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above comment for memory, but for CPU here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think that I made any changes createCPUFields function, please check again. |
||
} | ||
} | ||
} | ||
|
@@ -132,12 +177,10 @@ private function createStorageFields($groupId, $currencyId, $currencyCode){ | |
$optionId = Capsule::table('tblproductconfigoptions')->insertGetId(['gid' => $groupId, 'optionname' => 'storage|Storage', 'optiontype' => 1]); | ||
foreach ($storages as $storage => $vals) { | ||
Capsule::table('tblproductconfigoptionssub')->updateOrInsert(['optionname' => $storage.'|'.$vals], ['configid' => $optionId]); | ||
} | ||
foreach (Capsule::table('tblproductconfigoptionssub')->where('configid', $optionId)->get() as $id) { | ||
$parts = explode("|", $id->optionname); | ||
$fprice = $parts[0] * "0.10"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $id->id, 'monthly' => $monthlys['convertedAmount'] ], ['currency' => $currencyId] ); | ||
$relId = Capsule::table('tblproductconfigoptionssub')->where('optionname', $storage.'|'.$vals)->where('configid', $optionId)->first()->id; | ||
$fprice = $storage * "0.10"; | ||
$monthlys = $this->manager->CurrencyConvert('EUR', $currencyCode, $fprice); | ||
Capsule::table('tblpricing')->updateOrInsert(['type' => 'configoptions', 'relid' => $relId, 'monthly' => $monthlys['convertedAmount'] ], ['currency' => $currencyId] ); | ||
Comment on lines
-135
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above comment for memory, but for storage here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above for createStorageFields function |
||
} | ||
} | ||
} | ||
|
@@ -200,7 +243,6 @@ private function getBackups() | |
return $backups; | ||
} | ||
|
||
|
||
private function getZoneLocation() | ||
{ | ||
$zones = $this->manager->GetZones()['response']['zones']['zone']; | ||
|
@@ -213,17 +255,30 @@ private function getZoneLocation() | |
return $zoneLocation; | ||
} | ||
|
||
private function getTemplateIds() | ||
{ | ||
$templates = $this->manager->GetTemplate()['response']['storages']['storage']; | ||
$templateIds = []; | ||
private function getTemplateIds($vmtype = null) | ||
{ | ||
$templates = $this->manager->GetTemplate()['response']['storages']['storage']; | ||
$templateIds = []; | ||
|
||
foreach ($templates as $template) { | ||
$templateIds[$template['uuid']] = $template['title']; | ||
} | ||
foreach ($templates as $template) { | ||
if ($template['template_type'] == "native") { | ||
if ($vmtype == 'nativewindows' && preg_match('/Windows/', $template['title'])) { | ||
$templateIds[$template['uuid']] = $template['title']; | ||
} elseif ($vmtype == 'nativelinux' && !preg_match('/Windows/', $template['title'])) { | ||
$templateIds[$template['uuid']] = $template['title']; | ||
} | ||
} elseif ($template['template_type'] == "cloud-init" && $vmtype == 'cloudinit') { | ||
$templateIds[$template['uuid']] = $template['title']; | ||
Comment on lines
+265
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bodies of all these conditions are the same,
Is this on purpose? If yes, I feel this would be clearer refactored into a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How they are same? Have you checked the conditions? |
||
} | ||
} | ||
if (!$vmtype) { | ||
foreach ($templates as $template) { | ||
$templateIds[$template['uuid']] = $template['title']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's yet another same condition body as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do verify the conditions for the function getTemplateIds and let me know your issues |
||
} | ||
} | ||
|
||
return $templateIds; | ||
} | ||
return $templateIds; | ||
} | ||
|
||
private function getVmplans() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does "Cloud Linux" here and below mean that it is related to Linux instances set up from cloud-init templates? If I understand correctly, would be good to clarify the intents of these option sets in their names, for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names it self says https://prnt.sc/p-h7WOcY5_MF where Cloud Linux meaning cloud-init images