/** * load the container the need to be generate */ public function load() { $this->data = $this->collection->aggregate($this->aggregation_array); //TODO how to perform it on the secondaries? Billrun_Factory::log()->log("generator entities loaded: " . count($this->data), Zend_Log::INFO); Billrun_Factory::dispatcher()->trigger('afterGeneratorLoadData', array('generator' => $this)); }
/** * Gets all the account lines for this billrun from the db * @param int $aid the account id * @param int $start_time lower bound date to get lines from. A unix timestamp * @return Mongodloid_Cursor the mongo cursor used to iterate over the lines * @todo remove aid parameter */ protected function getAccountLines($aid, $start_time = 0, $include_flats = true) { $start_time = new MongoDate($start_time); $end_time = new MongoDate(Billrun_Util::getEndTime($this->billrun_key)); $query = array('aid' => $aid, 'urt' => array('$lte' => $end_time, '$gte' => $start_time)); if (!$include_flats) { $query['type'] = array('$ne' => 'flat'); } if ($this->allowOverride == 1) { $query['billrun']['$in'] = array('000000', $this->billrun_key); } else { if ($this->allowOverride == 2) { $query['billrun'] = $this->billrun_key; } else { $query['billrun'] = '000000'; } } $hint = array('aid' => 1, 'urt' => 1); $sort = array('aid' => 1, 'urt' => 1); Billrun_Factory::log()->log("Querying for account " . $aid . " lines", Zend_Log::INFO); $cursor = $this->lines->query($query)->cursor()->fields($this->filter_fields)->sort($sort)->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref'))->hint($hint); Billrun_Factory::log()->log("Finished querying for account " . $aid . " lines", Zend_Log::INFO); // $results = array(); // Billrun_Factory::log()->log("Saving account " . $aid . " lines to array", Zend_Log::DEBUG); // foreach ($cursor as $entity) { // $results[] = $entity; // } // Billrun_Factory::log()->log("Finished saving account " . $aid . " lines to array", Zend_Log::DEBUG); // return $results; return $cursor; }
/** * removes the transactions from the subscriber's balance to save space. * @param type $row */ public function removeBalanceTx($row) { $sid = $row['sid']; $billrun_key = Billrun_Util::getBillrunKey($row['urt']->sec); $query = array('billrun_month' => $billrun_key, 'sid' => $sid); $values = array('$unset' => array('tx.' . $row['stamp'] => 1)); $this->balances->update($query, $values); }
/** * Creates and saves a flat line to the db * @param Billrun_Subscriber $subscriber the subscriber to create a flat line to * @param string $billrun_key the billrun for which to add the flat line * @return array the inserted line or the old one if it already exists */ protected function saveFlatLine($subscriber, $billrun_key) { $flat_entry = $subscriber->getFlatEntry($billrun_key); try { $this->lines->insert($flat_entry, array("w" => 1)); } catch (Exception $e) { if ($e->getCode() == 11000) { Billrun_Factory::log("Flat line already exists for subscriber " . $subscriber->sid . " for billrun " . $billrun_key, Zend_log::ALERT); } else { Billrun_Factory::log("Problem inserting flat line for subscriber " . $subscriber->sid . " for billrun " . $billrun_key . ". error message: " . $e->getMessage() . ". error code: " . $e->getCode(), Zend_log::ALERT); } } return new Mongodloid_Entity($flat_entry); }
/** * create and save credit lines * @param type $subscriber * @param type $billrun_key * @return array of inserted lines */ protected function saveCreditLines($subscriber, $billrun_key) { $credits = $subscriber->getCredits($billrun_key, true); $ret = array(); foreach ($credits as $credit) { $rawData = $credit->getRawData(); try { $this->lines->insert($rawData, array("w" => 1)); } catch (Exception $e) { if ($e->getCode() == 11000) { Billrun_Factory::log("Credit already exists for subscriber " . $subscriber->sid . " for billrun " . $billrun_key . " credit details: " . print_R($rawData, 1), Zend_log::ALERT); } else { Billrun_Factory::log("Problem inserting credit for subscriber " . $subscriber->sid . " for billrun " . $billrun_key . ". error message: " . $e->getMessage() . ". error code: " . $e->getCode() . ". credit details:" . print_R($rawData, 1), Zend_log::ALERT); Billrun_Util::logFailedCreditRow($rawData); } } $ret[$credit['stamp']] = $credit; } return $ret; }
/** * Updates the billrun object to match the db * @return Billrun_Billrun */ protected function load() { $this->data = $this->billrun_coll->query(array('aid' => $this->aid, 'billrun_key' => $this->billrun_key))->cursor()->limit(1)->current(); $this->data->collection($this->billrun_coll); return $this; }