From ab739c7fb011d2a9a49c7ddb88bb46821484e985 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Sun, 28 Oct 2018 21:21:19 +0000 Subject: [PATCH] FIX Replace usage of Convert JSON methods with json_encode and json_decode --- code/Controllers/CMSMain.php | 10 +++++----- code/Forms/SiteTreeURLSegmentField.php | 2 +- code/Model/SiteTree.php | 2 +- tests/php/Controllers/CMSMainTest.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 8e8e37ce..f527f40a 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -734,7 +734,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this ->getResponse() ->addHeader('Content-Type', 'application/json') - ->setBody(Convert::raw2json($data)); + ->setBody(json_encode($data)); } /** @@ -859,7 +859,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this ->getResponse() ->addHeader('Content-Type', 'application/json') - ->setBody(Convert::raw2json($statusUpdates)); + ->setBody(json_encode($statusUpdates)); } public function CanOrganiseSitetree() @@ -927,7 +927,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'filters' => $searchParams ?: new \stdClass // stdClass maps to empty json object '{}' ]; - return Convert::raw2json($schema); + return json_encode($schema); } /** @@ -1161,7 +1161,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->extend('updateSiteTreeHints', $def); - $json = Convert::raw2json($def); + $json = json_encode($def); $cache->set($cacheKey, $json); return $json; @@ -1573,7 +1573,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this ->getResponse() ->addHeader('Content-Type', 'application/json; charset=utf-8') - ->setBody(Convert::raw2json($disallowedChildren)); + ->setBody(json_encode($disallowedChildren)); } /** diff --git a/code/Forms/SiteTreeURLSegmentField.php b/code/Forms/SiteTreeURLSegmentField.php index 76b82d7c..9b7da4b9 100644 --- a/code/Forms/SiteTreeURLSegmentField.php +++ b/code/Forms/SiteTreeURLSegmentField.php @@ -87,7 +87,7 @@ class SiteTreeURLSegmentField extends TextField } Controller::curr()->getResponse()->addHeader('Content-Type', 'application/json'); - return Convert::raw2json(array('value' => $page->URLSegment)); + return json_encode(array('value' => $page->URLSegment)); } /** diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 85be8e33..be216d8e 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -2736,7 +2736,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi $treeTitle = sprintf( "%s", Convert::raw2htmlid(static::class), - Convert::raw2att(Convert::raw2json($children)), + Convert::raw2att(json_encode($children)), Convert::raw2xml(str_replace(array("\n","\r"), "", $this->MenuTitle)) ); foreach ($flags as $class => $data) { diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index 35eed3c2..4d1a5e12 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -57,7 +57,7 @@ class CMSMainTest extends FunctionalTest $this->assertNotNull($rawHints); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); - $hints = Convert::json2array($rawHints); + $hints = json_decode($rawHints, true); $this->assertArrayHasKey('Root', $hints); $this->assertArrayHasKey('Page', $hints); @@ -137,7 +137,7 @@ class CMSMainTest extends FunctionalTest $actions = CMSBatchActionHandler::config()->batch_actions; if (isset($actions['publish'])) { $response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', array($page1->ID, $page2->ID))); - $responseData = Convert::json2array($response->getBody()); + $responseData = json_decode($response->getBody(), true); $this->assertArrayHasKey($page1->ID, $responseData['modified']); $this->assertArrayHasKey($page2->ID, $responseData['modified']); }