From 41e5dcc8f45f4808c836028bbf13c33ea35cf422 Mon Sep 17 00:00:00 2001 From: Parziphal Date: Sun, 26 Jan 2014 15:43:12 -0500 Subject: [PATCH] Added UserLog. --- app/controllers/UserController.php | 3 +- app/models/User.php | 13 +++---- app/models/UserLog.php | 12 +++++++ db/migrate/20140126192028_create_user_log.php | 23 +++++++++++++ db/table_schema/production/user_logs.php | 34 +++++++++++++++++++ 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100755 app/models/UserLog.php create mode 100755 db/migrate/20140126192028_create_user_log.php create mode 100644 db/table_schema/production/user_logs.php diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 41fdc66..1cf893f 100755 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -89,8 +89,9 @@ class UserController extends ApplicationController } if (current_user()->is_mod_or_higher()) { + # RP: Missing feature. // $this->user_ips = $this->user->user_logs->order('created_at DESC').pluck('ip_addr').uniq - $this->user_ips = array(); + $this->user_ips = array_unique(UserLog::where(['user_id' => $this->user->id])->order('created_at DESC')->take()->getAttributes('ip_addr')); } $tag_types = CONFIG()->tag_types; diff --git a/app/models/User.php b/app/models/User.php index 7a5e14d..914d22c 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -46,15 +46,14 @@ class User extends Rails\ActiveRecord\Base public function log($ip) { - # iTODO: UserLog doesn't exist yet. - return; - return Rails::cache()->fetch(['type' => 'user_logs', 'id' => $this->id, 'ip' => $ip], ['expires_in' => '10 minutes'], function() use ($ip) { Rails::cache()->fetch(['type' => 'user_logs', 'id' => 'all'], ['expires_in' => '1 day'], function() { - return UserLog::where('created_at < ?', date('Y-m-d 0:0:0', strtotime('-3 days')))->deleteAll(); + # RP: Missing relation method "deleteAll()" + return UserLog::where('created_at < ?', date('Y-m-d 0:0:0', strtotime('-3 days')))->take()->each('destroy'); }); - $log_entry = UserLog::where(['ip_addr' => $ip])->firstOrInitialize(); + # RP: Missing feature. + $log_entry = UserLog::where(['ip_addr' => $ip, 'user_id' => $this->id])->firstOrInitialize(); $log_entry->created_at = date('Y-m-d H:i:s'); return $log_entry->save(); }); @@ -65,10 +64,6 @@ class User extends Rails\ActiveRecord\Base # characters in tags, they can be used to separate lines (with whitespace separating # tags). Denormalizing this into a field in users would save a SQL query. public $blacklisted_tags; - // protected function setBlacklistedTags($blacklists) - // { - // $this->('blacklisted_tags', $blacklists); - // } public function blacklisted_tags() { diff --git a/app/models/UserLog.php b/app/models/UserLog.php new file mode 100755 index 0000000..5a71480 --- /dev/null +++ b/app/models/UserLog.php @@ -0,0 +1,12 @@ + [ + 'user' + ] + ]; + } +} diff --git a/db/migrate/20140126192028_create_user_log.php b/db/migrate/20140126192028_create_user_log.php new file mode 100755 index 0000000..9cab08f --- /dev/null +++ b/db/migrate/20140126192028_create_user_log.php @@ -0,0 +1,23 @@ +execute(<<execute( + "ALTER TABLE `user_logs` + ADD CONSTRAINT fk_user_logs__user_id FOREIGN KEY (user_id) REFERENCES `users`(id) ON DELETE CASCADE" + ); + } +} diff --git a/db/table_schema/production/user_logs.php b/db/table_schema/production/user_logs.php new file mode 100644 index 0000000..2aae0a8 --- /dev/null +++ b/db/table_schema/production/user_logs.php @@ -0,0 +1,34 @@ + + array ( + 'id' => + array ( + 'type' => 'int(11) unsigned', + 'default' => NULL, + ), + 'user_id' => + array ( + 'type' => 'int(11)', + 'default' => NULL, + ), + 'ip_addr' => + array ( + 'type' => 'varchar(46)', + 'default' => NULL, + ), + 'created_at' => + array ( + 'type' => 'datetime', + 'default' => NULL, + ), + ), + 1 => + array ( + 'pri' => + array ( + 0 => 'id', + ), + ), +) +; \ No newline at end of file