/** * method to execute the query * it's called automatically by the api main controller */ public function execute() { Billrun_Factory::log()->log("Execute api query billrun", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO); if (!isset($request['aid'])) { $this->setError('Require to supply aid or sid', $request); return true; } $find = array(); $max_list = 1000; if (isset($request['aid'])) { $aids = Billrun_Util::verify_array($request['aid'], 'int'); if (count($aids) > $max_list) { $this->setError('Maximum of aid is ' . $max_list, $request); return true; } $find['aid'] = array('$in' => $aids); } if (isset($request['billrun'])) { $find['billrun_key'] = $this->getBillrunQuery($request['billrun']); } $options = array('sort' => array('aid', 'billrun_key')); $cacheParams = array('fetchParams' => array('options' => $options, 'find' => $find)); $this->setCacheLifeTime(604800); // 1 week $results = $this->cache($cacheParams); Billrun_Factory::log()->log("query success", Zend_Log::INFO); $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $results)); $this->getController()->setOutput($ret); }
/** * method to execute the query * it's called automatically by the api main controller */ public function execute() { Billrun_Factory::log()->log("Execute api query aggregate", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::DEBUG); if (!isset($request['aid']) && !isset($request['sid'])) { $this->setError('Require to supply aid or sid', $request); return true; } $find = array(); $max_list = 1000; if (isset($request['aid'])) { $aids = Billrun_Util::verify_array($request['aid'], 'int'); if (count($aids) > $max_list) { $this->setError('Maximum of aid is ' . $max_list, $request); return true; } $find['aid'] = array('$in' => $aids); } if (isset($request['sid'])) { $sids = Billrun_Util::verify_array($request['sid'], 'int'); if (count($sids) > $max_list) { $this->setError('Maximum of sid is ' . $max_list, $request); return true; } $find['sid'] = array('$in' => $sids); } if (isset($request['billrun'])) { $find['billrun'] = $this->getBillrunQuery($request['billrun']); } if (isset($request['query'])) { $query = $this->getArrayParam($request['query']); $find = array_merge($find, (array) $query); } if (isset($request['groupby'])) { $groupby = array('_id' => $this->getArrayParam($request['groupby'])); } else { $groupby = array('_id' => null); } if (isset($request['aggregate'])) { $aggregate = $this->getArrayParam($request['aggregate']); } else { $aggregate = array('count' => array('$sum' => 1)); } $group = array_merge($groupby, $aggregate); $options = array('sort' => array('urt'), 'page' => isset($request['page']) && $request['page'] > 0 ? (int) $request['page'] : 0, 'size' => isset($request['size']) && $request['size'] > 0 ? (int) $request['size'] : 1000); $cacheParams = array('fetchParams' => array('options' => $options, 'find' => $find, 'group' => $group, 'groupby' => $groupby)); $this->setCacheLifeTime(604800); // 1 week $results = $this->cache($cacheParams); Billrun_Factory::log()->log("Aggregate query success", Zend_Log::INFO); $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $results)); $this->getController()->setOutput($ret); }
/** * method to clean account cache * * @param int $aid * * @return true on success, else false */ protected function cleanAccountCache($aid) { $cache = Billrun_Factory::cache(); if (empty($cache)) { return false; } $aids = array_unique(array_diff(Billrun_Util::verify_array(explode(',', $aid), 'int'), array(0))); $billrunKey = Billrun_Util::getBillrunKey(time()); $cachePrefix = 'balance_'; // this is not the action name because it's clear the balance cache foreach ($aids as $aid) { $cleanCacheKeys = array(Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => array(), 'stamp' => $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => null, 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => "", 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => 0, 'stamp' => (int) $billrunKey)))); foreach ($cleanCacheKeys as $cacheKey) { $cache->remove($cacheKey, $cachePrefix); } } return true; }
public function execute() { Billrun_Factory::log()->log("Execute recreate invoices", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests if (empty($request['account_id'])) { return $this->setError('Please supply at least one account id', $request); } $billrun_key = Billrun_Util::getPreviousBillrunKey(Billrun_Util::getBillrunKey(time())); // Warning: will convert half numeric strings / floats to integers $account_ids = array_unique(array_diff(Billrun_Util::verify_array(explode(',', $request['account_id']), 'int'), array(0))); if ($account_ids) { $options = array('autoload' => 0, 'stamp' => $billrun_key); $customer_aggregator_options = array('override_accounts' => $account_ids, 'bulk_account_preload' => 0); $customerOptions = array('type' => 'customer', 'aggregator' => $customer_aggregator_options); $customerAgg = Billrun_Aggregator::getInstance(array_merge($options, $customerOptions)); $customerAgg->load(); $successfulAccounts = $customerAgg->aggregate(); } else { return $this->setError('Illegal aids', $request); } $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'successfulAccounts' => $successfulAccounts))); return TRUE; }
protected function getBillrunQuery($billrun) { return array('$in' => Billrun_Util::verify_array($this->getArrayParam($billrun), 'str')); }