/** * 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; }