database and multi-post retrieval fixes

This commit is contained in:
John Bintz 2010-02-24 21:29:41 -05:00
parent cd64fbf416
commit bc2bc475d4
3 changed files with 39 additions and 10 deletions

View File

@ -101,6 +101,7 @@ class ComicPressDBInterface {
$op = ($next ? '>' : '<'); $op = ($next ? '>' : '<');
$order = ($next ? 'ASC' : 'DESC'); $order = ($next ? 'ASC' : 'DESC');
$cats = implode(',', $categories);
$query = $wpdb->prepare("SELECT p.* FROM $wpdb->posts AS p $query = $wpdb->prepare("SELECT p.* FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id
@ -109,10 +110,9 @@ class ComicPressDBInterface {
AND p.post_type = 'post' AND p.post_type = 'post'
AND p.post_status = 'publish' AND p.post_status = 'publish'
AND tt.taxonomy = 'category' AND tt.taxonomy = 'category'
AND tt.term_id IN (%s) AND tt.term_id IN (${cats})
ORDER BY p.post_date ${order} LIMIT %d", ORDER BY p.post_date ${order} LIMIT %d",
$post_to_use->post_date, $post_to_use->post_date,
implode(',', $categories),
$count); $count);
$query_key = 'comicpress_adjacent_post_' . md5($query); $query_key = 'comicpress_adjacent_post_' . md5($query);

View File

@ -110,8 +110,11 @@ class ComicPressTagBuilder {
$this->parent_post = $parent_post; $this->parent_post = $parent_post;
} }
public function _setup_postdata($post) { public function _setup_postdata($p) {
setup_postdata($post); global $post;
$post = $p;
setup_postdata($p);
} }
public function _new_comicpresscomicpost($post) { public function _new_comicpresscomicpost($post) {
@ -194,9 +197,19 @@ class ComicPressTagBuilder {
if ($count < 2) { if ($count < 2) {
$count = false; $count = false;
} }
$result = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post, $count); $result = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post, $count);
if ($count > 1) {
if (is_array($result)) { if (is_array($result)) {
return $result; return $result;
} else {
if (is_object($result)) {
return array($result);
} else {
return array();
}
}
} else { } else {
$this->post = $result; $this->post = $result;
} }

View File

@ -79,7 +79,23 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
), ),
array('get_next_post', array(1), $p, 3), array('get_next_post', array(1), $p, 3),
false, false,
true array('test')
),
array(
array(
array('next', 3)
),
array('get_next_post', array(1), $p, 3),
false,
(object)array('test' => 'test2')
),
array(
array(
array('next', 3)
),
array('get_next_post', array(1), $p, 3),
false,
"string"
), ),
array( array(
array( array(
@ -94,7 +110,7 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
/** /**
* @dataProvider providerTestBuilder * @dataProvider providerTestBuilder
*/ */
function testStorylineBuilder($instructions, $expected_dbi_call, $expects_setup_postdata = false, $returns_array = false) { function testStorylineBuilder($instructions, $expected_dbi_call, $expects_setup_postdata = false, $returns_override = null) {
global $post, $wp_test_expectations; global $post, $wp_test_expectations;
$post = (object)array('ID' => 1); $post = (object)array('ID' => 1);
@ -110,8 +126,8 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
call_user_func(array($expectation, 'will'), $this->returnValue('new-post')); call_user_func(array($expectation, 'will'), $this->returnValue('new-post'));
} }
if ($returns_array) { if (!empty($returns_override)) {
call_user_func(array($expectation, 'will'), $this->returnValue(array('new-post'))); call_user_func(array($expectation, 'will'), $this->returnValue($returns_override));
} }
$core = new ComicPressTagBuilderFactory($dbi); $core = new ComicPressTagBuilderFactory($dbi);