-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemJugglerModule.php
212 lines (159 loc) · 6.69 KB
/
ItemJugglerModule.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
class ItemJugglerModule extends System
{
public function myLoadDataContainer($strName)
{
if ($GLOBALS['ITEMJUGGLER_CONFIGMODE'])
return;
$this->import("Database");
$objDJCallback = $this->Database->prepare("SELECT dca_trigger_callback_list FROM tl_itemjuggler WHERE dca_trigger_callback=1")->execute();
while ($objDJCallback->next())
{
$arrTrigger = deserialize($objDJCallback->dca_trigger_callback_list);
if ((is_array($arrTrigger)) &&
(count($arrTrigger)>0))
{
foreach ($arrTrigger as $trigger)
{
if ($trigger['tables']==$strName)
{
$GLOBALS['TL_DCA'][$trigger['tables']]['config'][$trigger['callbacks']][] = array('ItemJugglerModule','handleItemJuggler_'.$trigger['callbacks']);
}
}
}
}
$objDJCron = $this->Database->prepare("SELECT dca_trigger_cron_list FROM tl_itemjuggler WHERE dca_trigger_cron=1")->execute();
$arrCronList = array();
while ($objDJCron->next())
{
$arrTrigger = deserialize($objDJCron->dca_trigger_cron_list);
if ((is_array($arrTrigger)) &&
(count($arrTrigger)>0))
{
foreach ($arrTrigger as $trigger)
{
$arrCron = array('ItemJugglerModule','handleItemJuggler_cron_'.$trigger['cron_type']);
if (($trigger['cron_type']) && (!in_array($arrCron,$GLOBALS['TL_CRON'][$trigger['cron_type']])))
{
$arrCronList[$trigger['cron_type']][] = $arrCron;
}
}
}
}
$this->Config->update("\$GLOBALS['ITEMJUGGLER_CRON']", serialize($arrCronList));
}
public function handleItemJuggler_ondelete_callback(DataContainer $dc)
{
$this->handleJob($dc,"ondelete_callback");
}
public function handleItemJuggler_onload_callback(DataContainer $dc)
{
$this->handleJob($dc,"onload_callback");
}
public function handleItemJuggler_onsubmit_callback(DataContainer $dc)
{
$this->handleJob($dc,"onsubmit_callback");
}
public function hhandleItemJuggler_oncut_callback(DataContainer $dc)
{
$this->handleJob($dc,"oncut_callback");
}
public function handleItemJuggler_oncopy_callback(DataContainer $dc)
{
$this->handleJob($dc,"oncopy_callback");
}
public function handleItemJuggler_cron_hourly(DataContainer $dc)
{
$this->handleCronJob($dc, 'hourly');
}
public function handleItemJuggler_cron_daily(DataContainer $dc)
{
$this->handleCronJob($dc, 'daily');
}
public function handleItemJuggler_cron_weekly(DataContainer $dc)
{
$this->handleCronJob($dc, 'weekly');
}
protected function handleCronJob(DataContainer $dc,$strCronType)
{
$this->import("Database");
$objDJ = $this->Database->prepare("SELECT id,dca_trigger_cron_list,query_string,append_data FROM tl_itemjuggler WHERE dca_trigger_cron=1")->execute();
while ($objDJ->next())
{
$arrTrigger = deserialize($objDJ->dca_trigger_cron_list);
foreach ($arrTrigger as $trigger)
{
if ($trigger['cron_type']==$strCronType)
{
}
}
}
}
protected function handleJob(DataContainer $dc,$strCallback)
{
$this->import("Database");
$objDJ = $this->Database->prepare("SELECT * FROM tl_itemjuggler WHERE dca_trigger_callback=1")->execute();
while ($objDJ->next())
{
$arrTrigger = deserialize($objDJ->dca_trigger_callback_list);
foreach ($arrTrigger as $trigger)
{
if (($trigger['tables']==$dc->table) &&
($trigger['callbacks'] == $strCallback))
{
$arrFilter = deserialize($objDJ->filterpart);
$arrWhere = array();
foreach ($arrFilter as $filter)
{
$strWhere = "";
switch ($filter['field_type'])
{
case "exactly" : $strWhere ="%s='%s'";
break;
case "startsWith" : $strWhere ="%s LIKE '%s%%'";
break;
case "endsWith" : $strWhere ="%s LIKE '%%%s'";
break;
case "like" : $strWhere ="%s LIKE '%%%s%%'";
break;
case "isEmpty" : $strWhere ="%s=''";
break;
}
if ($strWhere!='')
{
if ($filter['negate'])
$strWhere = sprintf("!(%s)",$strWhere);
$arrWhere[] = sprintf($strWhere,$objDJ->source_column,$filter['query']);
}
}
$strWhereQuery = implode(" AND ",$arrWhere);
$arrActionRows = deserialize($objDJ->action);
foreach ($arrActionRows as $arrAction)
{
$objQuery = $this->Database->prepare("SELECT * FROM ".$objDJ->source_table." WHERE ".$strWhereQuery)->execute();
while ($objQuery->next())
{
$strUpdate='';
$strSourceColumn = $objDJ->source_column;
switch ($arrAction['action_type'])
{
case 'prepend' : $strUpdate = sprintf("%s%s",$arrAction['replacement'],$objQuery->$strSourceColumn);
break;
case 'postpend' : $strUpdate = sprintf("%s%s",$objQuery->$strSourceColumn,$arrAction['replacement']);
break;
case 'rewriteTo' : $strUpdate = sprintf("%s",$arrAction['replacement']);
break;
case 'purge' : $strUpdate = '';
break;
}
if ($strUpdate!='')
{
$objUpdate = $this->Database->prepare("UPDATE ".$objDJ->source_table." SET ".$arrAction['dest_column']."=? WHERE id=?")->execute($strUpdate,$objQuery->id);
}
}
}
}
}
}
}
}