예제 #1
0
 public function __call($method, $arguments)
 {
     try {
         $logger = vB::getLogger('api.' . $this->controller . '.' . $method);
         //check so that we don't var_export large variables when we don't have to
         if ($logger->isInfoEnabled()) {
             if (!($ip = vB::getRequest()->getAltIp())) {
                 $ip = vB::getRequest()->getIpAddress();
             }
             $message = str_repeat('=', 80) . "\ncalled {$method} on {$this->controller} from ip {$ip} \n\$arguments = " . var_export($arguments, true) . "\n" . str_repeat('=', 80) . "\n";
             $logger->info($message);
             $logger->info("time: " . microtime(true));
         }
         if ($logger->isTraceEnabled()) {
             $message = str_repeat('=', 80) . "\n " . $this->getTrace() . str_repeat('=', 80) . "\n";
             $logger->trace($message);
         }
         $c = $this->api;
         // This is a hack to prevent method parameter reference error. See VBV-5546
         $hackedarguments = array();
         foreach ($arguments as $k => &$arg) {
             $hackedarguments[$k] =& $arg;
         }
         $return = call_user_func_array(array(&$c, $method), $hackedarguments);
         //check so that we don't var_export large variables when we don't have to
         if ($logger->isDebugEnabled()) {
             $message = str_repeat('=', 80) . "\ncalled {$method} on {$this->controller}\n\$return = " . var_export($return, true) . "\n" . str_repeat('=', 80) . "\n";
             $logger->debug($message);
         }
         return $return;
     } catch (vB_Exception_Api $e) {
         $errors = $e->get_errors();
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug'])) {
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
         }
         return array('errors' => $errors);
     } catch (vB_Exception_Database $e) {
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug']) or vB::getUserContext()->hasAdminPermission('cancontrolpanel')) {
             $errors = array('Error ' . $e->getMessage());
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
             return array('errors' => $errors);
         } else {
             // This text is purposely hard-coded since we don't have
             // access to the database to get a phrase
             return array('errors' => array(array('There has been a database error, and the current page cannot be displayed. Site staff have been notified.')));
         }
     } catch (Exception $e) {
         $errors = array(array('unexpected_error', $e->getMessage()));
         $config = vB::getConfig();
         if (!empty($config['Misc']['debug'])) {
             $trace = '## ' . $e->getFile() . '(' . $e->getLine() . ") Exception Thrown \n" . $e->getTraceAsString();
             $errors[] = array("exception_trace", $trace);
         }
         return array('errors' => $errors);
     }
 }
예제 #2
0
 public function assertQuery($queryid, $params = array(), $orderby = false)
 {
     //make sure we have been initialized
     if (!isset(self::$instance)) {
         return false;
     }
     if ($this->debugDisplayNextQuerySql) {
         $params[vB_dB_Query::DEBUG_QUERY] = 1;
     }
     // get the query object
     $query = vB_dB_Query::getQuery($queryid, $params, self::$db, self::$userinfo, self::$dbtype, self::$dbSlave);
     if (isset($params[vB_dB_Query::DEBUG_QUERY])) {
         unset($params[vB_dB_Query::DEBUG_QUERY]);
     }
     if ($this->debugDisplayNextQuerySql) {
         $this->debugDisplayNextQuerySql = false;
         $query->debugDisplayNextQuerySql();
     }
     //set the parameters. The children will raise an error if they don't have enough data.
     $check = $query->setQuery($params, $orderby);
     /**If we are in development mode, record this query **/
     if ($this->debug) {
         $this->queryCount += 1;
         /**for performance measuring- number of queries on this page **/
         if (!empty($_REQUEST['querylist'])) {
             $displayParams = $params;
             unset($displayParams[vB_dB_Query::TYPE_KEY]);
             $displayParam = var_export($displayParams, true);
             if (strlen($displayParam) > 256) {
                 $this->queries[] = $queryid . ': ' . substr($displayParam, 0, 256) . '...';
             } else {
                 $this->queries[] = $queryid . ': ' . $displayParam;
             }
         }
     }
     if ($this->debugLog) {
         $starttime = microtime(true);
         //We don't want a full trace.
         $stack = array();
         $trace = debug_backtrace(false);
         foreach ($trace as $key => $step) {
             $line = "Step {$key}: in " . $step['function'];
             foreach (array('line', 'step', 'file') as $field) {
                 if (!empty($step[$field])) {
                     $line .= ' ' . $field . ' ' . $step[$field];
                 }
             }
             $stack[] = $line;
         }
         $info = "---------------------\nQuery: " . $queryid . "\n" . var_export($params, true) . "\n" . implode("\n", $stack) . "\n";
         if (isset($params[vB_dB_Query::TYPE_KEY])) {
             vB::getLogger("dbAssertor.{$queryid}." . $params[vB_dB_Query::TYPE_KEY])->info($info);
         } else {
             vB::getLogger("dbAssertor.{$queryid}")->info($info);
         }
         $result = $query->execSQL();
         vB::getLogger("dbAssertor.{$queryid}")->info("time: " . (microtime(true) - $starttime));
         return $result;
     }
     return $query->execSQL();
 }