From 29a9e6bbd13eb34a0edb2f3b66eebbac1315217c Mon Sep 17 00:00:00 2001 From: real_nowhereman Date: Mon, 8 Sep 2008 15:20:07 +0000 Subject: [PATCH] suppressing "file not found" errors for indices, fall back to 404 error; correctly return seek position when inserting into SBPlusTrees --- fp-includes/core/core.bplustree.class.php | 1 + fp-includes/core/core.entry.php | 21 +++++++++++++++++++-- fp-includes/core/core.fpdb.class.php | 22 ++++++++++++++++++---- setup/lib/step1.lib.php | 2 ++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/fp-includes/core/core.bplustree.class.php b/fp-includes/core/core.bplustree.class.php index ffd61d2..78319f3 100755 --- a/fp-includes/core/core.bplustree.class.php +++ b/fp-includes/core/core.bplustree.class.php @@ -2537,6 +2537,7 @@ class SBPlusTree extends BPlusTree { function setitem($key, $val) { $seek = $this->setstring($val); parent::setitem($key, $seek); + return $seek; } function walker( diff --git a/fp-includes/core/core.entry.php b/fp-includes/core/core.entry.php index f1f88a9..ce08198 100755 --- a/fp-includes/core/core.entry.php +++ b/fp-includes/core/core.entry.php @@ -6,6 +6,7 @@ var $nodesize = 30; var $keylen = 12; + /** * opens the index belonging to a given category * @params int $id_cat @@ -15,6 +16,7 @@ if (!file_exists($F)) { trigger_error ("Can't find index '{$F}'", E_USER_ERROR); + } parent::caching_SBPT( @@ -121,8 +123,8 @@ $main =& $this->get_index(); $main->delitem($key); - if (isset($entry['categories']) && is_array($entry['categories'])) { - foreach ($entry['categories'] as $cat) { + if (isset($entry['CATEGORIES']) && is_array($entry['CATEGORIES'])) { + foreach ($entry['CATEGORIES'] as $cat) { if (!is_numeric($cat)) continue; $this_index =& $this->get_index($cat); $this_index->delitem($key); @@ -323,6 +325,21 @@ return $entry_index; } + + function &entry_cached_index($id_cat) { + + $F = INDEX_DIR.'index-'.$id_cat.'.dat'; + + if (!file_exists($F)) { + $o = false; + } else { + $o =& new entry_cached_index($id_cat); + } + + return $o; + + } + /* function entry_query($params=array()){ diff --git a/fp-includes/core/core.fpdb.class.php b/fp-includes/core/core.fpdb.class.php index c2bb36a..99c4166 100644 --- a/fp-includes/core/core.fpdb.class.php +++ b/fp-includes/core/core.fpdb.class.php @@ -163,6 +163,15 @@ $fpdb->init(); $entry_index =& $fpdb->get_index($this->params->category); + + $this->counter++; + + if (!$entry_index) { + $this->params->start = 0; + $this->params->count = 0; + $this->pointer = 0; + return; + } if ($this->single) { $this->_prepare_single($entry_index); @@ -173,7 +182,6 @@ } } - $this->counter++; } @@ -324,7 +332,12 @@ function &peekEntry() { global $post; - + + if (!$this->hasMore()) { + $false = array(false, false); + return $false; + } + $qp =& $this->params; @@ -368,7 +381,8 @@ } if (!$cont) { - return false; + $cont = false; + return $cont; } if ($qp->comments) { @@ -563,7 +577,7 @@ function &get_index($cat_id = 0) { if (!isset($this->_indexer[$cat_id])) { - $this->_indexer[$cat_id] =& new entry_cached_index($cat_id); + $this->_indexer[$cat_id] =& entry_cached_index($cat_id); } return $this->_indexer[$cat_id]; } diff --git a/setup/lib/step1.lib.php b/setup/lib/step1.lib.php index b96d4ac..4429c4e 100644 --- a/setup/lib/step1.lib.php +++ b/setup/lib/step1.lib.php @@ -7,6 +7,8 @@ if(check_write(SETUPTEMP_FILE, 2)) { $r = fs_mkdir(CACHE_DIR); + + $r &= fs_mkdir(INDEX_DIR); $r &= fs_copy(CONFIG_DEFAULT, CONFIG_FILE);