summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-01-24 19:28:17 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-01-24 19:29:48 +0100
commit7c7eaa5feb44ff93d30a97e8a323680419df3672 (patch)
tree060dc43f6edc15a252cbfd265f44281059cf4072
parent54eec0dfee36ba686cdcc4515bccea79b07c2393 (diff)
Repurpose invitations table to actions
This can be used to track data for all kinds of one-time actions like invitations and password resets. Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/config/config.php2
-rw-r--r--application/config/migration.php2
-rw-r--r--application/controllers/user.php27
-rw-r--r--application/migrations/007_repurpose_invitations.php37
4 files changed, 54 insertions, 14 deletions
diff --git a/application/config/config.php b/application/config/config.php
index 05d391307..cdcf2ff5e 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -375,7 +375,7 @@ $config['upload_max_text_size'] = 2*1024*1024;
// 0 disables deletion
$config['upload_max_age'] = 60*60*24*5; // 5 days
-$config['invitations_max_age'] = 60*60*24*5; // 5 days
+$config['actions_max_age'] = 60*60*24*5; // 5 days
// won't be deleted
$config['small_upload_size'] = 1024*10; // 10KB
diff --git a/application/config/migration.php b/application/config/migration.php
index ad75f740c..d083e7eb8 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -21,7 +21,7 @@ $config['migration_enabled'] = true;
| be upgraded / downgraded to.
|
*/
-$config['migration_version'] = 6;
+$config['migration_version'] = 7;
/*
diff --git a/application/controllers/user.php b/application/controllers/user.php
index 0550b0f6a..39bf1d767 100644
--- a/application/controllers/user.php
+++ b/application/controllers/user.php
@@ -81,8 +81,9 @@ class User extends CI_Controller {
// TODO: count both, invited users and key
$query = $this->db->query("
SELECT count(*) as count
- FROM invitations
- WHERE user = ?
+ FROM `actions`
+ WHERE `user` = ?
+ AND `action` = 'invitation'
", array($userid))->row_array();
if ($query["count"] + 1 > 3) {
@@ -92,9 +93,9 @@ class User extends CI_Controller {
$key = random_alphanum(12, 16);
$this->db->query("
- INSERT INTO invitations
- (`key`, `user`, `date`)
- VALUES (?, ?, ?)
+ INSERT INTO `actions`
+ (`key`, `user`, `date`, `action`)
+ VALUES (?, ?, ?, 'invitation')
", array($key, $userid, time()));
redirect("user/invite");
@@ -108,8 +109,9 @@ class User extends CI_Controller {
$query = $this->db->query("
SELECT `key`, `date`
- FROM invitations
- WHERE user = ?
+ FROM `actions`
+ WHERE `user` = ?
+ AND `action` = 'invitation'
", array($userid))->result_array();
$this->data["query"] = $query;
@@ -131,8 +133,9 @@ class User extends CI_Controller {
$query = $this->db->query("
SELECT `user`, `key`
- FROM invitations
+ FROM actions
WHERE `key` = ?
+ AND `action` = 'invitation'
", array($key))->row_array();
if (!isset($query["key"]) || $key != $query["key"]) {
@@ -176,7 +179,7 @@ class User extends CI_Controller {
$referrer
));
$this->db->query("
- DELETE FROM invitations
+ DELETE FROM actions
WHERE `key` = ?
", array($key));
$this->load->view('header', $this->data);
@@ -229,12 +232,12 @@ class User extends CI_Controller {
{
if (!$this->input->is_cli_request()) return;
- if ($this->config->item('invitations_max_age') == 0) return;
+ if ($this->config->item('actions_max_age') == 0) return;
- $oldest_time = (time() - $this->config->item('invitations_max_age'));
+ $oldest_time = (time() - $this->config->item('actions_max_age'));
$this->db->query("
- DELETE FROM invitations
+ DELETE FROM actions
WHERE date < ?
", array($oldest_time));
}
diff --git a/application/migrations/007_repurpose_invitations.php b/application/migrations/007_repurpose_invitations.php
new file mode 100644
index 000000000..36d3007e8
--- /dev/null
+++ b/application/migrations/007_repurpose_invitations.php
@@ -0,0 +1,37 @@
+<?php
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+class Migration_Repurpose_invitations extends CI_Migration {
+
+ public function up()
+ {
+ $this->db->query("
+ ALTER TABLE `invitations`
+ ADD `action` VARCHAR(255) NOT NULL,
+ ADD `data` TEXT NULL,
+ ADD INDEX `action` (`action`);
+ ");
+
+ $this->db->query("
+ UPDATE `invitations` SET `action` = 'invitation' WHERE `action` = '';
+ ");
+
+ $this->db->query("
+ RENAME TABLE `invitations` TO `actions` ;
+ ");
+
+ }
+
+ public function down()
+ {
+ $this->db->query("
+ RENAME TABLE `actions` TO `invitations` ;
+ ");
+
+ $this->db->query("
+ ALTER TABLE `invitations`
+ DROP `action`,
+ DROP `data`;
+ ");
+ }
+}