-
Notifications
You must be signed in to change notification settings - Fork 0
/
parserlink.class.php
148 lines (124 loc) · 3.3 KB
/
parserlink.class.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
class parserlink extends ModuleObject
{
private static $config_cache = NULL;
private static $triggers = array(
array('moduleHandler.init', 'parserlink', 'controller', 'triggerAfterModuleHandlerInit', 'after'),
array('document.insertDocument', 'parserlink', 'controller', 'triggerAfterInsertDocument', 'after'),
);
private static $delete_triggers = array(
array('moduleHandler.init', 'parserlink', 'controller', 'triggerBeforeModuleHandlerInit', 'before'),
array('display', 'parserlink', 'controller', 'triggerAfterDisplay', 'after'),
);
protected function getConfig()
{
if(self::$config_cache !== NULL)
{
return self::$config_cache;
}
/* @var $oModuleModel moduleModel */
$oModuleModel = getModel('module');
$config = $oModuleModel->getModuleConfig('parserlink');
if(!$config)
{
$config = new stdClass();
}
if(!$config->use)
{
$config->use = 'N';
}
if ($config->use_db_data !== 'yes')
{
$config->use_cache = 'no';
$config->cache_time = 0;
}
self::$config_cache = $config;
return self::$config_cache;
}
protected function setConfig($config)
{
/* @var $oModuleController moduleController */
$oModuleController = getController('module');
if ($config->use_db_data !== 'yes')
{
$config->use_cache = 'no';
$config->cache_time = 0;
}
$result = $oModuleController->insertModuleConfig($this->module, $config);
if ($result->toBool())
{
self::$config_cache = $config;
}
return $result;
}
function moduleInstall()
{
return $this->makeObject();
}
function checkUpdate()
{
/* @var $oModuleModel moduleModel */
$oModuleModel = getModel('module');
foreach(self::$triggers as $trigger)
{
if(!$oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4])) return true;
}
foreach (self::$delete_triggers as $trigger)
{
if($oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4])) return true;
}
return false;
}
function moduleUpdate()
{
$oModuleModel = getModel('module');
/** @var $oModuleController moduleController */
$oModuleController = getController('module');
foreach(self::$triggers as $trigger)
{
if(!$oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]))
{
$oModuleController->insertTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]);
}
}
foreach(self::$delete_triggers as $trigger)
{
if($oModuleModel->getTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]))
{
$oModuleController->deleteTrigger($trigger[0], $trigger[1], $trigger[2], $trigger[3], $trigger[4]);
}
}
return $this->makeObject();
}
protected function getCacheHandler()
{
$cache_type = config('cache.type') ?? '';
if ($cache_type && !preg_match('/^(?:file|dummy)\b/i', $cache_type))
{
$handler = CacheHandler::getInstance('object');
if ($handler->isSupport())
{
return $handler;
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* Create new Object for php7.2
* @param int $code
* @param string $msg
* @return BaseObject|Object
*/
public function makeObject($code = 0, $msg = 'success')
{
return class_exists('BaseObject') ? new BaseObject($code, $msg) : new Object($code, $msg);
}
}
/* End of file */