X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fmodels%2Fusers_model.php;h=30e18d70b7f6119a061fb90907e205018e2d8185;hb=e1f154780b5b004e047977b6582dd19bf85d4e4d;hp=252a5dba0ae3090fa146176d118a74ca9abd40c9;hpb=2881d1393f363efd3c5f0e9b58706e6e35e85717;p=living-lab-site.git diff --git a/application/models/users_model.php b/application/models/users_model.php index 252a5db..30e18d7 100644 --- a/application/models/users_model.php +++ b/application/models/users_model.php @@ -4,7 +4,7 @@ * Class Users_model models user information from DB * * @category Model - * @author calinburloiu + * @author Călin-Andrei Burloiu * */ class Users_model extends CI_Model { @@ -415,7 +415,7 @@ class Users_model extends CI_Model { * Adds a new user to DB. * Do not add join_date and last_login column, they will be automatically * added. - * Provide an 'openid' with the OpenID as value in order to register users + * Provide an $openid with the OpenID as value in order to register users * logging in this way. * * @param array $data corresponds to DB columns @@ -505,10 +505,45 @@ class Users_model extends CI_Model { return $query->row()->id; } - // TODO cleanup account activation - public function cleanup_account_activation() + /** + * Removes users that didn't activated their account within $days_to_expire + * days inclusively. + * + * @param int $days_to_expire + */ + public function cleanup_unactivated_users($days_to_expire) { + // Get user_id-s with expired activation period. + $query = $this->db->query("SELECT u.id + FROM `users` u, `users_unactivated` a + WHERE u.id = a.user_id + AND DATEDIFF(CURRENT_DATE(), u.registration_date) > $days_to_expire"); + if ($query->num_rows() > 0) + { + $str_user_ids = ''; + $results = $query->result(); + foreach ($results as $result) + $str_user_ids .= "{$result->id}, "; + $str_user_ids = substr($str_user_ids, 0, -2); + } + else + return FALSE; + + // Delete from `users` table. + $ret = $this->db->query("DELETE FROM `users` + WHERE id IN ($str_user_ids)"); + if (!$ret) + return FALSE; + + // Delete from `users_unactivated table. + $ret = $this->db->query("DELETE FROM `users_unactivated` + WHERE user_id IN ($str_user_ids)"); + if (!$ret) + return FALSE; + + // Success + return TRUE; } /**