This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Created a new info page to assist with the debugging process. Reviewed By: zlik Differential Revision: D30734422 fbshipit-source-id: 60097568
- Loading branch information
1 parent
e1d4306
commit 0f62824
Showing
10 changed files
with
389 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | ||
*/ | ||
|
||
namespace Facebook\BusinessExtension\Block\Adminhtml; | ||
|
||
use Facebook\BusinessExtension\Helper\FBEHelper; | ||
use Magento\Framework\Module\ModuleListInterface; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Magento\Framework\Escaper; | ||
use Facebook\BusinessExtension\Helper\LogOrganization; | ||
|
||
|
||
class Info extends \Magento\Backend\Block\Template | ||
{ | ||
/** | ||
* @var FBEHelper | ||
*/ | ||
protected $fbeHelper; | ||
|
||
/** | ||
* @var ModuleListInterface | ||
*/ | ||
protected $moduleList; | ||
|
||
/** | ||
* @var ProductMetadataInterface | ||
*/ | ||
protected $productMetadataInterface; | ||
|
||
/** | ||
* @var Escaper | ||
*/ | ||
private $escaper; | ||
|
||
|
||
|
||
/** | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param FBEHelper $fbeHelper | ||
* @param ModuleListInterface $moduleList | ||
* @param ProductMetadataInterface $productMetadataInterface | ||
* @param Escaper $escaper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
FBEHelper $fbeHelper, | ||
ModuleListInterface $moduleList, | ||
ProductMetadataInterface $productMetadataInterface, | ||
Escaper $escaper, | ||
array $data = [] | ||
) { | ||
$this->fbeHelper = $fbeHelper; | ||
$this->moduleList = $moduleList; | ||
$this->productMetadataInterface = $productMetadataInterface; | ||
$this->escaper = $escaper; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFBEVersion() { | ||
return $this->moduleList->getOne("Facebook_BusinessExtension")["setup_version"]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMagentoVersion() { | ||
return $this->productMetadataInterface->getVersion(); | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function fetchPixelId() | ||
{ | ||
return $this->fbeHelper->getConfigValue('fbpixel/id'); | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getExternalBusinessId() | ||
{ | ||
return $this->fbeHelper->getFBEExternalBusinessId(); | ||
} | ||
|
||
public function allLogs() { | ||
$sortedString = implode("\n", LogOrganization::organizeLogs()); | ||
return nl2br($sortedString); | ||
} | ||
|
||
public function publicIssueLink() { | ||
$magento_version = $this->getMagentoVersion(); | ||
$plugin_version = $this->getFBEVersion(); | ||
return "https://github.com/facebookincubator/facebook-for-magento2/issues/new?&template=bug-report.yml&magento_version=" | ||
. $magento_version . "&plugin_version=" . $plugin_version; | ||
} | ||
|
||
public function privateIssueLink() { | ||
$magento_version = $this->getMagentoVersion(); | ||
$plugin_version = $this->getFBEVersion(); | ||
$extern_bus_id = $this->getExternalBusinessId(); | ||
$pixel_id = $this->fetchPixelId(); | ||
|
||
return "https://www.facebook.com/help/contact/224834796277182?Field1264912827263491=" | ||
. $magento_version . "&Field1465992913778514=" . $plugin_version | ||
. "&Field1500601380300162=" . $extern_bus_id . "&Field2972445263018062=" . $pixel_id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
namespace Facebook\BusinessExtension\Controller\Adminhtml\Info; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\App\Action\HttpGetActionInterface; | ||
use Magento\Framework\View\Result\Page; | ||
use Magento\Framework\View\Result\PageFactory; | ||
|
||
/** | ||
* Class Index | ||
*/ | ||
|
||
class Index extends \Magento\Backend\App\Action | ||
{ | ||
/** | ||
* @var PageFactory | ||
*/ | ||
protected $resultPageFactory; | ||
|
||
/** | ||
* Index constructor. | ||
* | ||
* @param Context $context | ||
* @param PageFactory $resultPageFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
PageFactory $resultPageFactory | ||
) { | ||
parent::__construct($context); | ||
|
||
$this->resultPageFactory = $resultPageFactory; | ||
} | ||
|
||
/** | ||
* Load the page defined in view/adminhtml/layout/exampleadminnewpage_helloworld_index.xml | ||
* | ||
* @return Page | ||
*/ | ||
public function execute() | ||
{ | ||
$resultPage = $this->resultPageFactory->create(); | ||
$resultPage->getConfig()->getTitle()->prepend(__('Info')); | ||
|
||
return $resultPage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | ||
*/ | ||
|
||
/** | ||
* Helper class for generating and organizing log files. | ||
*/ | ||
namespace Facebook\BusinessExtension\Helper; | ||
|
||
class LogOrganization | ||
{ | ||
// 4096 -- Good balance for tracking backwards | ||
const BUFFER = 4096; | ||
|
||
static $criticalLines = array(); | ||
|
||
public static function organizeLogs() { | ||
$arrayOfFiles = array("var/log/debug.log", "var/log/cron.log", "var/log/magento.cron.log", "var/log/system.log"); | ||
$countCrit = 0; | ||
|
||
foreach($arrayOfFiles as $value) { | ||
if (!file_exists($value)) { | ||
continue; | ||
} | ||
|
||
$fp = fopen($value, 'r'); | ||
$pos = -2; // Skip final new line character (Set to -1 if not present) | ||
$currentLine = ''; | ||
|
||
while (-1 !== fseek($fp, $pos, SEEK_END)) { | ||
$char = fgetc($fp); | ||
if ("\n" == $char) { | ||
if (substr($currentLine, 0, 3) == "[20") { | ||
$time = strtotime(substr($currentLine, 1, 20)); | ||
if ($time > strtotime('-7 day')) { | ||
break; | ||
} | ||
|
||
// Saving only critical log entries with "Facebook" phrase | ||
if (strpos($currentLine, "CRITICAL") !== false && | ||
strpos($currentLine, "Facebook") !== false) { | ||
self::$criticalLines[] = $currentLine; | ||
$countCrit++; | ||
} | ||
$currentLine = ''; | ||
|
||
if ($countCrit == 500) { | ||
break; | ||
} | ||
} | ||
} else { | ||
$currentLine = $char . $currentLine; | ||
} | ||
$pos--; | ||
} | ||
|
||
if (substr($currentLine, 0, 3) == "[20") { | ||
$time = strtotime(substr($currentLine, 1, 20)); | ||
if ($time > strtotime('-7 day')) { | ||
break; | ||
} | ||
|
||
if (strpos($currentLine, "CRITICAL") !== false && | ||
strpos($currentLine, "Facebook") !== false) { | ||
self::$criticalLines[] = $currentLine; | ||
$countCrit++; | ||
} | ||
$currentLine = ''; | ||
} | ||
|
||
$countCrit = 0; | ||
} | ||
fclose($fp); | ||
|
||
$amuLogs = self::tailCustom("var/log/facebook-business-extension.log", 100); | ||
$amuLogsArr = explode("\n", $amuLogs); | ||
self::$criticalLines = array_merge(self::$criticalLines, $amuLogsArr); | ||
|
||
usort(self::$criticalLines, function ($x, $y) { | ||
$t1 = strtotime(substr($x, 1, 19)); | ||
$t2 = strtotime(substr($y, 1, 19)); | ||
|
||
return ($t1 - $t2); | ||
}); | ||
|
||
return self::$criticalLines; | ||
} | ||
|
||
public static function tailCustom($filepath, $lines) { | ||
$f = fopen($filepath, "rb"); | ||
if ($f === false) { | ||
return false; | ||
} | ||
|
||
fseek($f, -1, SEEK_END); | ||
if (fread($f, 1) != "\n") { | ||
$lines -= 1; | ||
} | ||
|
||
$output = ''; | ||
$chunk = ''; | ||
|
||
while (ftell($f) > 0 && $lines >= 0) { | ||
$seek = min(ftell($f), self::BUFFER); | ||
fseek($f, -$seek, SEEK_CUR); | ||
$output = ($chunk = fread($f, $seek)) . $output; | ||
fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR); | ||
$lines -= substr_count($chunk, "\n"); | ||
} | ||
|
||
while ($lines++ < 0) { | ||
$output = substr($output, strpos($output, "\n") + 1); | ||
} | ||
|
||
fclose($f); | ||
return trim($output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<referenceBlock name="page.title"> | ||
<action method="setPageTitle"> | ||
<argument name="title" xsi:type="string">Information</argument> | ||
</action> | ||
</referenceBlock> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Facebook\BusinessExtension\Block\Adminhtml\Info" template="Facebook_BusinessExtension::info.phtml"/> | ||
</referenceContainer> | ||
</body> | ||
</page> |
Oops, something went wrong.