Merge pull request #2302 from creative-commoners/pulls/4.4/replace-json-use

FIX Replace usage of Convert JSON methods with json_encode and json_decode
This commit is contained in:
Loz Calver 2018-10-29 17:50:10 +01:00 committed by GitHub
commit 45b092c121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 9 deletions

View File

@ -734,7 +734,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this return $this
->getResponse() ->getResponse()
->addHeader('Content-Type', 'application/json') ->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 return $this
->getResponse() ->getResponse()
->addHeader('Content-Type', 'application/json') ->addHeader('Content-Type', 'application/json')
->setBody(Convert::raw2json($statusUpdates)); ->setBody(json_encode($statusUpdates));
} }
public function CanOrganiseSitetree() public function CanOrganiseSitetree()
@ -927,7 +927,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'filters' => $searchParams ?: new \stdClass // stdClass maps to empty json object '{}' '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); $this->extend('updateSiteTreeHints', $def);
$json = Convert::raw2json($def); $json = json_encode($def);
$cache->set($cacheKey, $json); $cache->set($cacheKey, $json);
return $json; return $json;
@ -1573,7 +1573,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this return $this
->getResponse() ->getResponse()
->addHeader('Content-Type', 'application/json; charset=utf-8') ->addHeader('Content-Type', 'application/json; charset=utf-8')
->setBody(Convert::raw2json($disallowedChildren)); ->setBody(json_encode($disallowedChildren));
} }
/** /**

View File

@ -87,7 +87,7 @@ class SiteTreeURLSegmentField extends TextField
} }
Controller::curr()->getResponse()->addHeader('Content-Type', 'application/json'); Controller::curr()->getResponse()->addHeader('Content-Type', 'application/json');
return Convert::raw2json(array('value' => $page->URLSegment)); return json_encode(array('value' => $page->URLSegment));
} }
/** /**

View File

@ -2736,7 +2736,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$treeTitle = sprintf( $treeTitle = sprintf(
"<span class=\"jstree-pageicon page-icon class-%s\"></span><span class=\"item\" data-allowedchildren=\"%s\">%s</span>", "<span class=\"jstree-pageicon page-icon class-%s\"></span><span class=\"item\" data-allowedchildren=\"%s\">%s</span>",
Convert::raw2htmlid(static::class), Convert::raw2htmlid(static::class),
Convert::raw2att(Convert::raw2json($children)), Convert::raw2att(json_encode($children)),
Convert::raw2xml(str_replace(array("\n","\r"), "", $this->MenuTitle)) Convert::raw2xml(str_replace(array("\n","\r"), "", $this->MenuTitle))
); );
foreach ($flags as $class => $data) { foreach ($flags as $class => $data) {

View File

@ -57,7 +57,7 @@ class CMSMainTest extends FunctionalTest
$this->assertNotNull($rawHints); $this->assertNotNull($rawHints);
$rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints));
$hints = Convert::json2array($rawHints); $hints = json_decode($rawHints, true);
$this->assertArrayHasKey('Root', $hints); $this->assertArrayHasKey('Root', $hints);
$this->assertArrayHasKey('Page', $hints); $this->assertArrayHasKey('Page', $hints);
@ -137,7 +137,7 @@ class CMSMainTest extends FunctionalTest
$actions = CMSBatchActionHandler::config()->batch_actions; $actions = CMSBatchActionHandler::config()->batch_actions;
if (isset($actions['publish'])) { if (isset($actions['publish'])) {
$response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', array($page1->ID, $page2->ID))); $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($page1->ID, $responseData['modified']);
$this->assertArrayHasKey($page2->ID, $responseData['modified']); $this->assertArrayHasKey($page2->ID, $responseData['modified']);
} }