Databasejoin element in list view: "invalid argument", quotes around label data etc

Jaanus

Super Moderator
In list view, I see this message

Warning: Invalid argument supplied for foreach() in /plugins/fabrik_element/databasejoin/databasejoin.php on line 1269

The " quotes are around label data (some letters may be also replaced with code as "\u00fcld")

When there are no data then I see word null

I'm talking about the latest github update.
 
I noticed the same problem with the "quote". Problem started with

f9de068bdb112fd2d4b47ceabbc70421258e1eb0 is the first bad commit
commit f9de068bdb112fd2d4b47ceabbc70421258e1eb0
Author: pollen8 <rob@pollen-8.co.uk>
Date: Wed Sep 19 13:30:10 2012 +0200

db join ro in form was showing value and not label


ps: thank you janon for improving my knowledge of Git with a great tutorial.
very easy to identify the source of a regression ;D
 
Hello Jaanus,

I see you have a fork on GitHub. When you fork, is there a way to keep it synchronize with the main Fabrik? If so, can you explain how? So far, what I do is onc my pull requests are accepted, I delete my repository and fork a new one each time I make another change, but I suspect there might be another way.
I suspect it is something you can do only if you use Git on a local machine but I never could get it working. I am on Mac and the documentation for "Git on Mac" is useless!
 
Hello Jaanus,

I see you have a fork on GitHub. When you fork, is there a way to keep it synchronize with the main Fabrik? If so, can you explain how? So far, what I do is onc my pull requests are accepted, I delete my repository and fork a new one each time I make another change, but I suspect there might be another way.
I suspect it is something you can do only if you use Git on a local machine but I never could get it working. I am on Mac and the documentation for "Git on Mac" is useless!

Yes, I have it in my local machine. But the sync in not automatic. I use 2 programs on my local repository.

computer 1 with xp (in Rakvere)
TortoiseGit - I use it to pull new changes in Fabrik github.
Standard Git for Windows - I use it to push changes to my fork in Github.
Remote "origin" repository is Fabrik github
So first I pull from Fabrik and then push to my fork.

computer 2 with W7 (in Tallinn)
Git for Windows - to fetch & merge (=pull) changes from Fabrik Github
Github for Windows - to sync the changes with my fork in Github
Remote "origin" repository is my fork in github
First I fetch & merge from Fabrik, then I sync.

Of course everything could be made with only Git for Windows but the other programs just are offering sometimes more convenience :)

When I suggest some changes I make a special branch as Rob & Hugh suggested, push it to my fork and then make a pull request. When I have many different changes to propose I make more than one branches.
 
Noticed the same thing (warning / quotes around data) when I pulled the latest update from GitHub. For example, I have a user plugin element on one of my lists, and in the list view instead of Super User (no quotes) it shows "Super User" (with quotes).

Two small fixes to the renderListData function fix the warning (only tested with the User plugin). However it's just a workaround. The main issue seems to be that the value for $data getting passed to the function is already the label (not raw) value, which causes various things to screw up. For example, json_decode silently fails and returns null when it's not passed a valid JSON string, and getLabelForValue returns null when it's not passed the raw value of the element's data, meaning the SELECT query fails, and since nothing is passed for the $defaultLabel argument the function returns null (at least I think that's what's going on).

I've commented my changes below.

PHP:
	public function renderListData($data, &$thisRow)
	{
		$params = $this->getParams();
		$groupModel = $this->getGroupModel();
		$labeldata = array();		
		if (!$groupModel->isJoin() && $groupModel->canRepeat())
		{
			$opts = $this->_getOptionVals();
			$name = $this->getFullName(false, true, false) . '_raw';

			// If coming from fabrikemail plugin $thisRow is empty
			if (isset($thisRow->$name))
			{
				$data = $thisRow->$name;
			}
			if (!is_array($data))
			{
				$data = json_decode($data, true);
			}
			foreach ($data as $d)
			{
				foreach ($opts as $opt)
				{
					if ($opt->value == $d)
					{
						$labeldata[] = $opt->text;
						break;
					}
				}
			}
		}
		else{
			// $$$ hugh - $data may already be JSON encoded, so we don't want to double-encode.
			if (!FabrikWorker::isJSON($data))
			{
				/*$$$ cookn22 - needed because of the foreach block below */			
				$labeldata[] = $data;

			}
			else
			{
				// $$$ hugh - yeah, I know, kinda silly to decode right before we encode,
				// should really refactor so encoding goes in this if/else structure!
				$labeldata = json_decode($data);
		
			}
			
			foreach ($labeldata as &$l)
			{
				/*
					$$$ cookn22 - In some situations (like with the user plugin), the $data argument is apparently already set to the label value for the element and not the raw (database) value, in
					which case this function shouldn't be called. However, I'm not sure if that's always the case (if $data is never equal to the raw value at this point),
					so the workaround here is just to pass $l (or $data) for the $defaultLabel argument of getLabelForValue, so the function doesn't return null.
				*/ 
				$l = $this->getLabelForValue($l, $l);
			}
		}

		$data = json_encode($labeldata);		

		// $$$ rob add links and icons done in parent::renderListData();
		return parent::renderListData($data, $thisRow);
	}
 
Now we have issues in form/details:

1) dbjoin element shows raw data, not label data

2) Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/...../libraries/joomla/database/database/mysql.php on line 150
This warning is generally above form/details view but

when we show there a list using content plugin
1) then mysql_real_escape_string() appears also above this list view and
2) Warning: Invalid argument supplied for foreach() in /home/.../plugins/fabrik_element/databasejoin/databasejoin.php on line 1272 is present as well

NB! I just noticed that something else seems to be solved although I have yet no idea when and how :)
The probably solved issue is described here
http://fabrikar.com/forums/showpost.php?p=147466&postcount=9
and
https://github.com/Fabrik/fabrik/issues/390
My host upgraded php to 5.3; could it have something to do with this?
 
Can someone give me a step by step for replicating this? All my lists using user elements and joins seem to be working fine.

-- hugh
 
Warning: Invalid argument supplied for foreach() in /home/.../plugins/fabrik_element/databasejoin/databasejoin.php on line 1272 (line may differ depending on GitHub version),
quoted dbjoin labels, wrong displayed special characters
seem to be ok after the GitHub fix from yesterday (fixed: possible warnings in db join element)
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top