implement rewriteVotings() and unittest the method
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@448 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
03bc498eff
commit
bb5205053e
2 changed files with 33 additions and 4 deletions
|
@ -261,17 +261,18 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService
|
||||||
* Re-calculates all votings for all bookmarks
|
* Re-calculates all votings for all bookmarks
|
||||||
* and updates the voting values in the bookmarks
|
* and updates the voting values in the bookmarks
|
||||||
* table.
|
* table.
|
||||||
|
* This is mainly meant to be an administrative method
|
||||||
|
* to fix a broken database.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function rewriteVotings()
|
public function rewriteVotings()
|
||||||
{
|
{
|
||||||
throw new Exception('Not implemented yet');
|
|
||||||
//FIXME
|
|
||||||
$bm = SemanticScuttle_Service_Factory::get('Bookmark');
|
$bm = SemanticScuttle_Service_Factory::get('Bookmark');
|
||||||
$sql = 'UPDATE ' . $bm->getTableName() . ' as B SET bVoting = '
|
$query = 'UPDATE ' . $bm->getTableName() . ' as B SET bVoting = '
|
||||||
. '(SELECT SUM(vote) FROM ' . $this->getTableName() . ' as V'
|
. '(SELECT SUM(vote) FROM ' . $this->getTableName() . ' as V'
|
||||||
. ' WHERE V.bId = B.bId GROUP BY bid)';
|
. ' WHERE V.bId = B.bId GROUP BY bid)';
|
||||||
|
$this->db->sql_query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,34 @@ class VoteTest extends TestBase
|
||||||
$this->assertEquals(-1, $this->vs->getVote($bid, $uid));
|
$this->assertEquals(-1, $this->vs->getVote($bid, $uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that rewriting votings does work
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testRewriteVotings()
|
||||||
|
{
|
||||||
|
$uid = 1;
|
||||||
|
$bid = $this->addBookmark();
|
||||||
|
$this->assertTrue($this->vs->vote($bid, $uid, 1));
|
||||||
|
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
$this->assertEquals(1, $bm['bVoting']);
|
||||||
|
|
||||||
|
$this->vs->deleteAll();
|
||||||
|
//we assume that $vs->deleteAll() does *not* reset
|
||||||
|
//voting in bookmarks table
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
$this->assertEquals(1, $bm['bVoting']);
|
||||||
|
|
||||||
|
$this->vs->rewriteVotings();
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
//now it should be reset to 0
|
||||||
|
$this->assertEquals(0, $bm['bVoting']);
|
||||||
|
}
|
||||||
|
|
||||||
}//class VoteTest extends TestBase
|
}//class VoteTest extends TestBase
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue