Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
60d9384e
Unverified
Commit
60d9384e
authored
5 years ago
by
Joas Schilling
Browse files
Options
Downloads
Patches
Plain Diff
Optionally write the reference id into the database
Signed-off-by:
Joas Schilling
<
coding@schilljs.com
>
parent
a20e81f0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/private/Comments/Manager.php
+61
-22
61 additions, 22 deletions
lib/private/Comments/Manager.php
with
61 additions
and
22 deletions
lib/private/Comments/Manager.php
+
61
−
22
View file @
60d9384e
...
...
@@ -29,6 +29,7 @@
namespace
OC\Comments
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Exception\InvalidFieldNameException
;
use
OCP\Comments\CommentsEvent
;
use
OCP\Comments\IComment
;
use
OCP\Comments\ICommentsEventHandler
;
...
...
@@ -745,23 +746,46 @@ class Manager implements ICommentsManager {
* @param IComment $comment
* @return bool
*/
protected
function
insert
(
IComment
&
$comment
)
{
protected
function
insert
(
IComment
$comment
):
bool
{
try
{
$result
=
$this
->
insertQuery
(
$comment
,
true
);
}
catch
(
InvalidFieldNameException
$e
)
{
// The reference id field was only added in Nextcloud 19.
// In order to not cause too long waiting times on the update,
// it was decided to only add it lazy, as it is also not a critical
// feature, but only helps to have a better experience while commenting.
// So in case the reference_id field is missing,
// we simply save the comment without that field.
$result
=
$this
->
insertQuery
(
$comment
,
false
);
}
return
$result
;
}
protected
function
insertQuery
(
IComment
$comment
,
bool
$tryWritingReferenceId
):
bool
{
$qb
=
$this
->
dbConn
->
getQueryBuilder
();
$affectedRows
=
$qb
->
insert
(
'comments'
)
->
values
([
'parent_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getParentId
()),
'topmost_parent_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getTopmostParentId
()),
'children_count'
=>
$qb
->
createNamedParameter
(
$comment
->
getChildrenCount
()),
'actor_type'
=>
$qb
->
createNamedParameter
(
$comment
->
getActorType
()),
'actor_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getActorId
()),
'message'
=>
$qb
->
createNamedParameter
(
$comment
->
getMessage
()),
'verb'
=>
$qb
->
createNamedParameter
(
$comment
->
getVerb
()),
'creation_timestamp'
=>
$qb
->
createNamedParameter
(
$comment
->
getCreationDateTime
(),
'datetime'
),
'latest_child_timestamp'
=>
$qb
->
createNamedParameter
(
$comment
->
getLatestChildDateTime
(),
'datetime'
),
'object_type'
=>
$qb
->
createNamedParameter
(
$comment
->
getObjectType
()),
'object_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getObjectId
()),
])
$values
=
[
'parent_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getParentId
()),
'topmost_parent_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getTopmostParentId
()),
'children_count'
=>
$qb
->
createNamedParameter
(
$comment
->
getChildrenCount
()),
'actor_type'
=>
$qb
->
createNamedParameter
(
$comment
->
getActorType
()),
'actor_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getActorId
()),
'message'
=>
$qb
->
createNamedParameter
(
$comment
->
getMessage
()),
'verb'
=>
$qb
->
createNamedParameter
(
$comment
->
getVerb
()),
'creation_timestamp'
=>
$qb
->
createNamedParameter
(
$comment
->
getCreationDateTime
(),
'datetime'
),
'latest_child_timestamp'
=>
$qb
->
createNamedParameter
(
$comment
->
getLatestChildDateTime
(),
'datetime'
),
'object_type'
=>
$qb
->
createNamedParameter
(
$comment
->
getObjectType
()),
'object_id'
=>
$qb
->
createNamedParameter
(
$comment
->
getObjectId
()),
];
if
(
$tryWritingReferenceId
)
{
$values
[
'reference_id'
]
=
$qb
->
createNamedParameter
(
$comment
->
getReferenceId
());
}
$affectedRows
=
$qb
->
insert
(
'comments'
)
->
values
(
$values
)
->
execute
();
if
(
$affectedRows
>
0
)
{
...
...
@@ -786,8 +810,21 @@ class Manager implements ICommentsManager {
$this
->
sendEvent
(
CommentsEvent
::
EVENT_PRE_UPDATE
,
$this
->
get
(
$comment
->
getId
()));
$this
->
uncache
(
$comment
->
getId
());
try
{
$result
=
$this
->
updateQuery
(
$comment
,
true
);
}
catch
(
InvalidFieldNameException
$e
)
{
// See function insert() for explanation
$result
=
$this
->
updateQuery
(
$comment
,
false
);
}
$this
->
sendEvent
(
CommentsEvent
::
EVENT_UPDATE
,
$comment
);
return
$result
;
}
protected
function
updateQuery
(
IComment
$comment
,
bool
$tryWritingReferenceId
):
bool
{
$qb
=
$this
->
dbConn
->
getQueryBuilder
();
$affectedRows
=
$qb
$qb
->
update
(
'comments'
)
->
set
(
'parent_id'
,
$qb
->
createNamedParameter
(
$comment
->
getParentId
()))
->
set
(
'topmost_parent_id'
,
$qb
->
createNamedParameter
(
$comment
->
getTopmostParentId
()))
...
...
@@ -799,17 +836,19 @@ class Manager implements ICommentsManager {
->
set
(
'creation_timestamp'
,
$qb
->
createNamedParameter
(
$comment
->
getCreationDateTime
(),
'datetime'
))
->
set
(
'latest_child_timestamp'
,
$qb
->
createNamedParameter
(
$comment
->
getLatestChildDateTime
(),
'datetime'
))
->
set
(
'object_type'
,
$qb
->
createNamedParameter
(
$comment
->
getObjectType
()))
->
set
(
'object_id'
,
$qb
->
createNamedParameter
(
$comment
->
getObjectId
()))
->
where
(
$qb
->
expr
()
->
eq
(
'id'
,
$qb
->
createParameter
(
'id'
)))
->
setParameter
(
'id'
,
$comment
->
getId
())
->
set
(
'object_id'
,
$qb
->
createNamedParameter
(
$comment
->
getObjectId
()));
if
(
$tryWritingReferenceId
)
{
$qb
->
set
(
'reference_id'
,
$qb
->
createNamedParameter
(
$comment
->
getReferenceId
()));
}
$affectedRows
=
$qb
->
where
(
$qb
->
expr
()
->
eq
(
'id'
,
$qb
->
createNamedParameter
(
$comment
->
getId
())))
->
execute
();
if
(
$affectedRows
===
0
)
{
throw
new
NotFoundException
(
'Comment to update does ceased to exist'
);
}
$this
->
sendEvent
(
CommentsEvent
::
EVENT_UPDATE
,
$comment
);
return
$affectedRows
>
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment