We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Hi. So I'm working on an admin tool with newspublisher (allowing duplication of a resource from the front end) and found that when I hit duplicate resource I got

    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.

    [ed. note: redtoad last edited this post 8 years, 4 months ago.]
      ________

      Anne
      Toad-in-Chief
      Red Toad Media - Web Design, Louisville KY
      Hear me tweet: http://www.twitter.com/redtoadmedia
      "Bring on the imperialistic condiments." - Rory Gilmore