Skip to content

Commit

Permalink
Merge pull request #542 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogres] Bug Fixes
  • Loading branch information
sdwright committed Apr 16, 2016
2 parents ff70f6e + 4bf9910 commit e04ef1b
Show file tree
Hide file tree
Showing 29 changed files with 454 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Adapter\Mysql\Query\Preprocessor;
namespace Magento\Search\Adapter\Query\Preprocessor;

use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface;
use Magento\Search\Api\SynonymAnalyzerInterface;
Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/Search/Api/SynonymGroupRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ interface SynonymGroupRepositoryInterface
* Save synonym group data
*
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
* @param bool $errorOnMergeConflict
* @return \Magento\Search\Api\Data\SynonymGroupInterface saved attribute set
*/
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup, $errorOnMergeConflict = false);

/**
* Remove given synonym group data
Expand All @@ -25,4 +26,12 @@ public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGrou
* @return bool
*/
public function delete(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);

/**
* Return a paritcular synonym group interface instance based on passed in synonym group id
*
* @param int $synonymGroupId
* @return \Magento\Search\Api\Data\SynonymGroupInterface
*/
public function get($synonymGroupId);
}
51 changes: 43 additions & 8 deletions app/code/Magento/Search/Controller/Adminhtml/Synonyms/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,45 @@

namespace Magento\Search\Controller\Adminhtml\Synonyms;

use Magento\Search\Controller\Adminhtml\Synonyms;

/**
* Delete Controller
*/
class Delete extends Synonyms
class Delete extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Psr\Log\LoggerInterface $logger
*/
private $logger;

/**
* @var \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
private $synGroupRepository;

/**
* Constructor
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository,
\Psr\Log\LoggerInterface $logger
) {
$this->synGroupRepository = $synGroupRepository;
$this->logger = $logger;
parent::__construct($context);
}

/**
* Delete action
*
Expand All @@ -25,13 +57,16 @@ public function execute()
$resultRedirect = $this->resultRedirectFactory->create();
if ($id) {
try {
$model = $this->_objectManager->create('Magento\Search\Model\SynonymGroup');
$model->load($id);
$repository = $this->_objectManager->create('Magento\Search\Api\SynonymGroupRepositoryInterface');
$repository->delete($model);
/** @var \Magento\Search\Model\SynonymGroup $synGroupModel */
$synGroupModel = $this->synGroupRepository->get($id);
$this->synGroupRepository->delete($synGroupModel);
$this->messageManager->addSuccess(__('The synonym group has been deleted.'));
} catch (\Exception $e) {
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->logger->error($e);
} catch (\Exception $e) {
$this->messageManager->addError(__('An error was encountered while performing delete operation.'));
$this->logger->error($e);
}
} else {
$this->messageManager->addError(__('We can\'t find a synonym group to delete.'));
Expand Down
73 changes: 61 additions & 12 deletions app/code/Magento/Search/Controller/Adminhtml/Synonyms/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,51 @@
*/
namespace Magento\Search\Controller\Adminhtml\Synonyms;

class Edit extends \Magento\Search\Controller\Adminhtml\Synonyms
class Edit extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Magento\Framework\Registry $registry
*/
private $registry;

/**
* @var \Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder
*/
private $pageBuilder;

/**
* @var \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
private $synGroupRepository;

/**
* Edit constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Backend\Model\Session $session
* @param \Magento\Framework\Registry $registry
* @param \Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder
* @param \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder,
\Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
) {
$this->registry = $registry;
$this->synGroupRepository = $synGroupRepository;
$this->pageBuilder = $pageBuilder;
parent::__construct($context);
}

/**
* Edit Synonym Group
*
Expand All @@ -18,36 +61,42 @@ public function execute()
{
// 1. Get ID and create model
$groupId = $this->getRequest()->getParam('group_id');
$synGroupModel = $this->_objectManager->create('Magento\Search\Model\SynonymGroup');
/** @var \Magento\Search\Api\Data\SynonymGroupInterface $synGroup */
$synGroup = $this->synGroupRepository->get($groupId);

// 2. Initial checking
if ($groupId) {
$synGroupModel->load($groupId);
if (!$synGroupModel->getId()) {
if ($groupId && (!$synGroup->getGroupId())) {
$this->messageManager->addError(__('This synonyms group no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
}

// 3. Set entered data if was error when we do save
$data = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true);
$data = $this->_session->getFormData(true);
if (!empty($data)) {
$synGroupModel->setData($data);
$synGroup->setGroupId($data['group_id']);
$synGroup->setStoreId($data['store_id']);
$synGroup->setWebsiteId($data['website_id']);
$synGroup->setSynonymGroup($data['synonyms']);
}

// 4. Register model to use later in save
$this->registry->register(\Magento\Search\Controller\RegistryConstants::SEARCH_SYNONYMS, $synGroupModel);
$this->registry->register(
\Magento\Search\Controller\RegistryConstants::SEARCH_SYNONYMS,
$synGroup
);

// 5. Build edit synonyms group form
$resultPage = $this->_initAction();
$resultPage = $this->pageBuilder->build();
$resultPage->addBreadcrumb(
$groupId ? __('Edit Synonym Group') : __('New Synonym Group'),
$groupId ? __('Edit Synonym Group') : __('New Synonym Group')
);
$resultPage->getConfig()->getTitle()->prepend(__('Synonym Group'));
$resultPage->getConfig()->getTitle()
->prepend($synGroupModel->getId() ? $synGroupModel->getSynonymGroup() : __('New Synonym Group'));
$resultPage->getConfig()->getTitle()->prepend(
$synGroup->getGroupId() ? $synGroup->getSynonymGroup() : __('New Synonym Group')
);
return $resultPage;
}
}
30 changes: 28 additions & 2 deletions app/code/Magento/Search/Controller/Adminhtml/Synonyms/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,42 @@
*/
namespace Magento\Search\Controller\Adminhtml\Synonyms;

class Index extends \Magento\Search\Controller\Adminhtml\Synonyms
class Index extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder
*/
private $pageBuilder;

/**
* constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder $pageBuilder
) {
$this->pageBuilder = $pageBuilder;
parent::__construct($context);
}

/**
* Synonyms grid
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
$resultPage = $this->_initAction();
$resultPage = $this->pageBuilder->build();
$resultPage->getConfig()->getTitle()->prepend(__('Search Synonyms'));
return $resultPage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,53 @@

namespace Magento\Search\Controller\Adminhtml\Synonyms;

use Magento\Search\Controller\Adminhtml\Synonyms;

/**
* Mass-Delete Controller
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MassDelete extends Synonyms
class MassDelete extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Magento\Ui\Component\MassAction\Filter
*/
protected $filter;
private $filter;

/**
* @var \Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory
*/
protected $collectionFactory;
private $collectionFactory;

/**
* @var \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
private $synGroupRepository;

/**
* MassDelete constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Backend\Model\View\Result\ForwardFactory $forwardFactory
* @param \Magento\Framework\Registry $registry
* @param \Magento\Search\Model\EngineResolver $engineResolver
* @param \Magento\Framework\Search\SearchEngine\ConfigInterface $searchFeatureConfig
* @param \Magento\Ui\Component\MassAction\Filter $filter
* @param \Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory $collectionFactory
* @param \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\Model\View\Result\ForwardFactory $forwardFactory,
\Magento\Framework\Registry $registry,
\Magento\Search\Model\EngineResolver $engineResolver,
\Magento\Framework\Search\SearchEngine\ConfigInterface $searchFeatureConfig,
\Magento\Ui\Component\MassAction\Filter $filter,
\Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory $collectionFactory
\Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory $collectionFactory,
\Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository
) {
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct(
$context,
$resultPageFactory,
$forwardFactory,
$registry,
$engineResolver,
$searchFeatureConfig
);
$this->synGroupRepository = $synGroupRepository;
parent::__construct($context);
}

/**
Expand All @@ -68,12 +66,10 @@ public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();

$synonymGroupRepository = $this->_objectManager->create('Magento\Search\Api\SynonymGroupRepositoryInterface');

$deletedItems = 0;
foreach ($collection as $synonymGroup) {
try {
$synonymGroupRepository->delete($synonymGroup);
$this->synGroupRepository->delete($synonymGroup);
$deletedItems++;
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,34 @@
*/
namespace Magento\Search\Controller\Adminhtml\Synonyms;

class NewAction extends \Magento\Search\Controller\Adminhtml\Synonyms
class NewAction extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Search::synonyms';

/**
* @var \Magento\Backend\Model\View\Result\ForwardFactory $forwardFactory
*/
private $forwardFactory;

/**
* New Synonym Group Action constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Backend\Model\View\Result\ForwardFactory $forwardFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Backend\Model\View\Result\ForwardFactory $forwardFactory
) {
$this->forwardFactory = $forwardFactory;
parent::__construct($context);
}

/**
* Create new synonyms group action
*
Expand Down
Loading

0 comments on commit e04ef1b

Please sign in to comment.