/** * @brief Save the feed and all its items into the database * @returns The id of the feed in the database table. */ public function save(Item $item, $feedid) { $guid = $item->getGuid(); $guid_hash = md5($guid); $status = $item->getStatus(); $itemid = $this->findIdFromGuid($guid_hash, $guid, $feedid); if ($itemid == null) { $title = $item->getTitle(); $body = $item->getBody(); $author = $item->getAuthor(); $enclosure_mime = null; $enclosure_link = null; if ($enclosure = $item->getEnclosure()) { $enclosure_mime = $enclosure->getMimeType(); $enclosure_link = $enclosure->getLink(); } $stmt = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(url, title, body, author, guid, guid_hash, pub_date, enclosure_mime, enclosure_link, feed_id, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '); if (empty($title)) { $l = \OC_L10N::get('news'); $title = $l->t('no title'); } if (empty($body)) { $l = \OC_L10N::get('news'); $body = $l->t('no body'); } $pub_date = Utils::unixtimeToDbtimestamp($item->getDate()); $params = array($item->getUrl(), $title, $body, $author, $guid, $guid_hash, $pub_date, $enclosure_mime, $enclosure_link, $feedid, $status); $stmt->execute($params); $itemid = \OCP\DB::insertid(self::tableName); } else { $this->update($item); } $item->setId($itemid); return $itemid; }