/** * 框架错误 * @param objcet $e 错误对象 * @return viod */ public function appError($e) { if (404 == $e->getCode()) { $action = 'error404'; } else { $action = 'error'; } obj('base/Error', 'controller')->{$action}($e); }
/** * Build a temporary table with the list of IDs of records we need to update. * The table has a deleted flag to indicate newly deleted records. * @param objcet $db Database connection. * @param string $table Name of the table being cached, e.g. occurrences. * @param string $query A query which selects a list of IDs for all new, updated or * deleted records (including looking for updates or deletions caused by related * records). * @param string $last_run_date Date/time of the last time the cache builder was * run, used to filter records to only the recent changes. Supplied as a string * suitable for injection into an SQL query. */ private static function get_changelist($db, $table, $queries, $last_run_date) { $query = str_replace('#date#', $last_run_date, $queries['get_changed_items_query']); $db->query("create temporary table needs_update_{$table} as {$query}"); if (!variable::get("populated-{$table}")) { // as well as the changed records, pick up max 5000 previous records, which is important for initial population. // 5000 is an arbitrary number to compromise between performance and cache population. // of the cache $query = $queries['get_missing_items_query'] . ' limit 5000'; $result = $db->query("insert into needs_update_{$table} {$query}"); if ($result->count() === 0) { // Flag that we don't need to do any more previously existing records as they are all done. // Future cache updates can just pick up changes from now on. variable::set("populated-{$table}", true); echo "{$table} population completed<br/>"; } } $db->query("ALTER TABLE needs_update_{$table} ADD CONSTRAINT ix_nu_{$table} PRIMARY KEY (id)"); $r = $db->query("select count(*) as count from needs_update_{$table}")->result_array(false); $row = $r[0]; if (variable::get("populated-{$table}")) { if ($row['count'] > 0) { echo "Updating {$table} with {$row['count']} changes<br/>"; } else { echo "No changes for {$table}<br/>"; } } return $row['count']; }