Commit a95f6094 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(chore): Revert Network Boost changes

1 merge request!235WIP: Boost Campaigns (&24)
Pipeline #69301112 passed with stages
in 6 minutes and 55 seconds
......@@ -57,11 +57,6 @@ class Analytics
],
],
],
[
'term' => [
'is_campaign' => true
],
],
],
],
'aggs' => [
......
......@@ -4,26 +4,19 @@
*/
namespace Minds\Core\Boost\Network;
use Exception;
use Minds\Common\Repository\Response;
use Minds\Core\Boost\Raw\RawBoost;
use Minds\Core\Boost\Raw\ElasticRepository as RawElasticRepository;
use Minds\Core\Di\Di;
use Minds\Core\Data\ElasticSearch\Prepared;
use Minds\Core\Util\BigNumber;
class ElasticRepository
{
/** @var RawElasticRepository $rawElasticRepository */
protected $rawElasticRepository;
/** @var Client $es */
protected $es;
/**
* ElasticRepository constructor.
* @param RawElasticRepository $rawElasticRepository
*/
public function __construct(
$rawElasticRepository = null
)
public function __construct($es = null)
{
$this->rawElasticRepository = $rawElasticRepository ?: new RawElasticRepository();
$this->es = $es ?: Di::_()->get('Database\ElasticSearch');
}
/**
......@@ -34,32 +27,135 @@ class ElasticRepository
public function getList($opts = [])
{
$opts = array_merge([
'is_campaign' => false,
'rating' => 3,
'token' => 0,
'offset' => null,
], $opts);
$must = [];
$must_not = [];
$sort = [ '@timestamp' => 'asc' ];
$must[] = [
'term' => [
'bid_type' => 'tokens',
],
];
$must[] = [
'term' => [
'type' => $opts['type'],
],
];
if ($opts['offset']) {
$must[] = [
'range' => [
'@timestamp' => [
'gt' => $opts['offset'],
],
],
];
}
if ($opts['entity_guid']) {
$must[] = [
'term' => [
'entity_guid' => $opts['entity_guid']
]
];
}
if ($opts['state'] === 'approved') {
$must[] = [
'exists' => [
'field' => '@reviewed',
],
];
$must[] = [
'range' => [
'rating' => [
'lte' => $opts['rating'],
],
],
];
}
if ($opts['state'] === 'review') {
$must_not[] = [
'exists' => [
'field' => '@reviewed',
],
];
$sort = ['@timestamp' => 'asc'];
}
$response = $this->rawElasticRepository->getList($opts);
if ($opts['state'] === 'approved' || $opts['state'] === 'review') {
$must_not[] = [
'exists' => [
'field' => '@completed',
],
];
$must_not[] = [
'exists' => [
'field' => '@rejected',
],
];
$must_not[] = [
'exists' => [
'field' => '@revoked',
],
];
}
return $response->map(function (RawBoost $rawBoost) {
$body = [
'query' => [
'bool' => [
'must' => $must,
'must_not' => $must_not,
],
],
'sort' => $sort,
];
$prepared = new Prepared\Search();
$prepared->query([
'index' => 'minds-boost',
'type' => '_doc',
'body' => $body,
'size' => $opts['limit'],
'from' => (int) $opts['token'],
]);
$result = $this->es->request($prepared);
$response = new Response;
$offset = 0;
foreach ($result['hits']['hits'] as $doc) {
$boost = new Boost();
$boost
->setGuid($rawBoost->getGuid())
->setEntityGuid($rawBoost->getEntityGuid())
->setOwnerGuid($rawBoost->getOwnerGuid())
->setCreatedTimestamp($rawBoost->getCreatedTimestamp())
->setReviewedTimestamp($rawBoost->getReviewedTimestamp() ?? null)
->setRevokedTimestamp($rawBoost->getRevokedTimestamp() ?? null)
->setRejectedTimestamp($rawBoost->getRejectedTimestamp() ?? null)
->setCompletedTimestamp($rawBoost->getCompletedTimestamp() ?? null)
->setPriority((bool) $rawBoost->isPriority())
->setType($rawBoost->getType())
->setRating($rawBoost->getRating())
->setImpressions($rawBoost->getImpressions())
->setImpressionsMet($rawBoost->getImpressionsMet())
->setBid($rawBoost->getBid())
->setBidType($rawBoost->getBidType());
return $boost;
});
->setGuid($doc['_id'])
->setEntityGuid($doc['_source']['entity_guid'])
->setOwnerGuid($doc['_source']['owner_guid'])
->setCreatedTimestamp($doc['_source']['@timestamp'])
->setReviewedTimestamp($doc['_source']['@reviewed'] ?? null)
->setRevokedTimestamp($doc['_source']['@revoked'] ?? null)
->setRejectedTimestamp($doc['_source']['@rejected'] ?? null)
->setCompletedTimestamp($doc['_source']['@completed'] ?? null)
->setPriority($doc['_source']['priority'] ?? false)
->setType($doc['_source']['type'])
->setRating($doc['_source']['rating'])
->setImpressions($doc['_source']['impressions'])
->setImpressionsMet($doc['_source']['impressions_met'])
->setBid($doc['_source']['bid'])
->setBidType($doc['_source']['bid_type']);
$offset = $boost->getCreatedTimestamp();
$response[] = $boost;
}
$response->setPagingToken($offset);
return $response;
}
/**
......@@ -76,49 +172,67 @@ class ElasticRepository
* Add a boost
* @param Boost $boost
* @return bool
* @throws Exception
* @throws \Exception
*/
public function add($boost)
{
$rawBoost = new RawBoost();
$rawBoost
->setGuid($boost->getGuid())
->setOwnerGuid($boost->getOwnerGuid())
->setType($boost->getType())
->setEntityGuid($boost->getEntityGuid())
->setBid(
$boost->getBidType() === 'tokens' ?
(string) BigNumber::fromPlain($boost->getBid(), 18)->toDouble() :
$boost->getBid()
)
->setBidType($boost->getBidType())
->setPriority((bool) $boost->isPriority())
->setRating($boost->getRating())
->setImpressions($boost->getImpressions())
->setImpressionsMet($boost->getImpressionsMet())
->setCreatedTimestamp($boost->getCreatedTimestamp())
->setReviewedTimestamp($boost->getReviewedTimestamp())
->setRevokedTimestamp($boost->getRevokedTimestamp())
->setRejectedTimestamp($boost->getRejectedTimestamp())
->setCompletedTimestamp($boost->getCompletedTimestamp());
$body = [
'doc' => [
'@timestamp' => $boost->getCreatedTimestamp(),
'bid' => $boost->getBidType() === 'tokens' ?
(string) BigNumber::fromPlain($boost->getBid(), 18)->toDouble() : $boost->getBid(),
'bid_type' => $boost->getBidType(),
'entity_guid' => $boost->getEntityGuid(),
'impressions' => $boost->getImpressions(),
'owner_guid' => $boost->getOwnerGuid(),
'rating' => $boost->getRating(),
'type' => $boost->getType(),
'priority' => (bool) $boost->isPriority(),
],
'doc_as_upsert' => true,
];
if ($boost->getBidType() === 'tokens') {
$rawBoost->setTokenMethod(
(strpos($boost->getTransactionId(), '0x', 0) === 0) ?
'onchain' :
'offchain'
);
$body['doc']['token_method'] = (strpos($boost->getTransactionId(), '0x', 0) === 0)
? 'onchain' : 'offchain';
}
return $this->rawElasticRepository->add($rawBoost);
if ($boost->getImpressionsMet()) {
$body['doc']['impressions_met'] = $boost->getImpressionsMet();
}
if ($boost->getCompletedTimestamp()) {
$body['doc']['@completed'] = $boost->getCompletedTimestamp();
}
if ($boost->getReviewedTimestamp()) {
$body['doc']['@reviewed'] = $boost->getReviewedTimestamp();
}
if ($boost->getRevokedTimestamp()) {
$body['doc']['@revoked'] = $boost->getRevokedTimestamp();
}
if ($boost->getRejectedTimestamp()) {
$body['doc']['@rejected'] = $boost->getRejectedTimestamp();
}
$prepared = new Prepared\Update();
$prepared->query([
'index' => 'minds-boost',
'type' => '_doc',
'body' => $body,
'id' => $boost->getGuid(),
]);
return (bool) $this->es->request($prepared);
}
/**
* Update a boost
* @param Boost $boost
* @return bool
* @throws Exception
* @throws \Exception
*/
public function update($boost, $fields = [])
{
......
This diff is collapsed.
<?php
/**
* ElasticRepository
* @author edgebal
*/
namespace Minds\Core\Boost\Raw;
use Minds\Common\Repository\Response;
use Minds\Core\Data\ElasticSearch\Client as ElasticSearchClient;
use Minds\Core\Data\ElasticSearch\Prepared\Search;
use Minds\Core\Data\ElasticSearch\Prepared\Update;
use Minds\Core\Di\Di;
use NotImplementedException;
class ElasticRepository
{
/** @var ElasticSearchClient */
protected $elasticsearch;
/**
* Repository constructor.
* @param ElasticSearchClient $elasticsearch
*/
public function __construct(
$elasticsearch = null
)
{
$this->elasticsearch = $elasticsearch ?: Di::_()->get('Database\ElasticSearch');
}
/**
* @param array $opts
* @return Response
*/
public function getList(array $opts = [])
{
$opts = array_merge([
'rating' => 3,
'token' => 0,
'offset' => null,
'sort' => 'asc',
'is_campaign' => null,
], $opts);
$must = [];
$must_not = [];
$sort = [ '@timestamp' => $opts['sort'] ?: 'asc' ];
$must[] = [
'term' => [
'bid_type' => 'tokens',
],
];
if ($opts['is_campaign'] !== null) {
$must[] = [
'term' => [
'is_campaign' => (bool) $opts['is_campaign'],
],
];
}
if ($opts['type']) {
$must[] = [
'term' => [
'type' => $opts['type'],
],
];
}
if ($opts['guid']) {
$must[] = [
'term' => [
'_id' => (string) $opts['guid'],
],
];
}
if ($opts['owner_guid']) {
$must[] = [
'term' => [
'owner_guid' => (string) $opts['owner_guid'],
],
];
}
if ($opts['entity_guid']) {
$must[] = [
'term' => [
'entity_guid' => $opts['entity_guid']
]
];
}
if ($opts['state'] === 'approved') {
$must[] = [
'exists' => [
'field' => '@reviewed',
],
];
$must[] = [
'range' => [
'rating' => [
'lte' => $opts['rating'],
],
],
];
}
if ($opts['state'] === 'review') {
$must_not[] = [
'exists' => [
'field' => '@reviewed',
],
];
$sort = ['@timestamp' => 'asc'];
$opts['sort'] = 'asc';
}
if ($opts['state'] === 'approved' || $opts['state'] === 'review') {
$must_not[] = [
'exists' => [
'field' => '@completed',
],
];
$must_not[] = [
'exists' => [
'field' => '@rejected',
],
];
$must_not[] = [
'exists' => [
'field' => '@revoked',
],
];
}
if ($opts['offset']) {
$rangeKey = $opts['sort'] === 'asc' ? 'gt' : 'lt';
$must[] = [
'range' => [
'@timestamp' => [
$rangeKey => $opts['offset'],
],
],
];
}
$body = [
'query' => [
'bool' => [
'must' => $must,
'must_not' => $must_not,
],
],
'sort' => $sort,
];
$prepared = new Search();
$prepared->query([
'index' => 'minds-boost',
'type' => '_doc',
'body' => $body,
'size' => $opts['limit'],
'from' => (int) $opts['token'],
]);
$result = $this->elasticsearch->request($prepared);
$response = new Response();
$offset = 0;
foreach ($result['hits']['hits'] as $doc) {
$boost = new RawBoost();
$boost
->setGuid($doc['_id'])
->setOwnerGuid($doc['_source']['owner_guid'])
->setType($doc['_source']['type'])
->setEntityGuid($doc['_source']['entity_guid'])
->setEntityUrns($doc['_source']['entity_urns'])
->setBid($doc['_source']['bid'])
->setBidType($doc['_source']['bid_type'])
->setTokenMethod($doc['_source']['token_method'] ?? null)
->setPriority((bool) $doc['_source']['priority'] ?? false)
->setRating($doc['_source']['rating'])
->setImpressions($doc['_source']['impressions'])
->setImpressionsMet($doc['_source']['impressions_met'])
->setTags($doc['_source']['tags'])
->setCampaign((bool) $doc['_source']['is_campaign'] ?? false)
->setCampaignName($doc['_source']['campaign_name'] ?? null)
->setCampaignStart($doc['_source']['campaign_start'] ?? null)
->setCampaignEnd($doc['_source']['campaign_end'] ?? null)
->setCreatedTimestamp($doc['_source']['@timestamp'])
->setReviewedTimestamp($doc['_source']['@reviewed'] ?? null)
->setRevokedTimestamp($doc['_source']['@revoked'] ?? null)
->setRejectedTimestamp($doc['_source']['@rejected'] ?? null)
->setCompletedTimestamp($doc['_source']['@completed'] ?? null);
$response[] = $boost;
$offset = $boost->getCreatedTimestamp();
}
$response->setPagingToken($offset);
return $response;
}
/**
* @param RawBoost $rawBoost
* @return bool
*/
public function add(RawBoost $rawBoost)
{
$body = [
'doc' => [
'owner_guid' => $rawBoost->getOwnerGuid(),
'type' => $rawBoost->getType(),
'entity_guid' => $rawBoost->getEntityGuid(),
'entity_urns' => $rawBoost->getEntityUrns(),
'bid' => $rawBoost->getBid(),
'bid_type' => $rawBoost->getBidType(),
'priority' => (bool) $rawBoost->isPriority(),
'rating' => $rawBoost->getRating(),
'impressions' => $rawBoost->getImpressions(),
'tags' => $rawBoost->getTags() ?: [],
'is_campaign' => $rawBoost->isCampaign(),
'campaign_name' => $rawBoost->getCampaignName(),
'campaign_start' => $rawBoost->getCampaignStart(),
'campaign_end' => $rawBoost->getCampaignEnd(),
'@timestamp' => $rawBoost->getCreatedTimestamp(),
],
'doc_as_upsert' => true,
];
if ($rawBoost->getTokenMethod()) {
$body['doc']['token_method'] = $rawBoost->getTokenMethod();
}
if ($rawBoost->getImpressionsMet()) {
$body['doc']['impressions_met'] = $rawBoost->getImpressionsMet();
}
if ($rawBoost->getReviewedTimestamp()) {
$body['doc']['@reviewed'] = $rawBoost->getReviewedTimestamp();
}
if ($rawBoost->getRevokedTimestamp()) {
$body['doc']['@revoked'] = $rawBoost->getRevokedTimestamp();
}
if ($rawBoost->getRejectedTimestamp()) {
$body['doc']['@rejected'] = $rawBoost->getRejectedTimestamp();
}
if ($rawBoost->getCompletedTimestamp()) {
$body['doc']['@completed'] = $rawBoost->getCompletedTimestamp();
}
$prepared = new Update();
$prepared->query([
'index' => 'minds-boost',
'type' => '_doc',
'body' => $body,
'id' => $rawBoost->getGuid(),
]);
return (bool) $this->elasticsearch->request($prepared);
}
/**
* @param RawBoost $rawBoost
* @return bool
*/
public function update(RawBoost $rawBoost)
{
return $this->add($rawBoost);
}
/**
* @param RawBoost $rawBoost
* @throws NotImplementedException
*/
public function delete(RawBoost $rawBoost)
{
throw new NotImplementedException();
}
}
<?php
/**
* RawBoost
* @author edgebal
*/
namespace Minds\Core\Boost\Raw;
use Minds\Traits\MagicAttributes;
/**
* Class RawBoost
* @package Minds\Core\Boost\Raw
* @method int|string getGuid()
* @method RawBoost setGuid(int|string $guid)
* @method int|string getOwnerGuid()
* @method RawBoost setOwnerGuid(int|string $ownerGuid)
* @method string getType()
* @method RawBoost setType(string $type)
* @method int|string getEntityGuid()
* @method RawBoost setEntityGuid(int|string $entityGuid)
* @method string[] getEntityUrns()
* @method RawBoost setEntityUrns(string[] $entityUrns)
* @method string getBid()
* @method RawBoost setBid(string $bid)
* @method string getBidType()
* @method RawBoost setBidType(string $bidType)
* @method string getTokenMethod()
* @method RawBoost setTokenMethod(string $tokenMethod)
* @method bool isPriority()
* @method RawBoost setPriority(bool $priority)
* @method int getRating()
* @method RawBoost setRating(int $rating)
* @method string[] getTags()
* @method RawBoost setTags(string[] $tags)
* @method string[] getNsfw()
* @method RawBoost setNsfw(string[] $nsfw)
* @method int getImpressions()
* @method RawBoost setImpressions(int $impressions)
* @method int getImpressionsMet()
* @method RawBoost setImpressionsMet(int $impressionsMet)
* @method string getTransactionId()
* @method RawBoost setTransactionId(string $transactionId)
* @method string getChecksum()
* @method RawBoost setChecksum(string $checksum)
* @method int getRejectionReason()
* @method RawBoost setRejectionReason(int $rejectionReason)
* @method bool isCampaign()
* @method RawBoost setCampaign(bool $campaign)
* @method string getCampaignName()
* @method RawBoost setCampaignName(string $campaignName)
* @method int getCampaignStart()
* @method RawBoost setCampaignStart(int $campaignStart)
* @method int getCampaignEnd()
* @method RawBoost setCampaignEnd(int $campaignEnd)
* @method int getCreatedTimestamp()
* @method RawBoost setCreatedTimestamp(int $createdTimestamp)
* @method int getReviewedTimestamp()
* @method RawBoost setReviewedTimestamp(int $reviewedTimestamp)
* @method int getRevokedTimestamp()
* @method RawBoost setRevokedTimestamp(int $revokedTimestamp)
* @method int getRejectedTimestamp()
* @method RawBoost setRejectedTimestamp(int $rejectedTimestamp)
* @method int getCompletedTimestamp()
* @method RawBoost setCompletedTimestamp(int $completedTimestamp)
* @method mixed getMongoId()
* @method RawBoost setMongoId(mixed $deprecatedValue)
* @method mixed getEntity()
* @method RawBoost setEntity(mixed $deprecatedValue)
* @method mixed getOwner()
* @method RawBoost setOwner(mixed $deprecatedValue)
* @method mixed getState()
* @method RawBoost setState(mixed $deprecatedValue)
*/
class RawBoost
{
use MagicAttributes;
/** @var int|string */
protected $guid;
/** @var int|string */
protected $ownerGuid;
/** @var string */
protected $type;
/** @var int|string */
protected $entityGuid;
/** @var string */
protected $entityUrns;
/** @var string */
protected $bid;
/** @var string */
protected $bidType;
/** @var string */
protected $tokenMethod;
/** @var bool */
protected $priority;
/** @var int */
protected $rating;
/** @var string[] */
protected $tags = [];
/** @var int[] */
protected $nsfw = [];
/** @var int */
protected $impressions;
/** @var int */
protected $impressionsMet;
/** @var string */
protected $transactionId;
/** @var string */
protected $checksum;
/** @var int */
protected $rejectionReason;
/** @var string */
protected $campaignName;
/** @var int */
protected $campaignStart;
/** @var int */
protected $campaignEnd;
/** @var int */
protected $createdTimestamp;
/** @var int */
protected $reviewedTimestamp;
/** @var int */
protected $revokedTimestamp;
/** @var int */
protected $rejectedTimestamp;
/** @var int */
protected $completedTimestamp;
// Legacy below. Do not use.
/** @var mixed */
protected $mongoId;
/** @var mixed */
protected $entity;
/** @var mixed */
protected $owner;
/** @var mixed */
protected $state;
}
<?php
/**
* Repository
* @author edgebal
*/
namespace Minds\Core\Boost\Raw;
use Cassandra;
use Exception;
use Minds\Common\Repository\Response;
use Minds\Core\Data\Cassandra\Client as CassandraClient;
use Minds\Core\Data\Cassandra\Prepared\Custom;
use Minds\Core\Di\Di;
use NotImplementedException;
class Repository
{
/** @var CassandraClient */
protected $db;
/**
* Repository constructor.
* @param CassandraClient $db
*/
public function __construct(
$db = null
)
{
$this->db = $db ?: Di::_()->get('Database\Cassandra\Cql');
}
public function getList(array $opts = [])
{
$opts = array_merge([
'limit' => 12,
'token' => null
], $opts);
$template = "SELECT * FROM boosts WHERE type = ?";
$values = [ (string) $opts['type'] ];
if ($opts['guids']) {
$collection = Cassandra\Type::collection(Cassandra\Type::varint())->create(...array_values(array_map(function ($guid) {
return new Cassandra\Varint($guid);
}, $opts['guids'])));
$template .= " AND guid IN ?";
$values[] = $collection;
}
$query = new Custom();
$query->query($template, $values);
$query->setOpts([
'page_size' => (int) $opts['limit'],
'paging_state_token' => base64_decode($opts['offset'])
]);
$response = new Response();
try {
$result = $this->db->request($query);
foreach ($result as $row) {
$rawBoost = new RawBoost();
$data = json_decode($row['data'], true);
if (!isset($data['schema']) && $data['schema'] != '04-2019') {
$data['entity_guid'] = $data['entity']['guid'];
$data['owner_guid'] = $data['owner']['guid'];
$data['@created'] = $data['time_created'] * 1000;
$data['@reviewed'] = $data['state'] === 'accepted' ? ($data['last_updated'] * 1000) : null;
$data['@revoked'] = $data['state'] === 'revoked' ? ($data['last_updated'] * 1000) : null;
$data['@rejected'] = $data['state'] === 'rejected' ? ($data['last_updated'] * 1000) : null;
$data['@completed'] = $data['state'] === 'completed' ? ($data['last_updated'] * 1000) : null;
}
if ($data['@created'] < 1055503139000) {
$data['@created'] = $data['@created'] * 1000;
}
if ($data['is_campaign'] ?? false) {
// Skip campaigns
continue;
}
$rawBoost
->setGuid((string) $row['guid'])
->setOwnerGuid((string) $data['owner_guid'])
->setType($row['type'])
->setEntityGuid((string) $data['entity_guid'])
->setEntityUrns($data['entity_urns'] ?? [])
->setBid($data['bid'])
->setBidType($data['bidType'])
->setTokenMethod($data['token_method'] ?? null)
->setPriority($data['priority'])
->setRating($data['rating'])
->setImpressions($data['impressions'])
->setTags($data['tags'])
->setNsfw($data['nsfw'])
->setTransactionId($data['transactionId'])
->setRejectionReason($data['rejection_reason'])
->setChecksum($data['checksum'])
->setCampaign((bool) $data['is_campaign'] ?? false)
->setCampaignName($data['campaign_name'] ?? null)
->setCampaignStart($data['campaign_start'] ?? null)
->setCampaignEnd($data['campaign_end'] ?? null)
->setCreatedTimestamp($data['@created'])
->setReviewedTimestamp($data['@reviewed'])
->setRevokedTimestamp($data['@revoked'])
->setRejectedTimestamp($data['@rejected'])
->setCompletedTimestamp($data['@completed'])
->setMongoId($data['_id'])
;
$response[] = $rawBoost;
}
$response->setPagingToken(base64_encode($result->pagingStateToken()));
} catch (Exception $e) {
$response->setException($e);
}
return $response;
}
/**
* @param RawBoost $rawBoost
* @return bool
* @throws Exception
*/
public function add(RawBoost $rawBoost)
{
if (!$rawBoost->getType()) {
throw new Exception('Missing type');
}
if (!$rawBoost->getGuid()) {
throw new Exception('Missing GUID');
}
if (!$rawBoost->getOwnerGuid()) {
throw new Exception('Missing owner GUID');
}
$template = "INSERT INTO boosts
(type, guid, owner_guid, destination_guid, mongo_id, state, data)
VALUES
(?, ?, ?, ?, ?, ?, ?)
";
$data = [
'schema' => '04-2019',
'guid' => $rawBoost->getGuid(),
'entity_guid' => $rawBoost->getEntityGuid(),
'entity_urns' => $rawBoost->getEntityUrns(),
'bid' => $rawBoost->getBid(),
'impressions' => $rawBoost->getImpressions(),
'bidType' => $rawBoost->getBidType(),
'owner_guid' => $rawBoost->getOwnerGuid(),
'transactionId' => $rawBoost->getTransactionId(),
'type' => $rawBoost->getType(),
'priority' => $rawBoost->isPriority(),
'rating' => $rawBoost->getRating(),
'tags' => $rawBoost->getTags(),
'nsfw' => $rawBoost->getNsfw(),
'rejection_reason'=> $rawBoost->getRejectionReason(),
'checksum' => $rawBoost->getChecksum(),
'@created' => $rawBoost->getCreatedTimestamp(),
'@reviewed' => $rawBoost->getReviewedTimestamp(),
'@rejected' => $rawBoost->getRejectedTimestamp(),
'@revoked' => $rawBoost->getRevokedTimestamp(),
'@completed' => $rawBoost->getCompletedTimestamp(),
'token_method' => $rawBoost->getTokenMethod(),
'is_campaign' => $rawBoost->isCampaign(),
'campaign_name' => $rawBoost->getCampaignName(),
'campaign_start' => $rawBoost->getCampaignStart(),
'campaign_end' => $rawBoost->getCampaignEnd(),
// Legacy.
'_id' => $rawBoost->getMongoId(),
'entity' => $rawBoost->getEntity() ? $rawBoost->getEntity()->export() : null,
'owner' => $rawBoost->getOwner() ? $rawBoost->getOwner()->export() : null,
'time_created' => $rawBoost->getCreatedTimestamp(),
'last_updated' => time(),
'handler' => $rawBoost->getType(),
'state' => $rawBoost->getState(),
];
$values = [
(string) $rawBoost->getType(),
new Cassandra\Varint($rawBoost->getGuid()),
new Cassandra\Varint($rawBoost->getOwnerGuid()),
null,
(string) $rawBoost->getMongoId(),
(string) $rawBoost->getState(),
json_encode($data)
];
$query = new Custom();
$query->query($template, $values);
try {
$success = (bool) $this->db->request($query);
} catch (Exception $e) {
return false;
}
return $success;
}
/**
* @param RawBoost $rawBoost
* @return bool
* @throws Exception
*/
public function update(RawBoost $rawBoost)
{
return $this->add($rawBoost);
}
/**
* @param RawBoost $rawBoost
* @throws NotImplementedException
*/
public function delete(RawBoost $rawBoost)
{
throw new NotImplementedException();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment