Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

error when making a copy of survey

More
2 years 1 month ago #251568 by Riadh2020
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition Version 6.1.7+230710
Own server or LimeSurvey hosting: Self hosted with OVH
Survey theme/template: FRUITY
==================
Hello, do you Know why Im getting this error when making a copy of a survey.500: Internal Server Error XMLWriter::writeElement(): Argument #2 ($content) must be of type ?string, stdClass given
 
Thanks

Please Log in to join the conversation.

More
2 years 1 month ago #251572 by holch
As your version of LS6 is not the latest one and there have been quite a few updates in the last 3-4 months, I would recommend to update to the latest version (which currently is LS 6.3.1+231023) and see if the issue persists.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The following user(s) said Thank You: Riadh2020

Please Log in to join the conversation.

More
2 years 1 month ago #251616 by Riadh2020
Thanks holch ,
But still the same error messege after upgrade to 6.3.1
Thanks

Please Log in to join the conversation.

More
2 years 1 month ago #251617 by Riadh2020
 

File Attachment:

File Name: error.txt
File Size:18.5 KB
I get this error when I try to export the survey. thanks

Please Log in to join the conversation.

More
2 days 6 hours ago - 2 days 6 hours ago #273388 by bourginj
Hi,
If it can still help, I also had this issue and it seems that the problem is indeed that some theme configuration elements are considered as objects (stdClass) and not strings or arrays, which XMLwriter can't handle.

The following update worked for me. I changed writeXmlFromArray function in application/helpers/export_helper.php file. The original code was 

Code:
function writeXmlFromArray(XMLWriter $xml, $aData, $sParentKey = '')
{
    $bCloseElement = false;
    foreach ($aData as $key => $value) {
        if (!empty($value)) {
             if (is_array($value)) {
                if (is_numeric($key)) {
                    $xml->startElement($sParentKey);
                    $bCloseElement = true;
                } elseif (isAssociativeArray($value)) {
                    $xml->startElement($key);
                    $bCloseElement = true;
                }
 
                if (is_numeric($key)) {
                    writeXmlFromArray($xml, $value, $sParentKey);
                } else {
                    writeXmlFromArray($xml, $value, $key);
                }
 
                if ($bCloseElement === true) {
                    $xml->endElement();
                    $bCloseElement = false;
                }
                continue;
            } elseif (is_numeric($key)) {
                $xml->writeElement($sParentKey, $value);
            } else {
                $xml->writeElement($key, $value);
            }
        }
    }
    return $xml;
}


I changed it to the following one (added code surrounded by comments)

Code:
function writeXmlFromArray(XMLWriter $xml, $aData, $sParentKey = '')
{
    $bCloseElement = false;
    foreach ($aData as $key => $value) {
        if (!empty($value)) {
             /////////////////////
             // convert to json //
             /////////////////////
             if (is_object($value)) {
                $value = json_encode($value);
             }
             /////////////////////
             /////////////////////
             /////////////////////
 
             if (is_array($value)) {
                if (is_numeric($key)) {
                    $xml->startElement($sParentKey);
                    $bCloseElement = true;
                } elseif (isAssociativeArray($value)) {
                    $xml->startElement($key);
                    $bCloseElement = true;
                }
 
                if (is_numeric($key)) {
                    writeXmlFromArray($xml, $value, $sParentKey);
                } else {
                    writeXmlFromArray($xml, $value, $key);
                }
 
                if ($bCloseElement === true) {
                    $xml->endElement();
                    $bCloseElement = false;
                }
                continue;
            } elseif (is_numeric($key)) {
                $xml->writeElement($sParentKey, $value);
            } else {
                $xml->writeElement($key, $value);
            }
        }
    }
    return $xml;
}


Added code converts object (stdClass) to json, ensuring it can be handled by xmlwriter.

Please note that this is a manual fix that I made and is not part of the bug fixes provided by the Limesurvey developers. I cannot guarantee that this is the optimal solution, but only that it worked for me.
Last edit: 2 days 6 hours ago by bourginj.

Please Log in to join the conversation.

More
2 days 4 hours ago #273390 by holch
You might want to open a bug report at the bug tracker and provide this fix (if it still persists in the most recent LS 6.x of course).

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose