No Code Attached Yet
avatar alecrespi78
alecrespi78
6 Apr 2023

Steps to reproduce the issue

Open the link
https://www.joom-dev.it/tgw/index.php?option=com_content&view=article&id=236&catid=38&Itemid=559
Click on the TOP / DOWN arrow

Expected result

Write a value on the database

Actual result

After migrating a Joomla 3 (PHP 7.4) website to Joomla 4.2.9 (PHP 8.2.1) this custom plugin stoppeod working.
It correctly reads values from the DB but it's unable to write new values.

System information (as much as possible)

Joomla version: 4.2.9
Php version: 8.2.1
Database version: 5.7.32-35

Additional comments

After migrating a Joomla 3 (PHP 7.4) website to Joomla 4.2.9 (PHP 8.2.1) I've stumbled upon this issue in a custom plugin.

obj = jQuery.parseJSON(response.data[0]);

The plugin stopped writing a filed in a database table.

The code is able to read and render values from the DB but it's not albe to write new values.

There must be some logic error in the PHP code itself, but I cannot figure this out.

I'm no PHP programmer and I really don't know how to adapt this PHP code to 8.2 / J4 version.

This is a sample live site with the error.
https://www.joom-dev.it/tgw/index.php?option=com_content&view=article&id=236&catid=38&Itemid=559

Code extract:

if(($user->guest == 0) || ($this->params->get("ccv_registerd_required", "true") == "false")) {
    $ajax = "
			function currentTime()
			{
			var now = new Date();
			return now.getHours() + now.getMinutes() + now.getSeconds();
			}

			function sendVote(id, action, request)
			{
			jQuery('.status').html('${loading}');
			" .
        /* request.data += '&stamp=' + currentTime() */
        " jQuery.ajax({
			type   : 'GET',
			data   : request,
			success: function (response) {
			" .
        /* console.log(response.data[0]); */
        " obj = jQuery.parseJSON(response.data[0]);
			" .
        /*
        console.log(obj);
        console.log(obj['likes']);
        console.log(obj['unlikes']);
        */
        " jQuery('#cLike-{$art_id}').html(' ' + obj['pct_likes'] + ' %');
			jQuery('#cUnlike-{$art_id}').html(' ' + obj['pct_unlikes'] + ' %');
			jQuery('.status').html(obj['message']);
			},
			error: function(response) {
			obj = jQuery.parseJSON(response.responseText);
			var data2 = 'err: ';
			for(key in obj)
			{
			data2 = data2 + ' ' + obj[key] + '<br/>';
			}
			jQuery('.status').html(data2);
			}
			});
			}

			jQuery(document).ready( function() {
			jQuery('.like img').on( 'click', function(event) {
			var request = {
			'option' : 'com_ajax',
			'plugin' : 'ccvote',
			'group'  : 'content',
			'cmd'    : 'like',
			'data'   : { id: {$art_id} },
			'art_id' : '{$art_id}',
			'user_id': '{$user->id}',
			'user_name': '{$user->username}',
			'format' : '{$format}'
			};
			sendVote( {$art_id}, 'like', request);
			});
			jQuery('.unlike img').on( 'click', function(event) {
			var request = {
			'option' : 'com_ajax',
			'plugin' : 'ccvote',
			'group'  : 'content',
			'cmd'    : 'unlike',
			'data'   : { id: {$art_id} },
			'art_id' : '{$art_id}',
			'user_id': '{$user->id}',
			'user_name': '{$user->username}',
			'format' : '{$format}'
			};
			sendVote( {$art_id}, 'unlike', request);
			});
			});
			";
} else {
    $ajax = "
			var msg = '<b>You must be logged in to vote.</b>';
			jQuery(document).ready( function() {
			jQuery('.like img').on( 'click', function(event) {
			jQuery('.status').html(msg);
			});
			jQuery('.unlike img').on( 'click', function(event) {
			jQuery('.status').html(msg);
			});
			});
			";
}

How can I do to fix the PHP code to allow the correct addition of new fileds or values?

This is the error log from the console "console.log(response.data[0]);"

PHP Warning: Attempt to read property "id" on null in /web/htdocs/www.joom-dev.it/home/tgw/libraries/src/Updater/Adapter/ExtensionAdapter.php on line 303"

Line 303 below:

$this->latest->client_id = ApplicationHelper::getClientInfo($this->latest->client, true)->id;
avatar alecrespi78 alecrespi78 - open - 6 Apr 2023
avatar joomla-cms-bot joomla-cms-bot - change - 6 Apr 2023
Title
Uncaught SyntaxError: "undefined" is not valid JSON at Function.parse [as parseJSON] (<anonymous>)
Uncaught SyntaxError: "undefined" is not valid JSON at Function.parse [as parseJSON] ()
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Apr 2023
avatar dgrammatiko
dgrammatiko - comment - 6 Apr 2023

Try response.data instead of response.data[0]. Anyways this is not a Joomla issue. Also the code is completely unsafe as it's full of XSS vulnerabilities...

avatar alecrespi78
alecrespi78 - comment - 6 Apr 2023

Thank you I've tried "response.data" but the console.log is the same (same result in frontend).

WARNING: [pool www.joom-dev.it] child 185 said into stderr: "[06-Apr-2023 15:42:05 Europe/Rome] PHP Warning: Attempt to read property "id" on null in /web/htdocs/www.joom-dev.it/home/tgw/libraries/src/Updater/Adapter/ExtensionAdapter.php on line 303"

It's the very first time I'm posting something on github so I could have posted it in the wrong section...
Is there a way to move this isuue to PHP or somewhere else?

Thank you for both your kind support and patience.
Alessandro

avatar richard67
richard67 - comment - 6 Apr 2023

Closing as not a core issue.

avatar richard67 richard67 - close - 6 Apr 2023
avatar richard67 richard67 - change - 6 Apr 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-04-06 16:52:08
Closed_By richard67
avatar richard67
richard67 - comment - 6 Apr 2023
avatar alecrespi78 alecrespi78 - change - 6 Apr 2023
The description was changed
avatar alecrespi78 alecrespi78 - edited - 6 Apr 2023

Add a Comment

Login with GitHub to post a comment