From b8b69bba93299d1c8a56cc79d50cbce53e297e49 Mon Sep 17 00:00:00 2001 From: Pim Ruiter Date: Mon, 29 Jan 2024 16:20:42 +0100 Subject: [PATCH 1/3] Major cleanup old and unused code --- Block/Adminhtml/Akeneo.php | 4 - Block/Adminhtml/Akeneo/Edit/Tab/Main.php | 1 - Console/Command/MailNotificationCommand.php | 37 ----- Cron/CleanLogs.php | 59 -------- Cron/MailNotificationCron.php | 25 ---- Helper/MailHelper.php | 44 ------ Job/MailMessage.php | 84 ------------ Job/RunMailMessage.php | 142 -------------------- README.md | 5 +- etc/adminhtml/system.xml | 46 ------- etc/config.xml | 11 -- etc/cron_groups.xml | 9 -- etc/crontab.xml | 10 -- etc/di.xml | 2 - view/adminhtml/web/css/source/_module.less | 2 +- 15 files changed, 2 insertions(+), 479 deletions(-) delete mode 100644 Console/Command/MailNotificationCommand.php delete mode 100644 Cron/CleanLogs.php delete mode 100644 Cron/MailNotificationCron.php delete mode 100644 Helper/MailHelper.php delete mode 100644 Job/MailMessage.php delete mode 100644 Job/RunMailMessage.php diff --git a/Block/Adminhtml/Akeneo.php b/Block/Adminhtml/Akeneo.php index 19c0e38..9de9274 100755 --- a/Block/Adminhtml/Akeneo.php +++ b/Block/Adminhtml/Akeneo.php @@ -22,8 +22,6 @@ public function __construct(Context $context, array $data = []) /** * Prepare button and grid - * - * @return \Magento\Catalog\Block\Adminhtml\Product */ protected function _prepareLayout() { @@ -61,8 +59,6 @@ protected function _getAddButtonOptions() } /** - * - * * @param string $type * @return string */ diff --git a/Block/Adminhtml/Akeneo/Edit/Tab/Main.php b/Block/Adminhtml/Akeneo/Edit/Tab/Main.php index 016bca9..f40dfa0 100755 --- a/Block/Adminhtml/Akeneo/Edit/Tab/Main.php +++ b/Block/Adminhtml/Akeneo/Edit/Tab/Main.php @@ -55,7 +55,6 @@ public function __construct( */ protected function _prepareForm() { - /* @var $model \JustBetter\AkeneoBundle\Model\BlogPosts */ $model = $this->_coreRegistry->registry('akeneo'); $isElementDisabled = false; diff --git a/Console/Command/MailNotificationCommand.php b/Console/Command/MailNotificationCommand.php deleted file mode 100644 index 4796814..0000000 --- a/Console/Command/MailNotificationCommand.php +++ /dev/null @@ -1,37 +0,0 @@ -runMailMessage = $runMailMessage; - parent::__construct($name); - } - - protected function configure() - { - $this->setName('mail:imports'); - $this->setDescription( - 'This will check the status of today\'s Akeneo imports and send the results to your mail' - ); - parent::configure(); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $this->runMailMessage->execute($input, $output); - } -} diff --git a/Cron/CleanLogs.php b/Cron/CleanLogs.php deleted file mode 100644 index 6c9b326..0000000 --- a/Cron/CleanLogs.php +++ /dev/null @@ -1,59 +0,0 @@ -scopeConfig = $scopeConfig; - $this->collectionFactory = $collectionFactory; - $this->logRepository = $logRepository; - } - - /** - * @return void - */ - public function execute() - { - if ($this->scopeConfig->isSetFlag('akeneo_connector/justbetter/log_cleaner/enable')) { - $numberOfDays = (int) $this->scopeConfig->getValue('akeneo_connector/justbetter/log_cleaner/number_of_days'); - $date = date('Y-m-d', strtotime("-$numberOfDays days")); - $logs = $this->collectionFactory->create() - ->addFieldToFilter('created_at', ['lt' => $date]) - ->load(); - - foreach ($logs->getItems() as $item) { - $this->logRepository->delete($item); - } - } - } -} diff --git a/Cron/MailNotificationCron.php b/Cron/MailNotificationCron.php deleted file mode 100644 index 473907b..0000000 --- a/Cron/MailNotificationCron.php +++ /dev/null @@ -1,25 +0,0 @@ -runMailMessage = $runMailMessage; - } - - /** - * Write to system.log - * - * @return void - */ - public function execute() - { - $this->runMailMessage->execute(); - } -} diff --git a/Helper/MailHelper.php b/Helper/MailHelper.php deleted file mode 100644 index 34f907e..0000000 --- a/Helper/MailHelper.php +++ /dev/null @@ -1,44 +0,0 @@ -scopeConfig->getValue( - $field, - ScopeInterface::SCOPE_STORE, - $storeId - ); - } - - /** - * getGeneralConfig function - * @param String $code - * @param null $storeId - */ - public function getGeneralConfig($code, $storeId = null) - { - return $this->getConfigValue(self::XML_PATH . $code, $storeId); - } - - /** - * isEnable function - * @return boolean - */ - public function isEnable() - { - return $this->getGeneralConfig('enable'); - } -} diff --git a/Job/MailMessage.php b/Job/MailMessage.php deleted file mode 100644 index d1b7372..0000000 --- a/Job/MailMessage.php +++ /dev/null @@ -1,84 +0,0 @@ -store = $store->getStore(); - } - - /** - * @return string - */ - public function success() - { - return 'All of today\'s imports in ' . $this->store->getName() - . ' have been successfully completed.'; - } - - /** - * @param Collection $errorLogs - * @param Collection $processingLogs - * @return string - */ - public function warning(Collection $errorLogs = null, Collection $processingLogs = null) - { - $message = 'Warning! There\'s a problem with today’s imports in ' . $this->store->getName() - . ".\n\n"; - $message .= (isset($errorLogs) && $errorLogs->getData()) - ? $this->logList($errorLogs, ImportInterface::IMPORT_ERROR) - : ''; - $message .= (isset($processingLogs) && $processingLogs->getData()) - ? $this->logList($processingLogs, ImportInterface::IMPORT_PROCESSING) - : ''; - return $message; - } - - /** - * @param Collection $logs - * @param int $status - * @return string - */ - protected function logList(Collection $logs, int $status) - { - $message = ''; - switch ($status) { - case $status == ImportInterface::IMPORT_ERROR: - $message = "The following imports have failed:\n\n"; - break; - case ImportInterface::IMPORT_PROCESSING: - $message = "The following imports are still in process:\n\n"; - break; - } - foreach ($logs->getData() as $log) { - $message .= $this->formatList(date('H:i:s', strtotime($log['created_at'])), $log['name']); - } - return $message . "\n"; - } - - /** - * @return string - */ - public function noImports() - { - return $this->warning() . 'No imports have been made today.'; - } - - /** - * @param string $dateTime - * @param string $name - * @return string - */ - protected function formatList(string $dateTime, string $name) - { - return '> • _' . $dateTime . '_ *' . $name . "*\n"; - } -} diff --git a/Job/RunMailMessage.php b/Job/RunMailMessage.php deleted file mode 100644 index abcd9d7..0000000 --- a/Job/RunMailMessage.php +++ /dev/null @@ -1,142 +0,0 @@ -state->setAreaCode(Area::AREA_FRONTEND); - $message = $this->getMessage(); - if ($this->helperData->isEnable()) { - $output ? $output->writeln($this->send($message)) : $this->send($message); - } else { - $output->writeln( - 'This function has been disabled. ' . "\n" - . 'To enable: Go to Stores/Configuration/Catalog/Akeneo Connector/JustBetter Akeneo/mail and set Enabled to Yes' - ); - } - } - - public function __construct( - Client $client, - MailHelper $helperData, - Log\Collection $logCollection, - MailMessage $mailMessage, - State $state - ) { - $this->client = $client; - $this->helperData = $helperData; - $this->logCollection = $logCollection; - $this->logs = $this->getLogs(); - $this->state = $state; - $this->mailMessage = $mailMessage; - } - - /** - * Gets a collection of all Import logs of today - * @return Log\Collection - */ - protected function getLogs() - { - return $this->logCollection - ->addFieldToFilter('created_at', ['gteq' => date('Y-m-d')]) - ->addFieldToFilter('created_at', ['lt' => date('Y-m-d', strtotime(date('Y-m-d') . ' +1 day'))]); - } - - /** - * Gets a collection of all Import logs of today with a specific status - * @param int $status - * @return Log\Collection - */ - protected function getLogsByStatus(int $status) - { - $logs = clone $this->logs; - return $logs->addFieldToFilter('status', $status); - } - - /** - * Checks if a log with a specific status exists in the collection - * @param int $status - * @return bool - */ - protected function checkLogStatus(int $status) - { - foreach ($this->logs as $log) { - if ($log->getStatus() == $status) { - return true; - } - } - return false; - } - - /** - * Get the message to be sent - * @return string - */ - protected function getMessage() - { - if (!$this->logs->getData()) { - return $this->mailMessage->noImports(); - } elseif ($this->checkLogStatus(ImportInterface::IMPORT_ERROR) || - $this->checkLogStatus(ImportInterface::IMPORT_PROCESSING)) { - return $this->mailMessage->warning( - $this->getLogsByStatus(ImportInterface::IMPORT_ERROR), - $this->getLogsByStatus(ImportInterface::IMPORT_PROCESSING) - ); - } - return $this->mailMessage->success(); - } - - /** - * Sends the message to Mail - * @param string $message - * @return string - * @throws \GuzzleHttp\Exception\GuzzleException - */ - protected function send(string $message) - { - try { - $from = $this->helperData->getGeneralConfig('frommail'); - $nameFrom = $this->helperData->getGeneralConfig('fromname'); - $to = $this->helperData->getGeneralConfig('mail'); - $nameTo = $this->helperData->getGeneralConfig('mail'); - - $email = new mail(); - $email->setSubject("Akeneo import notification"); - $email->setBodyHtml($message); - $email->setFrom($from, $nameFrom); - $email->addTo($to, $nameTo); - $email->send(); - - return '✅ Message has been send to your mail: ' - . $this->helperData->getGeneralConfig('mail') . ''; - } catch (RequestException $e) { - $response = - '⚠️ There\'s a problem with sending the message to your mail: ' - . $this->helperData->getGeneralConfig('mail') . " \n\n" - . 'The following exception appeared:' - . '' . "\n\n" . $e->getResponse() . ''; - return $response; - } - } -} diff --git a/README.md b/README.md index 4d70f42..f1bd037 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ These features can be enabled / disabled via an extra configuration section call | Feature | Description | |--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Important Attributes | Select attributes that should always be added to the product tables even if all are empty, this fixes cases where you bulk empty attributes and it is not reflected in Magento. -| Fix Configurable Urls | Replaces the variant product url with the original url + sku to keep them unique | +| Important Attributes | Select attributes that should always be added to the product tables even if all are empty, this fixes cases where you bulk empty attributes and it is not reflected in Magento. | | Tier Prices | Maps specific Akeneo attribute code with a Magento Customer group. This ensures that the tier prices from Akeneo are imported into Magento customer tier prices | | Set default value for required attributes | Set a default value for required attributes if the value is missing | | Category exist | Skip inserting url paths when the category already exist | @@ -25,9 +24,7 @@ These features can be enabled / disabled via an extra configuration section call | Channel for metric conversions | What channel to use for metric conversions | | Set families to not visible individually after importing | Sets products in selected families to `Not Visible Individually` | | Unset Website when empty Product Attribute Mapping | When enabled this will unset the website from the product when a required attribute has no specific value. For example when the Name attribute in Akeneo is empty for the associated website | -| Akeneo Import e-mail notifications | Setup e-mail notifications of Akeneo imports | | Slack Akeneo import notifications | Setup Slack notifications of Akeneo imports | -| *Akeneo import log cleaner* | Cleans the Akeneo logs that are older then the configured number of days *Deprecated - the Akeneo Connector has this functionality built in since* [v102.2.0](https://github.com/akeneo/magento2-connector-community/releases/tag/v102.2.0) | | Import finished events | Fires an event for every job that is fully finished | | ## Installation diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 7f21d4d..05efd4a 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -52,12 +52,6 @@ Akeneo\Connector\Model\Source\Filters\Attribute 1 - - - Magento\Config\Model\Config\Source\Yesno - Replaces configurable product urls with the original url + sku. (Default no) - @@ -179,46 +173,6 @@ Slack api url. - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Enter your email where you want to receive notifications about akeneo imports. - - - - - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - The number of days the logs are kept. - - 1 - - - diff --git a/etc/config.xml b/etc/config.xml index 0e17b38..90467f4 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,7 +3,6 @@ - 0 0 0 0 @@ -21,16 +20,6 @@ https://slack.com/api/chat.postMessage - - 0 - john@example.com - noreply@akeneo-import.com - Akeneo Import - - - 0 - 30 - diff --git a/etc/cron_groups.xml b/etc/cron_groups.xml index bd4c668..86a0ef1 100644 --- a/etc/cron_groups.xml +++ b/etc/cron_groups.xml @@ -9,13 +9,4 @@ 600 1 - - 1440 - 10080 - 2 - 10 - 60 - 600 - 1 - diff --git a/etc/crontab.xml b/etc/crontab.xml index 391b440..014122b 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -5,14 +5,4 @@ 0 8 * * * - - - 0 8 * * * - - - - - 0 2 * * * - - diff --git a/etc/di.xml b/etc/di.xml index e78c555..60a8d8e 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,7 +1,6 @@ - @@ -42,7 +41,6 @@ Akeneo\Connector\Console\Command\AkeneoConnectorImportCommand JustBetter\AkeneoBundle\Console\Command\SlackNotificationCommand - JustBetter\AkeneoBundle\Console\Command\MailNotificationCommand JustBetter\AkeneoBundle\Console\Command\ImportMetricUnits JustBetter\AkeneoBundle\Console\Command\SetNotVisible diff --git a/view/adminhtml/web/css/source/_module.less b/view/adminhtml/web/css/source/_module.less index 9f22e9a..42f926c 100644 --- a/view/adminhtml/web/css/source/_module.less +++ b/view/adminhtml/web/css/source/_module.less @@ -1,6 +1,6 @@ @import '_icons.less'; -#menu-justbetter-akeneomanager-menu > a:before { +#menu-justbetter-akeneobundle-menu > a:before { content: @icon-justbetter__content; font-family: @icons-justbetter__font-name !important; font-size: 2rem; From 30ff5f6e360224f1f5f0230b3567b0bee7fa66f8 Mon Sep 17 00:00:00 2001 From: Pim Ruiter Date: Mon, 29 Jan 2024 16:38:54 +0100 Subject: [PATCH 2/3] PHP8.2 result page error fix --- Controller/Adminhtml/akeneo/Index.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Controller/Adminhtml/akeneo/Index.php b/Controller/Adminhtml/akeneo/Index.php index c403cc2..1fb6af0 100755 --- a/Controller/Adminhtml/akeneo/Index.php +++ b/Controller/Adminhtml/akeneo/Index.php @@ -10,7 +10,12 @@ class Index extends \Magento\Backend\App\Action /** * @var PageFactory */ - protected $resultPagee; + protected $resultPage; + + /** + * @var \Magento\Framework\View\Result\PageFactory + **/ + private \Magento\Framework\View\Result\PageFactory $resultPageFactory; /** * @param Context $context @@ -40,5 +45,4 @@ public function execute() return $resultPage; } -} -?> \ No newline at end of file +} \ No newline at end of file From af6849ae278c1e5ab5f68b2d8c607ac4ee911d42 Mon Sep 17 00:00:00 2001 From: Pim Ruiter Date: Tue, 30 Jan 2024 11:19:34 +0100 Subject: [PATCH 3/3] Deleted unused plugin --- Plugin/FixProductUrls.php | 92 --------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 Plugin/FixProductUrls.php diff --git a/Plugin/FixProductUrls.php b/Plugin/FixProductUrls.php deleted file mode 100644 index 5a913c1..0000000 --- a/Plugin/FixProductUrls.php +++ /dev/null @@ -1,92 +0,0 @@ -entitiesHelper = $entitiesHelper; - $this->storeHelper = $storeHelper; - $this->config = $config; - } - - /** - * afterCreateConfigurable function - * - * @param product $subject - * @param bool $result - * @return bool $result - */ - public function afterCreateConfigurable(product $subject, $result) - { - $extensionEnabled = $this->config->getValue('akeneo_connector/justbetter/fixconfigurableurls', scope::SCOPE_WEBSITE); - if (!$extensionEnabled) { - return $result; - } - $tmpTableName = $this->entitiesHelper->getTableName($subject->getCode()); - $this->fixDuplicateUrls($tmpTableName); - return $result; - } - - /** - * fix Duplicate Urls function - * - * @param string $tmpTableName - * @return void - */ - public function fixDuplicateUrls($tmpTableName) - { - $stores = $this->storeHelper->getStores(['lang']); - $connection = $this->entitiesHelper->getConnection(); - $identifier = " LOWER(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(`identifier`), ':', ''), ')', ''), '(', ''), ',', ''), '\/', ''), '\'', ''), '&', ''), '!', ''), '.', ''), ' ', '-'), '--', '-'), '--', '-')) "; - - foreach ($stores as $local) { - $data = []; - $channelCode = $local[0]['channel_code'] ?? false; - $local = "url_key-" . $local[0]['lang']; - $urlKey = $connection->tableColumnExists($tmpTableName, $local); - - if ($channelCode) { - if ($connection->tableColumnExists($tmpTableName, $local.'-'.$channelCode)) { - $urlKey = true; - $local = $local.'-'.$channelCode; - } - } - - if ($urlKey) { - $data[$local] = new expression("CONCAT(`" . $local . "`,'-' ," . $identifier . ")"); - - $where[] = "parent is not null"; - $where[] = "`$local` is not null"; - - $connection->update( - $tmpTableName, - $data, - $where - ); - } - } - } -}