/mvc/models/error
[return to app]1
<?php
2 class errorModel extends model {
3 /**
4 * Collection name (used only if Mongo is installed) - only need to change this if you will be operating
multiple
5 * Vork account instances on the same database
6 * @var string
7 */
8 protected $_collection = 'errors';
9
10 /**
11 * Logs errors - saves to a Mongo collection if Mongo is installed, otherwise it saves to the PHP error log
12 * @param array $error
13 */
14 public function logError(array $error) { //array_merge is used for array_unshift-like behavior
15 $error = array_merge(array('_url' => get::url(array('get' => true)), '_date' => date('r')), $error);
16 $error['_ts'] = time();
17 if (is::ajax()) {
18 $error['_isAjax'] = true;
19 }
20 if (isset($_SESSION)) {
21 $error['_SESSION'] = $_SESSION;
22 }
23 if ($_POST) {
24 $error['_POST'] = $_POST;
25 }
26 $error['_SERVER'] = $_SERVER;
27 if (!in_array('mongo', config::$modelObjects)) {
28 error_log(json_encode($error));
29 } else {
30 $col = $this->_collection;
31 if (isset($error['error']) && is_scalar($error['error'])) {
32 $col .= '_' . substr(preg_replace('/\W+/', '_', $error['error']), 0, 40);
33 }
34 $errors = $this->mongo->selectCollection($col);
35 $errors->insert($error);
36 $errors->ensureIndex(array('_ts' => -1));
37 }
38 }
39 }