-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrupalTableObj.php
185 lines (151 loc) · 5.6 KB
/
drupalTableObj.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
<?php
use mondrakeNG\dbol\DbConnection;
use mondrakeNG\dbol\Dbol;
use mondrakeNG\dbol\DbolEntry;
use mondrakeNG\mm\core\MMDiag;
use mondrakeNG\mm\core\MMUtils;
class drupalTableObj {
protected static $dbol = null;
protected static $dbObj = array();
protected static $childObjs = array();
protected $diag = null;
protected $tableName;
public function __construct($table = null) {
if (self::$dbol === NULL) {
$params = array(
'decimalPrecision' => DB_DECIMALPRECISION,
'perfLogging' => DB_QUERY_PERFORMANCE_LOGGING,
'perfThreshold' => DB_QUERY_PERFORMANCE_THRESHOLD,
);
self::$dbol = new Dbol(DBOL_CONNECTION_NAME, $params);
}
$this->diag = new MMDiag;
if ($table and !isset(self::$dbObj[$table])) {
$this->tableName = $table;
self::$dbObj[$this->tableName] = new dbolEntry;
self::$dbObj[$this->tableName]->table = $table;
self::$dbObj[$this->tableName]->tableProperties['auditLogLevel'] = 0;
self::$dbObj[$this->tableName]->tableProperties['listOrder'] = null;
self::$dbObj[$this->tableName]->tableProperties['environmentDependent'] = false;
self::$dbObj[$this->tableName]->tableProperties['clientTracking'] = false;
self::$dbObj[$this->tableName]->tableProperties['readBackOnChange'] = false;
self::$dbObj[$this->tableName]->tableProperties['performanceTracking'] = false;
self::$dbObj[$this->tableName]->tableProperties['sequencing'] = false;
DbConnection::fetchAllColumnsProperties(DBOL_CONNECTION_NAME, $this->tableName, self::$dbObj[$this->tableName]);
}
}
public function getdbol() {
return self::$dbol;
}
public function getDbObj() {
return self::$dbObj[$this->tableName];
}
public function fetchAllTables() {
return self::$dbol->fetchAllTables();
}
public function setSessionContext($params) {
self::$dbol->setSessionContext($params);
}
public function getSessionContext($var = NULL) {
return self::$dbol->getSessionContext($var);
}
public function setColumnProperty($cols, $prop, $value) {
return self::$dbol->setColumnProperty(self::$dbObj[$this->tableName], $cols, $prop, $value);
}
public function getColumnProperties() {
return self::$dbol->getColumnProperties(self::$dbObj[$this->tableName]);
}
public function setPKColumns($cols) {
return self::$dbol->setPKColumns(self::$dbObj[$this->tableName], $cols);
}
public function compactPKIntoString() {
return self::$dbol->compactPKIntoString($this, self::$dbObj[$this->tableName]);
}
public function read($pk) {
//$whereClause = self::$dbol->explodePKStringIntoWhere(self::$dbObj[$this->tableName], $pk);
//return self::readSingle($whereClause);
return self::$dbol->readSinglePK($this, self::$dbObj[$this->tableName], $pk);
}
public function readSingle($whereClause) {
$ret = self::$dbol->readSingle($this, self::$dbObj[$this->tableName], $whereClause);
return $ret;
}
public function readMulti($whereClause = NULL, $orderClause = NULL, $limit = NULL, $offset = NULL) {
$ret = self::$dbol->readMulti($this, self::$dbObj[$this->tableName], $whereClause, $orderClause, $limit, $offset);
return $ret;
}
public function listAll($whereClause = NULL, $limit = NULL, $offset = NULL) {
return $this->readMulti($whereClause, self::$dbObj[$this->tableName]->tableProperties['listOrder'], $limit, $offset);
}
public function create($clientPKMap = false) {
//$sessionContext = self::$dbol->getSessionContext();
if ($this->validate() > 3) {
$table = $this->getDbObj()->table;
throw new Exception("Validation error on create - Table: $table - PK: $this->primaryKeyString");
}
$res = self::$dbol->create($this, self::$dbObj[$this->tableName]);
return $res;
}
public function createMulti($arr) {
$res = 0;
foreach ($arr as $c => $obj) {
$res += $obj->create();
}
return $res;
}
public function update() {
//$sessionContext = self::$dbol->getSessionContext();
return self::$dbol->update($this, self::$dbObj[$this->tableName]);
}
public function delete($clientPKMap = false) {
//$sessionContext = self::$dbol->getSessionContext();
$res = self::$dbol->delete($this, self::$dbObj[$this->tableName]);
return $res;
}
public function query($sqlq, $limit = NULL, $offset = NULL, $sqlId = NULL) {
return self::$dbol->query($sqlq, $limit, $offset, $sqlId);
}
public function beginTransaction() {
return self::$dbol->beginTransaction();
}
public function commit() {
return self::$dbol->commit();
}
public function executeSql($sqlq) {
return self::$dbol->executeSql($sqlq);
}
protected function validate() {
}
protected function diagLog($severity, $id, $params, $tableName = null, $throwExceptionOnError = FALSE) {
if (empty($tableName)) {
$tableName = get_class($this);
}
$this->diag->sLog($severity, $tableName, $id, $params);
if ($severity == 4) {
// prepares msg for exception
foreach ($this->diag->get(FALSE) as $a) {
$msg .= $a->time . ' - ' . $a->severity . ' - ' . $a->tableName . ' - ' . $a->id . ' - ' . $a->fullText . " \n";
}
// logs backtrace
if ($link->backtrace) {
foreach ($link->backtrace as $a => $b) {
$this->diag->sLog(4, 'backtrace', 0, array('#text' => $a . ' ' . $b['class'] . '/' . $b['function'] . ' in ' . $b['file'] . ' line ' . $b['line'],));
}
}
if ($throwExceptionOnError) {
throw new Exception($msg);
}
}
}
public function startWatch($id) {
return $this->diag->startWatch($id);
}
public function getLog() {
return $this->diag->get();
}
public function __call($name, $args)
{
throw new Exception ('Undefined method ' . get_class($this) . '.' . $name . ' called');
}
}
?>