Skip to content
This repository
Browse code

store status_prev in message so it's easy to revert: fixes #53 (need …

…to populate existing data though)
  • Loading branch information...
commit efbb6b583dc7b0d4bc6ea2490c3290f974e382db 1 parent a14110f
Dave Whiteland authored November 19, 2012
12  app/Model/Message.php
@@ -105,6 +105,10 @@ public function beforeSave() {
105 105
 		} else {
106 106
 			$this->data['Message']['tag'] = null;
107 107
 		}
  108
+		// if status isn't hidden, make sure status_prev is tracking status
  109
+		if (!empty($this->data['Message']['status']) && $this->data['Message']['status'] != Status::$STATUS_HIDDEN) {
  110
+			$this->data['Message']['status_prev'] = $this->data['Message']['status'];
  111
+		}
108 112
 		return true;
109 113
 	}
110 114
 	
@@ -203,9 +207,13 @@ public function seconds_until_lock_expiry() {
203 207
 		}
204 208
 	}
205 209
 		
206  
-	// if a record is unhidden, its status depends on whether or not it has an FMS_id
  210
+	// if a record is unhidden, revert to it's old (pre-hidden) status
  211
+	// There was some logic here that's a little wonky, but keeping it in in case
  212
+	// status_prev fails: its status possibly depends on whether or not it has an FMS_id
207 213
 	private function _revert_status() {
208  
-		if (empty($this->data['Message']['fms_id'])) {
  214
+		if (! empty($this->data['Message']['status_prev']) && $this->data['Message']['status_prev'] != Status::$STATUS_HIDDEN) {
  215
+			$this->data['Message']['status'] = $this->data['Message']['status_prev'];
  216
+		} elseif (empty($this->data['Message']['fms_id'])) {
209 217
 			$this->data['Message']['status'] = Status::$STATUS_AVAILABLE;
210 218
 		} else {
211 219
 			$this->data['Message']['status'] = Status::$STATUS_ASSIGNED;
1  db/schema.sql
@@ -69,6 +69,7 @@ CREATE TABLE messages (
69 69
   assigned timestamp default null,
70 70
   lock_expires timestamp default null,
71 71
   status smallint not null default '0',
  72
+  status_prev smallint not null default '0',
72 73
   owner_id integer default null,
73 74
   session_key varchar(255) default null,
74 75
   fms_id integer default null,
3  db/schema_0010-add_status_prev_to_messages.sql
... ...
@@ -0,0 +1,3 @@
  1
+alter table  messages add status_prev smallint not null default '0';
  2
+
  3
+update messages set status_prev = status where status != 3;

0 notes on commit efbb6b5

Please sign in to comment.
Something went wrong with that request. Please try again.