Example #1
0
 /**
  * Start import process action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $data = $this->getRequest()->getPostValue();
     if ($data) {
         /** @var \Magento\Framework\View\Result\Layout $resultLayout */
         $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
         /** @var $resultBlock \Magento\ImportExport\Block\Adminhtml\Import\Frame\Result */
         $resultBlock = $resultLayout->getLayout()->getBlock('import.frame.result');
         $resultBlock->addAction('show', 'import_validation_container')->addAction('innerHTML', 'import_validation_container_header', __('Status'))->addAction('hide', ['edit_form', 'upload_button', 'messages']);
         $this->importModel->setData($data);
         $this->importModel->importSource();
         $errorAggregator = $this->importModel->getErrorAggregator();
         if ($this->importModel->getErrorAggregator()->hasToBeTerminated()) {
             $resultBlock->addError(__('Maximum error count has been reached or system error is occurred!'));
             $this->addErrorMessages($resultBlock, $errorAggregator);
         } else {
             $this->importModel->invalidateIndex();
             $this->addErrorMessages($resultBlock, $errorAggregator);
             $resultBlock->addSuccess(__('Import successfully done'));
         }
         return $resultLayout;
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     $resultRedirect->setPath('adminhtml/*/index');
     return $resultRedirect;
 }
 /**
  * @return bool
  */
 public function execute()
 {
     $result = $this->importModel->importSource();
     if ($result) {
         $this->importModel->invalidateIndex();
     }
     return $result;
 }
Example #3
0
 /**
  * @covers \Magento\ImportExport\Model\Import::_getEntityAdapter
  */
 public function testImportSource()
 {
     /** @var $customersCollection \Magento\Customer\Model\Resource\Customer\Collection */
     $customersCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Resource\\Customer\\Collection');
     $existCustomersCount = count($customersCollection->load());
     $customersCollection->resetData();
     $customersCollection->clear();
     $this->_model->importSource();
     $customers = $customersCollection->getItems();
     $addedCustomers = count($customers) - $existCustomersCount;
     $this->assertGreaterThan($existCustomersCount, $addedCustomers);
 }
 /**
  * @covers \Magento\ImportExport\Model\Import::_getEntityAdapter
  */
 public function testImportSource()
 {
     /** @var $customersCollection \Magento\Customer\Model\ResourceModel\Customer\Collection */
     $customersCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection');
     $existCustomersCount = count($customersCollection->load());
     $customersCollection->resetData();
     $customersCollection->clear();
     $this->_model->setData(Import::FIELD_NAME_VALIDATION_STRATEGY, Import\ErrorProcessing\ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS);
     $this->_model->importSource();
     $customers = $customersCollection->getItems();
     $addedCustomers = count($customers) - $existCustomersCount;
     $this->assertGreaterThan($existCustomersCount, $addedCustomers);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function importSource()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'importSource');
     if (!$pluginInfo) {
         return parent::importSource();
     } else {
         return $this->___callPlugins('importSource', func_get_args(), $pluginInfo);
     }
 }
Example #6
0
 public function testImportSource()
 {
     $entityTypeCode = 'code';
     $this->_importData->expects($this->any())->method('getEntityTypeCode')->will($this->returnValue($entityTypeCode));
     $behaviour = 'behaviour';
     $this->_importData->expects($this->once())->method('getBehavior')->will($this->returnValue($behaviour));
     $this->import->expects($this->any())->method('getDataSourceModel')->will($this->returnValue($this->_importData));
     $this->import->expects($this->any())->method('setData')->withConsecutive(['entity', $entityTypeCode], ['behavior', $behaviour]);
     $phraseClass = '\\Magento\\Framework\\Phrase';
     $this->import->expects($this->any())->method('addLogComment')->with($this->isInstanceOf($phraseClass));
     $this->_entityAdapter->expects($this->once())->method('importData')->will($this->returnSelf());
     $this->import->expects($this->once())->method('_getEntityAdapter')->will($this->returnValue($this->_entityAdapter));
     $importOnceMethodsReturnNull = ['getEntity', 'getBehavior', 'getProcessedRowsCount', 'getProcessedEntitiesCount', 'getInvalidRowsCount', 'getErrorsCount'];
     foreach ($importOnceMethodsReturnNull as $method) {
         $this->import->expects($this->once())->method($method)->will($this->returnValue(null));
     }
     $this->import->importSource();
 }
 /**
  * Test importSource with expected exception
  *
  */
 public function testImportSourceException()
 {
     $exceptionMock = new \Magento\Framework\Exception\AlreadyExistsException(__('URL key for specified store already exists.'));
     $entityTypeCode = 'code';
     $this->_importData->expects($this->any())->method('getEntityTypeCode')->will($this->returnValue($entityTypeCode));
     $behaviour = 'behaviour';
     $this->_importData->expects($this->any())->method('getBehavior')->will($this->returnValue($behaviour));
     $this->import->expects($this->any())->method('getDataSourceModel')->will($this->returnValue($this->_importData));
     $this->import->expects($this->any())->method('setData')->withConsecutive(['entity', $entityTypeCode], ['behavior', $behaviour]);
     $phraseClass = '\\Magento\\Framework\\Phrase';
     $this->import->expects($this->any())->method('addLogComment')->with($this->isInstanceOf($phraseClass));
     $this->_entityAdapter->expects($this->any())->method('importData')->will($this->throwException($exceptionMock));
     $this->import->expects($this->any())->method('_getEntityAdapter')->will($this->returnValue($this->_entityAdapter));
     $importOnceMethodsReturnNull = ['getBehavior'];
     foreach ($importOnceMethodsReturnNull as $method) {
         $this->import->expects($this->once())->method($method)->will($this->returnValue(null));
     }
     $this->import->importSource();
 }
 protected function _importData()
 {
     $this->importModel->importSource();
     $this->_handleImportResult();
 }