Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Questions related to using nuBuilder Forte.
Post Reply
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by incoherence »

I have a working system but with an older nuBuilder Forte 4.5 version:-
DB Version: V.4.5-2022.01.30.00
Files Version: V.4.5-2022.02.22.02

I built a new system using the above version.
I built it by installing LAMP, MariaDB and the above version of nuBuilder.
Then I imported the database from a backup.
The new system all seemed to be working - okay so far.

While logged into that system, I did Database -> Update and followed the update wizard instructions:-
1. Made backups of database and of nuBuilder files.
2 & 3. Deleted /var/www/html (after coping nuConfig.php) then downloaded and unpacked the latest version into "html", preserving nuconfig.php
4. Clicked the Update button and saw the expected: "You will need to log in again for the changes to take effect".

The "latest version" referred to above is:-
DB Version: V.4.5-2022.08.31.00
Files Version: V.4.5-2022.09.15.00

After logging in again, there is an issue after the update that did not exist before the update:-

I have a form that has several select objects.
One of them has ID select_system_model.
The form has JS code that runs on form load, that does the following:

Code: Select all

$("#select_system_model").empty();
nuRefreshSelectObject('select_system_model');
console.log("select_system_model: cause pick list refresh due to form refresh");
This console log shows the expected message in both the "before update" and "after update" case; that part is working.

The form also has JS code with the following callback function that starts with the code:-

Code: Select all

function nuSelectObjectRefreshed(formId, selectId, count) {
  var f = nuCurrentProperties();
  let message = selectId + ' has been refreshed; number of items: ' + count;
  console.log(message);
...
In this case the console log message in the "before update" case is as follows (as expected):-

select_system_model has been refreshed; number of items: 1077


but the console log message "after update" case looks like this (not as expected):-

#nurefreshselectobject_selectid# has been refreshed; number of items: -1


In addition, when I go to Form Properties -> Custom Code -> make a minor (whitespace only) change, in the code -> Save
I get the following (I was not cloning any form BTW) :-

After Save of Form nuform
/var/www/html/core/nucommon.php(1392) : eval()'d code
Call to undefined function nuCloneForm()
Traced from...
(line:101) /var/www/html/core/nuapi.php - nuUpdateDatabase
(line:467) /var/www/html/core/nudata.php - nuEval
(line:1392) /var/www/html/core/nucommon.php - eval


Due to both the issue with the select object and the above error, I am concerned that the newly-built system is not in a good state.

I could of course start with a virgin system, import my data tables and then build the whole UI from scratch, but that would be a lot of effort and would like to avoid that, if possible.

I also had a look at the release versions of 4.5, but I did not see anything mentioning a change relating to this. I also checked the JS documentation for nuRefreshSelectObject() and I think I am using it exactly as it says.

Any help would be appreciated! Thanks!
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by kev1n »

nuCloneForm() was removed some time ago since it hadn't been used and the function has become obsolete.
As I see, there are still some references to it.

Add this empty nuCloneForm() function in nudata.php

Code: Select all

function nuCloneForm(){
	
}

I'm not sure if that's going to solve your other issue though.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by kev1n »

Update: I don't see any reference to nuCloneForm() in the latest version.
I'm not sure if your update was really successful and if the latest "refresh select object" code is being used.

Could you open that url (replace your_url ) and post the PHP Code of the function NUREFRESHSELECTOBJECT here ?
http://your_url/index.php?f=nuphp&r=nu5ff7efb1ed369a6
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by incoherence »

Here is the code from the PHP field of http://your_url/index.php?f=nuphp&r=nu5ff7efb1ed369a6 :-

Code: Select all

function nuGetSelectValues($formId, $selectId) {

    $sql = "
        SELECT
            sob_select_sql
        FROM
            `zzzzsys_object`
        WHERE
            sob_all_zzzzsys_form_id = ? AND sob_all_id = ?
    ";

    $t = nuRunQuery($sql, array($formId, $selectId));

    $a = array();
    if (db_num_rows($t) == 1) {

        $r = db_fetch_row($t);
        if ($r != false) {
            
            $disS = nuReplaceHashVariables($r[0]);

            $t = nuRunQuery($disS);

            while ($row = db_fetch_row($t)) {
                $a[] = $row;
            }

            return json_encode($a);
        }

    }

    return false;

}

function nuPopulateSelectObject($formId, $selectId, $removeBlank, $prefix) {

    $j = nuGetSelectValues($formId, $selectId);

    $selectId = $prefix.$selectId;

    $cb = "if (window.nuSelectObjectRefreshed) {
    	    nuSelectObjectRefreshed('$formId', '$selectId', count);
         }";

    if ($j == false) {
        
        return "var count = -1; ".$cb;
        
    } else {
    	
    return "
    	function nuPopulateSelectObject() {
    	
    		var p = $j;
    
    		$('#$selectId').empty();
    		
    		if ('$removeBlank' == '0' ) {
    		    $('#$selectId').append('<option value=\"\"></option>');
    		}
            
            var count = 0;
    
    		if (p != '') {
    		    var s = nuIsSaved();
    			
    			for (var i = 0; i < p.length; i++) {
    				$('#$selectId').append('<option value=\"' + p[i][0] + '\">' + p[i][1] + '</option>');
    				count ++;
    			}
    			
    			if (s) { nuHasNotBeenEdited(); }
    			
    		}
    		
    		return count;
    	}
    	
    	var count = nuPopulateSelectObject();

    ".$cb;
    }

}

function nuRefreshSelectObject($selectId, $formId, $removeBlank, $prefix) {

    if (hashCookieNotSetOrEmpty($formId)) {
        $formId = '#form_id#';
    }

    $prefix = hashCookieNotSetOrEmpty($prefix) ? '' : $prefix;

    $js = nuPopulateSelectObject($formId, $selectId, $removeBlank, $prefix);
    nuJavascriptCallback($js);

}

nuRefreshSelectObject('#nurefreshselectobject_selectid#', '#nurefreshselectobject_formid#', '#nurefreshselectobject_removeblank#','#nurefreshselectobject_prefix#');
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by incoherence »

> I'm not sure if your update was really successful

I have the feeling that it wasn't.
When the "Update" button in the wizard is clicked, which Linux user is the code that performs the update run as?
Would it be the "apache" user?
I did not see any instructions in the update wizard about setting the user/group of the files unpacked into the html directory.
I am wondering whether that could be the root cause of an unsuccessful update?
Are there any logs generated during the update that I could check to see whether anything failed?
(There were only two lines that came up in the browser after clicking "Update", and neither of those indicated any issue).
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by kev1n »

The update log should look like this:
update.png
Errors may be found under the nuDebug results or server logs.

Was the updated nubuilder4.sql placed in nuBuilder's root directory?
What versions (db & files) are displayed under Setup -> Setup tab?
You do not have the required permissions to view the files attached to this post.
incoherence
Posts: 22
Joined: Sun May 08, 2022 2:36 pm
Has thanked: 9 times
Been thanked: 1 time

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by incoherence »

> The update log should look like this
Wow... is that what I should have seen in the browser window where I clicked the "Update" button?
I thought I had already closed it but in fact I hadn't: I found the window where I had clicked "Update" and it contained only two lines:-

This tab can be closed after the update.
You will need to log in again for the changes to take effect.


.. and nothing else.
I did not find anything in nuDebug.
I had a look at /var/log/httpd/error_log and did not see anything obvious.
So I thought I might as well try the update again whilst watching that file to see if anything new appeared.
Without changing anything, I clicked through the Wizard and clicked the "Update" button.
This time, I got (whitespace removed):-

Table : zzzzsys_access - Prefix : sal_json did not exist and so has been created
Table : zzzzsys_access_form - Prefix : slf_json did not exist and so has been created
Table : zzzzsys_access_php - Prefix : slp_json did not exist and so has been created
Table : zzzzsys_access_report - Prefix : srp_json did not exist and so has been created
Table : zzzzsys_browse - Prefix : sbr_json did not exist and so has been created
Table : zzzzsys_cloner - Prefix : clo_json did not exist and so has been created
Table : zzzzsys_code_snippet - Prefix : cot_json did not exist and so has been created
Table : zzzzsys_config - Prefix : cfg_json did not exist and so has been created
Table : zzzzsys_debug - Prefix : deb_json did not exist and so has been created
Table : zzzzsys_event - Prefix : sev_json did not exist and so has been created
Table : zzzzsys_form - Prefix : sfo_json did not exist and so has been created
Table : zzzzsys_format - Prefix : srm_json did not exist and so has been created
Table : zzzzsys_info - Prefix : inf_json did not exist and so has been created
Table : zzzzsys_note - Prefix : not_json did not exist and so has been created
Table : zzzzsys_note_category - Prefix : hoc_json did not exist and so has been created
Table : zzzzsys_object - Prefix : sob_json did not exist and so has been created
Table : zzzzsys_php - Prefix : sph_json did not exist and so has been created
Table : zzzzsys_report - Prefix : sre_json did not exist and so has been created
Table : zzzzsys_select_clause - Prefix : ssc_json did not exist and so has been created
Table : zzzzsys_session - Prefix : sss_json did not exist and so has been created
Table : zzzzsys_setup - Prefix : set_json did not exist and so has been created
Table : zzzzsys_tab - Prefix : syt_json did not exist and so has been created
Table : zzzzsys_timezone - Prefix : stz_json did not exist and so has been created
Table : zzzzsys_translate - Prefix : trl_json did not exist and so has been created
1. Altered System Tables
2. Copied SYSTEM zzzz-TABLES to TEMP sys-TABLES
3. Imported nubuilder4.sql into the DATABASE
4. Copied SYSTEM FILES to TEMP FILES for any new tables added from the import.
5. Updated TEMP FILE table structure's to SYSTEM FILES
6. Removed all ids starting with nu from TEMP FILES
7. Removed all ids not starting with nu from SYSTEM FILES
8. Inserted TEMP FILES into SYSTEM FILES
9. Imported the LANGUAGE FILES into the DATABASE
10. Set DB Collation
11. Run nuAfterUpdate
You will need to log in again for the changes to take effect


(Does this all look normal?)

Now both of the two issues (nuSelectObjectRefreshed() strangeness and the stack trace when I tried to save only a whitespace change to code) have gone!

Odd that it took two attempts to make it work! It's the first time I did an "Update", so I didn't know what to expect to see in the browser.

So quickly back up the database, I thought, so, in the UI, went to Database -> Backup, but it gives me "Internal Server Error. [500]".

[Mon Sep 26 06:56:03.223733 2022] [php7:error] [pid 11733] [client 10.19.42.17:62254] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 69632 bytes) in /var/www/html/core/nucommon.php(1392) : eval()'d code(2) : eval()'d code(2) : eval()'d code(2) : eval()'d code(2) : eval()'d code(2) : eval()'d code(2) .....

The "eval()'d code(2) :" just keeps repeating and repeating - looks like infinite recursion.

/var/www/html/core/nucommon.php line 1392 is doing "eval($php)" inside function nuEval($phpid), but I guess that's not much help without a stack trace to see what's calling nuEval() or what the parameter passed in looks like...
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Update to latest version impacts selectId received by nuSelectObjectRefreshed()

Unread post by kev1n »

As for the backup, I'm not sure what's going wrong there as nuBuilder uses a 3rd party library. You can always use phpMyAdmin or mysqldump to create backups.
Post Reply