summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-03-20 14:41:31 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-03-21 13:36:50 +0100
commit953b030e2678ce45d2f182c181ef2190f39d161d (patch)
tree0337988efca9bf3b714ca9af5e95e188d6ddb260
parent03ce3af3a51f51852cd0a3f06872fc36d7f62dfb (diff)
generate an index
-rw-r--r--appinfo/application.php2
-rw-r--r--appinfo/database.xml4
-rw-r--r--appinfo/info.xml2
-rw-r--r--db/feedmapper.php6
-rw-r--r--db/foldermapper.php6
-rw-r--r--db/item.php11
-rw-r--r--db/itemmapper.php4
-rw-r--r--db/mapperfactory.php4
-rw-r--r--db/mysql/itemmapper.php6
-rw-r--r--db/newsmapper.php8
-rw-r--r--fetcher/feedfetcher.php2
-rw-r--r--tests/unit/db/ItemTest.php12
-rw-r--r--tests/unit/db/mappertestutility.php73
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php1
14 files changed, 95 insertions, 46 deletions
diff --git a/appinfo/application.php b/appinfo/application.php
index dfbd81be4..428cd0e3a 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -52,7 +52,7 @@ class Application extends App {
*/
$container->registerService('OCA\News\Db\ItemMapper', function($c) {
return $c->query('OCA\News\Db\MapperFactory')->getItemMapper(
- $c->query('OCP\IDb')
+ $c->query('OCP\IDBConnection')
);
});
diff --git a/appinfo/database.xml b/appinfo/database.xml
index c2277d276..a500d538f 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -209,6 +209,10 @@
<length>32</length>
</field>
<field>
+ <name>search_index</name>
+ <type>clob</type>
+ </field>
+ <field>
<name>guid</name>
<type>clob</type>
<notnull>true</notnull>
diff --git a/appinfo/info.xml b/appinfo/info.xml
index a372ffa21..0744def15 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -7,7 +7,7 @@
<author>Bernhard Posselt, Alessandro Cosentino, Jan-Christoph Borchardt</author>
<category>multimedia</category>
<licence>AGPL</licence>
- <version>5.2.8</version>
+ <version>5.2.9</version>
<namespace>News</namespace>
<!-- resources -->
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 0d00057d3..479cead28 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -13,14 +13,14 @@
namespace OCA\News\Db;
-use \OCP\IDb;
-use \OCP\AppFramework\Db\Entity;
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\Entity;
class FeedMapper extends NewsMapper {
- public function __construct(IDb $db) {
+ public function __construct(IDBConnection $db) {
parent::__construct($db, 'news_feeds', '\OCA\News\Db\Feed');
}
diff --git a/db/foldermapper.php b/db/foldermapper.php
index f2a2ff68d..867e05493 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -13,12 +13,12 @@
namespace OCA\News\Db;
-use \OCP\IDb;
-use \OCP\AppFramework\Db\Entity;
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\Entity;
class FolderMapper extends NewsMapper {
- public function __construct(IDb $db) {
+ public function __construct(IDBConnection $db) {
parent::__construct($db, 'news_folders', '\OCA\News\Db\Folder');
}
diff --git a/db/item.php b/db/item.php
index 24cc45de1..8c555db86 100644
--- a/db/item.php
+++ b/db/item.php
@@ -57,6 +57,7 @@ class Item extends Entity implements IAPI, \JsonSerializable {
protected $feedId;
protected $status = 0;
protected $lastModified;
+ protected $searchIndex;
public function __construct(){
$this->addType('pubDate', 'integer');
@@ -196,6 +197,16 @@ class Item extends Entity implements IAPI, \JsonSerializable {
parent::setTitle(strip_tags($title));
}
+ public function generateSearchIndex() {
+ $this->setSearchIndex(
+ strtolower(
+ strip_tags($this->getBody()) .
+ $this->getAuthor() .
+ $this->getTitle() .
+ $this->getUrl()
+ )
+ );
+ }
public function setUrl($url) {
$url = trim($url);
diff --git a/db/itemmapper.php b/db/itemmapper.php
index a41ecfd66..cc34ddd9d 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -13,12 +13,12 @@
namespace OCA\News\Db;
-use \OCP\IDb;
+use \OCP\IDBConnection;
class ItemMapper extends NewsMapper {
- public function __construct(IDb $db){
+ public function __construct(IDBConnection $db){
parent::__construct($db, 'news_items', '\OCA\News\Db\Item');
}
diff --git a/db/mapperfactory.php b/db/mapperfactory.php
index 0b26574dc..6704842e4 100644
--- a/db/mapperfactory.php
+++ b/db/mapperfactory.php
@@ -13,7 +13,7 @@
namespace OCA\News\Db;
-use \OCP\IDb;
+use \OCP\IDBConnection;
use \OCA\News\Db\Mysql\ItemMapper as MysqlItemMapper;
class MapperFactory {
@@ -21,7 +21,7 @@ class MapperFactory {
private $dbType;
private $db;
- public function __construct($DatabaseType, IDb $db) {
+ public function __construct($DatabaseType, IDBConnection $db) {
$this->dbType = $DatabaseType;
$this->db = $db;
}
diff --git a/db/mysql/itemmapper.php b/db/mysql/itemmapper.php
index c58036350..61d32a821 100644
--- a/db/mysql/itemmapper.php
+++ b/db/mysql/itemmapper.php
@@ -13,14 +13,14 @@
namespace OCA\News\Db\Mysql;
-use \OCP\IDb;
+use OCP\IDBConnection;
-use \OCA\News\Db\StatusFlag;
+use OCA\News\Db\StatusFlag;
class ItemMapper extends \OCA\News\Db\ItemMapper {
- public function __construct(IDb $db){
+ public function __construct(IDBConnection $db){
parent::__construct($db);
}
diff --git a/db/newsmapper.php b/db/newsmapper.php
index c483bd329..d946a28a6 100644
--- a/db/newsmapper.php
+++ b/db/newsmapper.php
@@ -13,13 +13,13 @@
namespace OCA\News\Db;
-use \OCP\IDb;
-use \OCP\AppFramework\Db\Entity;
-use \OCP\AppFramework\Db\Mapper;
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\Entity;
+use OCP\AppFramework\Db\Mapper;
abstract class NewsMapper extends Mapper {
- public function __construct(IDb $db, $table, $entity) {
+ public function __construct(IDBConnection $db, $table, $entity) {
parent::__construct($db, $table, $entity);
}
diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php
index 815c0e4f4..2d3cdb0ba 100644
--- a/fetcher/feedfetcher.php
+++ b/fetcher/feedfetcher.php
@@ -172,6 +172,8 @@ class FeedFetcher implements IFeedFetcher {
}
}
+ $item->generateSearchIndex();
+
return $item;
}
diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php
index c937053d1..719e8d5da 100644
--- a/tests/unit/db/ItemTest.php
+++ b/tests/unit/db/ItemTest.php
@@ -186,6 +186,18 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
}
+ public function testSearchIndex() {
+ $item = new Item();
+ $item->setBody('<a>somEthing</a>');
+ $item->setUrl('http://link');
+ $item->setAuthor('author');
+ $item->setTitle('<a>title</a>');
+ $item->generateSearchIndex();
+ $expected = 'somethingauthortitlehttp://link';
+ $this->assertEquals($expected, $item->getSearchIndex());
+ }
+
+
public function testFromImport() {
$item = $this->createImportItem(false);
diff --git a/tests/unit/db/mappertestutility.php b/tests/unit/db/mappertestutility.php
index cba2aadd6..de07f136c 100644
--- a/tests/unit/db/mappertestutility.php
+++ b/tests/unit/db/mappertestutility.php
@@ -45,7 +45,7 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
parent::setUp();
$this->db = $this->getMockBuilder(
- '\OCP\IDb')
+ '\OCP\IDBConnection')
->disableOriginalConstructor()
->getMock();
@@ -56,6 +56,30 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
$this->fetchAt = 0;
}
+ /**
+ * Checks if an array is associative
+ * @param array $array
+ * @return bool true if associative
+ */
+ private function isAssocArray(array $array) {
+ return array_values($array) !== $array;
+ }
+
+ /**
+ * Returns the correct PDO constant based on the value type
+ * @param $value
+ * @return PDO constant
+ */
+ private function getPDOType($value) {
+ switch (gettype($value)) {
+ case 'integer':
+ return \PDO::PARAM_INT;
+ case 'boolean':
+ return \PDO::PARAM_BOOL;
+ default:
+ return \PDO::PARAM_STR;
+ }
+ }
/**
* Create mocks and set expected results for database queries
@@ -116,32 +140,28 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
}
));
- $index = 1;
- foreach($arguments as $argument) {
- switch (gettype($argument)) {
- case 'integer':
- $pdoConstant = \PDO::PARAM_INT;
- break;
-
- case 'NULL':
- $pdoConstant = \PDO::PARAM_NULL;
- break;
-
- case 'boolean':
- $pdoConstant = \PDO::PARAM_BOOL;
- break;
-
- default:
- $pdoConstant = \PDO::PARAM_STR;
- break;
+ if ($this->isAssocArray($arguments)) {
+ foreach($arguments as $key => $argument) {
+ $pdoConstant = $this->getPDOType($argument);
+ $this->query->expects($this->at($this->queryAt))
+ ->method('bindValue')
+ ->with($this->equalTo($key),
+ $this->equalTo($argument),
+ $this->equalTo($pdoConstant));
+ $this->queryAt++;
+ }
+ } else {
+ $index = 1;
+ foreach($arguments as $argument) {
+ $pdoConstant = $this->getPDOType($argument);
+ $this->query->expects($this->at($this->queryAt))
+ ->method('bindValue')
+ ->with($this->equalTo($index),
+ $this->equalTo($argument),
+ $this->equalTo($pdoConstant));
+ $index++;
+ $this->queryAt++;
}
- $this->query->expects($this->at($this->queryAt))
- ->method('bindValue')
- ->with($this->equalTo($index),
- $this->equalTo($argument),
- $this->equalTo($pdoConstant));
- $index++;
- $this->queryAt++;
}
$this->query->expects($this->at($this->queryAt))
@@ -186,4 +206,3 @@ class ArgumentIterator {
}
}
}
-
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index b0320de4b..e1a3997ac 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -217,6 +217,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
$item->setGuidHash($this->guid);
$item->setBody($this->body);
$item->setLastModified($this->time);
+ $item->generateSearchIndex();
$this->expectItem('getAuthor', $this->author);
$item->setAuthor(html_entity_decode($this->author));