public function replace(ResourceNode $resource, ResourceIcon $icon)
    {
        $this->om->startFlushSuite();
        $oldIcon = $resource->getIcon();

        if (!$oldIcon->isShortcut()) {
            $oldShortcutIcon = $oldIcon->getShortcutIcon();
            $shortcutIcon = $icon->getShortcutIcon();

            if (!is_null($oldShortcutIcon) && !is_null($shortcutIcon)) {
                $nodes = $this->om->getRepository('ClarolineCoreBundle:Resource\ResourceNode')
                    ->findBy(array('icon' => $oldShortcutIcon));

                foreach ($nodes as $node) {
                    $node->setIcon($shortcutIcon);
                    $this->om->persist($node);
                }
            }
        }
        $this->delete($oldIcon);
        $resource->setIcon($icon);
        $this->om->persist($resource);
        $this->om->endFlushSuite();

        return $resource;
    }