From 5c600f861e2eee46c09e0826c8b2fcb349c3d56f Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 30 Jul 2014 15:13:50 +0100 Subject: [PATCH] Switching project access information to use JSON instead of serialization, fixes #493 --- PHPCI/Model/Project.php | 18 +++++++++++++++++- PHPCI/Service/ProjectService.php | 3 +-- Tests/PHPCI/Model/ProjectTest.php | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/PHPCI/Model/Project.php b/PHPCI/Model/Project.php index 9047de02..702d9c89 100644 --- a/PHPCI/Model/Project.php +++ b/PHPCI/Model/Project.php @@ -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; diff --git a/PHPCI/Service/ProjectService.php b/PHPCI/Service/ProjectService.php index 1ab24aae..04636e3a 100644 --- a/PHPCI/Service/ProjectService.php +++ b/PHPCI/Service/ProjectService.php @@ -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]); } } diff --git a/Tests/PHPCI/Model/ProjectTest.php b/Tests/PHPCI/Model/ProjectTest.php index 95cf933c..48a101f8 100644 --- a/Tests/PHPCI/Model/ProjectTest.php +++ b/Tests/PHPCI/Model/ProjectTest.php @@ -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'));