public function processCMSNavItems(Plugin $plugin, &$log = '', $xml = false)
    {
        if (!$xml)
            $xml = $this->loadXML($plugin->Path);

        if(!$xml)
            throw new Exception('Missing plugin.xml file for plugin ['.$plugin->Slug.']');

        $processedSlugs = array();
        // add cmsnavitems
        $navitems = $xml->cmsnavitems;
        if (!empty($navitems)) {
            foreach ( $navitems->item as $xml_item ) {
                $cms_nav_item = new CMSNavItem();
                $this->ModelMapper->defaultsOnModel($cms_nav_item);
                $cms_nav_item = $this->SystemXMLConverter->xmlToCMSNavItem($cms_nav_item, $xml_item);

                if ($this->insertCMSNavItem($cms_nav_item, $plugin)) {
                    $log .= "CMSNavItem created...\n";
                    $log .= "ID: {$cms_nav_item->CMSNavItemID}\n";
                    $log .= "Slug: {$cms_nav_item->Slug}\n";
                    $log .= "Label: {$cms_nav_item->Label}\n";
                    $log .= "URI: {$cms_nav_item->URI}\n";
                    $log .= "\n";
                }

                $processedSlugs[] = $cms_nav_item->Slug;
                foreach($cms_nav_item->getChildren() as $child) {
                    if ($this->insertCMSNavItem($child, $plugin)) {
                        $log .= "CMSNavItem created...\n";
                        $log .= "ID: {$child->CMSNavItemID}\n";
                        $log .= "Slug: {$child->Slug}\n";
                        $log .= "Label: {$child->Label}\n";
                        $log .= "URI: {$child->URI}\n";
                        $log .= "\n";
                    }

                    $processedSlugs[] = $child->Slug;
                }
            }
        }

        if($plugin->PluginID == '')
            return;

        $existing = $this->CMSNavItemService->findAll(new DTO(array('PluginID' => $plugin->PluginID)))->getResults();
        foreach($existing as $e)
        {
            if(!in_array($e->Slug, $processedSlugs))
                $this->CMSNavItemService->delete($e->Slug);
        }

    }