Jump to content

Recommended Posts

Posted

This is a result of importing? I would expect services.package_group_id to be null if importing from Blesta 2.5 because 2.5 did not support package groups.

 

The solution would be to update services.package_group_id so that it matches the desired package group. Then you should be able to upgrade/downgrade between other packages in the same group that match the same module.

Posted

yes , is a result of importation from v 2.5

 

i know the solution is to update the services.package_group_id .

 

my concern here that we have more than  10000 services , and i can't play and testing in a live environement , i need a solid php  code to update the fields .

 

i hope tyson or cody can give a sample code that can be do the job .

Posted

s this code safe ?

$fields = array(
	"services.*",
	'pricings.term', 
	'packages.id' => "packages_id",
	'package_group.package_group_id' => "filled_package_group_id",
	'packages.name',
	'contacts.company' => "client_company"
	
);

$this->Record->select($fields)->
	from("services")->		
	innerJoin("package_pricing", "package_pricing.id", "=", "services.pricing_id", false)->
	innerJoin("pricings", "pricings.id", "=", "package_pricing.pricing_id", false)->
	innerJoin("packages", "packages.id", "=", "package_pricing.package_id", false)->
	innerJoin("package_group", "package_group.package_id", "=", "packages.id", false)->			
	innerJoin("clients", "services.client_id", "=", "clients.id", false)->
	innerJoin("client_groups", "client_groups.id", "=", "clients.client_group_id", false)->
	on("contacts.contact_type", "=", "primary")->
	innerJoin("contacts", "contacts.client_id", "=", "clients.id", false);
	
// Filter on client ID
if ($service_id != null)
	$this->Record->where("services.id", "=", $service_id);

$this->Record->where("services.status", "!=", "canceled")->
	where("services.package_group_id", "=", null);

// Ensure only fetching records for the current company
$this->Record->where("client_groups.company_id", "=", Configure::get("Blesta.company_id"));


$services = $this->Record->
	fetchAll();

foreach ($services as $service)
	$this->Record->where("services.id", "=", $service->id)->update("services", array('package_group_id' => $service->filled_package_group_id));



Posted

I haven't looked at the importer, but from your code I don't see any problems. You may want to group on the service ID though.

 

You mentioned you have 10k services. Fetching them all at once may exhaust memory. You can iterate over the records instead:

...

$services = $this->Record->group(array('services.id'))->getStatement();

foreach ($services as $service) {
	$this->Record->where("services.id", "=", $service->id)->update("services", array('package_group_id' => $service->filled_package_group_id));
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...