Move activity event data to json instead of PHP serialization
This commit is contained in:
@@ -22,7 +22,7 @@ class ProjectActivity extends Base
|
|||||||
*
|
*
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const MAX_EVENTS = 5000;
|
const MAX_EVENTS = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new event for the project
|
* Add a new event for the project
|
||||||
@@ -43,7 +43,7 @@ class ProjectActivity extends Base
|
|||||||
'creator_id' => $creator_id,
|
'creator_id' => $creator_id,
|
||||||
'event_name' => $event_name,
|
'event_name' => $event_name,
|
||||||
'date_creation' => time(),
|
'date_creation' => time(),
|
||||||
'data' => serialize($data),
|
'data' => json_encode($data),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->cleanup(self::MAX_EVENTS - 1);
|
$this->cleanup(self::MAX_EVENTS - 1);
|
||||||
@@ -91,7 +91,7 @@ class ProjectActivity extends Base
|
|||||||
|
|
||||||
foreach ($events as &$event) {
|
foreach ($events as &$event) {
|
||||||
|
|
||||||
$event += unserialize($event['data']);
|
$event += $this->decode($event['data']);
|
||||||
unset($event['data']);
|
unset($event['data']);
|
||||||
|
|
||||||
$event['author'] = $event['author_name'] ?: $event['author_username'];
|
$event['author'] = $event['author_name'] ?: $event['author_username'];
|
||||||
@@ -174,4 +174,20 @@ class ProjectActivity extends Base
|
|||||||
return '';
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ use Model\Project;
|
|||||||
|
|
||||||
class ProjectActivityTest extends Base
|
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()
|
public function testCreation()
|
||||||
{
|
{
|
||||||
$e = new ProjectActivity($this->container);
|
$e = new ProjectActivity($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user