-
Notifications
You must be signed in to change notification settings - Fork 30
/
ImpExSession.php
459 lines (413 loc) · 10.5 KB
/
ImpExSession.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<?php
/*======================================================================*\
|| ####################################################################
|| # vBulletin Impex
|| # ----------------------------------------------------------------
|| # All PHP code in this file is Copyright 2000-2014 vBulletin Solutions Inc.
|| # This code is made available under the Modified BSD License -- see license.txt
|| # http://www.vbulletin.com
|| ####################################################################
\*======================================================================*/
/**
* Core session module that holds the state of the system.
*
* Holds lots of groovy session data, yum yum yum.
*
* @package ImpEx
*
*/
if (!defined('IDIR')) { die; }
class ImpExSession
{
/**
* Class version
*
* This will allow the checking for interoprability of class version in diffrent
* versions of ImpEx
*
* @var string
*/
var $_version = "0.0.1";
/**
* The main data array for the storage of session variables
*
* All the session variables are stored in here
*
*
* @var array
*/
var $_session_vars = array
(
'version' => '0.0.1',
'system' => 'NONE',
'begun' => 'FALSE',
'warning' => 'FALSE',
'finished' => 'FALSE',
'modulelist' => 'FALSE'
);
/**
* The title text
*
* The title text for the modules of the currently running importer
*
*
* @var array
*/
var $_moduletitles = array();
var $_target_db;
/**
* The Session errors
*
* The errors are held in a 2D array, each entry holds : 'timestamp','type','module','errorstring','remedy'
*
*
* @var array
*/
var $_session_errors = array();
/**
* Constructor
*
* Empty
*
*/
function ImpExSession()
{
}
/**
* Lists all the modules in a system/XXXX/ folder and gets their title texts and adds the module
* number and sets it to FALSE
*
* @return none
*/
function build_module_list(&$displayobject)
{
if ($this->get_session_var('modulelist') == 'FALSE')
{
$dir = IDIR . '/systems/' . $this->get_session_var('system');
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($filename = readdir($dh)) !== false)
{
if (substr($filename, -strlen('.php')) == '.php' AND $filename{0} != '.' AND $filename != 'index.html' AND is_numeric(substr($filename, 0, 3)))
{
$sourcefile = '';
$sourcefile = $dir .'/'. $filename;
require_once($sourcefile);
$classname = $this->get_session_var('system') . '_'. substr($filename, 0 , 3);
$module = new $classname($displayobject);
$this->add_session_var(substr($filename, 0 , 3), 'FALSE');
$this->add_module_title(substr($filename, 0 , 3), $module->_modulestring);
unset($sourcefile);
}
}
closedir($dh);
}
}
// Add the default clean up ones
$this->add_session_var('cleanup_module_title', 'FALSE');
$this->add_module_title("901", $displayobject->phrases['cleanup_module_title']);
$this->add_session_var('feedback_module_title', 'FALSE');
$this->add_module_title("910", $displayobject->phrases['feedback_module_title']);
$this->set_session_var('modulelist', 'TRUE');
}
}
/**
* Adds an error to the error stack
*
* @param object mixed database connection object to use
* @param string mixed The type of error : 'invalid' | 'fatal' | 'warning'
* @param int mixed The class/module number where the error came from
* @param string mixed The error
* @param string mixed The suggested remedy
*
* @return none
*/
# old function
#function add_error($post['post_id'], $displayobject->phrases['post_not_imported'], $displayobject->phrases['post_not_imported_rem']);
function add_error($Db_target, $type, $classnumber, $importid = 0, $error = 'old', $remedy = 'false')
{
if(!is_object($Db_target))
{
// It's the legacy function call
return true;
}
if (impexdebug)
{
if (!is_numeric($importid))
{
return false;
}
$type = addslashes($type);
$error = addslashes($error);
$remedy = addslashes($remedy);
$Db_target->query("
INSERT INTO ". $this->_session_vars['targettableprefix'] ."impexerror
(
errortype,
classnumber,
importid,
error,
remedy
)
VALUES
(
'{$type}',
'{$classnumber}',
" . intval($importid) . ",
'{$error}',
'{$remedy}'
)"
);
}
}
/**
* Accessor : Returns a modules title text
*
* @param int mixed The 3 digit number refrence to the object
*
* @return none
*/
function get_module_string($position)
{
return $this->_moduletitles[$position];
}
/**
* Returns a count of the number of modules in a system
*
* @return int
*/
function get_number_of_modules()
{
return count($this->_moduletitles);
}
/**
* Accessor : Returns a session variable
*
* @param int mixed The 3 digit number refrence to the object
*
* @return mixed|boolean
*/
function get_session_var($name)
{
return stripslashes($this->_session_vars[$name]);
}
/**
* Returns a string of the errors
*
* @param string mixed Returns the errors : 'getdetails' | 'fatal' | 'warning' | 'alert' | 'notice' | 'all'
*
* @return string
*/
function display_errors($type)
{
$i = 0;
$return_string = '';
foreach ($this->_session_errors as $value)
{
if ($type == 'all' OR strtolower($type) == $value['type'])
{
$return_string .= '<br /><b>Timestamp</b> : ' . date("H:i:s",$value['timestamp']) . '. <b>Type</b> : ' . $value['type'] . '. <b>Module</b> : ' . $value['module'] . ' .<br /><u>Errorstring</u><br />' . $value['errorstring'] . '. <br /><u>Remedy</u><br />' . $value['remedy'] . '<br />';
$i++;
}
}
return "<h4>Error count of : $type = $i</h4>" . $return_string;
}
/**
* Accessor : Sets a session variable
*
* @param string mixed The name of the session variable
* @param mixed mixed The value to set the variable to
*
* @return boolean
*/
function set_session_var($name, $value)
{
if ($this->_session_vars[$name] == NULL)
{
return false;
}
else
{
$value = addslashes($value);
$this->_session_vars[$name] = $value;
return true;
}
}
/**
* Accessor : Adds a session variable, if the variable exsists it sets it
*
* @see set_session_var
*
* @param string mixed The name of the session variable
* @param mixed mixed The value to set the variable to
*
* @return boolean
*/
function add_session_var($key, $value)
{
if (empty($this->_session_vars[$key]))
{
$value = addslashes($value);
$tempArray = array($key => $value);
$this->_session_vars = array_merge($this->_session_vars, $tempArray);
return true;
}
else
{
return $this->set_session_var($key, $value);
}
}
/**
* Accessor : Adds a module title, if the variable exsists it sets it if it dosen't exsist it creates it
*
*
* @param string mixed The 3 digit number of the module
* @param mixed mixed The value to set the module title to
*
* @return boolean
*/
function add_module_title($key, $value)
{
$this->_moduletitles[$key] = $value;
}
/**
* Accessor : Returns a modules title
*
*
* @param string mixed The 3 digit number of the module
*
* @return boolean
*/
function get_module_title($name)
{
return $this->_moduletitles[$name];
}
/**
* Accessor : Returns the number of the current working module, or FALSE
*
* @return boolean|mixed
*/
function any_working()
{
if ($this->_session_vars[001] == 'FAILED')
{
// The tables didn't match, probally table prefix ....
return false;
}
for ($i = 0; $i <= $this->get_number_of_modules(); ++$i)
{
$position = str_pad($i, 3, '0', STR_PAD_LEFT);
if ($this->_session_vars[$position] == 'WORKING')
{
return $position;
}
}
return false;
}
/**
* Remvoes a session varaible from the array
*
* @param string var_name The vararaible to remove
*
* @return boolean
*/
function remove_session_var($name)
{
unset($this->_session_vars[$name]);
return $this->get_session_var($name);
}
/**
* Starts and stops a timer to roughly measure an import (only really works with auto commit on)
*
* @param string modulestring The name of the module calling the function
* @param string mixed Start or Stop
* @param boolean Checks wheter auto commit is on or not
*
* @return mixed string|NULL
*/
function timing($modulestring,$action,$isauto)
{
if ($action == 'start')
{
return $this->add_session_var($modulestring . '_' . $action, time());
}
else if ($action == 'stop')
{
$this->add_session_var($modulestring . '_' . $action, time());
$this->add_session_var($modulestring . '_auto', $isauto);
$taken = intval($this->get_session_var($modulestring . '_stop')) -
intval($this->get_session_var($modulestring . '_start'));
if ($taken == 0)
{
$taken = 1;
}
return $this->add_session_var($modulestring . '_time_taken', $taken);
}
else
{
return false;
}
}
/**
* Returns the module timings as a 3 element array : '_start', '_stop', '_time_taken'
*
* @param string modulestring The name of the module calling the function
* @param boolean false OR the name of one of the elements to retrive
*
* @return array start time stamp, end time stamp, seconds taken
*/
function return_stats($modulestring, $just_one = false)
{
if($just_one)
{
return intval($this->get_session_var($modulestring . $just_one));
}
return array (
'_start' => intval($this->get_session_var($modulestring . '_start')),
'_stop' => intval($this->get_session_var($modulestring . '_stop')),
'_time_taken' => intval($this->get_session_var($modulestring . '_time_taken')),
'_objects_done' => intval($this->get_session_var($modulestring . '_objects_done')),
'_objects_failed' => intval($this->get_session_var($modulestring . '_objects_failed'))
);
}
/**
* If a module complete in under 1 second it sets it to 0.
*
* @param string mixed The module being checked
*
* @return mixed string|NULL
*/
function end_timing($modulestring)
{
if($this->get_session_var($modulestring . '_time_taken') == '0')
{
$this->set_session_var($modulestring . '_time_taken', '1');
}
}
function get_users_to_associate()
{
$return_array = array();
foreach($this->_session_vars as $key => $value)
{
if (substr($key, 0, 12) == 'user_to_ass_' && $value != '')
{
array_push($return_array, array($key => $value));
}
}
return $return_array;
}
function delete_users_to_associate()
{
foreach($this->_session_vars as $key => $value)
{
if (substr($key, 0, 12) == 'user_to_ass_')
{
$this->remove_session_var($key);
}
}
}
}
/*======================================================================*/
?>