8: Array to string conversion

Started by Plantje, September 27, 2016, 10:49:36 AM

Previous topic - Next topic

Plantje

I have seen more of these topics. In the error log of our forum I see a lot of these error messages!

One of the lines affected is:
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
At least one other line is:
'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'],

I can see that the topics affected have a link like:
http://www.vliegvissers.com/SMForum/index.php?topic=Array.msg120710#msg120710
and that link doesn't work.
Whereas working links have something like:
http://www.vliegvissers.com/SMForum/index.php?topic=10773.msg165734#msg165734

I know the not working topic is a rather old topic. Perhaps this is a result of one of the mods. Is there a way to update all those links at once? I know that if the word "Array" is replaced by the topic number all is well. (In this case ;) )
I think we have quite some mods installed :S

Matthew K.

Where is that link with Array coming up? It might be a simple case of outputting an element on that array instead of the variable (the array) itself.

Dhayzon

'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',


NOT $topic , is $topic['id_topic']  or  $message['id_topic']

' . $topic['id_topic'] . '
'link' => '<a href="' . $scripturl . '?topic=' . $topic['id_topic'] . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',

Arantor

Except $topic is supposed to be a number ONLY, everywhere in SMF.

Some rogue mod is changing it.

Plantje

Sorry, should have checked the box to notify me of responses. I will update that setting to be the standard immediately after replying.

Thanks for the responses!

I saw that the links were translated to a link rather than the actual link text. And in the mean time I have looked at it again myself.

Quote from: тнє נя. on September 27, 2016, 09:42:07 PM
Where is that link with Array coming up? It might be a simple case of outputting an element on that array instead of the variable (the array) itself.
That link is coming up in most cases in rather old topics. In the newer topics I haven't seen it yet. I don't think users are actually reviewing those topics. The errors just popup because the links exist on the forum.
Quote from: Dhayzon on September 27, 2016, 11:19:44 PM
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',


NOT $topic , is $topic['id_topic']  or  $message['id_topic']

' . $topic['id_topic'] . '
'link' => '<a href="' . $scripturl . '?topic=' . $topic['id_topic'] . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
That's what I think as well. $topic should be something like  $topic['id_topic']. Strange thing is it seems to have happened only in the past.

Quote from: Arantor on September 28, 2016, 12:44:05 AM
Except $topic is supposed to be a number ONLY, everywhere in SMF.

Some rogue mod is changing it.
I can follow that as well. Perhaps some mod has changed it in the past and the mod is removed again without updating the links. Would it be possible to update this sort of stuff by using a SQL statement?

I am currently taking over an existing forum and understanding the biggest part is a first step in this regard. So please forgive me for being a noob :)

Kindred

no....   What Arantor just said is that $topic is correct.... and that $topic should always be a number. $topic is not an supposed to be an array.

and no... the issue has nothing to do with mySQL, the issue is that something seems to be improperly overwriting the $topic variable in the code
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Plantje

Ok, so the variable &topic should always hold one value being a number (or a string in the worst case :) )

Since this is only happening in older topics I think this is caused by some update at some time in the past. That's why I was thinking of altering the data in the DB. But if you say that is pointless I'll trust that judgement.

The forum has quite some mods and since I just started with taking this over I am not about to uninstall a few of them. What could be the best next step in troubleshooting this issue?

Kindred

well, the best thing to do would be to load a clean set of files and then reinstall ont he themes and mods that your site actively uses, testing after each one.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Plantje

I think getting rid of all the mods and building up from scratch again is the best thing to do anyway.

So, if I want to do that I still need to be able to access the file system of the web server. That may still take a while. A clean set of files is just removing everything and copy-pasting a clean install, right?
If I just keep the DB in place the users will still be able to access the site afterwards and the settings (apart from the set mods of course ;) ) will be as always?

Kindred

I was going to link you to our wiki... but it appears to be in the middle of an upgrade/fix.

Yes. As long as you don't touch the database, your users, messages, etc will be fine.

Step 0 - BACKUP -- ALWAYS BACKUP!!!!
Step 1- Reset everyone to the Default/Curve theme in the admin
Step 2- delete the Themes and Sources directories and all files in the forum root EXCEPT Settings.php and Settings_bak.php (KEEP THOSE!!!)
Step 3 - take the "large upgrade" archive files and extract them onto your webserver (this will rebuild the Sources and Themes directories and all files in the root)
Step 4 - load and run fix_packages.php (this will remove any "hooks" that mods have installed.

Now you should be running a clean forum (with all the data, untouched)

install your custom theme (install themes first, before mods)
install mods, one by one, testing after each install and backing up before the next install.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."


Plantje

Thanks guys! You are really helping me here!

I saw that we're using version 2.0.11 and that 2.0.12 is available and recommended to upgrade. The current administrator also stressed that no matter what you do: backup! Always backup! So, in case I want to do a refresh of files most likely the best thing I can do is: backup --> run update to 2.0.12 --> backup --> perform steps outlined in link provided.

Probably I can use those steps as well as soon as I want to migrate to a different host.

For now the first step for me is to gain access to the web server in order to do the refresh. Thanks again!

Matthew K.

That's also why I requested details on where this is happening so we can figure out what code is changing `$topic` from an integer to an Array and causing this issue.

Plantje

Copying the piece of code where I found the error is sufficient?

Matthew K.

No, it's not sufficient, because where you're seeing that code makes a difference in what's changing`$topic`.

Plantje

As far as I can see the only information on where it occurs is given in the error log.
Then I see a link to the topic and that's where I noticed the hyperlink of the replies are not correct.

The only other thing I have is a snippet of code:
1326:
$memberContext[$message['id_member']]['can_view_profile'] = allowedTo('profile_view_any') || ($message['id_member'] == $user_info['id'] && allowedTo('profile_view_own'));
1327:
$memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];
1328:
$memberContext[$message['id_member']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member']]['warning_status'] && ($context['user']['can_mod'] || (!$user_info['is_guest'] && !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member'] == $user_info['id'])));
1329:
}
1330:

1331:
$memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
1332:

1333:
// Do the censor thang.
1334:
censorText($message['body']);
1335:
censorText($message['subject']);
1336:

1337:
// Run BBC interpreter on the message.
1338:
$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1339:

1340:
// Compose the memory eat- I mean message array.
1341:
$output = array(
1342:
'attachment' => loadAttachmentContext($message['id_msg']),
1343:
'alternate' => $counter % 2,
1344:
'id' => $message['id_msg'],
1345:
'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'],
==>1346:
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
1347:
'member' => &$memberContext[$message['id_member']],
1348:
'icon' => $message['icon'],
1349:
'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.gif',
1350:
'subject' => $message['subject'],
1351:
'time' => timeformat($message['poster_time']),
1352:
'timestamp' => forum_time(true, $message['poster_time']),
1353:
'counter' => $counter,
1354:
'modified' => array(
1355:
'time' => timeformat($message['modified_time']),
1356:
'timestamp' => forum_time(true, $message['modified_time']),
1357:
'name' => $message['modified_name']
1358:
),
1359:
'body' => $message['body'],
1360:
'new' => empty($message['is_read']),
1361:
'approved' => $message['approved'],
1362:
'first_new' => isset($context['start_from']) && $context['start_from'] == $counter,
1363:
'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($message['id_member'], $context['user']['ignoreusers']),
1364:
'can_approve' => !$message['approved'] && $context['can_approve'],
1365:
'can_unapprove' => $message['approved'] && $context['can_approve'],
1366:
'can_modify' => (!$context['is_locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()))),

But that doesn't seem to be everything...is it?

Plantje

This issue is acting up again and now it is also hindering the viewing of some attachments for some users.

As of the beginning of this year I am owner of the forum, so I can perform somewhat more drastic actions. Any new insights?

Plantje

I think this is the MOD causing it:
https://custom.simplemachines.org/mods/index.php?mod=579

However, on my Test environment I don't have this issue. Tonight I will create a backup and remove the MOD from the Production website. Any additional thoughts are highly appreciated!

Advertisement: