forked from phpManufaktur/syncData
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.syncdata.php
More file actions
707 lines (644 loc) · 25.6 KB
/
class.syncdata.php
File metadata and controls
707 lines (644 loc) · 25.6 KB
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
/**
* @module syncData
* @version see info.php of this module
* @authors Ralf Hertsch (†), cms-lab
* @copyright 2011 - 2012 Ralf Hertsch (†)
* @copyright 2013-2014 cms-lab
* @license GNU GPL (http://www.gnu.org/licenses/gpl.html)
* @license terms see info.php of this module
*
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('LEPTON_PATH')) {
include(LEPTON_PATH.'/framework/class.secure.php');
} else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root.'/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root.'/framework/class.secure.php')) {
include($root.'/framework/class.secure.php');
} else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
// load dbConnect_LE from include directory
require_once LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/include/dbconnect_le/include.php';
class dbSyncDataCfg extends dbConnectLE {
const field_id = 'cfg_id';
const field_name = 'cfg_name';
const field_type = 'cfg_type';
const field_value = 'cfg_value';
const field_label = 'cfg_label';
const field_description = 'cfg_desc';
const field_status = 'cfg_status';
const field_update_by = 'cfg_update_by';
const field_update_when = 'cfg_update_when';
const status_active = 1;
const status_deleted = 0;
const type_undefined = 0;
const type_array = 7;
const type_boolean = 1;
const type_email = 2;
const type_float = 3;
const type_integer = 4;
const type_list = 9;
const type_path = 5;
const type_string = 6;
const type_url = 8;
public $type_array = array(
self::type_undefined => '-UNDEFINED-',
self::type_array => 'ARRAY',
self::type_boolean => 'BOOLEAN',
self::type_email => 'E-MAIL',
self::type_float => 'FLOAT',
self::type_integer => 'INTEGER',
self::type_list => 'LIST',
self::type_path => 'PATH',
self::type_string => 'STRING',
self::type_url => 'URL'
);
private $createTables = false;
private $message = '';
const cfgIgnoreDirectories = 'cfgIgnoreDirectories';
const cfgMaxExecutionTime = 'cfgMaxExecutionTime';
const cfgLimitExecutionTime = 'cfgLimitExecutionTime';
const cfgMemoryLimit = 'cfgMemoryLimit';
const cfgIgnoreTables = 'cfgIgnoreTables';
const cfgIgnoreFileExtensions = 'cfgIgnoreFileExtensions';
const cfgFileMTimeDiffAllowed = 'cfgFileMTimeDiffAllowed';
const cfgAutoExecMSec = 'cfgAutoExecMSec';
const cfgServerActive = 'cfgServerActive';
const cfgServerArchiveID = 'cfgServerArchiveID';
const cfgServerURL = 'cfgServerURL';
public $config_array = array(
array('sync_label_cfg_max_execution_time', self::cfgMaxExecutionTime, self::type_integer, '30', 'sync_desc_cfg_max_execution_time'),
array('sync_label_cfg_ignore_directories', self::cfgIgnoreDirectories, self::type_list, '/temp/,/modules/dwoo/dwoo-1.1.1/dwoo/cache/,/modules/dwoo/dwoo-1.1.1/dwoo/compiled/,/modules/sync_data/,/media/sync_data/', 'sync_desc_cfg_ignore_directories'),
array('sync_label_cfg_memory_limit', self::cfgMemoryLimit, self::type_string, '256M', 'sync_desc_cfg_memory_limit'),
array('sync_label_cfg_limit_execution_time', self::cfgLimitExecutionTime, self::type_integer, '25', 'sync_desc_cfg_limit_execution_time'),
array('sync_label_cfg_ignore_tables', self::cfgIgnoreTables, self::type_list, 'mod_sync_data_archives,mod_sync_data_config,mod_sync_data_cronjob_data,mod_sync_data_files,mod_sync_data_jobs,mod_sync_data_protocol,users', 'sync_desc_cfg_ignore_tables'),
array('sync_label_cfg_ignore_file_extensions', self::cfgIgnoreFileExtensions, self::type_array, 'buildpath,project,tmp', 'sync_desc_cfg_ignore_file_extensions'),
array('sync_label_cfg_filemtime_diff_allowed', self::cfgFileMTimeDiffAllowed, self::type_integer, '1', 'sync_desc_cfg_filemtime_diff_allowed'),
array('sync_label_cfg_auto_exec_msec', self::cfgAutoExecMSec, self::type_integer, '5000', 'sync_desc_cfg_auto_exec_msec'),
array('sync_label_cfg_server_active', self::cfgServerActive, self::type_boolean, '0', 'sync_desc_cfg_server_active'),
array('sync_label_cfg_server_archive_id', self::cfgServerArchiveID, self::type_string, '', 'sync_desc_cfg_server_archive_id'),
array('sync_label_cfg_server_url', self::cfgServerURL, self::type_string, '', 'sync_desc_cfg_server_url')
);
public function __construct($createTables = false) {
$this->createTables = $createTables;
parent::__construct();
$this->setTableName('mod_sync_data_config');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_name, "VARCHAR(32) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_type, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::type_undefined."'");
$this->addFieldDefinition(self::field_value, "TEXT NOT NULL DEFAULT ''", false, false, true);
$this->addFieldDefinition(self::field_label, "VARCHAR(64) NOT NULL DEFAULT 'sync_str_undefined'");
$this->addFieldDefinition(self::field_description, "VARCHAR(255) NOT NULL DEFAULT 'sync_str_undefined'");
$this->addFieldDefinition(self::field_status, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::status_active."'");
$this->addFieldDefinition(self::field_update_by, "VARCHAR(32) NOT NULL DEFAULT 'SYSTEM'");
$this->addFieldDefinition(self::field_update_when, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->setIndexFields(array(self::field_name));
$this->setAllowedHTMLtags('<a><abbr><acronym><span>');
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
// Default Werte garantieren
if ($this->sqlTableExists()) {
$this->checkConfig();
}
date_default_timezone_set(sync_cfg_time_zone);
} // __construct()
public function setMessage($message) {
$this->message = $message;
} // setMessage()
/**
* Get Message from $this->message;
*
* @return STR $this->message
*/
public function getMessage() {
return $this->message;
} // getMessage()
/**
* Check if $this->message is empty
*
* @return BOOL
*/
public function isMessage() {
return (bool) !empty($this->message);
} // isMessage
/**
* Aktualisiert den Wert $new_value des Datensatz $name
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*
*/
public function setValueByName($new_value, $name) {
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_cfg_name, $name)));
return false;
}
return $this->setValue($new_value, $config[0][self::field_id]);
} // setValueByName()
/**
* Haengt einen Slash an das Ende des uebergebenen Strings
* wenn das letzte Zeichen noch kein Slash ist
*
* @param STR $path
* @return STR
*/
public function addSlash($path) {
$path = substr($path, strlen($path)-1, 1) == "/" ? $path : $path."/";
return $path;
}
/**
* Wandelt einen String in einen Float Wert um.
* Geht davon aus, dass Dezimalzahlen mit ',' und nicht mit '.'
* eingegeben wurden.
*
* @param STR $string
* @return FLOAT
*/
public function str2float($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$float = floatval($string);
return $float;
}
public function str2int($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$int = intval($string);
return $int;
}
/**
* Ueberprueft die uebergebene E-Mail Adresse auf logische Gueltigkeit
*
* @param STR $email
* @return BOOL
*/
public function validateEMail($email) {
// PHP 5.3 compatibility - eregi is deprecated
if(preg_match("/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/i", $email)) {
return true; }
else {
return false; }
}
/**
* Aktualisiert den Wert $new_value des Datensatz $id
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*/
public function setValue($new_value, $id) {
$value = '';
$where = array();
$where[self::field_id] = $id;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_cfg_id, $id)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
// Funktion geht davon aus, dass $value als STR uebergeben wird!!!
$worker = explode(",", $new_value);
$data = array();
foreach ($worker as $item) {
$data[] = trim($item);
};
$value = implode(",", $data);
break;
case self::type_boolean:
$value = (bool) $new_value;
$value = (int) $value;
break;
case self::type_email:
if ($this->validateEMail($new_value)) {
$value = trim($new_value);
}
else {
$this->setMessage(sprintf(sync_msg_invalid_email, $new_value));
return false;
}
break;
case self::type_float:
$value = $this->str2float($new_value);
break;
case self::type_integer:
$value = $this->str2int($new_value);
break;
case self::type_url:
case self::type_path:
$value = $this->addSlash(trim($new_value));
break;
case self::type_string:
$value = (string) trim($new_value);
// Hochkommas demaskieren
$value = str_replace('"', '"', $value);
break;
case self::type_list:
$lines = nl2br($new_value);
$lines = explode('<br />', $lines);
$val = array();
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line)) $val[] = $line;
}
$value = implode(",", $val);
break;
endswitch;
unset($config[self::field_id]);
$config[self::field_value] = (string) $value;
$config[self::field_update_by] = 'SYSTEM';
$config[self::field_update_when] = date('Y-m-d H:i:s');
if (!$this->sqlUpdateRecord($config, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
return true;
} // setValue()
/**
* Gibt den angeforderten Wert zurueck
*
* @param $name - Bezeichner
*
* @return WERT entsprechend des TYP
*/
public function getValue($name) {
$result = '';
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_cfg_name, $name)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
$result = explode(",", $config[self::field_value]);
break;
case self::type_boolean:
$result = (bool) $config[self::field_value];
break;
case self::type_email:
case self::type_path:
case self::type_string:
case self::type_url:
$result = (string) utf8_decode($config[self::field_value]);
break;
case self::type_float:
$result = (float) $config[self::field_value];
break;
case self::type_integer:
$result = (integer) $config[self::field_value];
break;
case self::type_list:
$result = str_replace(",", "\n", $config[self::field_value]);
break;
default:
echo $config[self::field_value];
$result = utf8_decode($config[self::field_value]);
break;
endswitch;
return $result;
} // getValue()
public function checkConfig() {
foreach ($this->config_array as $item) {
$where = array();
$where[self::field_name] = $item[1];
$check = array();
if (!$this->sqlSelectRecord($where, $check)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($check) < 1) {
// Eintrag existiert nicht
$data = array();
$data[self::field_label] = $item[0];
$data[self::field_name] = $item[1];
$data[self::field_type] = $item[2];
$data[self::field_value] = $item[3];
$data[self::field_description] = $item[4];
$data[self::field_update_when] = date('Y-m-d H:i:s');
$data[self::field_update_by] = 'SYSTEM';
if (!$this->sqlInsertRecord($data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
}
}
return true;
}
} // class dbSyncDataCfg
class dbSyncDataJobs extends dbConnectLE {
const field_id = 'job_id';
const field_start = 'job_start';
const field_end = 'job_end';
const field_total_time = 'job_total_time'; // Sekunden, FLOAT
const field_type = 'job_type';
const field_status = 'job_status';
const field_errors = 'job_errors';
const field_last_error = 'job_last_error';
const field_last_message = 'job_last_message';
const field_next_action = 'job_next_action';
const field_next_file = 'job_next_file';
const field_archive_id = 'job_archive_id';
const field_archive_number = 'job_archive_number';
const field_archive_file = 'job_archive_file';
const field_restore_mode = 'job_restore_mode';
const field_replace_LEPTON_URL = 'job_replace_LEPTON_URL';
const field_replace_table_prefix = 'job_replace_table_prefix';
const field_ignore_htaccess = 'job_ignore_htaccess';
const field_ignore_config = 'job_ignore_config';
const field_delete_tables = 'job_delete_tables';
const field_delete_files = 'job_delete_files';
const field_timestamp = 'job_timestamp';
const type_undefined = 1;
const type_backup_complete = 2;
const type_backup_mysql = 4;
const type_backup_files = 8;
const type_restore_complete = 16;
const type_restore_mysql = 32;
const type_restore_files = 64;
const mode_replace_all = 1;
const mode_changed_date_size = 2;
const mode_changed_binary = 4;
public $job_type_array = array(
self::type_backup_complete => sync_type_complete,
self::type_backup_mysql => sync_type_mysql,
self::type_backup_files => sync_type_files,
);
const status_undefined = 1;
const status_start = 2;
const status_running = 4;
const status_aborted = 8;
const status_finished = 16;
const status_time_out = 32;
const next_action_none = 1;
const next_action_mysql = 2;
const next_action_file = 4;
private $createTables = false;
public function __construct($createTables = false) {
$this->createTables = $createTables;
parent::__construct();
$this->setTableName('mod_sync_data_jobs');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_start, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->addFieldDefinition(self::field_end, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->addFieldDefinition(self::field_total_time, "FLOAT NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_type, "INT(11) NOT NULL DEFAULT '".self::type_undefined."'");
$this->addFieldDefinition(self::field_status, "INT(11) NOT NULL DEFAULT '".self::status_undefined."'");
$this->addFieldDefinition(self::field_errors, "INT(11) NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_last_error, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_last_message, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_id, "VARCHAR(40) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_number, "INT(11) NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_next_action, "TINYINT NOT NULL DEFAULT '".self::next_action_none."'");
$this->addFieldDefinition(self::field_next_file, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_file, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_restore_mode, "TINYINT NOT NULL DEFAULT '".self::mode_changed_date_size."'");
$this->addFieldDefinition(self::field_replace_table_prefix, "TINYINT NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_replace_LEPTON_URL, "TINYINT NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_ignore_config, "TINYINT NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_ignore_htaccess, "TINYINT NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_delete_files, "TINYINT NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_delete_tables, "TINYINT NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_timestamp, "TIMESTAMP");
$this->setIndexFields(array(self::field_type, self::field_status, self::field_archive_id));
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
date_default_timezone_set(sync_cfg_time_zone);
} // __construct()
} // class dbSyncDataJob
class dbSyncDataArchives extends dbConnectLE {
const field_id = 'id';
const field_archive_id = 'archive_id';
const field_archive_number = 'archive_number';
const field_archive_date = 'archive_date';
const field_archive_name = 'archive_name';
const field_archive_type = 'archive_type';
const field_backup_type = 'backup_type';
const field_status = 'status';
const field_timestamp = 'timestamp';
const archive_type_backup = 1;
const archive_type_update = 2;
const backup_type_complete = 1;
const backup_type_mysql = 2;
const backup_type_files = 4;
public $backup_type_array = array(
array('key' => self::backup_type_complete, 'value' => sync_type_complete),
array('key' => self::backup_type_mysql, 'value' => sync_type_mysql),
array('key' => self::backup_type_files, 'value' => sync_type_files)
);
public $backup_type_array_text = array(
self::backup_type_complete => sync_type_complete,
self::backup_type_mysql => sync_type_mysql,
self::backup_type_files => sync_type_files,
);
const status_active = 1;
const status_deleted = 2;
private $createTables = false;
public function __construct($createTables = false) {
$this->createTables = $createTables;
parent::__construct();
$this->setTableName('mod_sync_data_archives');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_archive_id, "VARCHAR(40) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_number, "INT(11) NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_archive_date, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->addFieldDefinition(self::field_archive_name, "VARCHAR(255) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_type, "INT(11) NOT NULL DEFAULT '".self::archive_type_backup."'");
$this->addFieldDefinition(self::field_status, "INT(11) NOT NULL DEFAULT '".self::status_active."'");
$this->addFieldDefinition(self::field_timestamp, "TIMESTAMP");
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
date_default_timezone_set(sync_cfg_time_zone);
} // __construct()
} // class dbSyncDataArchive
class dbSyncDataFiles extends dbConnectLE {
const field_id = 'id';
const field_archive_id = 'archive_id';
const field_archive_number = 'archive_number';
const field_file_type = 'file_type';
const field_file_path = 'file_path';
const field_file_name = 'file_name';
const field_file_checksum = 'file_checksum';
const field_file_date = 'file_date';
const field_file_size = 'file_size';
const field_action = 'action';
const field_status = 'status';
const field_error_msg = 'error_message';
const field_timestamp = 'timestamp';
const file_type_mysql = 1;
const file_type_file = 2;
const file_type_unknown = 4;
const action_add = 1;
const action_replace = 2;
const action_delete = 4;
const action_ignore = 8;
const status_ok = 1;
const status_error = 2;
private $createTables = false;
public function __construct($createTables = false) {
$this->createTables = $createTables;
parent::__construct();
$this->setTableName('mod_sync_data_files');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_archive_id, "VARCHAR(40) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_number, "INT(11) NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_file_type, "INT(11) NOT NULL DEFAULT '".self::file_type_unknown."'");
$this->addFieldDefinition(self::field_file_path, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_file_name, "VARCHAR(255) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_file_checksum, "VARCHAR(40) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_file_date, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->addFieldDefinition(self::field_file_size, "INT(11) NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_action, "INT(11) NOT NULL DEFAULT '".self::action_add."'");
$this->addFieldDefinition(self::field_status, "TINYINT NOT NULL DEFAULT '".self::status_ok."'");
$this->addFieldDefinition(self::field_error_msg, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_timestamp, "TIMESTAMP");
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
date_default_timezone_set(sync_cfg_time_zone);
} // __construct()
} // class dbSyncDataFiles
class dbSyncDataProtocol extends dbConnectLE {
const field_id = 'id';
const field_archive_id = 'archive_id';
const field_archive_number = 'archive_number';
const field_job_id = 'job_id';
const field_text = 'text';
const field_file = 'file';
const field_size = 'size';
const field_action = 'action';
const field_status = 'status';
const field_timestamp = 'timestamp';
const status_ok = 1;
const status_error = 2;
const action_file_add = 16;
const action_file_compare = 128;
const action_file_delete = 8;
const action_file_ignore = 512;
const action_file_replace = 2;
const action_mysql_add = 32;
const action_mysql_delete = 4;
const action_mysql_replace = 1;
const action_mysql_ignore = 256;
const action_unknown = 64;
private $createTables = false;
/**
* Constructor
*
* @param BOOL $createTables
*/
public function __construct($createTables = false) {
$this->createTables = $createTables;
parent::__construct();
$this->setTableName('mod_sync_data_protocol');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_archive_id, "VARCHAR(40) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_archive_number, "INT(11) NOT NULL DEFAULT '1'");
$this->addFieldDefinition(self::field_job_id, "INT(11) NOT NULL DEFAULT '-1'");
$this->addFieldDefinition(self::field_text, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_file, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_size, "INT(11) NOT NULL DEFAULT '-1'");
$this->addFieldDefinition(self::field_action, "INT(11) NOT NULL DEFAULT '".self::action_unknown."'");
$this->addFieldDefinition(self::field_status, "TINYINT NOT NULL DEFAULT '".self::status_ok."'");
$this->addFieldDefinition(self::field_timestamp, "TIMESTAMP");
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
date_default_timezone_set(sync_cfg_time_zone);
} // __construct()
/**
* Add a new entry into the protocol
*
* @param VARCHAR $archive_id
* @param INT $archive_number
* @param INT $job_id
* @param VARCHAR $text
* @param VARCHAR $file
* @param INT $size
* @param INT $action
* @param INT $status
* @return BOOL
*/
public function addEntry($archive_id, $archive_number, $job_id, $text, $file, $size, $action, $status) {
$data = array(
self::field_archive_id => $archive_id,
self::field_archive_number => $archive_number,
self::field_job_id => $job_id,
self::field_text => $text,
self::field_file => $file,
self::field_size => $size,
self::field_action => $action,
self::field_status => $status
);
if (!$this->sqlInsertRecord($data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
return true;
} // addEntry()
} // class dbSyncDataProtocol
?>