ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Controller\Adminhtml\Geoip;
|
||||
|
||||
use Amasty\Geoip\Controller\Adminhtml\GeoipAbstract;
|
||||
|
||||
class Commit extends GeoipAbstract
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$result = [];
|
||||
|
||||
try {
|
||||
$type = $this->getRequest()->getParam('type');
|
||||
$action = $this->getRequest()->getParam('action');
|
||||
$isDownload = false;
|
||||
if ($action == 'download_and_import') {
|
||||
$isDownload = true;
|
||||
}
|
||||
$this->importModel->commitProcess($type, $isDownload);
|
||||
$result['status'] = 'done';
|
||||
$result['full_import_done'] = $this->geoipHelper->isDone() ? "1" : "0";
|
||||
} catch (\Exception $e) {
|
||||
$result['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody($this->jsonHelper->jsonEncode($result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Controller\Adminhtml\Geoip;
|
||||
|
||||
use Amasty\Geoip\Controller\Adminhtml\GeoipAbstract as GeoipAbstract;
|
||||
|
||||
class Process extends GeoipAbstract
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$result = [];
|
||||
try {
|
||||
$type = $this->getRequest()->getParam('type');
|
||||
$action = $this->getRequest()->getParam('action');
|
||||
$filePath = $this->geoipHelper->getCsvFilePath($type);
|
||||
$ret = $this->importModel->doProcess($type, $filePath, $action);
|
||||
$result['type'] = $type;
|
||||
$result['status'] = 'processing';
|
||||
$result['position'] = ceil($ret['current_row'] / $ret['rows_count'] * 100);
|
||||
|
||||
if ($result['position'] > 100) {
|
||||
$result['position'] = 100;
|
||||
}
|
||||
if ($type == 'block' && $result['position'] == 100 && $ret['current_row'] + 3 < $ret['rows_count']) {
|
||||
$result['position'] = 99;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$result['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody($this->jsonHelper->jsonEncode($result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Controller\Adminhtml\Geoip;
|
||||
|
||||
use Amasty\Geoip\Controller\Adminhtml\GeoipAbstract;
|
||||
|
||||
class Start extends GeoipAbstract
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$result = [];
|
||||
try {
|
||||
$type = $this->getRequest()->getParam('type');
|
||||
$action = $this->getRequest()->getParam('action');
|
||||
|
||||
$this->geoipHelper->resetDone();
|
||||
$filePath = $this->geoipHelper->getCsvFilePath($type);
|
||||
$ret = $this->importModel->startProcess(
|
||||
$type,
|
||||
$filePath,
|
||||
$action,
|
||||
$this->geoipHelper->_geoipIgnoredLines[$type]
|
||||
);
|
||||
$result['position'] = ceil($ret['current_row'] / $ret['rows_count'] * 100);
|
||||
$result['status'] = 'started';
|
||||
$result['file'] = $this->geoipHelper->_geoipCsvFiles[$type];
|
||||
} catch (\Exception $e) {
|
||||
$result['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody($this->jsonHelper->jsonEncode($result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Controller\Adminhtml\Geoip;
|
||||
|
||||
use Amasty\Geoip\Controller\Adminhtml\GeoipAbstract;
|
||||
|
||||
class StartDownloading extends GeoipAbstract
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$result = [];
|
||||
try {
|
||||
$type = $this->getRequest()->getParam('type');
|
||||
$url = $this->_getFileUrl($type);
|
||||
$dir = $this->geoipHelper->getDirPath();
|
||||
$newFilePath = $this->geoipHelper->getCsvFilePath($type);
|
||||
$needToUpdate = true;
|
||||
$needToDownload = true;
|
||||
|
||||
if ($this->driverFile->isExists($newFilePath)) {
|
||||
$hashUrl = $this->getHashUrl($type);
|
||||
if ($hashUrl
|
||||
&& hash_file('md5', $newFilePath) == trim($this->driverFile->fileGetContents($hashUrl))
|
||||
) {
|
||||
$needToDownload = false;
|
||||
if ($this->geoipHelper->isDone(false)) {
|
||||
$needToUpdate = false;
|
||||
}
|
||||
} else {
|
||||
$this->driverFile->deleteFile($newFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
if ($needToUpdate && !$this->driverFile->isExists($dir)) {
|
||||
$this->driverFile->createDirectory($dir, 0770);
|
||||
}
|
||||
|
||||
if ($needToUpdate) {
|
||||
if ($needToDownload) {
|
||||
$source = $this->driverFile->fileOpen($url, 'r');
|
||||
$dest = $this->driverFile->fileOpen($newFilePath, 'w');
|
||||
//@codingStandardsIgnoreStart
|
||||
stream_copy_to_stream($source, $dest);
|
||||
//@codingStandardsIgnoreEnd
|
||||
}
|
||||
$result['status'] = 'finish_downloading';
|
||||
} else {
|
||||
$result['status'] = 'done';
|
||||
}
|
||||
$result['file'] = $this->geoipHelper->_geoipCsvFiles[$type];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$result['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody($this->jsonHelper->jsonEncode($result));
|
||||
}
|
||||
|
||||
protected function _getFileUrl($type)
|
||||
{
|
||||
$url = '';
|
||||
switch ($type) {
|
||||
case 'block':
|
||||
$url = $this->geoipHelper->getUrlBlockFile();
|
||||
break;
|
||||
case 'location':
|
||||
$url = $this->geoipHelper->getUrlLocationFile();
|
||||
break;
|
||||
case 'block_v6':
|
||||
$url = $this->geoipHelper->getUrlBlockV6File();
|
||||
break;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHashUrl($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'block':
|
||||
return $this->geoipHelper->getHashUrlBlock();
|
||||
case 'location':
|
||||
return $this->geoipHelper->getHashUrlLocation();
|
||||
case 'block_v6':
|
||||
return $this->geoipHelper->getHashUrlBlockV6();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
namespace Amasty\Geoip\Controller\Adminhtml;
|
||||
|
||||
use Amasty\Geoip\Helper\Data as Helper;
|
||||
use Amasty\Geoip\Model\Import;
|
||||
use Amasty\Geoip\Model\Geolocation;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Json\Helper\Data as JsonData;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
|
||||
/**
|
||||
* Class GeoipAbstract
|
||||
*/
|
||||
abstract class GeoipAbstract extends Action
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Import
|
||||
*/
|
||||
protected $importModel;
|
||||
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $geoipHelper;
|
||||
|
||||
/**
|
||||
* @var JsonData
|
||||
*/
|
||||
protected $jsonHelper;
|
||||
|
||||
/**
|
||||
* @var File
|
||||
*/
|
||||
protected $driverFile;
|
||||
|
||||
/**
|
||||
* @var Geolocation
|
||||
*/
|
||||
protected $geolocationModel;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Import $importModel,
|
||||
Helper $geoipHelper,
|
||||
JsonData $jsonHelper,
|
||||
File $driverFile,
|
||||
Geolocation $geolocationModel
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->importModel = $importModel;
|
||||
$this->geoipHelper = $geoipHelper;
|
||||
$this->jsonHelper = $jsonHelper;
|
||||
$this->driverFile = $driverFile;
|
||||
$this->geolocationModel = $geolocationModel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user