diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 09d7c52..b5d63f1 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -9,18 +9,21 @@ public function after($event = array()) { } public $logs = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'type' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 50, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'message' => array('type' => 'text', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'message' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'ip' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 50, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'hostname' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 50, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'uri' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'refer' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'user_agent' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'number' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false), + 'session_data' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'type' => array('column' => 'type', 'unique' => 0), - 'message' => array('column' => 'message', 'type' => 'fulltext') + 'type' => array('column' => 'type', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM') ); diff --git a/Controller/DatabaseLoggerAppController.php b/Controller/DatabaseLoggerAppController.php index 8bb856b..14caf6d 100644 --- a/Controller/DatabaseLoggerAppController.php +++ b/Controller/DatabaseLoggerAppController.php @@ -1,4 +1,5 @@ request->params['named']) ? $this->request->params['named'] : array(); diff --git a/Controller/LogsController.php b/Controller/LogsController.php index 3465d2d..2ba69bb 100644 --- a/Controller/LogsController.php +++ b/Controller/LogsController.php @@ -3,17 +3,20 @@ class LogsController extends DatabaseLoggerAppController { var $name = 'Logs'; var $helpers = array('Time','Icing.Csv'); - var $paginate = array( - 'order' => 'Log.id DESC', + public $paginate = array( + 'order' => 'Log.created DESC', 'fields' => array( 'Log.created', 'Log.type', 'Log.message', - 'Log.id' + 'Log.id', + 'Log.user_id' + ) ); function admin_index($filter = null) { + $this->Paginator->settings = $this->paginate; if(!empty($this->data)){ $filter = $this->data['Log']['filter']; } @@ -22,6 +25,8 @@ function admin_index($filter = null) { $this->Log->search($this->request->params['named']), $this->Log->textSearch($filter) ); + + $this->set('logs',$this->paginate($conditions)); $this->set('types', $this->Log->getTypes()); $this->set('filter', $filter); @@ -65,4 +70,21 @@ function admin_delete($id = null) { $this->Session->setFlash(__('Log was not deleted')); $this->redirect(array('action' => 'index')); } + + public function admin_delete_similar($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for log')); + $this->redirect(array('action'=>'index')); + } + $log = $this->Log->findById($id); + if ($this->Log->deleteAll(['Log.message LIKE'=>'%'.$log['Log']['message'].'%'])) { + $this->Session->setFlash(__('Log deleted')); + $this->redirect(array('action'=>'index')); + } + $this->Session->setFlash(__('Log was not deleted')); + $this->redirect(array('action' => 'index')); + } + public function teste(){ + + } } diff --git a/Model/Log.php b/Model/Log.php index daf64e9..9bfe315 100755 --- a/Model/Log.php +++ b/Model/Log.php @@ -9,6 +9,8 @@ function beforeSave($options = array()){ $this->data[$this->alias]['hostname'] = env('HTTP_HOST'); $this->data[$this->alias]['uri'] = env('REQUEST_URI'); $this->data[$this->alias]['refer'] = env('HTTP_REFERER'); + $this->data[$this->alias]['user_id'] = CakeSession::read('Auth.User.id'); + $this->data[$this->alias]['session_data'] = json_encode(CakeSession::read()); return true; } diff --git a/View/Logs/admin_index.ctp b/View/Logs/admin_index.ctp index 74c98ff..a727f1d 100755 --- a/View/Logs/admin_index.ctp +++ b/View/Logs/admin_index.ctp @@ -1,34 +1,43 @@ Html->css('/database_logger/css/style'); ?>
- element('admin_filter', array('plugin' => 'database_logger', 'model' => 'Log')); ?> -
-

- - - - - - - - - > - - - - - - -
Paginator->sort('created');?>Paginator->sort('type');?>Paginator->sort('message');?>
Time->niceShort($log['Log']['created']); ?>    - Html->link(__('View Details'), array('action' => 'view', $log['Log']['id'])); ?> - Html->link(__('Delete'), array('action' => 'delete', $log['Log']['id']), null, sprintf(__('Are you sure you want to delete this log # %s?'), $log['Log']['id'])); ?> -
- element('paging', array('plugin' => 'database_logger')); ?> -
+ element('admin_filter', ['plugin' => 'database_logger', 'model' => 'Log']); ?> +
+

+ + + + + + + + + + > + + + + + + + +
Paginator->sort('created'); ?>Paginator->sort('type'); ?>Paginator->sort('message'); ?>Paginator->sort('user_id'); ?>
Time->niceShort($log['Log']['created']); ?>     + Html->link(__('View Details'), + ['action' => 'view', $log['Log']['id']]); ?> + Html->link(__('Delete'), ['action' => 'delete', $log['Log']['id']], null, + sprintf(__('Are you sure you want to delete this log # %s?'), + $log['Log']['id'])); ?> + Html->link(__('Delete Similar'), + ['action' => 'delete_similar', $log['Log']['id']], + null, + sprintf(__('Are you sure you want to delete ALL logs similar to this?'))); ?> +
+ element('paging', ['plugin' => 'database_logger']); ?> +
\ No newline at end of file diff --git a/View/Logs/admin_view.ctp b/View/Logs/admin_view.ctp index 1701a5f..029f481 100755 --- a/View/Logs/admin_view.ctp +++ b/View/Logs/admin_view.ctp @@ -43,6 +43,16 @@   + > + > + +   + + > + > + +   + \ No newline at end of file