Skip to content

Commit

Permalink
Merge pull request #20 from exponea/feature/sync-14
Browse files Browse the repository at this point in the history
v0.9.4 Release
  • Loading branch information
eduard13 authored Mar 14, 2022
2 parents 6df67d3 + ae68b8a commit c3b8da1
Show file tree
Hide file tree
Showing 44 changed files with 1,411 additions and 309 deletions.
55 changes: 55 additions & 0 deletions Block/Adminhtml/System/Config/RunInitialImportButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* @author Bloomreach
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/)
*/
declare(strict_types=1);

namespace Bloomreach\EngagementConnector\Block\Adminhtml\System\Config;

use Bloomreach\EngagementConnector\Service\InitialImport\ProcessStatus;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Phrase;

/**
* Button for running Initial Import in admin panel
*/
class RunInitialImportButton extends Button
{
/**
* @var ProcessStatus
*/
private $processStatus;

/**
* @param Context $context
* @param ProcessStatus $processStatus
* @param array $data
*/
public function __construct(
Context $context,
ProcessStatus $processStatus,
array $data = []
) {
parent::__construct($context, $data);
$this->processStatus = $processStatus;
}

/**
* Get the button and scripts contents
*
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
parent::_getElementHtml($element);
$this->addData([
'is_import_in_progress' => $this->processStatus->execute()
]);

return $this->_toHtml();
}
}
6 changes: 3 additions & 3 deletions Console/Command/StartExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Data export to Bloomreach has started');

$importId = $input->getOption('import_id');
$importId = (string) $input->getOption('import_id');

if ($importId) {
try {
$result = $this->startApiImportService->execute(
$importId,
$input->getOption('csv_file_path'),
$input->getOption('test_connection')
(string) $input->getOption('csv_file_path'),
(bool) $input->getOption('test_connection')
);

$output->writeln('Status: ' . $result->getStatusCode());
Expand Down
49 changes: 49 additions & 0 deletions Exception/ExportRequestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @author Bloomreach
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/)
*/
declare(strict_types=1);

namespace Bloomreach\EngagementConnector\Exception;

use Exception;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;

/**
* An exception that is thrown when the request to the Bloomreach API is unsuccessful
*/
class ExportRequestException extends LocalizedException
{
/**
* @var bool
*/
private $isNeedUpdateRetryCounter;

/**
* @param Phrase $phrase
* @param bool $isNeedUpdateRetryCounter
* @param Exception|null $cause
* @param int $code
*/
public function __construct(
Phrase $phrase,
bool $isNeedUpdateRetryCounter = true,
Exception $cause = null,
$code = 0
) {
$this->isNeedUpdateRetryCounter = $isNeedUpdateRetryCounter;
parent::__construct($phrase, $cause, $code);
}

/**
* Is need to update retry counter after failed attempt
*
* @return bool
*/
public function isNeedUpdateRetryCounter(): bool
{
return $this->isNeedUpdateRetryCounter;
}
}
97 changes: 97 additions & 0 deletions Logger/Debugger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @author Bloomreach
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/)
*/
declare(strict_types=1);

namespace Bloomreach\EngagementConnector\Logger;

use Bloomreach\EngagementConnector\Model\DataMapping\Config\ConfigProvider;
use Magento\Framework\Phrase;
use Magento\Framework\Serialize\SerializerInterface;
use Psr\Log\LoggerInterface;

/**
* The class is responsible for saving the debug information to the log file
*/
class Debugger
{
/**
* @var ConfigProvider
*/
private $configProvider;

/**
* @var SerializerInterface
*/
private $jsonSerializer;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var bool
*/
private $isDebugModeEnabled;

/**
* @param ConfigProvider $configProvider
* @param SerializerInterface $jsonSerializer
* @param LoggerInterface $logger
*/
public function __construct(
ConfigProvider $configProvider,
SerializerInterface $jsonSerializer,
LoggerInterface $logger
) {
$this->configProvider = $configProvider;
$this->jsonSerializer = $jsonSerializer;
$this->logger = $logger;
}

/**
* Log debugging information
*
* @param Phrase|string $message
*
* @return void
*/
public function log($message): void
{
if ($this->isDebugModeEnabled()) {
$this->logger->debug($message);
}
}

/**
* Log debugging information
*
* @param string $placeholder
* @param array $data
*
* @return void
*/
public function logArray(string $placeholder, array $data): void
{
if ($this->isDebugModeEnabled()) {
$this->logger->debug(__($placeholder, $this->jsonSerializer->serialize($data)));
}
}

/**
* Checks whether is debug mode enabled
*
* @return bool
*/
private function isDebugModeEnabled(): bool
{
if ($this->isDebugModeEnabled === null) {
$this->isDebugModeEnabled = $this->configProvider->isDebugModeEnabled();
}

return $this->isDebugModeEnabled;
}
}
40 changes: 40 additions & 0 deletions Model/DataMapping/Config/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ class ConfigProvider
*/
public const XPATH_CATALOG_VARIANTS_ID = 'bloomreach_engagement/general/variants_id';

/**
* Enable Debug Mode system configuration value XPATH
*/
public const XPATH_ENABLE_DEBUG_MODE = 'bloomreach_engagement/general/debug_mode';

/**
* Request timeout system configuration value XPATH
*/
public const XPATH_REQUEST_TIMEOUT = 'bloomreach_engagement/general/request_timeout';

/**
* @var ScopeConfigInterface
*/
Expand Down Expand Up @@ -342,4 +352,34 @@ public function getCatalogVariantsId(
): string {
return (string) $this->scopeConfig->getValue(self::XPATH_CATALOG_VARIANTS_ID, $scopeType, $scopeCode);
}

/**
* Get is enable Debug Mode
*
* @param string $scopeType
* @param int|string $scopeCode
*
* @return bool
*/
public function isDebugModeEnabled(
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeCode = null
): bool {
return $this->scopeConfig->isSetFlag(self::XPATH_ENABLE_DEBUG_MODE, $scopeType, $scopeCode);
}

/**
* Get Request Timeout
*
* @param string $scopeType
* @param int|string $scopeCode
*
* @return int
*/
public function getRequestTimeout(
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeCode = null
): int {
return (int) $this->scopeConfig->getValue(self::XPATH_REQUEST_TIMEOUT, $scopeType, $scopeCode);
}
}
4 changes: 2 additions & 2 deletions Model/DataMapping/DataMapper/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use Bloomreach\EngagementConnector\Model\DataMapping\Config\Data\FieldMappingConfigDataInterface;
use Bloomreach\EngagementConnector\Model\DataMapping\MappingProcessor;
use Magento\Framework\Api\AbstractSimpleObject;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\DataObject;
use Magento\Framework\Model\AbstractModel;

/**
* Maps Customer data to Bloomreach data
*/
class Customer implements DataMapperInterface
{
private const ENTITY_TYPE = 'customer';
const ENTITY_TYPE = 'customer';

/**
* @var MappingProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Timestamp implements RenderInterface

/**
* @param DateTime $dateTime
* @param GetCustomerAttributeValue $getCustomerAttributeValue
*/
public function __construct(
DateTime $dateTime,
Expand Down
Loading

0 comments on commit c3b8da1

Please sign in to comment.