Commits (2)
<?php
namespace Minds\Controllers\Cli;
use Minds\Cli;
use Minds\Core;
use Minds\Core\Data\ElasticSearch;
use Minds\Core\Di\Di;
use Minds\Interfaces;
class Test extends Cli\Controller implements Interfaces\CliControllerInterface
{
public function __construct()
{
define('__MINDS_INSTALLING__', true);
}
public function help($command = null)
{
$this->out('TBD');
}
public function exec()
{
$client = Di::_()->get('Database\ElasticSearch');
$query = [
'index' => 'minds-boost-campaigns',
//'type' => 'activity',
'_source' => true,
'size' => 100,
'body' => [
'query' => [
'bool' => [
'must_not' => [
[
'exists' => [
'field' => '@completed',
],
],
[
'exists' => [
'field' => '@rejected',
],
],
[
'exists' => [
'field' => '@revoked',
],
],
],
'filter' => [
'script' => [
'script' => [
"inline" => "
if(doc._index.value == 'minds-boost')
return true;
ZonedDateTime start = ZonedDateTime.ofInstant(doc.start.value.toInstant(), ZoneId.systemDefault());
ZonedDateTime end = ZonedDateTime.ofInstant(doc.end.value.toInstant(), ZoneId.systemDefault());
def totalAmountOfDays = ChronoUnit.DAYS.between(start, end);
def impressionsPerDay = doc.impressions.value / totalAmountOfDays;
ZonedDateTime now = ZonedDateTime.ofInstant(Instant.ofEpochMilli(params.nowMillis), ZoneId.systemDefault());
def passedDays = ChronoUnit.DAYS.between(now, end);
def impressionsMetPerDay = (doc.impressions_met.value ?: doc.impressions.value) / passedDays;
Debug.explain(impressionsPerDay);
return impressionsMetPerDay <= impressionsPerDay;
",
'lang' => 'painless',
'params' => [
'nowMillis' => time() * 1000,
],
],
],
],
],
],
],
];
$prepared = new ElasticSearch\Prepared\Search();
$prepared->query($query);
try {
$result = $client->request($prepared);
var_dump($result);
} catch (\Exception $e) {
var_dump(str_replace("\\n", "\r\n", $e->getMessage()));
}
<<<<<<< Updated upstream
$this->out($namespace);
=======
// var_dump($result);
// die();
>>>>>>> Stashed changes
}
private function getTrendingActivities()
{
$result = Core\Di\Di::_()->get('Trending\Repository')->getList([
'type' => 'newsfeed',
'limit' => 12,
]);
ksort($result['guids']);
$options['guids'] = $result['guids'];
$activities = Core\Entities::get(array_merge([
<<<<<<< Updated upstream
'type' => 'activity'
], $options));
=======
'type' => 'activity',
]
, $options));
>>>>>>> Stashed changes
$activities = array_filter($activities, function ($activity) {
if ($activity->paywall) {
return false;
}
if ($activity->remind_object && $activity->remind_object['paywall']) {
return false;
}
return true;
});
return $activities;
}
}
......@@ -10,6 +10,7 @@ use Minds\Core\Permissions\Roles\Roles;
/*
* Manager for managing role based permissions
*/
class Manager
{
/** @var EntitiesBuilder */
......@@ -43,9 +44,15 @@ class Manager
throw new \InvalidArgumentException('user_guid is required');
}
$guids = $opts['guids'] ?: array_map(function ($item) { return $item['guid']; }, $opts['entities']);
$user = $this->entitiesBuilder->single($opts['user_guid']);
$entities = $this->entitiesBuilder->get($opts) ?: [];
$entities = $this->entitiesBuilder->get(['guids' => $guids]);
if (!$user) {
throw new \InvalidArgumentException('User does not exist');
}
if ($user && $user->getType() !== 'user') {
throw new \InvalidArgumentException('Entity is not a user');
}
......