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
Write a value on the database
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.
Joomla version: 4.2.9
Php version: 8.2.1
Database version: 5.7.32-35
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;
Title |
|
||||||
Labels |
Added:
No Code Attached Yet
|
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
Closing as not a core issue.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-04-06 16:52:08 |
Closed_By | ⇒ | richard67 |
@alecrespi78 You could try to get advice in the support forum here https://forum.joomla.org/viewforum.php?f=831&sid=0859700d62335207b547263efa056b00 .
Try
response.data
instead ofresponse.data[0]
. Anyways this is not a Joomla issue. Also the code is completely unsafe as it's full of XSS vulnerabilities...