diff --git a/Block/Adminhtml/Info.php b/Block/Adminhtml/Info.php new file mode 100644 index 0000000..6d04160 --- /dev/null +++ b/Block/Adminhtml/Info.php @@ -0,0 +1,115 @@ +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; + } +} diff --git a/Controller/Adminhtml/Info/Index.php b/Controller/Adminhtml/Info/Index.php new file mode 100644 index 0000000..e54c466 --- /dev/null +++ b/Controller/Adminhtml/Info/Index.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/Cron/AAMSettingsCron.php b/Cron/AAMSettingsCron.php index fef75ca..973a4f2 100644 --- a/Cron/AAMSettingsCron.php +++ b/Cron/AAMSettingsCron.php @@ -26,14 +26,11 @@ public function __construct( public function execute() { $pixelId = $this->fbeHelper->getPixelID(); - $this->fbeHelper->log('In CronJob for fetching AAM Settings for Pixel: ' . $pixelId); $settingsAsString = null; if ($pixelId) { $settingsAsString = $this->fbeHelper->fetchAndSaveAAMSettings($pixelId); - if ($settingsAsString) { - $this->fbeHelper->log('Saving settings '.$settingsAsString); - } else { - $this->fbeHelper->log('Error saving settings'); + if (!$settingsAsString) { + $this->fbeHelper->log('Error saving settings. Currently:', $settingsAsString); } } return $settingsAsString; diff --git a/Cron/CategorySyncCron.php b/Cron/CategorySyncCron.php index c86537e..6d9c540 100644 --- a/Cron/CategorySyncCron.php +++ b/Cron/CategorySyncCron.php @@ -45,7 +45,6 @@ public function __construct( public function execute() { if ($this->systemConfig->isActiveCollectionsSync() == true) { - $this->fbeHelper->log('start category sync cron job '); $this->categoryCollection->pushAllCategoriesToFbCollections(); return true; } diff --git a/Helper/FBEHelper.php b/Helper/FBEHelper.php index ac09eb2..b74991f 100644 --- a/Helper/FBEHelper.php +++ b/Helper/FBEHelper.php @@ -327,7 +327,6 @@ public function getFBEExternalBusinessId() return $stored_external_id; } $storeId = $this->getStore()->getId(); - $this->log("Store id---" . $storeId); return uniqid('fbe_magento_' . $storeId . '_'); } diff --git a/Helper/LogOrganization.php b/Helper/LogOrganization.php new file mode 100644 index 0000000..477c56d --- /dev/null +++ b/Helper/LogOrganization.php @@ -0,0 +1,119 @@ + 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); + } +} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 375277c..018dc41 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -158,7 +158,7 @@ public function upgrade( // verify if already installed before if (!$eavSetup->getAttributeId(Product::ENTITY, $attrCode)) { //Create the attribute - $this->helper->log($attrCode . " not exist before, process it"); + // $this->helper->log($attrCode . " not exist before, process it"); // attribute does not exist // add a new attribute // and assign it to the "FacebookAttributeSet" attribute set diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml index b0ad6d0..10bd0aa 100644 --- a/etc/adminhtml/menu.xml +++ b/etc/adminhtml/menu.xml @@ -18,7 +18,17 @@ parent="Facebook_BusinessExtension::facebook" sortOrder="10" dependsOnModule="Facebook_BusinessExtension" - action="fbeadmin/setup" + action="fbeadmin/setup/index" resource="Facebook_BusinessExtension::facebook"/> + diff --git a/view/adminhtml/layout/fbeadmin_info_index.xml b/view/adminhtml/layout/fbeadmin_info_index.xml new file mode 100644 index 0000000..182f802 --- /dev/null +++ b/view/adminhtml/layout/fbeadmin_info_index.xml @@ -0,0 +1,13 @@ + + + + + Information + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/templates/info.phtml b/view/adminhtml/templates/info.phtml new file mode 100644 index 0000000..5c66285 --- /dev/null +++ b/view/adminhtml/templates/info.phtml @@ -0,0 +1,80 @@ + + +

getMagentoVersion()) ?>

+

getFBEVersion()) ?>

+ +
+

+ + + +
+
+ +

+
+
+ +

+
+
+ +

+ +
+
+ +
+ + + + + +