On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • 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 5 years, 5 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