diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/indexer.php | 14 | ||||
-rw-r--r-- | lib/plugins/importoldindex/action.php | 58 |
2 files changed, 71 insertions, 1 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 224c54311..12177406f 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -120,6 +120,18 @@ function runIndexer(){ global $conf; print "runIndexer(): started".NL; + // Move index files (if needed) + // Uses the importoldindex plugin to upgrade the index automatically. + // FIXME: Remove this from runIndexer when it is no longer needed. + if (@file_exists($conf['cachedir'].'/page.idx') && + (!@file_exists($conf['indexdir'].'/page.idx') || + !filesize($conf['indexdir'].'/page.idx')) && + !@file_exists($conf['indexdir'].'/index_importing')) { + echo "trigger TEMPORARY_INDEX_UPGRADE_EVENT\n"; + $tmp = array(); // no event data + trigger_event('TEMPORARY_INDEX_UPGRADE_EVENT', $tmp); + } + $ID = cleanID($_REQUEST['id']); if(!$ID) return false; @@ -233,7 +245,7 @@ function runSitemapper(){ return false; } - $pages = file($conf['cachedir'].'/page.idx'); + $pages = file($conf['indexdir'].'/page.idx'); print 'runSitemapper(): creating sitemap using '.count($pages).' pages'.NL; // build the sitemap diff --git a/lib/plugins/importoldindex/action.php b/lib/plugins/importoldindex/action.php new file mode 100644 index 000000000..26b37664c --- /dev/null +++ b/lib/plugins/importoldindex/action.php @@ -0,0 +1,58 @@ +<?php +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'action.php'); + +class action_plugin_importoldindex extends DokuWiki_Action_Plugin { + + function getInfo(){ + return array( + 'author' => 'Tom N Harris', + 'email' => 'tnharris@whoopdedo.org', + 'date' => '2006-11-09', + 'name' => 'Import Old Index', + 'desc' => 'Moves old index files to a new location, sorted by string length.', + 'url' => 'http://whoopdedo.org/doku/wiki' + ); + } + + function register(&$controller) { + $controller->register_hook('TEMPORARY_INDEX_UPGRADE_EVENT', 'BEFORE', $this, 'run_import'); + } + + function run_import(&$event, $args) { + global $conf; + + touch($conf['indexdir'].'/index_importing'); // changelog importing lock + // load old index + $word_idx = file($conf['cachedir'].'/word.idx'); + $idx = file($conf['cachedir'].'/index.idx'); + $words = array(); + for ($lno=0;$lno<count($word_idx);$lno++){ + $wlen = strlen($word_idx[$lno])-1; + //if($wlen<3) continue; + if(!isset($words[$wlen])) $words[$wlen] = array(); + $words[$wlen][] = $lno; + } + + foreach (array_keys($words) as $wlen) { + $new_words = array(); + $new_idx = array(); + foreach ($words[$wlen] as $lno) { + $new_words[] = $word_idx[$lno]; + $new_idx[] = $idx[$lno]; + } + io_saveFile($conf['indexdir']."/w$wlen.idx", implode('', $new_words)); + io_saveFile($conf['indexdir']."/i$wlen.idx", implode('', $new_idx)); + } + + @copy($conf['cachedir'].'/page.idx', $conf['indexdir'].'/page.idx'); + if($conf['fperm']) chmod($conf['indexdir'].'/page.idx', $conf['fperm']); + unlink($conf['indexdir'].'/index_importing'); // changelog importing unlock + plugin_disable('importoldindex'); // only needs to run once + } + +} + |