diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-07-23 18:34:17 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-07-23 18:34:17 +0200 |
commit | 9b1fe46fe995bc103d3c5cfa9a552d050ff0ead8 (patch) | |
tree | 7b86abb65272df89f61e849a08edef5326207b8a /db | |
parent | b88d42074dcd0842d0db3ca8ed24b0b9ccb78a7a (diff) |
Add timestamps for all entities in milisecond unix time format
Diffstat (limited to 'db')
-rw-r--r-- | db/feed.php | 2 | ||||
-rw-r--r-- | db/feedmapper.php | 5 | ||||
-rw-r--r-- | db/foldermapper.php | 5 | ||||
-rw-r--r-- | db/itemmapper.php | 6 | ||||
-rw-r--r-- | db/mapperfactory.php | 14 | ||||
-rw-r--r-- | db/mysql/itemmapper.php | 5 | ||||
-rw-r--r-- | db/newsmapper.php | 31 |
7 files changed, 50 insertions, 18 deletions
diff --git a/db/feed.php b/db/feed.php index 3a8444276..62d49c01b 100644 --- a/db/feed.php +++ b/db/feed.php @@ -80,6 +80,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable { protected $deletedAt; protected $articlesPerUpdate; protected $httpLastModified; + protected $lastModified; protected $httpEtag; protected $location; protected $ordering; @@ -104,6 +105,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable { $this->addType('fullTextEnabled', 'boolean'); $this->addType('updateMode', 'integer'); $this->addType('updateErrorCount', 'integer'); + $this->addType('lastModified', 'integer'); } diff --git a/db/feedmapper.php b/db/feedmapper.php index 93d919410..80d75e723 100644 --- a/db/feedmapper.php +++ b/db/feedmapper.php @@ -13,6 +13,7 @@ namespace OCA\News\Db; +use OCA\News\Utility\Time; use OCP\IDBConnection; use OCP\AppFramework\Db\Entity; @@ -20,8 +21,8 @@ use OCP\AppFramework\Db\Entity; class FeedMapper extends NewsMapper { - public function __construct(IDBConnection $db) { - parent::__construct($db, 'news_feeds', Feed::class); + public function __construct(IDBConnection $db, Time $time) { + parent::__construct($db, 'news_feeds', Feed::class, $time); } diff --git a/db/foldermapper.php b/db/foldermapper.php index 498b1b6f8..30acb455c 100644 --- a/db/foldermapper.php +++ b/db/foldermapper.php @@ -13,13 +13,14 @@ namespace OCA\News\Db; +use OCA\News\Utility\Time; use OCP\IDBConnection; use OCP\AppFramework\Db\Entity; class FolderMapper extends NewsMapper { - public function __construct(IDBConnection $db) { - parent::__construct($db, 'news_folders', Folder::class); + public function __construct(IDBConnection $db, Time $time) { + parent::__construct($db, 'news_folders', Folder::class, $time); } public function find($id, $userId){ diff --git a/db/itemmapper.php b/db/itemmapper.php index 220b4f153..091022c6c 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -14,16 +14,16 @@ namespace OCA\News\Db; use Exception; +use OCA\News\Utility\Time; use OCP\IDBConnection; class ItemMapper extends NewsMapper { - public function __construct(IDBConnection $db) { - parent::__construct($db, 'news_items', Item::class); + public function __construct(IDBConnection $db, Time $time) { + parent::__construct($db, 'news_items', Item::class, $time); } - private function makeSelectQuery($prependTo = '', $oldestFirst = false, $distinctFingerprint = false) { if ($oldestFirst) { diff --git a/db/mapperfactory.php b/db/mapperfactory.php index adcde6c4a..9e99e44bc 100644 --- a/db/mapperfactory.php +++ b/db/mapperfactory.php @@ -13,6 +13,7 @@ namespace OCA\News\Db; +use OCA\News\Utility\Time; use OCP\IDBConnection; use OCA\News\Db\Mysql\ItemMapper as MysqlItemMapper; @@ -23,18 +24,23 @@ class MapperFactory implements IFactory { private $dbType; private $db; + /** + * @var Time + */ + private $time; - public function __construct(IDBConnection $db, $databaseType) { + public function __construct(IDBConnection $db, $databaseType, Time $time) { $this->dbType = $databaseType; $this->db = $db; - } + $this->time = $time; + } public function build() { switch($this->dbType) { case 'mysql': - return new MysqlItemMapper($this->db); + return new MysqlItemMapper($this->db, $this->time); default: - return new ItemMapper($this->db); + return new ItemMapper($this->db, $this->time); } } diff --git a/db/mysql/itemmapper.php b/db/mysql/itemmapper.php index 633f13967..70eefe457 100644 --- a/db/mysql/itemmapper.php +++ b/db/mysql/itemmapper.php @@ -13,6 +13,7 @@ namespace OCA\News\Db\Mysql; +use OCA\News\Utility\Time; use OCP\IDBConnection; use OCA\News\Db\StatusFlag; @@ -20,8 +21,8 @@ use OCA\News\Db\StatusFlag; class ItemMapper extends \OCA\News\Db\ItemMapper { - public function __construct(IDBConnection $db){ - parent::__construct($db); + public function __construct(IDBConnection $db, Time $time){ + parent::__construct($db, $time); } diff --git a/db/newsmapper.php b/db/newsmapper.php index feef949e8..0acc252b9 100644 --- a/db/newsmapper.php +++ b/db/newsmapper.php @@ -5,26 +5,46 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Alessandro Cosentino 2012 * @copyright Bernhard Posselt 2012, 2014 */ namespace OCA\News\Db; +use OCA\News\Utility\Time; use OCP\IDBConnection; use OCP\AppFramework\Db\Mapper; +use OCP\AppFramework\Db\Entity; abstract class NewsMapper extends Mapper { - public function __construct(IDBConnection $db, $table, $entity) { + /** + * @var Time + */ + private $time; + + public function __construct(IDBConnection $db, $table, $entity, + Time $time) { parent::__construct($db, $table, $entity); + $this->time = $time; + } + + public function update(Entity $entity) { + $entity->setLastModified($this->time->getMicroTime()); + return parent::update($entity); + } + + public function insert(Entity $entity) { + $entity->setLastModified($this->time->getMicroTime()); + return parent::insert($entity); } /** - * @param int $id the id of the feed + * @param int $id the id of the feed * @param string $userId the id of the user + * * @return \OCP\AppFramework\Db\Entity */ abstract public function find($id, $userId); @@ -38,10 +58,11 @@ abstract class NewsMapper extends Mapper { * * @param array $search an assoc array from property to filter value * @param int $limit + * * @paran int $offset * @return array */ - public function where(array $search=[], $limit=null, $offset=null) { + public function where(array $search = [], $limit = null, $offset = null) { $entity = new $this->entityClass; // turn keys into sql query filter, e.g. feedId -> feed_id = :feedId |