/** * Caches links in the wiki page into database for faster "what links here" queries */ private function _update_link_cache() { $parser = new net_nemein_wiki_parser($this); $links_in_content = $parser->find_links_in_content(); $qb = net_nemein_wiki_link_dba::new_query_builder(); $qb->add_constraint('frompage', '=', $this->id); $links_in_db = $qb->execute(); $links_matched = array(); // Check links in DB versus links in content to see what needs to be removed foreach ($links_in_db as $link) { if (!array_key_exists($link->topage, $links_in_content)) { // This link is not any more in content, remove $link->delete(); continue; } $links_matched[$link->topage] = $link; } // Check links in content versus matched links to see what needs to be added foreach ($links_in_content as $wikilink => $label) { if (array_key_exists($wikilink, $links_matched)) { // This is already in DB, skip continue; } $link = new net_nemein_wiki_link_dba(); $link->frompage = $this->id; $link->topage = $wikilink; debug_add("Creating net_nemein_wiki_link_dba: from page #{$link->frompage}, to page: '{$link->topage}'"); $link->create(); } }