Skip to content

Commit 83cb9a0

Browse files
committed
MAGETWO-98584: Google chart API used by Magento dashboard scheduled to be turned off
1 parent fdca1ad commit 83cb9a0

File tree

2 files changed

+52
-35
lines changed
  • app/code/Magento/Backend/Block/Dashboard
  • dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml

2 files changed

+52
-35
lines changed

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ public function getChartUrl($directUrl = true)
320320

321321
foreach ($this->getAllSeries() as $index => $serie) {
322322
$thisdataarray = $serie;
323-
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
323+
$count = count($thisdataarray);
324+
for ($j = 0; $j < $count; $j++) {
324325
$currentvalue = $thisdataarray[$j];
325326
if (is_numeric($currentvalue)) {
326327
$ylocation = $yorigin + $currentvalue;
@@ -341,45 +342,13 @@ public function getChartUrl($directUrl = true)
341342

342343
$valueBuffer = [];
343344

344-
if (sizeof($this->_axisLabels) > 0) {
345+
if (count($this->_axisLabels) > 0) {
345346
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
346347
$indexid = 0;
347348
foreach ($this->_axisLabels as $idx => $labels) {
348349
if ($idx == 'x') {
349-
/**
350-
* Format date
351-
*/
352-
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
353-
if ($_label != '') {
354-
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
355-
switch ($this->getDataHelper()->getParam('period')) {
356-
case '24h':
357-
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
358-
$period->setTime($period->format('H'), 0, 0),
359-
\IntlDateFormatter::NONE,
360-
\IntlDateFormatter::SHORT
361-
);
362-
break;
363-
case '7d':
364-
case '1m':
365-
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
366-
$period,
367-
\IntlDateFormatter::SHORT,
368-
\IntlDateFormatter::NONE
369-
);
370-
break;
371-
case '1y':
372-
case '2y':
373-
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
374-
break;
375-
}
376-
} else {
377-
$this->_axisLabels[$idx][$_index] = '';
378-
}
379-
}
380-
350+
$this->formatAxisLabelDate($idx, $timezoneLocal);
381351
$tmpstring = implode('|', $this->_axisLabels[$idx]);
382-
383352
$valueBuffer[] = $indexid . ":|" . $tmpstring;
384353
} elseif ($idx == 'y') {
385354
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
@@ -407,6 +376,46 @@ public function getChartUrl($directUrl = true)
407376
}
408377
}
409378

379+
/**
380+
* Format dates for axis labels
381+
*
382+
* @param string $idx
383+
* @param string $timezoneLocal
384+
*
385+
* @return void
386+
*/
387+
private function formatAxisLabelDate($idx, $timezoneLocal)
388+
{
389+
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
390+
if ($_label != '') {
391+
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
392+
switch ($this->getDataHelper()->getParam('period')) {
393+
case '24h':
394+
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
395+
$period->setTime($period->format('H'), 0, 0),
396+
\IntlDateFormatter::NONE,
397+
\IntlDateFormatter::SHORT
398+
);
399+
break;
400+
case '7d':
401+
case '1m':
402+
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
403+
$period,
404+
\IntlDateFormatter::SHORT,
405+
\IntlDateFormatter::NONE
406+
);
407+
break;
408+
case '1y':
409+
case '2y':
410+
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
411+
break;
412+
}
413+
} else {
414+
$this->_axisLabels[$idx][$_index] = '';
415+
}
416+
}
417+
}
418+
410419
/**
411420
* Get rows data
412421
*

dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/DashboardTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ public function testAjaxBlockAction()
1919
$this->assertContains('dashboard-diagram', $actual);
2020
}
2121

22+
/**
23+
* Tests tunnelAction
24+
*
25+
* @throws \Exception
26+
* @return void
27+
*/
2228
public function testTunnelAction()
2329
{
30+
// phpcs:disable Magento2.Functions.DiscouragedFunction
2431
$testUrl = \Magento\Backend\Block\Dashboard\Graph::API_URL . '?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World';
2532
$handle = curl_init();
2633
curl_setopt($handle, CURLOPT_URL, $testUrl);
@@ -34,6 +41,7 @@ public function testTunnelAction()
3441
curl_close($handle);
3542
throw $e;
3643
}
44+
// phpcs:enable
3745

3846
$gaData = [
3947
'cht' => 'lc',

0 commit comments

Comments
 (0)