Completed
Push — master ( 43a8fc...7ac4eb )
by Joas
25:05 queued 05:06
created
lib/private/Comments/Manager.php 1 patch
Indentation   +1546 added lines, -1546 removed lines patch added patch discarded remove patch
@@ -30,1550 +30,1550 @@
 block discarded – undo
30 30
 use Psr\Log\LoggerInterface;
31 31
 
32 32
 class Manager implements ICommentsManager {
33
-	/** @var IComment[] */
34
-	protected array $commentsCache = [];
35
-
36
-	/** @var \Closure[] */
37
-	protected array $eventHandlerClosures = [];
38
-
39
-	/** @var ICommentsEventHandler[] */
40
-	protected array $eventHandlers = [];
41
-
42
-	/** @var \Closure[] */
43
-	protected array $displayNameResolvers = [];
44
-
45
-	public function __construct(
46
-		protected IDBConnection $dbConn,
47
-		protected LoggerInterface $logger,
48
-		protected IConfig $config,
49
-		protected ITimeFactory $timeFactory,
50
-		protected IEmojiHelper $emojiHelper,
51
-		protected IInitialStateService $initialStateService,
52
-		protected IRootFolder $rootFolder,
53
-		protected IEventDispatcher $eventDispatcher,
54
-	) {
55
-	}
56
-
57
-	/**
58
-	 * converts data base data into PHP native, proper types as defined by
59
-	 * IComment interface.
60
-	 *
61
-	 * @param array $data
62
-	 */
63
-	protected function normalizeDatabaseData(array $data): array {
64
-		$data['id'] = (string)$data['id'];
65
-		$data['parent_id'] = (string)$data['parent_id'];
66
-		$data['topmost_parent_id'] = (string)$data['topmost_parent_id'];
67
-		$data['creation_timestamp'] = new \DateTime($data['creation_timestamp']);
68
-		if (!is_null($data['latest_child_timestamp'])) {
69
-			$data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']);
70
-		}
71
-		if (!is_null($data['expire_date'])) {
72
-			$data['expire_date'] = new \DateTime($data['expire_date']);
73
-		}
74
-		$data['children_count'] = (int)$data['children_count'];
75
-		$data['reference_id'] = $data['reference_id'];
76
-		$data['meta_data'] = json_decode($data['meta_data'], true);
77
-		if ($this->supportReactions()) {
78
-			if ($data['reactions'] !== null) {
79
-				$list = json_decode($data['reactions'], true);
80
-				// Ordering does not work on the database with group concat and Oracle,
81
-				// So we simply sort on the output.
82
-				if (is_array($list)) {
83
-					uasort($list, static function ($a, $b) {
84
-						if ($a === $b) {
85
-							return 0;
86
-						}
87
-						return ($a > $b) ? -1 : 1;
88
-					});
89
-					$data['reactions'] = $list;
90
-				} else {
91
-					$data['reactions'] = [];
92
-				}
93
-			} else {
94
-				$data['reactions'] = [];
95
-			}
96
-		}
97
-		return $data;
98
-	}
99
-
100
-	public function getCommentFromData(array $data): IComment {
101
-		return new Comment($this->normalizeDatabaseData($data));
102
-	}
103
-
104
-	/**
105
-	 * prepares a comment for an insert or update operation after making sure
106
-	 * all necessary fields have a value assigned.
107
-	 *
108
-	 * @param IComment $comment
109
-	 * @return IComment returns the same updated IComment instance as provided
110
-	 *                  by parameter for convenience
111
-	 * @throws \UnexpectedValueException
112
-	 */
113
-	protected function prepareCommentForDatabaseWrite(IComment $comment): IComment {
114
-		if (!$comment->getActorType()
115
-			|| $comment->getActorId() === ''
116
-			|| !$comment->getObjectType()
117
-			|| $comment->getObjectId() === ''
118
-			|| !$comment->getVerb()
119
-		) {
120
-			throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving');
121
-		}
122
-
123
-		if ($comment->getVerb() === 'reaction' && !$this->emojiHelper->isValidSingleEmoji($comment->getMessage())) {
124
-			// 4 characters: laptop + person + gender + skin color => "
Please login to merge, or discard this patch.