Jump to content

Module Getpackagefields() Doesn't Display When Module Has Row Stored


Jamie

Recommended Posts

Hello, me again,

 

I was continuing to creating my module today when I noticed that none of the fields I created in getPackageFields() was showing up when editing / creating a package.

 

After several hours to attempting to see how the fields weren't displaying, I noticed that the fields were only displaying when I had no data stored for the Module.

 

However, when I managed the module and added some data (Using addModuleRow()), the fields would disappear without any errors. I re-installed my Module several times to confirm this and it seems like that the fields will only display when there is no data stored.

 

I re-write all of my 'admin side' (adding rows etc) and based it off the cPanel / Multicraft module as I thought I was doing something wrong. However, this didn't fix it.

 

I am obviously doing something wrong but I cannot figure out what it is.

 

I did some more debug and traced it back to 'admin_packages.php' in '/app/controllers/admin_packages.php'.

	/**
	 * List module options for ajax requests
	 */
	public function moduleOptions() {
		if (!$this->isAjax() || !isset($this->post['module_id']))
			return false;
		
		$this->uses(array("ModuleManager"));
		$this->components(array("Modules"));

		if (!isset($this->post['module_row']))
			$this->post['module_row'] = 0;
		if (!isset($this->post['module_group']))
			$this->post['module_group'] = "";

		$module = $this->ModuleManager->initModule($this->post['module_id'], $this->company_id);	
		
		if (!$module)
			return false;
		
		// Fetch all package fields this module requires
		$package_fields = $module->getPackageFields((object)$this->post);
		$fields = $package_fields->getFields();
		$html = $package_fields->getHtml();
		$tags = $module->getEmailTags();
		
		// Fetch the parser options to determine the start and end characters for template variables
		$parser_options = Configure::get("Blesta.parser_options");
		
		$module_email_tags = "";
		if (!empty($tags)) {
			$i=0;
			foreach ($tags as $group => $group_tags) {
				foreach ($group_tags as $tag) {
					$module_email_tags .= ($i++ > 0 ? " " : "") .
						$parser_options['VARIABLE_START'] . $group . "." . $tag . $parser_options['VARIABLE_END'];
				}
			}
		}
		
		$groups = $this->ArrayHelper->numericToKey((array)$this->ModuleManager->getGroups($this->post['module_id']), 'id', 'name');
		$rows = $this->ArrayHelper->numericToKey((array)$this->ModuleManager->getRows($this->post['module_id']), 'id', 'meta');
				
		$row_key = $module->moduleRowMetaKey();
		
                // ********** Here **********
		foreach ($rows as $key => &$value)					
			$value = $value->$row_key;
				
		$data = array(
			'module_options'=>$this->partial('admin_packages_moduleoptions',
				array(
					'fields'=>$fields,
					'html'=>$html,
					'group_name'=>$module->moduleGroupName(),
					'groups'=>$groups,
					'row_name'=>$module->moduleRowName(),
					'rows'=>$rows,
					'vars'=>(object)$this->post
				)
			),
			'module_email_tags'=>$module_email_tags
		);
		
		$this->outputAsJson($data);		
		return false;
	}
	

I used ob_start() to log all my var_dumps to a file, I could dump all the variables up to '// ********** Here **********' and past that point (when I stored data), I couldn't log anything else. (But it would work when i deleted the row).

 

My apologies if I didn't explain clearly as I am not really sure what the problem is.

 

I am attempting to create a TCAdmin module which I was planning on making public, I can put all of my (not so tidy) code on github if you need to have a better look.

 

I appreciate your help,

 

Jamie

 

Link to comment
Share on other sites

Hello,
 
Thank for your response.
 
I have had a look in the database and everything seems to be fine.
 
I essentially store the TCAdmin's servers information (Hostname, username and password). I get all this information on the manage module page which all displays fine.
 
This was all working fine a couple of days ago. For whatever reason it just decided to stop working after not working on it.
 
I did today remove everything which was not essential to see if it would fix itself but unfortunately, I had no luck.
 
I have put on a 'minimal' version of my module which also has the same problem as I described above.
 
https://github.com/JamiesServers/TCAdmin-Minimal
 
I went through all of the documentation to see If i missed something but I couldn't figure it out.
 
How to recreate my problem:

  • Install the module
  • Before adding a 'Server', create a new package and check if you can see the module's options (which you should be able to)

c2d54a836f.png

  • Manage the module and add a server (there is no rules except isEmpty, any info will be used)
  • Go back and try add another package, this time you won't be able to see the module's options.
  • If you uninstall the module and re-install it, this problem will still persist.

I hope this isn't down to a silly little mistake I might have made  :P.

 

I really appreciate your help.
 
Jamie

Link to comment
Share on other sites

I think you were right.

 

I did a fresh installation of Blesta on my another machine and installed just my module and it seems to work.

 

I think I might have changed something and then uploaded a version of my module which caused an incompatibility and when I uninstalled the module, some of the data must have not been removed from the database.

 

I'll have to go through the database and see what is left behind in a little while.

 

I'll get back to you if I find the issue.

 

Thanks again.

 

Edit:

 

I spoke too soon.

 

Went to edit a package and I get the same problem.

 

And I'm back to square one again  :(

 

Edit 2:

 

I have a look in the database when the module is uninstalled and there is nothing left over to do with the plugin; there is something definitely wrong with the meta but I have no idea what it is.

Link to comment
Share on other sites

I was getting an error when attempting to load the Module Options on the add/edit package page. It looks like a simple issue caused by the module declaring the wrong key name, which is used to reference the primary module row field. The module uses the primary meta field "hostname", but says its primary field is "server_name". Changing that should fix it.

 

i.e. Update:

public function moduleRowMetaKey() {
    return "server_name";
}

to:

public function moduleRowMetaKey() {
    return "hostname";
}
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...