Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
155
Issues
155
List
Boards
Labels
Service Desk
Milestones
Merge Requests
40
Merge Requests
40
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
5a36078a
Commit
5a36078a
authored
13 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(fix): debit on duplicate boosts should not happen
parent
e8162f59
master
No related merge requests found
Pipeline
#66600982 (#760)
failed with stages
in 6 minutes and 5 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
46 deletions
+54
-46
boost.php
Controllers/api/v2/boost.php
+8
-0
Manager.php
Core/Boost/Network/Manager.php
+18
-12
ManagerSpec.php
Spec/Core/Boost/Network/ManagerSpec.php
+28
-34
No files found.
Controllers/api/v2/boost.php
View file @
5a36078a
...
...
@@ -275,6 +275,7 @@ class boost implements Interfaces\Api
$state
=
'pending'
;
}
/** @var Network\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Boost\Network\Manager'
);
$boost
=
(
new
Network\Boost
())
...
...
@@ -289,6 +290,13 @@ class boost implements Interfaces\Api
->
setType
(
lcfirst
(
$pages
[
0
]))
->
setPriority
(
false
);
if
(
$manager
->
checkExisting
(
$boost
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
"There's already an ongoing boost for this entity"
]);
}
// Pre-set GUID
if
(
$bidType
==
'tokens'
&&
isset
(
$_POST
[
'guid'
]))
{
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/Manager.php
View file @
5a36078a
...
...
@@ -121,18 +121,6 @@ class Manager
*/
public
function
add
(
$boost
)
{
$existingBoost
=
$this
->
getList
([
'useElastic'
=>
true
,
'state'
=>
'review'
,
'type'
=>
$boost
->
getType
(),
'entity_guid'
=>
$boost
->
getEntityGuid
(),
'limit'
=>
1
]);
if
(
$existingBoost
->
count
()
>
0
)
{
throw
new
EntityAlreadyBoostedException
();
}
if
(
!
$boost
->
getGuid
())
{
$boost
->
setGuid
(
$this
->
guidBuilder
->
build
());
}
...
...
@@ -151,4 +139,22 @@ class Manager
{
$this
->
elasticRepository
->
update
(
$boost
,
$fields
);
}
/**
* Checks if a boost already exists for a given entity
* @param $boost
* @return bool
*/
public
function
checkExisting
(
$boost
)
{
$existingBoost
=
$this
->
getList
([
'useElastic'
=>
true
,
'state'
=>
'review'
,
'type'
=>
$boost
->
getType
(),
'entity_guid'
=>
$boost
->
getEntityGuid
(),
'limit'
=>
1
]);
return
$existingBoost
->
count
()
>
0
;
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Network/ManagerSpec.php
View file @
5a36078a
...
...
@@ -3,7 +3,6 @@
namespace
Spec\Minds\Core\Boost\Network
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Boost\Exceptions\EntityAlreadyBoostedException
;
use
Minds\Core\Boost\Network\Boost
;
use
Minds\Core\Boost\Network\ElasticRepository
;
use
Minds\Core\Boost\Network\Manager
;
...
...
@@ -232,18 +231,6 @@ class ManagerSpec extends ObjectBehavior
function
it_should_add_a_boost
(
Boost
$boost
)
{
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'network'
);
$boost
->
getEntityGuid
()
->
shouldBeCalled
()
->
willReturn
(
'2'
);
$this
->
elasticRepository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
());
$this
->
guidBuilder
->
build
()
->
shouldBeCalled
()
->
willReturn
(
1
);
...
...
@@ -264,27 +251,6 @@ class ManagerSpec extends ObjectBehavior
->
shouldReturn
(
true
);
}
function
it_should_not_add_a_boost_if_the_entity_has_already_been_boosted
(
Boost
$boost
,
Boost
$oldBoost
)
{
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'network'
);
$boost
->
getEntityGuid
()
->
shouldBeCalled
()
->
willReturn
(
'2'
);
$this
->
elasticRepository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$oldBoost
]));
$this
->
repository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$oldBoost
]));
$this
->
shouldThrow
(
new
EntityAlreadyBoostedException
())
->
during
(
'add'
,
[
$boost
]);
}
function
it_should_update_a_boost
(
Boost
$boost
)
{
$this
->
repository
->
update
(
$boost
,
[
'@timestamp'
])
...
...
@@ -302,4 +268,32 @@ class ManagerSpec extends ObjectBehavior
$this
->
resync
(
$boost
,
[
'@timestamp'
]);
}
function
it_should_check_if_the_entity_was_already_boosted
(
Boost
$boost
)
{
$this
->
elasticRepository
->
getList
([
'useElastic'
=>
true
,
'state'
=>
'review'
,
'type'
=>
'newsfeed'
,
'entity_guid'
=>
'123'
,
'limit'
=>
1
,
'hydrate'
=>
true
,
])
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$boost
],
''
));
$this
->
repository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
([
$boost
]));
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'newsfeed'
);
$boost
->
getEntityGuid
()
->
shouldBeCalled
()
->
willReturn
(
'123'
);
$this
->
checkExisting
(
$boost
)
->
shouldReturn
(
true
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment