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
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
167
Issues
167
List
Boards
Labels
Service Desk
Milestones
Merge Requests
47
Merge Requests
47
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
Compare Revisions
a537c3ebec3c08be114641470ff0415bc640cb10...693590056d8600f1cab14ac2aacf40665405adb8
Source
693590056d8600f1cab14ac2aacf40665405adb8
Select Git revision
...
Target
a537c3ebec3c08be114641470ff0415bc640cb10
Select Git revision
Compare
Commits (2)
(refactor): Deprecate CockroachDB
· 55c93318
Emiliano Balbuena
authored
31 minutes ago
55c93318
Merge branch 'hotfix/cdb-deprec-569' into 'master'
· 69359005
Mark Harding
authored
31 minutes ago
(refactor): Deprecate CockroachDB See merge request
!245
69359005
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
133 additions
and
2003 deletions
+133
-2003
Suggested.php
Controllers/Cli/Suggested.php
+0
-95
fetch.php
Controllers/api/v1/boost/fetch.php
+2
-26
suggested.php
Controllers/api/v2/entities/suggested.php
+8
-9
Manager.php
Core/Feeds/Controversial/Manager.php
+0
-236
Repository.php
Core/Feeds/Controversial/Repository.php
+0
-195
FeedsProvider.php
Core/Feeds/FeedsProvider.php
+0
-8
Manager.php
Core/Feeds/Suggested/Manager.php
+0
-252
Repository.php
Core/Feeds/Suggested/Repository.php
+0
-202
Repository.php
Core/Hashtags/Entity/Repository.php
+0
-64
HashtagEntity.php
Core/Hashtags/HashtagEntity.php
+0
-1
HashtagsProvider.php
Core/Hashtags/HashtagsProvider.php
+0
-8
Repository.php
Core/Hashtags/Suggested/Repository.php
+0
-60
Repository.php
Core/Hashtags/Trending/Repository.php
+55
-62
LegacyRepository.php
Core/Hashtags/User/LegacyRepository.php
+0
-106
Repository.php
Core/Hashtags/User/Repository.php
+1
-32
CassandraRepository.php
Core/Notification/CassandraRepository.php
+7
-3
Counters.php
Core/Notification/Counters.php
+30
-18
Manager.php
Core/Notification/Manager.php
+14
-5
cassandra-provision.cql
Core/Provisioner/Provisioners/cassandra-provision.cql
+8
-1
Manager.php
Core/Suggestions/Manager.php
+0
-10
ManagerSpec.php
Spec/Core/Feeds/Suggested/ManagerSpec.php
+0
-162
RepositorySpec.php
Spec/Core/Feeds/Suggested/RepositorySpec.php
+0
-227
RepositorySpec.php
Spec/Core/Hashtags/Entity/RepositorySpec.php
+0
-73
RepositorySpec.php
Spec/Core/Hashtags/Suggested/RepositorySpec.php
+0
-51
LegacyRepositorySpec.php
Spec/Core/Hashtags/User/LegacyRepositorySpec.php
+0
-94
CassandraRepositorySpec.php
Spec/Core/Notification/CassandraRepositorySpec.php
+1
-1
ManagerSpec.php
Spec/Core/Notification/ManagerSpec.php
+7
-2
No files found.
Controllers/Cli/Suggested.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Controllers\Cli
;
use
Minds\Core\Minds
;
use
Minds\Cli
;
use
Minds\Core\Feeds\Suggested\Manager
;
use
Minds\Interfaces
;
class
Suggested
extends
Cli\Controller
implements
Interfaces\CliControllerInterface
{
/** @var Manager */
private
$manager
;
public
function
__construct
()
{
$minds
=
new
Minds
();
$minds
->
start
();
$this
->
manager
=
new
Manager
();
}
public
function
help
(
$command
=
null
)
{
$this
->
out
(
'Syntax usage: cli trending <type>'
);
}
public
function
exec
()
{
$this
->
out
(
'Syntax usage: cli trending <type>'
);
}
public
function
sync_all
()
{
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
$this
->
out
(
'Collecting trending items'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'all'
);
$this
->
out
(
'Completed syncing all'
);
}
public
function
sync_newsfeed
()
{
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
$this
->
out
(
'Syncing newsfeed'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'newsfeed'
);
$this
->
out
(
'Completed syncing newsfeed'
);
}
public
function
sync_images
()
{
$this
->
out
(
'Syncing images'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'images'
);
$this
->
out
(
'Completed syncing images'
);
}
public
function
sync_videos
()
{
$this
->
out
(
'Syncing videos'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'videos'
);
$this
->
out
(
'Completed syncing videos'
);
}
public
function
sync_groups
()
{
$this
->
out
(
'Syncing groups'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'groups'
);
$this
->
out
(
'Completed syncing groups'
);
}
public
function
sync_blogs
()
{
$this
->
out
(
'Syncing blogs'
);
$this
->
manager
->
setFrom
(
$this
->
getOpt
(
'from'
)
?:
strtotime
(
'-12 hours'
)
*
1000
);
$this
->
manager
->
setTo
(
$this
->
getOpt
(
'to'
)
?:
time
()
*
1000
);
$this
->
manager
->
run
(
'blogs'
);
$this
->
out
(
'Completed syncing blogs'
);
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v1/boost/fetch.php
View file @
69359005
...
...
@@ -178,32 +178,8 @@ class fetch implements Interfaces\Api
private
function
getSuggestedPosts
(
$opts
=
[])
{
$opts
=
array_merge
([
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
1
,
],
$opts
);
/** @var Core\Feeds\Suggested\Manager $repo */
$repo
=
Di
::
_
()
->
get
(
'Feeds\Suggested\Manager'
);
$opts
=
[
'user_guid'
=>
Core\Session
::
getLoggedInUserGuid
(),
'rating'
=>
$opts
[
'rating'
],
'limit'
=>
$opts
[
'limit'
],
'offset'
=>
$opts
[
'offset'
],
'type'
=>
'newsfeed'
,
'all'
=>
true
,
];
$result
=
$repo
->
getFeed
(
$opts
);
// Remove all unlisted content if it appears
$result
=
array_values
(
array_filter
(
$result
,
function
(
$entity
)
{
return
$entity
->
getAccessId
()
!=
0
;
}));
return
$result
;
// @deprecated
return
[];
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v2/entities/suggested.php
View file @
69359005
...
...
@@ -68,9 +68,6 @@ class suggested implements Interfaces\Api
$hashtag
=
$_GET
[
'hashtag'
];
}
/** @var Core\Feeds\Suggested\Manager $repo */
$repo
=
Di
::
_
()
->
get
(
'Feeds\Suggested\Manager'
);
$opts
=
[
'user_guid'
=>
Core\Session
::
getLoggedInUserGuid
(),
'rating'
=>
$rating
,
...
...
@@ -84,17 +81,19 @@ class suggested implements Interfaces\Api
$opts
[
'hashtag'
]
=
$hashtag
;
}
$result
=
$repo
->
getFeed
(
$opts
);
// @deprecated
$result
=
[];
// Remove all unlisted content if it appears
$result
=
array_values
(
array_filter
(
$result
,
function
(
$entity
)
{
return
$entity
->
getAccessId
()
!=
0
;
}));
// @deprecated
// // Remove all unlisted content if it appears
// $result = array_values(array_filter($result, function($entity) {
// return $entity->getAccessId() != 0;
// }));
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
Factory
::
exportable
(
$result
),
'load-next'
=>
$limit
+
$offset
,
'load-next'
=>
''
,
]);
}
...
...
This diff is collapsed.
Click to expand it.
Core/Feeds/Controversial/Manager.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Feeds\Suggested
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities\Entity
;
use
Minds\Core\EntitiesBuilder
;
class
Manager
{
/** @var Repository */
protected
$feedsRepository
;
/** @var Core\EntitiesBuilder */
protected
$entitiesBuilder
;
/** @var \Minds\Core\Hashtags\Entity\Repository */
private
$entityHashtagsRepository
;
/** @var array */
private
$maps
;
/** @var Core\Trending\EntityValidator */
private
$validator
;
private
$from
;
private
$to
;
public
function
__construct
(
$repo
=
null
,
$entityHashtagsRepository
=
null
,
$validator
=
null
,
$maps
=
null
,
$entitiesBuilder
=
null
)
{
$this
->
feedsRepository
=
$repo
?:
Di
::
_
()
->
get
(
'Feeds\Suggested\Repository'
);
$this
->
entityHashtagsRepository
=
$entityHashtagsRepository
?:
Di
::
_
()
->
get
(
'Hashtags\Entity\Repository'
);
$this
->
validator
=
$validator
?:
new
Core\Trending\EntityValidator
();
$this
->
maps
=
$maps
?:
Core\Trending\Maps
::
$maps
;
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
new
EntitiesBuilder
;
$this
->
from
=
strtotime
(
'-12 hours'
)
*
1000
;
$this
->
to
=
time
()
*
1000
;
}
/**
* @param array $opts
* @return Entity[]
* @throws \Exception
*/
public
function
getFeed
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
1
,
'type'
=>
null
,
'all'
=>
false
,
],
$opts
);
$guids
=
[];
foreach
(
$this
->
feedsRepository
->
getFeed
(
$opts
)
as
$item
)
{
$guids
[]
=
$item
[
'guid'
];
}
$entities
=
[];
if
(
count
(
$guids
)
>
0
)
{
$entities
=
$this
->
entitiesBuilder
->
get
([
'guids'
=>
$guids
]);
}
return
$entities
;
}
public
function
run
(
string
$type
)
{
//\Minds\Core\Security\ACL::$ignore = true;
$scores
=
[];
$maps
=
null
;
switch
(
$type
)
{
case
'all'
:
$maps
=
$this
->
maps
;
break
;
case
'channels'
:
$maps
=
[
'user'
=>
$this
->
maps
[
'channels'
]];
break
;
case
'newsfeed'
:
$maps
=
[
'newsfeed'
=>
$this
->
maps
[
'newsfeed'
]];
break
;
case
'images'
:
$maps
=
[
'image'
=>
$this
->
maps
[
'images'
]];
break
;
case
'videos'
:
$maps
=
[
'video'
=>
$this
->
maps
[
'videos'
]];
break
;
case
'groups'
:
$maps
=
[
'group'
=>
$this
->
maps
[
'groups'
]];
break
;
case
'blogs'
:
$maps
=
[
'blog'
=>
$this
->
maps
[
'blogs'
]];
break
;
case
'default'
:
throw
new
\Exception
(
"Invalid type. Valid values are: 'newsfeed', 'images', 'videos', 'groups' and 'blogs'"
);
break
;
}
foreach
(
$maps
as
$key
=>
$map
)
{
if
(
!
isset
(
$scores
[
$key
]))
{
$scores
[
$key
]
=
[];
}
$ratings
=
[];
foreach
(
$map
[
'aggregates'
]
as
$aggregate
)
{
$class
=
is_string
(
$aggregate
)
?
new
$aggregate
:
$aggregate
;
$class
->
setLimit
(
10000
);
$class
->
setType
(
$map
[
'type'
]);
$class
->
setSubtype
(
$map
[
'subtype'
]);
$class
->
setFrom
(
$this
->
from
);
$class
->
setTo
(
$this
->
to
);
foreach
(
$class
->
get
()
as
$guid
=>
$score
)
{
if
(
$score
<
2
)
{
continue
;
}
echo
"
\n
$guid
(
$score
)"
;
//collect the entity
$entity
=
$this
->
entitiesBuilder
->
single
(
$guid
);
if
(
!
$entity
->
guid
)
{
continue
;
}
$tags
=
$entity
->
getTags
();
if
(
$entity
->
container_guid
!=
0
&&
$entity
->
container_guid
!=
$entity
->
owner_guid
&&
$key
==
'newsfeed'
)
{
echo
" skipping because group post"
;
continue
;
// skip groups
}
$this
->
saveTags
(
$entity
->
guid
,
$tags
);
$ratings
[
$entity
->
guid
]
=
$entity
->
getRating
();
//validate this entity is ok
if
(
!
$this
->
validator
->
isValid
(
$entity
))
{
echo
"
\n
[
$entity->getRating
()]
$key
:
$guid
(
$score
) invalid"
;
continue
;
}
//is this an activity entity?
//if so, let add it the guids for this key
if
(
$entity
->
custom_type
==
'batch'
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'image'
][
$entity
->
entity_guid
]))
{
$scores
[
'image'
][
$entity
->
entity_guid
]
=
0
;
}
$scores
[
'image'
][
$entity
->
entity_guid
]
+=
$score
;
$ratings
[
$entity
->
entity_guid
]
=
$ratings
[
$guid
];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
}
elseif
(
$entity
->
custom_type
==
'video'
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'video'
][
$entity
->
entity_guid
]))
{
$scores
[
'video'
][
$entity
->
entity_guid
]
=
0
;
}
$scores
[
'video'
][
$entity
->
entity_guid
]
+=
$score
;
$ratings
[
$entity
->
entity_guid
]
=
$ratings
[
$guid
];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
}
elseif
(
strpos
(
$entity
->
perma_url
,
'/blog'
)
!==
false
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'blog'
][
$entity
->
entity_guid
]))
{
$scores
[
'blog'
][
$entity
->
entity_guid
]
=
0
;
}
$scores
[
'blog'
][
$entity
->
entity_guid
]
+=
$score
;
$ratings
[
$entity
->
entity_guid
]
=
$ratings
[
$guid
];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
echo
"
\n\t
blog here
$entity->entity_guid
"
;
}
if
(
!
isset
(
$scores
[
$key
][
$guid
]))
{
$scores
[
$key
][
$guid
]
=
0
;
}
$scores
[
$key
][
$guid
]
+=
$score
;
}
}
//arsort($scores[$key]);
$sync
=
time
();
foreach
(
$scores
as
$_key
=>
$_scores
)
{
foreach
(
$_scores
as
$guid
=>
$score
)
{
if
(
!
(
int
)
$score
||
!
$guid
)
{
continue
;
}
if
(
!
isset
(
$ratings
[
$guid
]))
{
$ratings
[
$guid
]
=
2
;
}
$this
->
feedsRepository
->
add
([
'entity_guid'
=>
$guid
,
'score'
=>
(
int
)
$score
,
'type'
=>
$_key
,
'rating'
=>
$ratings
[
$guid
],
'lastSynced'
=>
$sync
,
]);
echo
"
\n
[
{
$ratings
[
$guid
]
}
]
$_key
:
$guid
(
$score
)"
;
}
}
}
//\Minds\Core\Security\ACL::$ignore = false;
}
private
function
saveTags
(
$guid
,
$tags
)
{
if
(
!
$tags
)
{
echo
" no tags"
;
return
;
}
$hashtagEntities
=
[];
foreach
(
$tags
as
$tag
)
{
if
(
strpos
(
$tag
,
'#'
,
0
)
===
0
)
{
$tag
=
substr
(
$tag
,
1
);
}
echo
"
\n\t
#
$tag
"
;
$hashtagEntity
=
new
Core\Hashtags\HashtagEntity
();
$hashtagEntity
->
setGuid
(
$guid
);
$hashtagEntity
->
setHashtag
(
strtolower
(
$tag
));
$hashtagEntities
[]
=
$hashtagEntity
;
}
//if ($key == 'newsfeed' && count($hashtagEntities) >= 5) {
// continue;
//}
foreach
(
$hashtagEntities
as
$hashtagEntity
)
{
$this
->
entityHashtagsRepository
->
add
([
$hashtagEntity
]);
}
echo
"
\n
Saved tags to repo"
;
}
}
This diff is collapsed.
Click to expand it.
Core/Feeds/Controversial/Repository.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Feeds\Suggested
;
use
Minds\Core\Di\Di
;
class
Repository
{
/** @var \PDO */
protected
$db
;
public
function
__construct
(
$db
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
}
/**
* @param array $opts
* @return array
* @throws \Exception
*/
public
function
getFeed
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
1
,
'hashtag'
=>
null
,
'type'
=>
null
,
'all'
=>
false
,
// if true, it ignores user selected hashtags
],
$opts
);
if
(
!
$opts
[
'user_guid'
])
{
throw
new
\Exception
(
'user_guid must be provided'
);
}
if
(
!
$opts
[
'type'
])
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
$opts
[
'hashtag'
])
{
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
WHERE entity_hashtags.hashtag = ?
AND type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'hashtag'
],
$opts
[
'type'
],
$opts
[
'rating'
],
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
else
{
// ignore user selected hashtags if all is true
if
(
$opts
[
'all'
])
{
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM suggested
WHERE type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'type'
],
$opts
[
'rating'
],
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
else
{
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM user_hashtags
INNER JOIN entity_hashtags
ON user_hashtags.hashtag = entity_hashtags.hashtag
INNER JOIN suggested
ON entity_hashtags.guid = suggested.guid
WHERE user_hashtags.guid = ?
AND type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'user_guid'
],
$opts
[
'type'
],
$opts
[
'rating'
],
//date('c', strtotime('-48 minutes') / $opts['user_hashtag_count']),
//strtotime('-48 hours'),
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
}
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$opts
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
public
function
add
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'entity_guid'
=>
null
,
'score'
=>
null
,
'type'
=>
null
,
'rating'
=>
null
,
'lastSynced'
=>
time
(),
],
$opts
);
if
(
!
$opts
[
'entity_guid'
])
{
throw
new
\Exception
(
'entity_guid must be provided'
);
}
if
(
!
$opts
[
'score'
])
{
throw
new
\Exception
(
'score must be provided'
);
}
if
(
!
$opts
[
'type'
])
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
!
$opts
[
'rating'
])
{
throw
new
\Exception
(
'rating must be provided'
);
}
$query
=
"UPSERT INTO suggested (guid, rating, type, score, lastSynced) VALUES (?, ?, ?, ?, ?)"
;
$values
=
[
$opts
[
'entity_guid'
],
$opts
[
'rating'
],
$opts
[
'type'
],
$opts
[
'score'
],
date
(
'c'
,
$opts
[
'lastSynced'
]),
];
$statement
=
$this
->
db
->
prepare
(
$query
);
return
$statement
->
execute
(
$values
);
//if ($rating > 1) {
// $template .= " USING TTL 1200";
//}
}
public
function
removeAll
(
$type
)
{
if
(
!
$type
)
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
$type
===
'all'
)
{
$statement
=
$this
->
db
->
prepare
(
"TRUNCATE suggested"
);
return
$statement
->
execute
();
}
$selectQuery
=
"SELECT suggested.guid AS guid
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
WHERE suggested.type = ?"
;
$params
=
[
$type
];
$statement
=
$this
->
db
->
prepare
(
$selectQuery
);
$statement
->
execute
(
$params
);
$guids
=
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
$guids
=
array_map
(
function
(
$item
)
{
return
$item
[
'guid'
];
},
$guids
);
$variables
=
implode
(
','
,
array_fill
(
0
,
count
(
$guids
),
'?'
));
$deleteQuery
=
"DELETE FROM suggested WHERE guid IN (
{
$variables
}
)"
;
$statement
=
$this
->
db
->
prepare
(
$deleteQuery
);
return
$statement
->
execute
(
$guids
);
}
}
This diff is collapsed.
Click to expand it.
Core/Feeds/FeedsProvider.php
View file @
69359005
...
...
@@ -8,14 +8,6 @@ class FeedsProvider extends Provider
{
public
function
register
()
{
$this
->
di
->
bind
(
'Feeds\Suggested\Repository'
,
function
(
$di
)
{
return
new
Suggested\Repository
();
});
$this
->
di
->
bind
(
'Feeds\Suggested\Manager'
,
function
(
$di
)
{
return
new
Suggested\Manager
();
});
$this
->
di
->
bind
(
'Feeds\Top\Manager'
,
function
(
$di
)
{
return
new
Top\Manager
();
});
...
...
This diff is collapsed.
Click to expand it.
Core/Feeds/Suggested/Manager.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Feeds\Suggested
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities\Entity
;
use
Minds\Core\EntitiesBuilder
;
class
Manager
{
/** @var Repository */
protected
$feedsRepository
;
/** @var Core\EntitiesBuilder */
protected
$entitiesBuilder
;
/** @var \Minds\Core\Hashtags\Entity\Repository */
private
$entityHashtagsRepository
;
/** @var array */
private
$maps
;
/** @var Core\Trending\EntityValidator */
private
$validator
;
private
$from
;
private
$to
;
public
function
__construct
(
$repo
=
null
,
$entityHashtagsRepository
=
null
,
$validator
=
null
,
$maps
=
null
,
$entitiesBuilder
=
null
)
{
$this
->
feedsRepository
=
$repo
?:
Di
::
_
()
->
get
(
'Feeds\Suggested\Repository'
);
$this
->
entityHashtagsRepository
=
$entityHashtagsRepository
?:
Di
::
_
()
->
get
(
'Hashtags\Entity\Repository'
);
$this
->
validator
=
$validator
?:
new
Core\Trending\EntityValidator
();
$this
->
maps
=
$maps
?:
Core\Trending\Maps
::
$maps
;
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
new
EntitiesBuilder
;
$this
->
from
=
strtotime
(
'-12 hours'
)
*
1000
;
$this
->
to
=
time
()
*
1000
;
}
public
function
setFrom
(
$from
)
{
$this
->
from
=
$from
;
return
$this
;
}
/**
* @param array $opts
* @return Entity[]
* @throws \Exception
*/
public
function
getFeed
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
1
,
'type'
=>
null
,
'all'
=>
false
,
],
$opts
);
$guids
=
[];
foreach
(
$this
->
feedsRepository
->
getFeed
(
$opts
)
as
$item
)
{
$guids
[]
=
$item
[
'guid'
];
}
$entities
=
[];
if
(
count
(
$guids
)
>
0
)
{
$entities
=
$this
->
entitiesBuilder
->
get
([
'guids'
=>
$guids
]);
}
return
$entities
;
}
public
function
run
(
string
$type
)
{
//\Minds\Core\Security\ACL::$ignore = true;
$scores
=
[];
$maps
=
null
;
switch
(
$type
)
{
case
'all'
:
$maps
=
$this
->
maps
;
break
;
case
'channels'
:
$maps
=
[
'user'
=>
$this
->
maps
[
'channels'
]];
break
;
case
'newsfeed'
:
$maps
=
[
'newsfeed'
=>
$this
->
maps
[
'newsfeed'
]];
break
;
case
'images'
:
$maps
=
[
'image'
=>
$this
->
maps
[
'images'
]];
break
;
case
'videos'
:
$maps
=
[
'video'
=>
$this
->
maps
[
'videos'
]];
break
;
case
'groups'
:
$maps
=
[
'group'
=>
$this
->
maps
[
'groups'
]];
break
;
case
'blogs'
:
$maps
=
[
'blog'
=>
$this
->
maps
[
'blogs'
]];
break
;
case
'default'
:
throw
new
\Exception
(
"Invalid type. Valid values are: 'newsfeed', 'images', 'videos', 'groups' and 'blogs'"
);
break
;
}
foreach
(
$maps
as
$key
=>
$map
)
{
if
(
!
isset
(
$scores
[
$key
]))
{
$scores
[
$key
]
=
[];
}
$ratings
=
[];
$ownersCounts
=
[];
foreach
(
$map
[
'aggregates'
]
as
$aggregate
)
{
$class
=
is_string
(
$aggregate
)
?
new
$aggregate
:
$aggregate
;
$class
->
setLimit
(
10000
);
$class
->
setType
(
$map
[
'type'
]);
$class
->
setSubtype
(
$map
[
'subtype'
]);
$class
->
setFrom
(
$this
->
from
);
$class
->
setTo
(
$this
->
to
);
foreach
(
$class
->
get
()
as
$guid
=>
$score
)
{
if
(
$score
<
2
)
{
// continue;
}
echo
"
\n
$guid
(
$score
)"
;
//collect the entity
$entity
=
$this
->
entitiesBuilder
->
single
(
$guid
);
if
(
!
$entity
->
guid
)
{
continue
;
}
if
(
isset
(
$ownersCounts
[
$entity
->
owner_guid
])
&&
$entity
->
type
!=
'user'
)
{
continue
;
}
$ownersCounts
[
$entity
->
owner_guid
]
=
1
;
$tags
=
$entity
->
getTags
();
if
(
$entity
->
container_guid
!=
0
&&
$entity
->
container_guid
!=
$entity
->
owner_guid
)
{
echo
" skipping because group post"
;
continue
;
// skip groups
}
$this
->
saveTags
(
$entity
->
guid
,
$tags
);
$ratings
[
$entity
->
guid
]
=
$entity
->
getRating
();
//validate this entity is ok
if
(
!
$this
->
validator
->
isValid
(
$entity
))
{
echo
"
\n
[
$entity->getRating
()]
$key
:
$guid
(
$score
) invalid"
;
$this
->
feedsRepository
->
remove
(
$key
,
$guid
);
continue
;
}
//is this an activity entity?
//if so, let add it the guids for this key
if
(
$entity
->
custom_type
==
'batch'
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'image'
][
$entity
->
entity_guid
]))
{
$scores
[
'image'
][
$entity
->
entity_guid
]
=
0
;
}
//$scores['image'][$entity->entity_guid] += $score;
//$ratings[$entity->entity_guid] = $ratings[$guid];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
}
elseif
(
$entity
->
custom_type
==
'video'
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'video'
][
$entity
->
entity_guid
]))
{
$scores
[
'video'
][
$entity
->
entity_guid
]
=
0
;
}
//$scores['video'][$entity->entity_guid] += $score;
//$ratings[$entity->entity_guid] = $ratings[$guid];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
}
elseif
(
strpos
(
$entity
->
perma_url
,
'/blog'
)
!==
false
&&
$entity
->
entity_guid
)
{
if
(
!
isset
(
$scores
[
'blog'
][
$entity
->
entity_guid
]))
{
$scores
[
'blog'
][
$entity
->
entity_guid
]
=
0
;
}
//$scores['blog'][$entity->entity_guid] += $score;
//$ratings[$entity->entity_guid] = $ratings[$guid];
$this
->
saveTags
(
$entity
->
entity_guid
,
$tags
);
echo
"
\n\t
blog here
$entity->entity_guid
"
;
}
if
(
!
isset
(
$scores
[
$key
][
$guid
]))
{
$scores
[
$key
][
$guid
]
=
0
;
}
$scores
[
$key
][
$guid
]
+=
$score
;
}
}
//arsort($scores[$key]);
$sync
=
time
();
foreach
(
$scores
as
$_key
=>
$_scores
)
{
foreach
(
$_scores
as
$guid
=>
$score
)
{
if
(
!
(
int
)
$score
||
!
$guid
)
{
echo
"
\n
[
{
$ratings
[
$guid
]
}
]
$_key
:
$guid
(
$score
) FAILED"
;
continue
;
}
if
(
!
isset
(
$ratings
[
$guid
]))
{
$ratings
[
$guid
]
=
2
;
}
$this
->
feedsRepository
->
add
([
'entity_guid'
=>
$guid
,
'score'
=>
(
int
)
$score
,
'type'
=>
$_key
,
'rating'
=>
$ratings
[
$guid
],
'lastSynced'
=>
$sync
,
]);
echo
"
\n
[
{
$ratings
[
$guid
]
}
]
$_key
:
$guid
(
$score
)"
;
}
}
}
//\Minds\Core\Security\ACL::$ignore = false;
}
private
function
saveTags
(
$guid
,
$tags
)
{
if
(
!
$tags
)
{
echo
" no tags"
;
return
;
}
$hashtagEntities
=
[];
foreach
(
$tags
as
$tag
)
{
if
(
strpos
(
$tag
,
'#'
,
0
)
===
0
)
{
$tag
=
substr
(
$tag
,
1
);
}
echo
"
\n\t
#
$tag
"
;
$hashtagEntity
=
new
Core\Hashtags\HashtagEntity
();
$hashtagEntity
->
setGuid
(
$guid
);
$hashtagEntity
->
setHashtag
(
strtolower
(
$tag
));
$hashtagEntities
[]
=
$hashtagEntity
;
}
//if ($key == 'newsfeed' && count($hashtagEntities) >= 5) {
// continue;
//}
foreach
(
$hashtagEntities
as
$hashtagEntity
)
{
$this
->
entityHashtagsRepository
->
add
([
$hashtagEntity
]);
}
echo
"
\n
Saved tags to repo"
;
}
}
This diff is collapsed.
Click to expand it.
Core/Feeds/Suggested/Repository.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Feeds\Suggested
;
use
Minds\Core\Di\Di
;
class
Repository
{
/** @var \PDO */
protected
$db
;
public
function
__construct
(
$db
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
}
/**
* @param array $opts
* @return array
* @throws \Exception
*/
public
function
getFeed
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
1
,
'hashtag'
=>
null
,
'type'
=>
null
,
'all'
=>
false
,
// if true, it ignores user selected hashtags
],
$opts
);
if
(
!
$opts
[
'user_guid'
])
{
throw
new
\Exception
(
'user_guid must be provided'
);
}
if
(
!
$opts
[
'type'
])
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
$opts
[
'hashtag'
])
{
$opts
[
'hashtag'
]
=
strtolower
(
$opts
[
'hashtag'
]);
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
WHERE entity_hashtags.hashtag = ?
AND type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'hashtag'
],
$opts
[
'type'
],
$opts
[
'rating'
],
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
else
{
// ignore user selected hashtags if all is true
if
(
$opts
[
'all'
])
{
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM suggested
WHERE type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'type'
],
$opts
[
'rating'
],
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
else
{
$query
=
"SELECT DISTINCT suggested.guid as guid,
lastSynced, score
FROM user_hashtags
INNER JOIN entity_hashtags
ON user_hashtags.hashtag = entity_hashtags.hashtag
INNER JOIN suggested
ON entity_hashtags.guid = suggested.guid
WHERE user_hashtags.guid = ?
AND type = ?
AND rating <= ?
ORDER BY lastSynced DESC, score DESC
LIMIT ? OFFSET ?"
;
$opts
=
[
$opts
[
'user_guid'
],
$opts
[
'type'
],
$opts
[
'rating'
],
//date('c', strtotime('-48 minutes') / $opts['user_hashtag_count']),
//strtotime('-48 hours'),
$opts
[
'limit'
],
$opts
[
'offset'
]
];
}
}
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$opts
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
public
function
add
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'entity_guid'
=>
null
,
'score'
=>
null
,
'type'
=>
null
,
'rating'
=>
null
,
'lastSynced'
=>
time
(),
],
$opts
);
if
(
!
$opts
[
'entity_guid'
])
{
throw
new
\Exception
(
'entity_guid must be provided'
);
}
if
(
!
$opts
[
'score'
])
{
throw
new
\Exception
(
'score must be provided'
);
}
if
(
!
$opts
[
'type'
])
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
!
$opts
[
'rating'
])
{
throw
new
\Exception
(
'rating must be provided'
);
}
$query
=
"UPSERT INTO suggested (guid, rating, type, score, lastSynced) VALUES (?, ?, ?, ?, ?)"
;
$values
=
[
$opts
[
'entity_guid'
],
$opts
[
'rating'
],
$opts
[
'type'
],
$opts
[
'score'
],
date
(
'c'
,
$opts
[
'lastSynced'
]),
];
$statement
=
$this
->
db
->
prepare
(
$query
);
return
$statement
->
execute
(
$values
);
//if ($rating > 1) {
// $template .= " USING TTL 1200";
//}
}
public
function
removeAll
(
$type
)
{
if
(
!
$type
)
{
throw
new
\Exception
(
'type must be provided'
);
}
if
(
$type
===
'all'
)
{
$statement
=
$this
->
db
->
prepare
(
"TRUNCATE suggested"
);
return
$statement
->
execute
();
}
$selectQuery
=
"SELECT suggested.guid AS guid
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
WHERE suggested.type = ?"
;
$params
=
[
$type
];
$statement
=
$this
->
db
->
prepare
(
$selectQuery
);
$statement
->
execute
(
$params
);
$guids
=
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
$guids
=
array_map
(
function
(
$item
)
{
return
$item
[
'guid'
];
},
$guids
);
$variables
=
implode
(
','
,
array_fill
(
0
,
count
(
$guids
),
'?'
));
$deleteQuery
=
"DELETE FROM suggested WHERE guid IN (
{
$variables
}
)"
;
$statement
=
$this
->
db
->
prepare
(
$deleteQuery
);
return
$statement
->
execute
(
$guids
);
}
public
function
remove
(
$key
,
$guid
)
{
$statement
=
$this
->
db
->
prepare
(
"DELETE FROM suggested WHERE guid = ?"
);
return
$statement
->
execute
([
$guid
]);
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/Entity/Repository.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Hashtags\Entity
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Hashtags\HashtagEntity
;
class
Repository
{
/** @var \PDO */
protected
$db
;
public
function
__construct
(
$db
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
}
/**
* Return all hashtags
*/
public
function
getAll
(
$opts
=
[])
{
$opts
=
array_merge
([
'entity_guid'
=>
null
],
$opts
);
if
(
!
$opts
[
'entity_guid'
])
{
throw
new
\Exception
(
'entity_guid must be provided'
);
}
$query
=
"SELECT * FROM entity_hashtags WHERE guid=?"
;
$params
=
[
$opts
[
'entity_guid'
]];
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
/**
* @param HashtagEntity[] $hashtags
* @return bool
*/
public
function
add
(
$hashtags
)
{
$query
=
"UPSERT INTO entity_hashtags (guid, hashtag) VALUES (?, ?)"
;
foreach
(
$hashtags
as
$hashtag
)
{
try
{
$statement
=
$this
->
db
->
prepare
(
$query
);
if
(
!
$hashtag
->
getHashtag
())
{
continue
;
}
return
$statement
->
execute
([
$hashtag
->
getGuid
(),
$hashtag
->
getHashtag
()]);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
->
getMessage
());
}
}
return
false
;
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/HashtagEntity.php
View file @
69359005
...
...
@@ -32,5 +32,4 @@ class HashtagEntity
'hashtag'
=>
$this
->
getHashtag
(),
];
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/HashtagsProvider.php
View file @
69359005
...
...
@@ -17,14 +17,6 @@ class HashtagsProvider extends Provider
return
new
User\Manager
();
});
$this
->
di
->
bind
(
'Hashtags\Entity\Repository'
,
function
(
$di
)
{
return
new
Entity\Repository
();
});
$this
->
di
->
bind
(
'Hashtags\Suggested\Repository'
,
function
(
$di
)
{
return
new
Suggested\Repository
();
});
$this
->
di
->
bind
(
'Hashtags\Trending\Repository'
,
function
(
$di
)
{
return
new
Trending\Repository
();
});
...
...
This diff is collapsed.
Click to expand it.
Core/Hashtags/Suggested/Repository.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Hashtags\Suggested
;
use
Minds\Core\Di\Di
;
class
Repository
{
/** @var \PDO $db */
protected
$db
;
public
function
__construct
(
\PDO
$db
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
}
/**
* @param array $opts
* @return array
* @throws \Exception
*/
public
function
getAll
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
,
'limit'
=>
null
],
$opts
);
if
(
!
$opts
[
'user_guid'
])
{
throw
new
\Exception
(
'user_guid must be provided'
);
}
$query
=
"SELECT DISTINCT
CASE WHEN user_hashtags.hashtag IS NOT NULL THEN user_hashtags.hashtag ELSE entity_hashtags.hashtag END as value,
CASE WHEN user_hashtags.guid IS NOT NULL THEN true ELSE false END as selected
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
FULL OUTER JOIN user_hashtags
ON (entity_hashtags.hashtag = user_hashtags.hashtag OR user_hashtags.hashtag = null)
WHERE suggested.lastSynced > ? OR suggested.lastsynced IS NULL AND user_hashtags.guid = ?
ORDER BY selected DESC, suggested.score DESC"
;
$params
=
[
date
(
'c'
,
strtotime
(
'24 hours ago'
)),
$opts
[
'user_guid'
],
];
if
(
$opts
[
'limit'
])
{
$query
.=
" LIMIT ?"
;
$params
[]
=
$opts
[
'limit'
];
}
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/Trending/Repository.php
View file @
69359005
...
...
@@ -2,6 +2,11 @@
namespace
Minds\Core\Hashtags\Trending
;
use
Cassandra\Timestamp
;
use
Cassandra\Bigint
;
use
Minds\Core\Data\Cassandra\Client
as
CassandraClient
;
use
Minds\Core\Data\Cassandra\Prepared\Custom
;
use
Minds\Core\Data\ElasticSearch\Client
as
ElasticSearchClient
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Data\ElasticSearch\Prepared\Search
as
Prepared
;
use
Minds\Common\Repository\Response
;
...
...
@@ -11,15 +16,15 @@ use Minds\Common\Repository\Response;
*/
class
Repository
{
/** @var
\PDO
$db */
/** @var
CassandraClient
$db */
protected
$db
;
/** @var ElasticSearch $es */
/** @var ElasticSearch
Client
$es */
protected
$es
;
public
function
__construct
(
\PDO
$db
=
null
,
$es
=
null
)
public
function
__construct
(
$db
=
null
,
$es
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\
PDO
'
);
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\
Cassandra\Cql
'
);
$this
->
es
=
$es
?:
Di
::
_
()
->
get
(
'Database\ElasticSearch'
);
}
...
...
@@ -122,7 +127,7 @@ class Repository
}
/**
* Return a confi
f
dence score
* Return a confidence score
* TODO: Move to global helper
* @param int $positive
* @param int $total
...
...
@@ -137,114 +142,102 @@ class Repository
return
$n
/
$d
;
}
/**
* Get trending hashtags
*
* @param array $opts
* @return array
*/
public
function
getTrending
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'from_date'
=>
date
(
'c'
,
strtotime
(
'24 hours ago'
)),
'limit'
=>
20
],
$opts
);
$query
=
"SELECT entity_hashtags.hashtag, COUNT(*) as hashCount
FROM entity_hashtags
JOIN suggested ON suggested.guid = entity_hashtags.guid
LEFT JOIN hidden_hashtags ON hidden_hashtags.hashtag = entity_hashtags.hashtag
WHERE suggested.lastsynced >= ? AND hidden_hashtags.hashtag IS NULL
GROUP BY entity_hashtags.hashtag
ORDER BY hashCount Desc
LIMIT ?"
;
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
([
$opts
[
'from_date'
],
$opts
[
'limit'
]]);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
/**
* Hide a tag from trending list
*
* @param string $tag
* @param string $admin_guid
* @return
void
* @return
bool
*/
public
function
hide
(
$tag
,
$admin_guid
)
{
$query
=
"INSERT INTO hidden_hashtags(hashtag, hidden_since, admin_guid) VALUES (?, ?, ?)"
;
$cql
=
"INSERT INTO hidden_hashtags (hashtag, hidden_since, admin_guid) VALUES (?, ?, ?)"
;
$values
=
[
$tag
,
new
Timestamp
(
time
()),
new
Bigint
(
$admin_guid
),
];
try
{
$statement
=
$this
->
db
->
prepare
(
$query
);
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
,
$values
);
return
$statement
->
execute
([
$tag
,
date
(
'c'
),
$admin_guid
]);
try
{
return
(
bool
)
$this
->
db
->
request
(
$prepared
,
true
);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
->
getMessage
());
return
false
;
}
return
false
;
}
/**
* Unhide a tag from trending list
*
* @param string $tag
* @return
void
* @return
bool
*/
public
function
unhide
(
$tag
)
{
$query
=
"DELETE FROM hidden_hashtags WHERE hashtag = ?"
;
$cql
=
"DELETE FROM hidden_hashtags WHERE hashtag = ?"
;
$values
=
[
$tag
];
try
{
$statement
=
$this
->
db
->
prepare
(
$query
);
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
,
$values
);
return
$statement
->
execute
([
$tag
]);
try
{
return
(
bool
)
$this
->
db
->
request
(
$prepared
,
true
);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
->
getMessage
());
return
false
;
}
return
false
;
}
/**
* Return hidden hashtags list
* @param array $opts
* @return array
*/
public
function
getHidden
(
$opts
=
[])
public
function
getHidden
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'limit'
=>
500
],
$opts
);
$query
=
"SELECT hashtag, admin_guid, hidden_since FROM hidden_hashtags LIMIT ?"
;
$params
=
[
$opts
[
'limit'
]];
$cql
=
"SELECT hashtag, hidden_since, admin_guid FROM hidden_hashtags"
;
$statement
=
$this
->
db
->
prepare
(
$query
);
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
);
$prepared
->
setOpts
([
'page_size'
=>
(
int
)
$opts
[
'limit'
],
]);
$statement
->
execute
(
$params
);
$rows
=
$this
->
db
->
request
(
$prepared
);
$response
=
[];
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
foreach
(
$rows
as
$row
)
{
$response
[]
=
$row
;
}
return
$response
;
}
/**
* Clear trending hidden table
*
* @return void
* @return bool
*/
public
function
clearHidden
()
{
$
query
=
"TRUNCATE TABLE hidden_hashtags"
;
$
cql
=
"TRUNCATE TABLE hidden_hashtags"
;
try
{
$statement
=
$this
->
db
->
prepare
(
$query
);
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
);
return
$statement
->
execute
();
try
{
return
(
bool
)
$this
->
db
->
request
(
$prepared
,
true
);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
->
getMessage
());
return
false
;
}
return
false
;
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/User/LegacyRepository.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Minds\Core\Hashtags\User
;
use
Minds\Core\Data\cache\abstractCacher
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Hashtags\HashtagEntity
;
class
LegacyRepository
{
/** @var \PDO */
protected
$db
;
/** @var abstractCacher */
protected
$cacher
;
public
function
__construct
(
$db
=
null
,
$cacher
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
$this
->
cacher
=
$cacher
?:
Di
::
_
()
->
get
(
'Cache'
);
}
/**
* Return all hashtags
*/
public
function
getAll
(
$opts
=
[])
{
$opts
=
array_merge
([
'user_guid'
=>
null
],
$opts
);
if
(
!
$opts
[
'user_guid'
])
{
throw
new
\Exception
(
'user_guid must be provided'
);
}
$query
=
"SELECT hashtag FROM user_hashtags WHERE guid = ?"
;
$params
=
[
$opts
[
'user_guid'
]];
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
/**
* Return all hashtags in db
* For migration
*/
public
function
_getEverything
(
$offset
,
$limit
)
{
$query
=
"SELECT * FROM user_hashtags LIMIT ? OFFSET ?"
;
$params
=
[
intval
(
$limit
),
intval
(
$offset
)];
$statement
=
$this
->
db
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
return
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
/**
* @param HashtagEntity[] $hashtags
* @return bool
*/
public
function
add
(
$hashtags
)
{
$query
=
"UPSERT INTO user_hashtags(guid, hashtag) VALUES (?, ?)"
;
foreach
(
$hashtags
as
$hashtag
)
{
try
{
$statement
=
$this
->
db
->
prepare
(
$query
);
$this
->
cacher
->
destroy
(
"user-selected-hashtags:
{
$hashtag
->
getGuid
()
}
"
);
return
$statement
->
execute
([
$hashtag
->
getGuid
(),
$hashtag
->
getHashtag
()]);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
->
getMessage
());
}
}
return
false
;
}
/**
* @param $user_guid
* @param array $hashtags
* @return bool
*/
public
function
remove
(
$user_guid
,
array
$hashtags
)
{
$variables
=
implode
(
','
,
array_fill
(
0
,
count
(
$hashtags
),
'?'
));
$query
=
"DELETE FROM user_hashtags WHERE guid = ? AND hashtag IN (
{
$variables
}
)"
;
$statement
=
$this
->
db
->
prepare
(
$query
);
$this
->
cacher
->
destroy
(
"user-selected-hashtags:
{
$user_guid
}
"
);
return
$statement
->
execute
(
array_merge
([
$user_guid
],
$hashtags
));
}
public
function
update
()
{
}
}
This diff is collapsed.
Click to expand it.
Core/Hashtags/User/Repository.php
View file @
69359005
...
...
@@ -4,7 +4,6 @@ namespace Minds\Core\Hashtags\User;
use
Cassandra\Varint
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Config
;
use
Minds\Core\Data\Cassandra\Client
;
use
Minds\Core\Data\Cassandra\Prepared\Custom
;
use
Minds\Core\Di\Di
;
...
...
@@ -15,17 +14,9 @@ class Repository
/** @var Client */
protected
$db
;
/** @var LegacyRepository */
protected
$legacyRepository
;
/** @var Config */
protected
$config
;
public
function
__construct
(
$db
=
null
,
$legacyRepository
=
null
,
$config
=
null
)
public
function
__construct
(
$db
=
null
)
{
$this
->
db
=
$db
?:
Di
::
_
()
->
get
(
'Database\Cassandra\Cql'
);
$this
->
legacyRepository
=
$legacyRepository
?:
new
LegacyRepository
();
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
}
/**
...
...
@@ -35,20 +26,6 @@ class Repository
*/
public
function
getAll
(
$opts
=
[])
{
// Legacy fallback
if
(
$this
->
config
->
get
(
'user_hashtags_legacy_read'
))
{
$rows
=
$this
->
legacyRepository
->
getAll
(
$opts
);
$response
=
new
Response
();
foreach
(
$rows
as
$row
)
{
$response
[]
=
(
new
HashtagEntity
())
->
setGuid
(
$opts
[
'user_guid'
])
->
setHashtag
(
$row
[
'hashtag'
]);
}
return
$response
;
}
$opts
=
array_merge
([
'user_guid'
=>
null
],
$opts
);
...
...
@@ -112,10 +89,6 @@ class Repository
}
}
if
(
$this
->
config
->
get
(
'user_hashtags_migration'
))
{
$this
->
legacyRepository
->
add
(
$hashtags
);
}
return
true
;
}
...
...
@@ -148,10 +121,6 @@ class Repository
return
false
;
}
if
(
$this
->
config
->
get
(
'user_hashtags_migration'
))
{
$this
->
legacyRepository
->
remove
(
$userGuid
,
$hashtagValues
);
}
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Core/Notification/CassandraRepository.php
View file @
69359005
...
...
@@ -74,6 +74,10 @@ class CassandraRepository
return
false
;
}
if
(
!
$result
)
{
return
false
;
}
$response
=
new
Response
();
foreach
(
$result
as
$row
)
{
$notification
=
new
Notification
();
...
...
@@ -100,8 +104,8 @@ class CassandraRepository
*/
public
function
get
(
$urn
)
{
list
(
$to_guid
,
$uuid
)
=
explode
(
'-'
,
$this
->
urn
->
setUrn
(
$urn
)
->
getNss
());
list
(
$to_guid
,
$uuid
)
=
explode
(
'-'
,
$this
->
urn
->
setUrn
(
$urn
)
->
getNss
()
,
2
);
$response
=
$this
->
getList
([
'to_guid'
=>
$to_guid
,
'uuid'
=>
$uuid
,
...
...
@@ -162,7 +166,7 @@ class CassandraRepository
return
false
;
}
return
$
success
;
return
$
notification
->
getUuid
()
;
}
// TODO
...
...
This diff is collapsed.
Click to expand it.
Core/Notification/Counters.php
View file @
69359005
...
...
@@ -6,6 +6,7 @@
namespace
Minds\Core\Notification
;
use
Minds\Core
;
use
Minds\Core\Features\Manager
as
FeaturesManager
;
use
Minds\Entities
;
use
Minds\Helpers
;
use
Minds\Core\Di\Di
;
...
...
@@ -17,13 +18,20 @@ class Counters
/** @var $sql */
private
$sql
;
/** @var FeaturesManager */
private
$features
;
/** @var User $user */
private
$user
;
public
function
__construct
(
$sql
=
null
)
public
function
__construct
(
$sql
=
null
,
$features
=
null
)
{
$this
->
sql
=
$sql
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
$this
->
user
=
Core\Session
::
getLoggedInUser
();
$this
->
features
=
$features
?:
new
FeaturesManager
;
if
(
!
$this
->
features
->
has
(
'cassandra-notifications'
))
{
$this
->
sql
=
$sql
?:
Di
::
_
()
->
get
(
'Database\PDO'
);
}
}
/**
...
...
@@ -50,7 +58,9 @@ class Counters
*/
public
function
getCount
(
array
$options
=
[])
{
// return Helpers\Counters::get($this->user, 'notifications:count', false);
if
(
$this
->
features
->
has
(
'cassandra-notifications'
))
{
return
Helpers\Counters
::
get
(
$this
->
user
,
'notifications:count'
,
false
);
}
// TODO: Remove below once settled
...
...
@@ -104,21 +114,23 @@ class Counters
// TODO: Remove below once settled
$query
=
"BEGIN;
UPDATE notifications
SET read_timestamp = NOW()
WHERE to_guid = ?
ORDER BY created_timestamp DESC
LIMIT 6
RETURNING NOTHING;
COMMIT;"
;
$params
=
[
(
int
)
$this
->
user
->
getGuid
(),
];
if
(
!
$this
->
features
->
has
(
'cassandra-notifications'
))
{
$query
=
"BEGIN;
UPDATE notifications
SET read_timestamp = NOW()
WHERE to_guid = ?
ORDER BY created_timestamp DESC
LIMIT 6
RETURNING NOTHING;
COMMIT;"
;
$statement
=
$this
->
sql
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
$params
=
[
(
int
)
$this
->
user
->
getGuid
(),
];
$statement
=
$this
->
sql
->
prepare
(
$query
);
$statement
->
execute
(
$params
);
}
}
}
This diff is collapsed.
Click to expand it.
Core/Notification/Manager.php
View file @
69359005
...
...
@@ -37,9 +37,12 @@ class Manager
)
{
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
$this
->
repository
=
$repository
?:
new
Repository
;
$this
->
cassandraRepository
=
$cassandraRepository
?:
new
CassandraRepository
;
$this
->
features
=
$features
?:
new
FeaturesManager
;
if
(
!
$this
->
features
->
has
(
'cassandra-notifications'
))
{
$this
->
repository
=
$repository
?:
new
Repository
;
}
}
/**
...
...
@@ -60,10 +63,13 @@ class Manager
*/
public
function
getSingle
(
$urn
)
{
if
(
strpos
(
$urn
,
'urn:'
)
!==
FALSE
)
{
return
$this
->
cassandraRepository
->
get
(
$urn
);
if
(
strpos
(
$urn
,
'urn:'
)
===
FALSE
)
{
$urn
=
"urn:notification:"
.
implode
(
'-'
,
[
$this
->
user
->
getGuid
(),
$urn
]);
}
return
$this
->
r
epository
->
get
(
$urn
);
return
$this
->
cassandraR
epository
->
get
(
$urn
);
}
/**
...
...
@@ -154,7 +160,10 @@ class Manager
{
try
{
$this
->
cassandraRepository
->
add
(
$notification
);
$uuid
=
$this
->
repository
->
add
(
$notification
);
if
(
!
$this
->
features
->
has
(
'cassandra-notifications'
))
{
$uuid
=
$this
->
repository
->
add
(
$notification
);
}
return
$uuid
;
}
catch
(
\Exception
$e
)
{
...
...
This diff is collapsed.
Click to expand it.
Core/Provisioner/Provisioners/cassandra-provision.cql
View file @
69359005
...
...
@@ -1406,4 +1406,11 @@ CREATE TABLE minds.update_markers (
read_timestamp timestamp,
updated_timestamp timestamp,
PRIMARY KEY (user_guid, entity_type, entity_guid, marker)
);
\ No newline at end of file
);
CREATE TABLE minds.hidden_hashtags (
hashtag text,
admin_guid bigint,
hidden_since timestamp,
PRIMARY KEY (hashtag)
);
This diff is collapsed.
Click to expand it.
Core/Suggestions/Manager.php
View file @
69359005
...
...
@@ -23,12 +23,10 @@ class Manager
public
function
__construct
(
$repository
=
null
,
$entitiesBuilder
=
null
,
$suggestedFeedsManager
=
null
,
$subscriptionsManager
=
null
)
{
$this
->
repository
=
$repository
?:
new
Repository
();
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
new
EntitiesBuilder
();
//$this->suggestedFeedsManager = $suggestedFeedsManager ?: Di::_()->get('Feeds\Suggested\Manager');
$this
->
subscriptionsManager
=
$subscriptionsManager
?:
Di
::
_
()
->
get
(
'Subscriptions\Manager'
);
}
...
...
@@ -106,14 +104,6 @@ class Manager
$response
=
new
Response
();
//$result = $this->suggestedFeedsManager->getFeed($opts);
//foreach ($result as $user) {
// $suggestion = new Suggestion();
// $suggestion->setEntityGuid($user->guid);
// $response[] = $suggestion;
//}
$guids
=
[
626772382194872329
,
100000000000065670
,
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Feeds/Suggested/ManagerSpec.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Spec\Minds\Core\Feeds\Suggested
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core\Feeds\Suggested\Manager
;
use
Minds\Core\Feeds\Suggested\Repository
;
use
Minds\Core\Trending\Aggregates\Aggregate
;
use
Minds\Core\Trending\EntityValidator
;
use
Minds\Entities\Activity
;
use
Minds\Entities\Entity
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
ManagerSpec
extends
ObjectBehavior
{
private
$repo
;
private
$entityHashtagsRepo
;
private
$agg
;
private
$aggImages
;
private
$validator
;
private
$entitiesBuilder
;
function
let
(
Repository
$repo
,
\Minds\Core\Hashtags\Entity\Repository
$entityHashtagsRepo
,
Aggregate
$agg
,
Aggregate
$aggImages
,
EntityValidator
$validator
,
EntitiesBuilder
$entitiesBuilder
)
{
$this
->
repo
=
$repo
;
$this
->
agg
=
$agg
;
$this
->
aggImages
=
$aggImages
;
$this
->
entityHashtagsRepo
=
$entityHashtagsRepo
;
$this
->
validator
=
$validator
;
$maps
=
[
'newsfeed'
=>
[
'type'
=>
'activity'
,
'subtype'
=>
''
,
'aggregates'
=>
[
$agg
]
],
'images'
=>
[
'type'
=>
'object'
,
'subtype'
=>
'image'
,
'aggregates'
=>
[
$aggImages
]
]
];
$this
->
entitiesBuilder
=
$entitiesBuilder
;
$this
->
beConstructedWith
(
$repo
,
$entityHashtagsRepo
,
$validator
,
$maps
,
$entitiesBuilder
);
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Manager
::
class
);
}
function
it_should_get_an_empty_feed
()
{
$this
->
repo
->
getFeed
([
'user_guid'
=>
100
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
2
,
'type'
=>
'activity'
,
'all'
=>
false
])
->
shouldBeCalled
()
->
willReturn
([]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
,
'rating'
=>
2
,
'all'
=>
false
])
->
shouldReturn
([]);
}
function
it_should_get_the_suggested_feed
(
Activity
$activity1
,
Activity
$activity2
)
{
$this
->
repo
->
getFeed
([
'user_guid'
=>
100
,
'offset'
=>
0
,
'limit'
=>
12
,
'rating'
=>
2
,
'type'
=>
'activity'
,
'all'
=>
false
])
->
shouldBeCalled
()
->
willReturn
([[
'guid'
=>
1
],
[
'guid'
=>
2
]]);
$this
->
entitiesBuilder
->
get
([
'guids'
=>
[
1
,
2
]])
->
shouldBeCalled
()
->
willReturn
([
$activity1
,
$activity2
]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
,
'rating'
=>
2
,
'all'
=>
false
])
->
shouldReturn
([
$activity1
,
$activity2
]);
}
function
it_should_collect_and_store_suggested_entities
()
{
$entities
=
[
1
=>
(
new
Entity
)
->
set
(
'guid'
,
10
)
->
set
(
'owner_guid'
,
1
)
->
set
(
'type'
,
'activity'
)
->
set
(
'perma_url'
,
'https://minds.com/blog/view/1000001'
)
->
set
(
'message'
,
'#hashtag'
)
->
setRating
(
1
),
2
=>
(
new
Entity
)
->
set
(
'guid'
,
20
)
->
set
(
'owner_guid'
,
2
)
->
set
(
'type'
,
'activity'
)
->
set
(
'message'
,
'#hashtag'
)
->
setRating
(
1
),
3
=>
(
new
Entity
)
->
set
(
'guid'
,
30
)
->
set
(
'owner_guid'
,
3
)
->
set
(
'type'
,
'activity'
)
->
set
(
'message'
,
'#hashtag'
)
->
setRating
(
1
),
];
foreach
(
$entities
as
$entity
)
{
$this
->
entitiesBuilder
->
single
(
$entity
->
guid
)
->
willReturn
(
$entity
);
}
$this
->
validator
->
isValid
(
Argument
::
any
())
->
shouldBeCalledTimes
(
4
)
->
willReturn
(
true
);
$this
->
agg
->
setType
(
'activity'
)
->
shouldBeCalled
();
$this
->
agg
->
setSubtype
(
''
)
->
shouldBeCalled
();
$this
->
agg
->
setFrom
(
Argument
::
any
())
->
shouldBeCalled
();
$this
->
agg
->
setTo
(
Argument
::
any
())
->
shouldBeCalled
();
$this
->
agg
->
setLimit
(
10000
)
->
shouldBeCalled
();
$this
->
agg
->
get
()
->
shouldBeCalled
()
->
willReturn
([
10
=>
5
,
20
=>
10
,
30
=>
10
,
]);
$this
->
aggImages
->
setType
(
'object'
)
->
shouldBeCalled
();
$this
->
aggImages
->
setSubtype
(
'image'
)
->
shouldBeCalled
();
$this
->
aggImages
->
setFrom
(
Argument
::
any
())
->
shouldBeCalled
();
$this
->
aggImages
->
setTo
(
Argument
::
any
())
->
shouldBeCalled
();
$this
->
aggImages
->
setLimit
(
10000
)
->
shouldBeCalled
();
$this
->
aggImages
->
get
()
->
shouldBeCalled
()
->
willReturn
([
10
=>
5
,
]);
$this
->
repo
->
add
(
Argument
::
any
())
->
shouldBeCalledTimes
(
7
);
$this
->
run
(
'all'
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Feeds/Suggested/RepositorySpec.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Spec\Minds\Core\Feeds\Suggested
;
use
Minds\Core\Feeds\Suggested\Repository
;
use
Minds\Entities\Activity
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
RepositorySpec
extends
ObjectBehavior
{
private
$db
;
function
let
(
\PDO
$db
)
{
$this
->
db
=
$db
;
$this
->
beConstructedWith
(
$db
);
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Repository
::
class
);
}
function
it_should_throw_an_exception_when_getting_the_feed_if_user_guid_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'user_guid must be provided'
))
->
during
(
'getFeed'
);
}
function
it_should_throw_an_exception_when_getting_the_feed_if_type_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'type must be provided'
))
->
during
(
'getFeed'
,
[[
'user_guid'
=>
'100'
]]);
}
function
it_should_get_the_suggested_feed
(
Activity
$activity
,
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
100
,
'activity'
,
1
,
12
,
0
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([
$activity
]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
])
->
shouldReturn
([
$activity
]);
}
function
it_should_get_the_suggested_feed_filtering_by_hashtag
(
Activity
$activity
,
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
'hashtag'
,
'activity'
,
1
,
12
,
0
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([
$activity
]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
,
'hashtag'
=>
'hashtag'
])
->
shouldReturn
([
$activity
]);
}
function
it_should_get_the_suggested_feed_filtering_by_capitalized_hashtag
(
Activity
$activity
,
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
'hashtag'
,
'activity'
,
1
,
12
,
0
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([
$activity
]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
,
'hashtag'
=>
'HaShTag'
])
->
shouldReturn
([
$activity
]);
}
function
it_should_get_the_suggested_feed_ignoring_user_selected_hashtags
(
Activity
$activity
,
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
'activity'
,
1
,
12
,
0
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([
$activity
]);
$this
->
getFeed
([
'user_guid'
=>
100
,
'type'
=>
'activity'
,
'all'
=>
true
])
->
shouldReturn
([
$activity
]);
}
function
it_should_fail_to_add_add_an_entry_to_suggested_if_entity_guid_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'entity_guid must be provided'
))
->
during
(
'add'
,
[[
'score'
=>
100
,
'rating'
=>
1
]]);
}
function
it_should_fail_to_add_add_an_entry_to_suggested_if_score_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'score must be provided'
))
->
during
(
'add'
,
[[
'entity_guid'
=>
100
,
'rating'
=>
1
]]);
}
function
it_should_fail_to_add_add_an_entry_to_suggested_if_type_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'type must be provided'
))
->
during
(
'add'
,
[[
'entity_guid'
=>
100
,
'score'
=>
100
]]);
}
function
it_should_fail_to_add_add_an_entry_to_suggested_if_rating_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'rating must be provided'
))
->
during
(
'add'
,
[[
'entity_guid'
=>
100
,
'score'
=>
100
,
'type'
=>
'image'
]]);
}
function
it_should_add_an_entry_to_suggested
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
add
([
'entity_guid'
=>
100
,
'score'
=>
100
,
'rating'
=>
1
,
'type'
=>
'image'
])
->
shouldReturn
(
true
);
}
function
it_should_fail_to_remove_from_suggested_table_if_type_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'type must be provided'
))
->
during
(
'removeAll'
,
[
null
]);
}
function
it_should_truncate_suggested_table
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
"TRUNCATE suggested"
)
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
()
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
removeAll
(
'all'
)
->
shouldReturn
(
true
);
}
function
it_should_delete_all_entities_with_a_specific_type_from_the_suggested_table
(
\PDOStatement
$statement1
,
\PDOStatement
$statement2
)
{
$this
->
db
->
prepare
(
"SELECT suggested.guid AS guid
FROM suggested
JOIN entity_hashtags
ON suggested.guid = entity_hashtags.guid
WHERE suggested.type = ?"
)
->
shouldBeCalled
()
->
willReturn
(
$statement1
);
$statement1
->
execute
([
'activity'
])
->
shouldBeCalled
();
$statement1
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([[
'guid'
=>
1
],
[
'guid'
=>
2
]]);
$this
->
db
->
prepare
(
"DELETE FROM suggested WHERE guid IN (?,?)"
)
->
shouldBeCalled
()
->
willReturn
(
$statement2
);
$statement2
->
execute
([
1
,
2
])
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
removeAll
(
'activity'
)
->
shouldReturn
(
true
);
}
function
it_should_remove_a_key
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
"DELETE FROM suggested WHERE guid = ?"
)
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
123123
])
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
remove
(
'key'
,
123123
)
->
shouldReturn
(
true
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Hashtags/Entity/RepositorySpec.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Spec\Minds\Core\Hashtags\Entity
;
use
Minds\Core\Hashtags\Entity\Repository
;
use
Minds\Core\Hashtags\HashtagEntity
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
RepositorySpec
extends
ObjectBehavior
{
private
$db
;
function
let
(
\PDO
$db
)
{
$this
->
db
=
$db
;
$this
->
beConstructedWith
(
$db
);
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Repository
::
class
);
}
function
it_should_throw_an_exception_when_getting_hashtags_if_entity_guid_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'entity_guid must be provided'
))
->
during
(
'getAll'
);
}
function
it_should_get_all_hashtags
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
100
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([[
'guid'
=>
1
,
'hashtag'
=>
'hashtag1'
]]);
$this
->
getAll
([
'entity_guid'
=>
100
])
->
shouldReturn
([[
'guid'
=>
1
,
'hashtag'
=>
'hashtag1'
]]);
}
function
it_should_add_an_entity_hashtag
(
\PDOStatement
$statement
,
HashtagEntity
$hashtag
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
100
,
'hashtag1'
])
->
shouldBeCalled
()
->
willReturn
(
true
);
$hashtag
->
getGuid
()
->
shouldBeCalled
()
->
willReturn
(
100
);
$hashtag
->
getHashtag
()
->
shouldBeCalled
()
->
willReturn
(
'hashtag1'
);
$this
->
add
([
$hashtag
])
->
shouldReturn
(
true
);
}
function
it_should_try_to_add_any_hashtags_if_array_is_empty
()
{
$this
->
add
([])
->
shouldReturn
(
false
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Hashtags/Suggested/RepositorySpec.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Spec\Minds\Core\Hashtags\Suggested
;
use
Minds\Core\Hashtags\Suggested\Repository
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
RepositorySpec
extends
ObjectBehavior
{
protected
$db
;
function
let
(
\PDO
$db
)
{
$this
->
db
=
$db
;
$this
->
beConstructedWith
(
$db
);
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Repository
::
class
);
}
function
it_should_throw_an_exception_when_getting_the_suggested_hashtags_if_user_guid_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'user_guid must be provided'
))
->
during
(
'getAll'
);
}
function
it_should_get_the_suggested_hashtags
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
date
(
'c'
,
strtotime
(
'24 hours ago'
)),
100
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([
[
'value'
=>
'hashtag1'
,
'selected'
=>
true
],
[
'value'
=>
'hashtag2'
,
'selected'
=>
false
]
]);
$this
->
getAll
([
'user_guid'
=>
100
])
->
shouldReturn
([
[
'value'
=>
'hashtag1'
,
'selected'
=>
true
],
[
'value'
=>
'hashtag2'
,
'selected'
=>
false
]
]);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Hashtags/User/LegacyRepositorySpec.php
deleted
100644 → 0
View file @
a537c3eb
<?php
namespace
Spec\Minds\Core\Hashtags\User
;
use
Minds\Core\Data\cache\Redis
;
use
Minds\Core\Hashtags\HashtagEntity
;
use
Minds\Core\Hashtags\User\LegacyRepository
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
LegacyRepositorySpec
extends
ObjectBehavior
{
private
$db
;
private
$cacher
;
function
let
(
\PDO
$db
,
Redis
$cacher
)
{
$this
->
db
=
$db
;
$this
->
cacher
=
$cacher
;
$this
->
beConstructedWith
(
$db
,
$cacher
);
}
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
LegacyRepository
::
class
);
}
function
it_should_throw_an_exception_when_getting_hashtags_if_user_guid_isnt_set
()
{
$this
->
shouldThrow
(
new
\Exception
(
'user_guid must be provided'
))
->
during
(
'getAll'
);
}
function
it_should_get_all_hashtags
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
100
])
->
shouldBeCalled
();
$statement
->
fetchAll
(
\PDO
::
FETCH_ASSOC
)
->
shouldBeCalled
()
->
willReturn
([[
'hashtag'
=>
'hashtag1'
]]);
$this
->
getAll
([
'user_guid'
=>
100
])
->
shouldReturn
([[
'hashtag'
=>
'hashtag1'
]]);
}
function
it_should_add_a_user_hashtag
(
\PDOStatement
$statement
,
HashtagEntity
$hashtag
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$statement
->
execute
([
100
,
'hashtag1'
])
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
cacher
->
destroy
(
"user-selected-hashtags:100"
)
->
shouldBeCalled
();
$hashtag
->
getGuid
()
->
shouldBeCalled
()
->
willReturn
(
100
);
$hashtag
->
getHashtag
()
->
shouldBeCalled
()
->
willReturn
(
'hashtag1'
);
$this
->
add
([
$hashtag
])
->
shouldReturn
(
true
);
}
function
it_should_try_to_add_any_hashtags_if_array_is_empty
()
{
$this
->
add
([])
->
shouldReturn
(
false
);
}
function
it_should_remove_a_user_hashtag
(
\PDOStatement
$statement
)
{
$this
->
db
->
prepare
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$statement
);
$this
->
cacher
->
destroy
(
"user-selected-hashtags:100"
)
->
shouldBeCalled
();
$statement
->
execute
([
100
,
'hashtag1'
])
->
shouldBeCalled
()
->
willReturn
(
true
);
$this
->
remove
(
100
,
[
'hashtag1'
])
->
shouldReturn
(
true
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Notification/CassandraRepositorySpec.php
View file @
69359005
...
...
@@ -95,7 +95,7 @@ class CassandraRepositorySpec extends ObjectBehavior
->
willReturn
(
null
);
$this
->
add
(
$notification
)
->
should
Return
(
tru
e
);
->
should
NotReturn
(
fals
e
);
}
function
it_should_load_notification_for_user
()
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Notification/ManagerSpec.php
View file @
69359005
...
...
@@ -9,6 +9,7 @@ use Minds\Core\Notification\Notification;
use
Minds\Core\Notification\Repository
;
use
Minds\Core\Notification\CassandraRepository
;
use
Minds\Core\Features\Manager
as
FeaturesManager
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -46,9 +47,13 @@ class ManagerSpec extends ObjectBehavior
$this
->
shouldHaveType
(
Manager
::
class
);
}
function
it_should_get_a_single_notification
(
Notification
$notification
)
function
it_should_get_a_single_notification
(
Notification
$notification
,
User
$user
)
{
$this
->
repository
->
get
(
'1234'
)
$this
->
setUser
(
$user
);
$user
->
getGUID
()
->
willReturn
(
456
);
$this
->
cassandraRepository
->
get
(
'urn:notification:456-1234'
)
->
shouldBeCalled
()
->
willReturn
(
$notification
);
...
...
This diff is collapsed.
Click to expand it.