<![CDATA[ SimpleSearch/Newspublisher fix - My Forums]]> https://forums.modx.com/thread/?thread=99113 <![CDATA[SimpleSearch/Newspublisher fix]]> https://forums.modx.com/thread/99113/simplesearch-newspublisher-fix#dis-post-536009
Cannot redeclare SimpleSearchGetChildren() (previously declared in /path/to/core/cache/includes/elements/modplugin/2.include.cache.php:49) in /path/to/core/cache/includes/elements/modplugin/2.include.cache.php on line 62

which was this code:
function SimpleSearchGetChildren(&$modx,&$children,$parent) {
    $success = false;
    $kids = $modx->getCollection('modResource',array(
        'parent' => $parent,
    ));
    if (!empty($kids)) {
        /** @var modResource $kid */
        foreach ($kids as $kid) {
            $children[] = $kid->toArray();
            SimpleSearchGetChildren($modx,$children,$kid->get('id'));
        }
    }
    return $success;
}


so I wrapped it thusly:

if(!function_exists(SimpleSearchGetChildren)){
function SimpleSearchGetChildren(&$modx,&$children,$parent) {
    $success = false;
    $kids = $modx->getCollection('modResource',array(
        'parent' => $parent,
    ));
    if (!empty($kids)) {
        /** @var modResource $kid */
        foreach ($kids as $kid) {
            $children[] = $kid->toArray();
            SimpleSearchGetChildren($modx,$children,$kid->get('id'));
        }
    }
    return $success;
}
}



and it works fine now, hurray. However I know this is a cache file and am going to go hunt for the original/source so it doesnt get undone now. All direction gratefully accepted. I dont know if anyone else will have this issue but wanted to share just in case.

]]>
redtoad Dec 16, 2015, 01:20 PM https://forums.modx.com/thread/99113/simplesearch-newspublisher-fix#dis-post-536009