public function validateDb() { $errors = array('message' => 'Database structure is invalid'); try { $db = $this->get('db'); // Reconnect in case the database was created just now $db->reconnect(); $tables = $db->getTables(); $expectedTables = array(UserModel::repo()->getTableName(), MessageModel::repo()->getTableName(), DataModel::repo('')->getTableName()); } catch (Exception $ex) { $errors['message'] = 'Database exception: ' . $ex->getMessage(); return $errors; } if (count(array_diff($expectedTables, $tables)) !== 0) { $errors['message'] = 'Invalid table structure, actual tables: ' . join(', ', $tables) . ', expected tables: ' . join(', ', $expectedTables); return $errors; } return array(); }
public function generateTalkId() { // Find the last talk ID $result = self::$db->queryOne('SELECT MAX(talk_id) AS talk_id FROM ' . MessageModel::repo()->getTableName()); return $result['talk_id'] + 1; }
public function clearHistoryAction() { $request = $this->get('request'); // Force POST requests if (!$request->isPost()) { return $this->json(array('success' => false)); } // Clear the history $success = MessageModel::repo()->clearHistory(); if ($success) { // Log $this->get('logger')->info('History cleared'); } return $this->json(array('success' => $success)); }