Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/26/2022 in all areas

  1. 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);
    1 point
×
×
  • Create New...