Skip to content

Commit 5ea9898

Browse files
committed
Inital Magento 2 Data Migration Extension
0 parents  commit 5ea9898

File tree

131 files changed

+2537
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2537
-0
lines changed

Block/Adminhtml/Migration.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Block\Adminhtml;
20+
21+
use Magento\Backend\Block\Template\Context;
22+
use Magento\Backend\Model\UrlInterface;
23+
24+
class Migration extends \Magento\Backend\Block\Template
25+
{
26+
27+
protected $configPayment;
28+
protected $urlBuilder;
29+
30+
public function __construct(
31+
Context $context,
32+
array $data = []
33+
)
34+
{
35+
parent::__construct($context, $data);
36+
}
37+
}

Controller/Adminhtml/Migration.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Controller\Adminhtml;
20+
21+
use Magento\Backend\App\Action\Context;
22+
use Magento\Backend\App\Action as AppAction;
23+
use Magento\Framework\View\Result\PageFactory;
24+
use D2DSoft\DataMigration\Helper\Data as HelperData;
25+
use Magento\Backend\Model\Auth\Session as AuthSession;
26+
use Magento\Backend\Model\Session;
27+
28+
abstract class Migration extends AppAction
29+
{
30+
protected $resultPageFactory;
31+
32+
protected $helper;
33+
34+
protected $migrationApp;
35+
36+
protected $authSession;
37+
38+
protected $session;
39+
40+
public function __construct(
41+
Context $context,
42+
PageFactory $resultPageFactory,
43+
HelperData $helper,
44+
AuthSession $authSession,
45+
Session $session
46+
) {
47+
parent::__construct($context);
48+
$this->resultPageFactory = $resultPageFactory;
49+
$this->helper = $helper;
50+
$this->authSession = $authSession;
51+
$this->session = $session;
52+
}
53+
54+
protected function getMigrationApp()
55+
{
56+
if($this->migrationApp){
57+
return $this->migrationApp;
58+
}
59+
$user = $this->authSession->getUser();
60+
$library_folder = $this->helper->getLibraryFolder();
61+
include_once $this->helper->getInitLibrary();
62+
\D2dInit::initEnv();
63+
$app = \D2dInit::getAppInstance(\D2dInit::APP_HTTP, \D2dInit::TARGET_RAW, 'magento20');
64+
$app->setRequest($this->getRequest()->getParams());
65+
$config = array();
66+
$config['user_id'] = $user->getId();
67+
$config['upload_dir'] = $library_folder . '/files';
68+
$config['upload_location'] = ltrim($this->helper->getLibraryLocation()) . '/files';
69+
$config['log_dir'] = $library_folder . '/log';
70+
$app->setConfig($config);
71+
$this->migrationApp = $app;
72+
return $this->migrationApp;
73+
}
74+
75+
public function setMessage($type, $message){
76+
$messages = $this->session->getMigrationMessage();
77+
if(!$messages)
78+
$messages = array();
79+
$messages[] = array(
80+
'type' => $type,
81+
'message' => $message
82+
);
83+
$this->session->setMigrationMessage($messages);
84+
return $this;
85+
}
86+
87+
public function getMessage(){
88+
$messages = $this->session->getMigrationMessage();
89+
$this->session->setMigrationMessage(array());
90+
return $messages;
91+
}
92+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Controller\Adminhtml\Migration;
20+
21+
use D2DSoft\DataMigration\Controller\Adminhtml\Migration;
22+
23+
class Index extends Migration
24+
{
25+
public function execute()
26+
{
27+
if(!$this->helper->isInstallLibrary()){
28+
$this->_redirect('*/*/license');
29+
return;
30+
}
31+
$resultPage = $this->resultPageFactory->create();
32+
$resultPage->setActiveMenu('D2DSoft_DataMigration::datamigration');
33+
$resultPage->getConfig()->getTitle()->prepend(__('Data Migration'));
34+
$block = $resultPage->getLayout()->getBlock('datamigration.migration.index');
35+
$app = $this->getMigrationApp();
36+
$target = $app->getInitTarget();
37+
$response = $app->process(\D2dInit::PROCESS_INIT);
38+
$html = '';
39+
if($response['status'] == \D2dCoreLibConfig::STATUS_SUCCESS){
40+
$html = $response['html'];
41+
}
42+
$block->setHtmlContent($html)
43+
->setMigrationMessage($this->getMessage())
44+
->setJsConfig($target->getConfigJs());
45+
return $resultPage;
46+
}
47+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Controller\Adminhtml\Migration;
20+
21+
use D2DSoft\DataMigration\Controller\Adminhtml\Migration;
22+
23+
class License extends Migration
24+
{
25+
public function execute()
26+
{
27+
if(!ini_get('allow_url_fopen')){
28+
$this->setMessage('error', 'The PHP "allow_url_fopen" must is enabled. Please follow <a href="https://www.a2hosting.com/kb/developer-corner/php/using-php.ini-directives/php-allow-url-fopen-directive" target="_blank">here</a> to enable the setting.');
29+
}
30+
$resultPage = $this->resultPageFactory->create();
31+
$resultPage->setActiveMenu('D2DSoft_DataMigration::datamigration');
32+
$resultPage->getConfig()->getTitle()->prepend(__('Data Migration'));
33+
$block = $resultPage->getLayout()->getBlock('datamigration.migration.license');
34+
$block->setMigrationMessage($this->getMessage());
35+
return $resultPage;
36+
}
37+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Controller\Adminhtml\Migration;
20+
21+
use D2DSoft\DataMigration\Controller\Adminhtml\Migration;
22+
use Zend_Json_Encoder;
23+
24+
class Process extends Migration
25+
{
26+
public function execute()
27+
{
28+
$type = $this->getRequest()->getParam('action_type', 'import');
29+
return $this->$type();
30+
}
31+
32+
public function import(){
33+
$app = $this->getMigrationApp();
34+
$process = $this->getRequest()->getParam('process');
35+
if(!$process || !in_array($process, array(
36+
\D2dInit::PROCESS_SETUP,
37+
\D2dInit::PROCESS_CHANGE,
38+
\D2dInit::PROCESS_UPLOAD,
39+
\D2dInit::PROCESS_STORED,
40+
\D2dInit::PROCESS_STORAGE,
41+
\D2dInit::PROCESS_CONFIG,
42+
\D2dInit::PROCESS_CONFIRM,
43+
\D2dInit::PROCESS_PREPARE,
44+
\D2dInit::PROCESS_CLEAR,
45+
\D2dInit::PROCESS_IMPORT,
46+
\D2dInit::PROCESS_RESUME,
47+
\D2dInit::PROCESS_REFRESH,
48+
\D2dInit::PROCESS_FINISH))){
49+
$this->responseJson(array(
50+
'status' => 'error',
51+
'message' => 'Process Invalid.'
52+
));
53+
return;
54+
}
55+
$response = $app->process($process);
56+
$this->responseJson($response);
57+
return;
58+
}
59+
60+
public function download(){
61+
$app = $this->getMigrationApp();
62+
$app->process(\D2dInit::PROCESS_DOWNLOAD);
63+
}
64+
65+
protected function responseJson($data)
66+
{
67+
$this->getResponse()
68+
->clearHeaders()
69+
->setHeader('Content-type', 'application/json' ,true);
70+
$this->getResponse()
71+
->setBody(Zend_Json_Encoder::encode($data));
72+
return;
73+
}
74+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* D2dSoft
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License (AFL v3.0) that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL: https://d2d-soft.com/license/AFL.txt
10+
*
11+
* DISCLAIMER
12+
* Do not edit or add to this file if you wish to upgrade this extension/plugin/module to newer version in the future.
13+
*
14+
* @author D2dSoft Developers <develop@d2d-soft.com>
15+
* @copyright Copyright (c) 2021 D2dSoft (https://d2d-soft.com)
16+
* @license https://d2d-soft.com/license/AFL.txt
17+
*/
18+
19+
namespace D2DSoft\DataMigration\Controller\Adminhtml\Migration;
20+
21+
use D2DSoft\DataMigration\Controller\Adminhtml\Migration;
22+
23+
class Setting extends Migration
24+
{
25+
public function execute()
26+
{
27+
if(!$this->helper->isInstallLibrary()){
28+
return $this->_redirect('*/*/license');
29+
}
30+
$app = $this->getMigrationApp();
31+
$target = $app->getInitTarget();
32+
if($this->getRequest()->isPost()){
33+
$keys = array(
34+
'license', 'storage', 'taxes', 'manufacturers', 'customers', 'orders', 'reviews', 'delay', 'retry', 'src_prefix', 'target_prefix', 'other'
35+
);
36+
foreach($keys as $key){
37+
$target->dbSaveSetting($key, $this->getRequest()->getParam($key));
38+
}
39+
$this->setMessage('success', 'Save successfully.');
40+
}
41+
$settings = $target->dbSelectSettings();
42+
$resultPage = $this->resultPageFactory->create();
43+
$resultPage->setActiveMenu('D2DSoft_DataMigration::datamigration');
44+
$resultPage->getConfig()->getTitle()->prepend(__('Data Migration'));
45+
$block = $resultPage->getLayout()->getBlock('datamigration.migration.setting');
46+
$block->setMigrationSetting($settings)
47+
->setMigrationMessage($this->getMessage());
48+
return $resultPage;
49+
}
50+
}

0 commit comments

Comments
 (0)