• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

One insert command, two records

Status
Not open for further replies.

jarea

Member
I don't think this is a Fabrik issue and I have included it over at joomla.stackexchange as well, but I am posting it here just in case something is happening with Fabrik in the background that I am not aware of.

I have a JFactory insert that is producing a strange result. For some reason that I cannot determine, it inserts a blank record and then about 20 seconds later the proper record that was submitted by the user is written. Here is the code for the insert:

Code:
// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Determine the value for the next record

$columns = array( 'email_address', 'url', 'username');

$values = array($db->quote($email), $db->quote($url), $db->quote($userid));


// Build the query

$query

->insert($db->quoteName('review_requests'))

->columns($db->quoteName($columns))

->values(implode(',', $values));

// Execute the query

$db->setQuery($query);

$db->execute();

The settings for the database table are:

Code:
1 id Primary int(11) No None AUTO_INCREMENT
2 date_time timestamp Yes CURRENT_TIMESTAMP
3 email_address varchar(255) latin1_swedish_ci Yes NULL
4 url varchar(255) latin1_swedish_ci Yes NULL
5 username int(11) Yes NULL

The records look like:

Code:
20 2015-08-01 11:39:52                                                                         0
21 2015-08-01 11:40:13 frank@sbcglobal.net http://test.com 402

As a postscript, I'll add the following information. I don't think it is important, but just in case something is going on in the background it will be noted.

The table and elements were created by Fabrik and the table can be displayed by Fabrik.

The insert statement was done outside of the Fabrik realm, with the code actually placed inside of an article using Sourcerer {source} {/source} tags.

Any help in figuring this out is greatly appreciated.
 
They are POST variables from a form. Let me know if you would like to see the whole code. Actually the username is really the user ID, though Fabrik displays it as the user name and it comes from the Joomla $user variable.
 
If you want to point me at the site, I'll take a look. I'd need to actually get my hands on it to help. Your code looks fine.

Sent from my HTC One using Tapatalk
 
Definitely something froggy going on here. The example that I gave was for submitting an email record to table review_requests. As I continued with the development of the process and got around to submitting a new website record to table sites, it wrote one empty record and then two copies of the record that was submitted.
 
Well I just confirmed it is not a Fabrik problem. I created a test table independent of Fabrik and inserted a test record and it added the record three times. Don't know what is going on but it certainly is strange. Marking this closed.
 
Your site is not accessible (time out).
I tried your code locally, it's working fine.

Which article is it?
Is it displayed multiple times, e.g. with your Fabrik search form (empty values) and then after submitting the form?
 
Posts crossing.
But keep in mind that your code is run every time the article is loaded (not necessarily displayed).
If you want your code run in connection with a Fabrik form use php form plugins.
 
Your site is not accessible (time out).
I tried your code locally, it's working fine.

Which article is it?
Is it displayed multiple times, e.g. with your Fabrik search form (empty values) and then after submitting the form?

But keep in mind that your code is run every time the article is loaded (not necessarily displayed).
If you want your code run in connection with a Fabrik form use php form plugins.

Sorry about that - I had the firewall closed. I'll open it up if you want to take a look.
One article takes the data input and then hands it off to another article that reads the post data. If you read the notes on the my-sites page it will tell you how to replicate the problem and which article to use.

The reason that I am not using PHP inside of Fabrik is because this is a special front end process that Fabrik does not handle well. See Search Form Redirect http://fabrikar.com/forums/index.php?posts/210882/
This process works very well with the exception of too many database records being inserted.
 
Ack, i thought I'd already replied along those lines. Yes, that was my initial guess, was that something else was calling onPrepareContent.

It's not really a bug in J!, it's more an assumption on the part of both Sourcerer / people coding with it. Plugins in articles get run whenever the onPrepareContent hook gets called. Which isn't necessarily only when the article is rendered for display. For instance, the indexing engine will often do it, when you save an article on the backend (depending on your setup). Lots of code in J! has reason to fully render articles, for reasons other than displaying them with option=com_content&view=article (or whatever).

Best bet is just to put some defensive code in there, and don't run your stuff if all your query string / post data isn't present and correct.

-- hugh
 
I can see your point of view that this might actually be a feature rather than a bug. In my instance, this is a very specific function that I need and as I mentioned at the end of the bug report, I have a workaround that will suit me just fine.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top