-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public interfaces for Comments #20562
Changes from all commits
d43abd0
4005c03
ab8937b
d660c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?php | ||
|
||
namespace OCP\Comments; | ||
|
||
/** | ||
* Interface IComment | ||
* | ||
* This class represents a comment and offers methods for modification. | ||
* | ||
* @package OCP\Comments | ||
* @since 9.0.0 | ||
*/ | ||
interface IComment { | ||
|
||
/** | ||
* returns the ID of the comment | ||
* | ||
* It may return an empty string, if the comment was not stored. | ||
* It is expected that the concrete Comment implementation gives an ID | ||
* by itself (e.g. after saving). | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getId(); | ||
|
||
/** | ||
* sets the ID of the comment and returns itself | ||
* | ||
* It is only allowed to set the ID only, if the current id is an empty | ||
* string (which means it is not stored in a database, storage or whatever | ||
* the concrete implementation does), or vice versa. Changing a given ID is | ||
* not permitted and must result in an IllegalIDChangeException. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a thing for the constructor then? ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. For one and mainly, the ID is only available after save() is done, which is done by the manager and independent from IComment instantiation. Secondly, I prefer to keep the constructor open to the implementor. |
||
* | ||
* @param string $id | ||
* @return IComment | ||
* @throws IllegalIDChangeException | ||
* @since 9.0.0 | ||
*/ | ||
public function setId($id); | ||
|
||
/** | ||
* returns the parent ID of the comment | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getParentId(); | ||
|
||
/** | ||
* sets the parent ID and returns itself | ||
* | ||
* @param string $parentId | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setParentId($parentId); | ||
|
||
/** | ||
* returns the number of children | ||
* | ||
* @return int | ||
* @since 9.0.0 | ||
*/ | ||
public function getChildrenCount(); | ||
|
||
/** | ||
* sets the number of children | ||
* | ||
* @param int $count | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setChildrenCount($count); | ||
|
||
/** | ||
* returns the message of the comment | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getMessage(); | ||
|
||
/** | ||
* sets the message of the comment and returns itself | ||
* | ||
* @param string $message | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setMessage($message); | ||
|
||
/** | ||
* returns the verb of the comment | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getVerb(); | ||
|
||
/** | ||
* sets the verb of the comment, e.g. 'comment' or 'like' | ||
* | ||
* @param string $verb | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setVerb($verb); | ||
|
||
/** | ||
* returns the actor type | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getActorType(); | ||
|
||
/** | ||
* returns the actor ID | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getActorId(); | ||
|
||
/** | ||
* sets (overwrites) the actor type and id | ||
* | ||
* @param string $actorType e.g. 'user' | ||
* @param string $actorId e.g. 'zombie234' | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setActor($actorType, $actorId); | ||
|
||
/** | ||
* returns the creation date of the comment. | ||
* | ||
* If not explicitly set, it shall default to the time of initialization. | ||
* | ||
* @return \DateTime | ||
* @since 9.0.0 | ||
*/ | ||
public function getCreationDateTime(); | ||
|
||
/** | ||
* sets the creation date of the comment and returns itself | ||
* | ||
* @param \DateTime $dateTime | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setCreationDateTime(\DateTime $dateTime); | ||
|
||
/** | ||
* returns the date of the most recent child | ||
* | ||
* @return \DateTime | ||
* @since 9.0.0 | ||
*/ | ||
public function getLatestChildDateTime(); | ||
|
||
/** | ||
* sets the date of the most recent child | ||
* | ||
* @param \DateTime $dateTime | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setLatestChildDateTime(\DateTime $dateTime); | ||
|
||
/** | ||
* returns the object type the comment is attached to | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getObjectType(); | ||
|
||
/** | ||
* returns the object id the comment is attached to | ||
* | ||
* @return string | ||
* @since 9.0.0 | ||
*/ | ||
public function getObjectId(); | ||
|
||
/** | ||
* sets (overwrites) the object of the comment | ||
* | ||
* @param string $objectType e.g. 'file' | ||
* @param string $objectId e.g. '16435' | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function setObject($objectType, $objectId); | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
namespace OCP\Comments; | ||
|
||
/** | ||
* Interface ICommentsManager | ||
* | ||
* This class manages the access to comments | ||
* | ||
* @package OCP\Comments | ||
* @since 9.0.0 | ||
*/ | ||
interface ICommentsManager { | ||
|
||
/** | ||
* returns a comment instance | ||
* | ||
* @param string $id the ID of the comment | ||
* @return IComment | ||
* @throws NotFoundException | ||
* @since 9.0.0 | ||
*/ | ||
public function get($id); | ||
|
||
/** | ||
* returns the comment specified by the id and all it's child comments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sounds expensive, should have a limit for both, the nesting depth and the number of children. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mkes sense, if there should be really a lot of comments – we should assume that. Offering a limit also requires offering an offset. This complicates things though, because of the hierarchy. We'd need always need to start from the beginning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought about it. Since we agreed that nesting level of 1 is maximum that makes sense, this is not a problem. Then, we do not need a parameter for nesting depth either. However, if we want to keep the possibility of deeper threads open, we also need to provide a topmostparentid to our data model. OTOH we ought to keep this possibility… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add it anyway to support potential threaded approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still feeling unhappy about the depth parameter. Will sleep the weekend over it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still unhappy ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Respecting $depth with our DB scheme will be expensive, because we cannot just have our nice query and add limit and offset parameters, because we cannot select any depth level. Except, we also write the hierarchy level in to the database (and the IComment interface). Would require to adjust the DB scheme again, but this would make me happy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added #20622 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed with @DeepDiver1975 we will leave the depth out for now, because we do not really have a use case for this. We might add another method to read hierarchy levels in on of the next releases if necessary. Which makes the new columns also unnecessary. |
||
* | ||
* @param string $id | ||
* @param int $limit max number of entries to return, 0 returns all | ||
* @param int $offset the start entry | ||
* @return [] | ||
* @since 9.0.0 | ||
* | ||
* The return array looks like this | ||
* [ | ||
* 'comment' => IComment, // root comment | ||
* 'replies' => | ||
* [ | ||
* 0 => | ||
* [ | ||
* 'comment' => IComment, | ||
* 'replies' => | ||
* [ | ||
* 0 => | ||
* [ | ||
* 'comment' => IComment, | ||
* 'replies' => [ … ] | ||
* ], | ||
* … | ||
* ] | ||
* ] | ||
* 1 => | ||
* [ | ||
* 'comment' => IComment, | ||
* 'replies'=> [ … ] | ||
* ], | ||
* … | ||
* ] | ||
* ] | ||
*/ | ||
public function getTree($id, $limit = 0, $offset = 0); | ||
|
||
/** | ||
* returns comments for a specific object (e.g. a file). | ||
* | ||
* The sort order is always newest to oldest. | ||
* | ||
* @param string $objectType the object type, e.g. 'files' | ||
* @param string $objectId the id of the object | ||
* @param int $limit optional, number of maximum comments to be returned. if | ||
* not specified, all comments are returned. | ||
* @param int $offset optional, starting point | ||
* @param \DateTime $notOlderThan optional, timestamp of the oldest comments | ||
* that may be returned | ||
* @return IComment[] | ||
* @throws NotFoundException in case the requested type or id is not present | ||
* @since 9.0.0 | ||
*/ | ||
public function getForObject( | ||
$objectType, | ||
$objectId, | ||
$limit = 0, | ||
$offset = 0, | ||
\DateTime $notOlderThan = null | ||
); | ||
|
||
/** | ||
* @param $objectType string the object type, e.g. 'files' | ||
* @param $objectId string the id of the object | ||
* @return Int | ||
* @throws NotFoundException in case the requested type or id is not present | ||
* @since 9.0.0 | ||
*/ | ||
public function getNumberOfCommentsForObject($objectType, $objectId); | ||
|
||
/** | ||
* creates a new comment and returns it. At this point of time, it is not | ||
* saved in the used data storage. Use save() after setting other fields | ||
* of the comment (e.g. message or verb). | ||
* | ||
* @param string $actorType the actor type (e.g. 'user') | ||
* @param string $actorId a user id | ||
* @param string $objectType the object type the comment is attached to | ||
* @param string $objectId the object id the comment is attached to | ||
* @return IComment | ||
* @since 9.0.0 | ||
*/ | ||
public function create($actorType, $actorId, $objectType, $objectId); | ||
|
||
/** | ||
* permanently deletes the comment specified by the ID | ||
* | ||
* When the comment has child comments, their parent ID will be changed to | ||
* the parent ID of the item that is to be deleted. | ||
* | ||
* @param string $id | ||
* @return bool | ||
* @since 9.0.0 | ||
*/ | ||
public function delete($id); | ||
|
||
/** | ||
* saves the comment permanently and returns it | ||
* | ||
* if the supplied comment has an empty ID, a new entry comment will be | ||
* saved and the instance updated with the new ID. | ||
* | ||
* Otherwise, an existing comment will be updated. | ||
* | ||
* Throws NotFoundException when a comment that is to be updated does not | ||
* exist anymore at this point of time. | ||
* | ||
* @param IComment | ||
* @return bool | ||
* @throws NotFoundException | ||
* @since 9.0.0 | ||
*/ | ||
public function save(&$comment); | ||
|
||
/** | ||
* removes references to specific actor (e.g. on user delete) of a comment. | ||
* The comment itself must not get lost/deleted. | ||
* | ||
* @param string $actorType the actor type (e.g. 'user') | ||
* @param string $actorId a user id | ||
* @return boolean | ||
* @since 9.0.0 | ||
*/ | ||
public function deleteReferencesOfActor($actorType, $actorId); | ||
|
||
/** | ||
* deletes all comments made of a specific object (e.g. on file delete) | ||
* | ||
* @param string $objectType the object type (e.g. 'file') | ||
* @param string $objectId e.g. the file id | ||
* @return boolean | ||
* @since 9.0.0 | ||
*/ | ||
public function deleteCommentsAtObject($objectType, $objectId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doc looks wrong, object vs actor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, did not adjust after paste'n'copy |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace OCP\Comments; | ||
|
||
/** | ||
* Exception for illegal attempts to modify a comment ID | ||
* @since 9.0.0 | ||
*/ | ||
class IllegalIDChangeException extends \Exception {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace OCP\Comments; | ||
|
||
/** | ||
* Exception for not found entity | ||
* @since 9.0.0 | ||
*/ | ||
class NotFoundException extends \Exception {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PHPdoc here, especially
@since 9.0.0