Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
284
Merge Requests
40
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
3fe57cd1
Commit
3fe57cd1
authored
35 minutes ago
by
Emiliano Balbuena
Browse files
Options
Download
(chore): Explicit from and to on CLI
parent
2602a4b7
goal/top-feeds-redux
1 merge request
!406
WIP: Top Feed algorithm changes
Pipeline
#97746934
failed with stages
in 2 minutes and 43 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
11 deletions
+61
-11
Controllers/Cli/Top.php
View file @
3fe57cd1
...
...
@@ -2,6 +2,7 @@
namespace
Minds\Controllers\Cli
;
use
Exception
;
use
Minds\Core\Feeds\Elastic\Sync
;
use
Minds\Core\Minds
;
use
Minds\Cli
;
...
...
@@ -13,6 +14,9 @@ class Top extends Cli\Controller implements Interfaces\CliControllerInterface
/** @var Sync */
private
$sync
;
/**
* Top constructor.
*/
public
function
__construct
()
{
$minds
=
new
Minds
();
...
...
@@ -21,52 +25,98 @@ class Top extends Cli\Controller implements Interfaces\CliControllerInterface
$this
->
sync
=
new
Sync
();
}
/**
* @param null $command
* @return void
*/
public
function
help
(
$command
=
null
)
{
$this
->
out
(
'Syntax usage: cli top sync_<type> --metric=?'
);
$this
->
out
(
'Syntax usage: cli top sync_<type> --metric=?
--from=? --to=?
'
);
}
/**
* @return void
*/
public
function
exec
()
{
$this
->
out
(
'Syntax usage: cli top sync_<type> --metric=?'
);
$this
->
help
(
);
}
/**
* @throws CliException
*/
public
function
sync_activity
()
{
return
$this
->
syncBy
(
'activity'
,
null
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'activity'
,
null
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
/**
* @throws CliException
*/
public
function
sync_images
()
{
return
$this
->
syncBy
(
'object'
,
'image'
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'object'
,
'image'
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
/**
* @throws CliException
*/
public
function
sync_videos
()
{
return
$this
->
syncBy
(
'object'
,
'video'
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'object'
,
'video'
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
/**
* @throws CliException
*/
public
function
sync_blogs
()
{
return
$this
->
syncBy
(
'object'
,
'blog'
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'object'
,
'blog'
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
/**
* @throws CliException
*/
public
function
sync_groups
()
{
return
$this
->
syncBy
(
'group'
,
null
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'group'
,
null
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
/**
* @throws CliException
*/
public
function
sync_channels
()
{
return
$this
->
syncBy
(
'user'
,
null
,
$this
->
getOpt
(
'metric'
)
??
null
);
return
$this
->
syncBy
(
'user'
,
null
,
$this
->
getOpt
(
'metric'
)
,
$this
->
getOpt
(
'from'
),
$this
->
getOpt
(
'to'
)
);
}
protected
function
syncBy
(
$type
,
$subtype
,
$metric
)
/**
* @param $type
* @param $subtype
* @param $metric
* @param $from
* @param $to
* @throws CliException
* @throws Exception
*/
protected
function
syncBy
(
$type
,
$subtype
,
$metric
,
$from
,
$to
)
{
if
(
!
$metric
)
{
throw
new
CliException
(
'Missing --metric flag'
);
}
if
(
!
$from
||
!
is_numeric
(
$from
))
{
throw
new
CliException
(
'Missing --from flag'
);
}
if
(
!
$to
||
!
is_numeric
(
$to
))
{
throw
new
CliException
(
'Missing --to flag'
);
}
if
(
$from
>
$to
)
{
throw
new
CliException
(
'--from should be before --to'
);
}
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
...
...
@@ -78,8 +128,8 @@ class Top extends Cli\Controller implements Interfaces\CliControllerInterface
->
setType
(
$type
?:
''
)
->
setSubtype
(
$subtype
?:
''
)
->
setMetric
(
$metric
)
->
setFrom
(
strtotime
(
'-1 day'
)
*
1000
)
->
setTo
(
time
()
*
1000
)
->
setFrom
(
$from
*
1000
)
->
setTo
(
$to
*
1000
)
->
run
();
$this
->
out
(
"
\n
Completed syncing '
{
$displayType
}
'."
);
...
...
This diff is collapsed.
Please
register
or
sign in
to comment