Blesta Addons Posted March 19, 2016 Report Share Posted March 19, 2016 i want to change a package belong to universal module ,to a new coded module , the problem is in the universal module the main field is user1 , and the custom module has the field named ip_key . when i change the package the main field is not shown in the new package in admin/client side i believe i should change the old name of field to the new one my question what is the best and the safe way to do this ? any mysql code that can help is appreciated activa 1 Quote Link to comment Share on other sites More sharing options...
PauloV Posted March 19, 2016 Report Share Posted March 19, 2016 i want to change a package belong to universal module ,to a new coded module , the problem is in the universal module the main field is user1 , and the custom module has the field named ip_key . when i change the package the main field is not shown in the new package in admin/client side i believe i should change the old name of field to the new one my question what is the best and the safe way to do this ? any mysql code that can help is appreciated Hello naja7host I Have a Plugin for that alredy made I have made for a blesta member some time ago to move from Universal Module to OpenSRS Module I was working on it to be able to move from any Module as easy as a Drop Down to choose from Give me until monday and I will try and release it here niyo, activa, Nelsa and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted March 19, 2016 Author Report Share Posted March 19, 2016 Hello naja7host I Have a Plugin for that alredy made I have made for a blesta member some time ago to move from Universal Module to OpenSRS Module I was working on it to be able to move from any Module as easy as a Drop Down to choose from Give me until monday and I will try and release it here perfect , you will save me the time to code it again Quote Link to comment Share on other sites More sharing options...
PauloV Posted March 21, 2016 Report Share Posted March 21, 2016 perfect , you will save me the time to code it again Hello, It will take more time that I expected to finish the Plugin to work with any outher Module, But I will post below the Code I have iis working in my client case that I have "comment" below for you to understand Im sure there are many outher ways, maybe more easy, but its working great I have set the code below in a Plugin on Blesta, so you can use as you want // Set your email adress to send the report $universaltoany_email = "email@mydomain.com"; // Set Universal Module module_row_id $universal_module_row_id = "1"; // Set the main key to be changed to anouther module key $universal_key_change = "user1"; // Set all Universal Module Keys to be deleted that dosent make sense on the new Module $universal_delete_key = array("opt1","opt2","pass","user2"); // Set Outher Module to transfer to module_row_id $any_module_row_id = "2"; // Set the main key for the new Module to be changed from $universal_key_change $any_key_change = "domain"; // Add all Universal Package Pricing ID's you want to transfer here $universal=array('16','17','26','27','28','38','48','52','53','57','59','66','67','70','74','75','79'); // Add all equivalent new Module Package Pricing ID's here to match the above "universal" $any_module=array('108','86','88','109','107','89','110','111','106','105','104','103','102','112','101','99','84'); // Now we map the array to match each Package Pricing $univ_to_opensrs_map = array_map(null, $universal, $any_module); // Now we start the processes for transfer foreach ($univ_to_opensrs_map as &$value) { // get all universal Packages mapped above $upackages = $this->Record->select(array("pricing_id","package_id"))->from("package_pricing")->where("package_pricing.package_id", "=", $value[0])->fetchAll(); // we start logging the Transfer Report to recive as an email $sendreport .= "Universal Package ID = ". $value[0]."\n"; // start reading all Packages foreach ($upackages as $upackage) { // Now we get all Universal Pricing ID's to transfer $upricings = $this->Record->select(array("id","period","term"))->from("pricings")->where("pricings.id", "=", $upackage->pricing_id)->fetchAll(); // we add all Universal Package Pricing ID's that will be converted $sendreport .= "Universal Package Price ID = ". $upackage->pricing_id."\n"; // now we start reading all Universal Pricing ID's foreach ($upricings as $upricing) { // now we get the pricing term to check if its OK, because some times we onlly use months and in this client case we converted months to years for OpenSRS $gterm = $upricing->term; if ($upricing->period == "month") $gterm = ($upricing->term / 12); // We log the original period and the converted period just to make sure its OK $sendreport .= "Universal Package Price Period = ". $upricing->period."\n"; $sendreport .= "Universal Package Price Term = ". $gterm." -> Original Term = ".$upricing->term." \n\n"; // we logs the outher Moduke Package ID that will convert to $sendreport .= "AnyModule Package ID = ". $value[1]."\n"; // Now we strat getting all outher Module Package Pricing ID's $opackages = $this->Record->select(array("pricing_id","package_id"))->from("package_pricing")->where("package_pricing.package_id", "=", $value[1])->fetchAll(); // Now we start the process of transfer to the outher module foreach ($opackages as $opackage) { // we log the Other Module Package Pricing ID $sendreport .= "AnyModule Package Price ID = ". $opackage->pricing_id."\n"; // now we get all all Package Princig ID's mapped (in this case we will get only the "period" by "year" but you can change that for your case) $opricings = $this->Record->select(array("id","period","term"))->from("pricings")->where("pricings.id", "=", $opackage->pricing_id)->where("pricings.period", "=", "year")->where("pricings.term", "=", $gterm)->fetchAll(); // now we read all pricings foreach ($opricings as $opricing) { // we get the outher module princing ID $opricingid = $opricing->id; // we logs all pricing period and term $sendreport .= "AnyModule Package Price Period = ". $opricing->period."\n"; $sendreport .= "AnyModule Package Price Term = ". $opricing->term."\n"; $sendreport .= "\n\n---------------BEGINING---------------\n"; // now we finally have all correct client/service princing ID and service ID we can convert/transfer $oservices = $this->Record->select(array("id"))->from("services")->where("pricing_id", "=", $upricing->id)->fetchAll(); // we strat the final process foreach ($oservices as $oservice) { // we log all transfered service ID to make sure was transfer sucessfull $sendreport .= "Universal to AnyModule Imported Service ID = ". $oservice->id."\n"; // we update the Universal Module ID to the new Module ID $this->Record->where("pricing_id", "=", $upricing->id)->where("module_row_id", "=", $universal_module_row_id)->update("services", array("pricing_id"=>$opricingid, "module_row_id"=>$any_module_row_id)); // we change the Module "key" in this case "user1" to the new "key", in this case "domain" $this->Record->where("service_id", "=", $oservice->id)->where("key", "=", $universal_key_change)->update("service_fields", array("key"=>$any_key_change)); // we remove all unecessary key's that dosent make sense for this Module, in this case we will remove "opt1","opt2","pass","user2" $this->Record->from("service_fields")->where("service_id", "=", $oservice->id)->where("key", "in", $universal_delete_key)->delete(); } $sendreport .= "\n------------------END-------------------\n\n"; } } } } $sendreport .= "\n\n"; } mail($universaltoany_email, "Blesta - Universal to AnyModule Report", $sendreport); Michael, Blesta Addons and Micahel Yoon 3 Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted March 21, 2016 Author Report Share Posted March 21, 2016 Thanks Paulov ..i will try it and why not if i have time convert it to a plugin . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.