/** * Calculate downline snapshots up to requested date (including). * * @param Request\Calc $request * * @return Response\Calc */ public function calc(Request\Calc $request) { $result = new Response\Calc(); $this->_logger->info("New downline snapshot calculation is requested."); $periodTo = $request->getDatestampTo(); $def = $this->_manTrans->begin(); try { /* get the last date with calculated snapshots */ $reqLast = new Request\GetLastDate(); /** @var $resp Response\GetLastDate */ $respLast = $this->getLastDate($reqLast); $lastDatestamp = $respLast->getLastDate(); /* get the snapshot on the last date */ $snapshot = $this->_repoSnap->getStateOnDate($lastDatestamp); /* get change log for the period */ $tsFrom = $this->_toolPeriod->getTimestampNextFrom($lastDatestamp); $tsTo = $this->_toolPeriod->getTimestampTo($periodTo); $changelog = $this->_repoChange->getChangesForPeriod($tsFrom, $tsTo); /* calculate snapshots for the period */ $updates = $this->_subCalc->calcSnapshots($snapshot, $changelog); /* save new snapshots in DB */ $this->_repoSnap->saveCalculatedUpdates($updates); $this->_manTrans->commit($def); $result->markSucceed(); } finally { $this->_manTrans->end($def); } return $result; }
protected function _createDownlineSnapshots($dsUpTo) { $req = new DownlineSnapCalcRequest(); $req->setDatestampTo($dsUpTo); $resp = $this->_callDownlineSnap->calc($req); $this->assertTrue($resp->isSucceed()); }
private function _createCustomerDownlineTreeSnap() { /* calculate snapshots */ $this->_logger->debug("Calculate snapshots."); $req = new SnapCalcRequest(); $req->setDatestampTo(self::DS_CUSTOMER_ADDED); $respCalc = $this->_callDownlineSnap->calc($req); $this->assertTrue($respCalc->isSucceed()); }
private function _changeC13ToRoot() { $this->_logger->debug("Change parent to root for customer #13."); $this->_dayIsOver(); /** @var $period \Praxigento\Core\Tool\IPeriod */ $period = $this->_toolPeriod; $customerId = $this->_mapCustomerMageIdByIndex[13]; /* get snapshot before calculation */ $reqSnap = new SnapGetStateOnDateRequest(); $reqSnap->setDatestamp($this->_dtToday); $respSnap = $this->_callSnap->getStateOnDate($reqSnap); $this->assertTrue($respSnap->isSucceed()); $beforeData = $respSnap->getData($customerId); $beforeParentId = $beforeData[Snap::ATTR_PARENT_ID]; $this->assertNotEquals($customerId, $beforeParentId); $this->_logger->debug("Mage ID of the #10 customer's parent is {$beforeParentId} (before update)."); /* change parent */ $reqChange = new CustomerChangeParentRequest(); $reqChange->setCustomerId($customerId); $reqChange->setNewParentId($customerId); $reqChange->setDate($period->getTimestampFrom($this->_dtToday)); $respChange = $this->_callDownlineCustomer->changeParent($reqChange); $this->assertTrue($respChange->isSucceed()); /* calculate snapshots */ $this->_logger->debug("Calculate snapshots."); $req = new SnapCalcRequest(); $req->setDatestampTo($this->_dtToday); $respCalc = $this->_callSnap->calc($req); $this->assertTrue($respCalc->isSucceed()); /* get snapshot after calculation */ $reqSnap->datestamp = $this->_dtToday; $respSnap = $this->_callSnap->getStateOnDate($reqSnap); $this->assertTrue($respSnap->isSucceed()); $afterData = $respSnap->getData($customerId); $afterParentId = $afterData[Snap::ATTR_PARENT_ID]; $this->assertNotEquals($beforeParentId, $afterParentId); $this->_logger->debug("Mage ID of the #13 customer's parent is {$afterParentId} (after update)."); }