This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathData.php
120 lines (102 loc) · 3.16 KB
/
Data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* FACTFinder_Suggest
*
* @category Mage
* @package FACTFinder_Suggest
* @author Flagbit Magento Team <[email protected]>
* @copyright Copyright (c) 2016 Flagbit GmbH & Co. KG
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
* @link http://www.flagbit.de
*
*/
/**
* Helper class
*
* @category Mage
* @package FACTFinder_Suggest
* @author Flagbit Magento Team <[email protected]>
* @copyright Copyright (c) 2016 Flagbit GmbH & Co. KG
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
* @link http://www.flagbit.de
*/
class FACTFinder_Suggest_Helper_Data extends Mage_Core_Helper_Abstract
{
const XML_CONFIG_PATH_USE_PROXY = 'factfinder/config/proxy';
const IMPORT_TYPE = 'suggest';
/**
* Get FACT-Finder Suggest URL
*
* @return string
*/
public function getSuggestUrl()
{
if ($this->isSuggestProxyActivated()) {
$params = array();
if (Mage::app()->getStore()->isCurrentlySecure()) {
$params['_secure'] = true;
}
$url = $this->_getUrl('factfinder_suggest/proxy/suggest', $params);
} else {
$url = Mage::getSingleton('factfinder_suggest/facade')->getSuggestUrl();
if (Mage::app()->getStore()->isCurrentlySecure()) {
$url = preg_replace('/^http:/', 'https:', $url);
}
}
// avoid specifying the default port for http
$url = preg_replace('/^(http:[^\:]+)\:80\//', "$1/", $url);
// remove param "query"
$url = preg_replace('/([&|?])query=[^&]*&?/', "$1", $url);
return $url;
}
/**
* Check config is proxy is activated
*
* @return bool
*/
public function isSuggestProxyActivated()
{
return Mage::getStoreConfig(self::XML_CONFIG_PATH_USE_PROXY);
}
/**
* Check if import should be triggered for store
*
* @param int $storeId
*
* @return bool
*/
public function shouldTriggerImport($storeId)
{
if (!Mage::getStoreConfigFlag('factfinder/modules/suggest', $storeId)) {
return false;
}
return Mage::getStoreConfigFlag('factfinder/export/trigger_suggest_import', $storeId);
}
/**
* Trigger suggest import
*
* @param int $storeId
*
* @return void
*/
public function triggerImport($storeId)
{
$exportHelper = Mage::helper('factfinder/export');
$channel = Mage::helper('factfinder')->getPrimaryChannel($storeId);
/** @var FACTFinder_Suggest_Model_Facade $facade */
$facade = Mage::getModel('factfinder_suggest/facade');
$facade->setStoreId($storeId);
$download = !$exportHelper->useFtp($storeId);
$delay = $exportHelper->getImportDelay(self::IMPORT_TYPE);
if ($exportHelper->isImportDelayEnabled($storeId)) {
$pid = pcntl_fork();
if (!$pid) {
sleep($delay);
$facade->triggerSuggestImport($channel, $download);
exit(0);
}
} else {
$facade->triggerSuggestImport($channel, $download);
}
}
}