Loading Core/Boost/Campaigns/Manager.php +22 −12 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,9 @@ class Manager /** @var ElasticRepository */ /** @var ElasticRepository */ protected $elasticRepository; protected $elasticRepository; /** @var Metrics */ protected $metrics; /** @var PaymentsRepository */ /** @var PaymentsRepository */ protected $paymentsRepository; protected $paymentsRepository; Loading Loading @@ -51,8 +54,9 @@ class Manager * Manager constructor. * Manager constructor. * @param Repository $repository * @param Repository $repository * @param ElasticRepository $elasticRepository * @param ElasticRepository $elasticRepository * @param Metrics $metrics * @param PaymentsRepository $paymentsRepository * @param PaymentsRepository $paymentsRepository * @param null $queueClient * @param QueueClientInterface $queueClient * @param Delegates\CampaignUrnDelegate $campaignUrnDelegate * @param Delegates\CampaignUrnDelegate $campaignUrnDelegate * @param Delegates\NormalizeDatesDelegate $normalizeDatesDelegate * @param Delegates\NormalizeDatesDelegate $normalizeDatesDelegate * @param Delegates\NormalizeEntityUrnsDelegate $normalizeEntityUrnsDelegate * @param Delegates\NormalizeEntityUrnsDelegate $normalizeEntityUrnsDelegate Loading @@ -63,6 +67,7 @@ class Manager public function __construct( public function __construct( $repository = null, $repository = null, $elasticRepository = null, $elasticRepository = null, $metrics = null, $paymentsRepository = null, $paymentsRepository = null, $queueClient = null, $queueClient = null, $campaignUrnDelegate = null, $campaignUrnDelegate = null, Loading @@ -74,6 +79,7 @@ class Manager { { $this->repository = $repository ?: new Repository(); $this->repository = $repository ?: new Repository(); $this->elasticRepository = $elasticRepository ?: new ElasticRepository(); $this->elasticRepository = $elasticRepository ?: new ElasticRepository(); $this->metrics = $metrics ?: new Metrics(); $this->paymentsRepository = $paymentsRepository ?: new PaymentsRepository(); $this->paymentsRepository = $paymentsRepository ?: new PaymentsRepository(); $this->queueClient = $queueClient ?: QueueClient::build(); $this->queueClient = $queueClient ?: QueueClient::build(); Loading @@ -99,6 +105,7 @@ class Manager /** /** * @param array $opts * @param array $opts * @return Response * @return Response * @throws Exception */ */ public function getList(array $opts = []) public function getList(array $opts = []) { { Loading Loading @@ -146,6 +153,7 @@ class Manager /** /** * @param $urn * @param $urn * @param array $opts * @return Campaign|null * @return Campaign|null * @throws Exception * @throws Exception */ */ Loading Loading @@ -241,6 +249,7 @@ class Manager * @param mixed $paymentPayload * @param mixed $paymentPayload * @return Campaign * @return Campaign * @throws CampaignException * @throws CampaignException * @throws Exception */ */ public function update(Campaign $campaignRef, $paymentPayload = null) public function update(Campaign $campaignRef, $paymentPayload = null) { { Loading Loading @@ -286,8 +295,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // Queue for lifecycle events // Queue for lifecycle events Loading @@ -309,7 +317,7 @@ class Manager */ */ public function sync(Campaign $campaign) public function sync(Campaign $campaign) { { $this->repository->update($campaign); $this->repository->update($campaign, true); $this->elasticRepository->update($campaign); $this->elasticRepository->update($campaign); return $campaign; return $campaign; Loading Loading @@ -362,8 +370,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -398,6 +405,12 @@ class Manager throw new CampaignException('Campaign should be in [created] or [approved] state in order to cancel it'); throw new CampaignException('Campaign should be in [created] or [approved] state in order to cancel it'); } } // Sync impressions $campaign = $this->metrics ->setCampaign($campaign) ->syncImpressionsMet(); // Update // Update $campaign $campaign Loading @@ -409,8 +422,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -454,8 +466,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -499,8 +510,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); return $campaign; return $campaign; } } Loading Core/Boost/Campaigns/Repository.php +7 −7 Original line number Original line Diff line number Diff line Loading @@ -99,7 +99,7 @@ class Repository ->setImpressionsMet($data['impressions_met']) ->setImpressionsMet($data['impressions_met']) ->setRating($data['rating']) ->setRating($data['rating']) ->setQuality($data['quality']) ->setQuality($data['quality']) ->setCreatedTimestamp(((int) $data['timestamp_timestamp']) ?: null) ->setCreatedTimestamp(((int) $data['created_timestamp']) ?: null) ->setReviewedTimestamp(((int) $data['reviewed_timestamp']) ?: null) ->setReviewedTimestamp(((int) $data['reviewed_timestamp']) ?: null) ->setRejectedTimestamp(((int) $data['rejected_timestamp']) ?: null) ->setRejectedTimestamp(((int) $data['rejected_timestamp']) ?: null) ->setRevokedTimestamp(((int) $data['revoked_timestamp']) ?: null) ->setRevokedTimestamp(((int) $data['revoked_timestamp']) ?: null) Loading @@ -120,10 +120,10 @@ class Repository /** /** * @param Campaign $campaign * @param Campaign $campaign * @param bool $async * @return bool * @return bool * @throws Exception */ */ public function add(Campaign $campaign) public function add(Campaign $campaign, $async = true) { { $cql = "INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"; $cql = "INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"; $values = [ $values = [ Loading Loading @@ -159,17 +159,17 @@ class Repository $prepared = new Custom(); $prepared = new Custom(); $prepared->query($cql, $values); $prepared->query($cql, $values); return (bool) $this->db->request($prepared, true); return (bool) $this->db->request($prepared, $async); } } /** /** * @param Campaign $campaign * @param Campaign $campaign * @param bool $async * @return bool * @return bool * @throws Exception */ */ public function update(Campaign $campaign) public function update(Campaign $campaign, $async = true) { { return $this->add($campaign); return $this->add($campaign, $async); } } /** /** Loading Loading
Core/Boost/Campaigns/Manager.php +22 −12 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,9 @@ class Manager /** @var ElasticRepository */ /** @var ElasticRepository */ protected $elasticRepository; protected $elasticRepository; /** @var Metrics */ protected $metrics; /** @var PaymentsRepository */ /** @var PaymentsRepository */ protected $paymentsRepository; protected $paymentsRepository; Loading Loading @@ -51,8 +54,9 @@ class Manager * Manager constructor. * Manager constructor. * @param Repository $repository * @param Repository $repository * @param ElasticRepository $elasticRepository * @param ElasticRepository $elasticRepository * @param Metrics $metrics * @param PaymentsRepository $paymentsRepository * @param PaymentsRepository $paymentsRepository * @param null $queueClient * @param QueueClientInterface $queueClient * @param Delegates\CampaignUrnDelegate $campaignUrnDelegate * @param Delegates\CampaignUrnDelegate $campaignUrnDelegate * @param Delegates\NormalizeDatesDelegate $normalizeDatesDelegate * @param Delegates\NormalizeDatesDelegate $normalizeDatesDelegate * @param Delegates\NormalizeEntityUrnsDelegate $normalizeEntityUrnsDelegate * @param Delegates\NormalizeEntityUrnsDelegate $normalizeEntityUrnsDelegate Loading @@ -63,6 +67,7 @@ class Manager public function __construct( public function __construct( $repository = null, $repository = null, $elasticRepository = null, $elasticRepository = null, $metrics = null, $paymentsRepository = null, $paymentsRepository = null, $queueClient = null, $queueClient = null, $campaignUrnDelegate = null, $campaignUrnDelegate = null, Loading @@ -74,6 +79,7 @@ class Manager { { $this->repository = $repository ?: new Repository(); $this->repository = $repository ?: new Repository(); $this->elasticRepository = $elasticRepository ?: new ElasticRepository(); $this->elasticRepository = $elasticRepository ?: new ElasticRepository(); $this->metrics = $metrics ?: new Metrics(); $this->paymentsRepository = $paymentsRepository ?: new PaymentsRepository(); $this->paymentsRepository = $paymentsRepository ?: new PaymentsRepository(); $this->queueClient = $queueClient ?: QueueClient::build(); $this->queueClient = $queueClient ?: QueueClient::build(); Loading @@ -99,6 +105,7 @@ class Manager /** /** * @param array $opts * @param array $opts * @return Response * @return Response * @throws Exception */ */ public function getList(array $opts = []) public function getList(array $opts = []) { { Loading Loading @@ -146,6 +153,7 @@ class Manager /** /** * @param $urn * @param $urn * @param array $opts * @return Campaign|null * @return Campaign|null * @throws Exception * @throws Exception */ */ Loading Loading @@ -241,6 +249,7 @@ class Manager * @param mixed $paymentPayload * @param mixed $paymentPayload * @return Campaign * @return Campaign * @throws CampaignException * @throws CampaignException * @throws Exception */ */ public function update(Campaign $campaignRef, $paymentPayload = null) public function update(Campaign $campaignRef, $paymentPayload = null) { { Loading Loading @@ -286,8 +295,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // Queue for lifecycle events // Queue for lifecycle events Loading @@ -309,7 +317,7 @@ class Manager */ */ public function sync(Campaign $campaign) public function sync(Campaign $campaign) { { $this->repository->update($campaign); $this->repository->update($campaign, true); $this->elasticRepository->update($campaign); $this->elasticRepository->update($campaign); return $campaign; return $campaign; Loading Loading @@ -362,8 +370,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -398,6 +405,12 @@ class Manager throw new CampaignException('Campaign should be in [created] or [approved] state in order to cancel it'); throw new CampaignException('Campaign should be in [created] or [approved] state in order to cancel it'); } } // Sync impressions $campaign = $this->metrics ->setCampaign($campaign) ->syncImpressionsMet(); // Update // Update $campaign $campaign Loading @@ -409,8 +422,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -454,8 +466,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); // // Loading Loading @@ -499,8 +510,7 @@ class Manager // Write // Write $this->repository->update($campaign); $this->sync($campaign); $this->elasticRepository->update($campaign); return $campaign; return $campaign; } } Loading
Core/Boost/Campaigns/Repository.php +7 −7 Original line number Original line Diff line number Diff line Loading @@ -99,7 +99,7 @@ class Repository ->setImpressionsMet($data['impressions_met']) ->setImpressionsMet($data['impressions_met']) ->setRating($data['rating']) ->setRating($data['rating']) ->setQuality($data['quality']) ->setQuality($data['quality']) ->setCreatedTimestamp(((int) $data['timestamp_timestamp']) ?: null) ->setCreatedTimestamp(((int) $data['created_timestamp']) ?: null) ->setReviewedTimestamp(((int) $data['reviewed_timestamp']) ?: null) ->setReviewedTimestamp(((int) $data['reviewed_timestamp']) ?: null) ->setRejectedTimestamp(((int) $data['rejected_timestamp']) ?: null) ->setRejectedTimestamp(((int) $data['rejected_timestamp']) ?: null) ->setRevokedTimestamp(((int) $data['revoked_timestamp']) ?: null) ->setRevokedTimestamp(((int) $data['revoked_timestamp']) ?: null) Loading @@ -120,10 +120,10 @@ class Repository /** /** * @param Campaign $campaign * @param Campaign $campaign * @param bool $async * @return bool * @return bool * @throws Exception */ */ public function add(Campaign $campaign) public function add(Campaign $campaign, $async = true) { { $cql = "INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"; $cql = "INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"; $values = [ $values = [ Loading Loading @@ -159,17 +159,17 @@ class Repository $prepared = new Custom(); $prepared = new Custom(); $prepared->query($cql, $values); $prepared->query($cql, $values); return (bool) $this->db->request($prepared, true); return (bool) $this->db->request($prepared, $async); } } /** /** * @param Campaign $campaign * @param Campaign $campaign * @param bool $async * @return bool * @return bool * @throws Exception */ */ public function update(Campaign $campaign) public function update(Campaign $campaign, $async = true) { { return $this->add($campaign); return $this->add($campaign, $async); } } /** /** Loading