diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-12-31 15:30:21 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-12-31 15:30:21 -0500 |
commit | c32567857db9bb1a6dfa339f58d817c97f64db11 (patch) | |
tree | a9a5524fdeab5d4c6b599ddd94ef7f2c2e610d65 | |
parent | ee8ec7685f95125c385d17dad41369a549ce9bbf (diff) |
Move activity event data to json instead of PHP serialization
-rw-r--r-- | app/Model/ProjectActivity.php | 22 | ||||
-rw-r--r-- | tests/units/ProjectActivityTest.php | 11 |
2 files changed, 30 insertions, 3 deletions
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php index 87c9bb56..bbcb7f5b 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivity.php @@ -22,7 +22,7 @@ class ProjectActivity extends Base * * @var integer */ - const MAX_EVENTS = 5000; + const MAX_EVENTS = 1000; /** * Add a new event for the project @@ -43,7 +43,7 @@ class ProjectActivity extends Base 'creator_id' => $creator_id, 'event_name' => $event_name, 'date_creation' => time(), - 'data' => serialize($data), + 'data' => json_encode($data), ); $this->cleanup(self::MAX_EVENTS - 1); @@ -91,7 +91,7 @@ class ProjectActivity extends Base foreach ($events as &$event) { - $event += unserialize($event['data']); + $event += $this->decode($event['data']); unset($event['data']); $event['author'] = $event['author_name'] ?: $event['author_username']; @@ -174,4 +174,20 @@ class ProjectActivity extends Base return ''; } } + + /** + * Decode event data, supports unserialize() and json_decode() + * + * @access public + * @param string $data Serialized data + * @return array + */ + public function decode($data) + { + if ($data{0} === 'a') { + return unserialize($data); + } + + return json_decode($data, true) ?: array(); + } } diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php index 67d94ecf..e70dfb0e 100644 --- a/tests/units/ProjectActivityTest.php +++ b/tests/units/ProjectActivityTest.php @@ -10,6 +10,17 @@ use Model\Project; class ProjectActivityTest extends Base { + public function testDecode() + { + $e = new ProjectActivity($this->container); + $input = array('test'); + $serialized = serialize($input); + $json = json_encode($input); + + $this->assertEquals($input, $e->decode($serialized)); + $this->assertEquals($input, $e->decode($json)); + } + public function testCreation() { $e = new ProjectActivity($this->container); |