Jump to content

Addservice: How To Retrieve Service Fields


sktan

Recommended Posts

Hey, I'm creating a module, and ran into a problem when attempting to provision a service.

 

Heres my current 'addService' code.

public function addService($package, array $vars=null, $parent_package=null, $parent_service=null, $status="pending") {
		$params = $this->getFieldsFromInput((array)$vars, $package);
                // logging functions here
		return array(
			array(
				'key' => 'gsp_game_id',
				'value' => $params['game_id'],
				'encrypted' => 0,
			),
			array(
				'key' => 'gsp_machine_location',
				'value' => $params['machine_location'],
				'encrypted' => 0,
			),
			array(
				'key' => 'gsp_server_name',
				'value' => $params['server_name'],
				'encrypted' => 0,
			),
			array(
				'key' => 'gsp_rcon_password',
				'value' => $params['rcon_password'],
				'encrypted' => 0,
			),
			array(
				'key' => 'gsp_slots',
				'value' => $params['slots'],
				'encrypted' => 0,
			),
			array(
				'key' => 'gsp_extra_slots',
				'value' => $params['extra_slots'],
				'encrypted' => 0,
			),
		);
	}

The service fields get stored on my DB when the client orders the package and the status is 'pending', but when I activate the product the values that's been saved as a service field isn't passed onto the $vars variable which then over-writes the data as null.

 

Is there any way to grab the service fields from the DB once the package is active? or am I doing something horribly wrong.

Link to comment
Share on other sites

What's contained in $vars and how does ::getFieldsFromInput modify the data?

 

Fetching the service fields from the database is not necessary, and in some cases may be incorrect anyway. You should check both for the service field in $vars and the package meta fields to determine which value to use.

Link to comment
Share on other sites

What's contained in $vars and how does ::getFieldsFromInput modify the data?

 

Fetching the service fields from the database is not necessary, and in some cases may be incorrect anyway. You should check both for the service field in $vars and the package meta fields to determine which value to use.

 

At the moment, the "getFieldsFromInput" function looks like this.


	private function getFieldsFromInput($vars, $package) {
		$fields = array(
			'game_id' => $package->meta->game_id,
			'server_name' => isset($vars['gsp_server_name']) ? $vars['gsp_server_name'] : null,
			'rcon_password' => isset($vars['gsp_rcon_password']) ? $vars['gsp_rcon_password'] : null,
			'machine_location' => isset($vars['gsp_machine_location']) ? $vars['gsp_machine_location'] : null,
			'extra_slots' => isset($vars['configoptions']['ExtraSlots']) ? $vars['configoptions']['ExtraSlots'] : 0,
			'slots' => isset($package->meta->default_slots) ? $package->meta->default_slots : null,
		);
		
		if(isset($vars['configoptions']['slots']))
		{
			$fields['slots'] = $vars['configoptions']['slots'];
		}
		if(isset($vars['configoptions']['dedicated']))
		{
			$fields['dedicated'] = $vars['configoptions']['dedicated'];
		}
		
		return $fields;
	}
	

And the logs from the function params have been attached as a .txt file.

addService.txt

Link to comment
Share on other sites

Are you trying to activate the pending service as an admin from the Manage Service page? If so, are the fields (e.g. game ID, machine location, etc.) shown on this page? If not, that would be why they are missing from $vars. Your module should define these fields in its ::getAdminAddFields method so that a service can be added/activated manually by an admin.

Link to comment
Share on other sites

Are you trying to activate the pending service as an admin from the Manage Service page? If so, are the fields (e.g. game ID, machine location, etc.) shown on this page? If not, that would be why they are missing from $vars. Your module should define these fields in its ::getAdminAddFields method so that a service can be added/activated manually by an admin.

 

That would actually make loads of sense.

That has definitely solved my problem (thought it would retrieve the fields automatically)

 

Thanks alot!

Link to comment
Share on other sites

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...