Switching project access information to use JSON instead of serialization, fixes #493

This commit is contained in:
Dan Cryer 2014-07-30 15:13:50 +01:00
parent 490b9cf019
commit 2875badb0a
3 changed files with 19 additions and 4 deletions

View file

@ -44,9 +44,25 @@ class Project extends ProjectBase
return null;
}
public function setAccessInformation($value)
{
if (is_array($value)) {
$value = json_encode($value);
}
parent::setAccessInformation($value);
}
public function getAccessInformation($key = null)
{
$data = unserialize($this->data['access_information']);
$info = $this->data['access_information'];
// Handle old-format (serialized) access information first:
if (!empty($info) && substr($info, 0, 1) != '{') {
$data = unserialize($info);
} else {
$data = json_decode($info, true);
}
if (is_null($key)) {
$rtn = $data;

View file

@ -112,8 +112,7 @@ class ProjectService
$info['user'] = $matches[1];
$info['domain'] = $matches[2];
/** @todo At a later date, we need to find a way to replace this serialized data with JSON */
$project->setAccessInformation(serialize($info));
$project->setAccessInformation($info);
$project->setReference($matches[3] . '/' . $matches[4]);
}
}

View file

@ -99,7 +99,7 @@ class ProjectTest extends \PHPUnit_Framework_TestCase
);
$project = new Project();
$project->setAccessInformation(serialize($info));
$project->setAccessInformation($info);
$this->assertEquals('Item One', $project->getAccessInformation('item1'));
$this->assertEquals(2, $project->getAccessInformation('item2'));