-
Notifications
You must be signed in to change notification settings - Fork 0
/
denuke_config.php
76 lines (63 loc) · 2.8 KB
/
denuke_config.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
<?php
class Configuration {
var $data;
function Configuration($cfg) {
if (!isset($cfg['nucleus_prefix'])) {
$cfg['nucleus_prefix'] = '';
}
$this->data = $cfg;
}
// accessors
function isFiles() { return $this->data['process_files']; }
function validate() {
try {
if (($this->data['import_to']=='content') && !isset($this->data['contenttype_name'])) {
throw new Exception('Please provide destination content type');
}
// other logic checks
// ....
// check DB connection. Both DB must be available even if we not committing result
$sql_src = new mysqli($this->data['nucleus_server'], $this->data['nucleus_user'], $this->data['nucleus_pass'], $this->data['nucleus_db']);
if (mysqli_connect_errno()) { throw new Exception('Cannot connect to source: ' . mysqli_connect_error()); }
if (!module_exists('taxonomy')) { throw new Exception('Taxonomy support is not enabled'); }
if ($this->data['import_to'] == 'content') {
$types = node_get_types();
$passed = isset($types[$this->data['contenttype_name']]);
if (!$passed) { throw new Exception('Drupal - not exist selected content type: ' . $this->data['contenttype_name']); }
}
else {
// taxonomy is the default
$this->data['import_to'] = 'taxonomy';
}
$vocabularies = taxonomy_get_vocabularies();
if ($this->data['import_to']=='taxonomy') {
$term = taxonomy_get_term($this->data['taxonomy_term_id']);
if (!$term) { throw new Exception('Drupal - taxonomy term for tagging import not exist, ID: ' . $this->data['taxonomy_term_id']); }
}
$passed = isset($vocabularies[$this->data['taxonomy_cat']]);
if (!$passed) { throw new Exception('Drupal - Vocabulary for tagging not exist, ID: ' . $this->data['taxonomy_cat']); }
if ($result = $sql_src->query("SELECT * FROM " . $this->data['nucleus_prefix'] . "blog WHERE bnumber = "
. $this->data['nucleus_blog_id'])) {
if (!$result->fetch_assoc()) {
throw new Exception('Nucleus - blog with this ID doen not exists: ' . $this->data['nucleus_blog_id']);
}
$result->close();
}
if ($this->data['process_files']) {
if (!is_dir($this->data['nucleus_base_dir'])) {
throw new Exception('Nucleus - media directory inaccessible: ' . $this->data['nucleus_base_dir']);
}
if (!is_dir($this->data['drupal_base_dir'])) {
throw new Exception('Drupal - media directory inaccessible: ' . $this->data['drupal_base_dir']);
}
}
}
catch(Exception $e) {
printf('Configuration error: ' . $e->getMessage());
return FALSE;
}
$sql_src->close();
return TRUE;
}
};
?>