core: Add item uid (#1017)

'uid' represents the unique id for a feed item. This item is null by
default and can be set to any string value. The provided string value
is always hashed to sha1 to make it the same length in all cases.

References #977, #1005
This commit is contained in:
LogMANOriginal 2019-02-03 20:56:41 +01:00 committed by GitHub
parent a29512deee
commit 394149b114
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 23 deletions

View file

@ -55,6 +55,9 @@ class FeedItem {
/** @var array List of category names or tags */
protected $categories = array();
/** @var string Unique ID for the current item */
protected $uid = null;
/** @var array Associative list of additional parameters */
protected $misc = array(); // Custom parameters
@ -391,6 +394,37 @@ class FeedItem {
return $this;
}
/**
* Get unique id
*
* Use {@see FeedItem::setUid()} to set the unique id.
*
* @param string The unique id.
*/
public function getUid() {
return $this->uid;
}
/**
* Set unique id.
*
* Use {@see FeedItem::getUid()} to get the unique id.
*
* @param string $uid A string that uniquely identifies the current item
* @return self
*/
public function setUid($uid) {
$this->uid = null; // Clear previous data
if(!is_string($uid)) {
Debug::log('Unique id must be a string!');
} else {
$this->uid = sha1($uid);
}
return $this;
}
/**
* Add miscellaneous elements to the item.
*
@ -426,6 +460,7 @@ class FeedItem {
'content' => $this->content,
'enclosures' => $this->enclosures,
'categories' => $this->categories,
'uid' => $this->uid,
), $this->misc
);
}
@ -454,6 +489,7 @@ class FeedItem {
case 'content': $this->setContent($value); break;
case 'enclosures': $this->setEnclosures($value); break;
case 'categories': $this->setCategories($value); break;
case 'uid': $this->setUid($value); break;
default: $this->addMisc($name, $value);
}
}
@ -476,6 +512,7 @@ class FeedItem {
case 'content': return $this->getContent();
case 'enclosures': return $this->getEnclosures();
case 'categories': return $this->getCategories();
case 'uid': return $this->getUid();
default:
if(array_key_exists($name, $this->misc))
return $this->misc[$name];