Skip to content

Commit a64461a

Browse files
committed
[NEW] Update domains table on record create/update/delete
[FIX] PM_DISABLE_SYSLOG renamed to DISABLE_SYSLOG [FIX] minor bug fixes
1 parent 5a13111 commit a64461a

19 files changed

+219
-114
lines changed

class/Admin.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(PassManDb $db)
6363
public function fetchNumRecords(string $table)
6464
{
6565

66-
if (empty(PM_DISABLE_SYSLOG)) {
66+
if (empty(DISABLE_SYSLOG)) {
6767
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
6868
}
6969

@@ -90,7 +90,7 @@ public function fetchNumRecords(string $table)
9090
public function lastXrecords(array $columns, string $table, int $limit = 0)
9191
{
9292

93-
if (empty(PM_DISABLE_SYSLOG)) {
93+
if (empty(DISABLE_SYSLOG)) {
9494
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
9595
}
9696

@@ -115,7 +115,7 @@ public function lastXrecords(array $columns, string $table, int $limit = 0)
115115
*/
116116
public function topXbyRecords(string $table, int $limit = 0)
117117
{
118-
if (empty(PM_DISABLE_SYSLOG)) {
118+
if (empty(DISABLE_SYSLOG)) {
119119
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
120120
}
121121

@@ -165,7 +165,7 @@ public function fetchAll(
165165
int $offset = 0
166166
) {
167167

168-
if (empty(PM_DISABLE_SYSLOG)) {
168+
if (empty(DISABLE_SYSLOG)) {
169169
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
170170
}
171171

@@ -202,7 +202,7 @@ public function fetchAll(
202202
public function update(array $fields, string $table, int $id)
203203
{
204204

205-
if (empty(PM_DISABLE_SYSLOG)) {
205+
if (empty(DISABLE_SYSLOG)) {
206206
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
207207
}
208208

@@ -231,15 +231,15 @@ public function update(array $fields, string $table, int $id)
231231

232232
try {
233233
$query->execute();
234-
if (empty(PM_DISABLE_SYSLOG)) {
234+
if (empty(DISABLE_SYSLOG)) {
235235
pm_syslog(get_class($this) . ':: record with id=' . $id . ' from ' . $table . 'was updated', PM_LOG_INFO);
236236
}
237237
$this->db->db->commit();
238238

239239
return 1;
240240
} catch (PDOException $e) {
241241
$this->db->db->rollBack();
242-
if (empty(PM_DISABLE_SYSLOG)) {
242+
if (empty(DISABLE_SYSLOG)) {
243243
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $e->getMessage(), PM_LOG_ERR);
244244
}
245245

class/Domains.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(PassManDb $db)
107107
public function create()
108108
{
109109

110-
if (empty(PM_DISABLE_SYSLOG)) {
110+
if (empty(DISABLE_SYSLOG)) {
111111
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
112112
}
113113
$array = [];
@@ -137,7 +137,7 @@ public function create()
137137
public function update(array $fields)
138138
{
139139

140-
if (empty(PM_DISABLE_SYSLOG)) {
140+
if (empty(DISABLE_SYSLOG)) {
141141
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
142142
}
143143
$array_to_update = [];
@@ -163,7 +163,7 @@ public function update(array $fields)
163163
public function delete()
164164
{
165165

166-
if (empty(PM_DISABLE_SYSLOG)) {
166+
if (empty(DISABLE_SYSLOG)) {
167167
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
168168
}
169169
$res = $this->db->fetchAll([], $this->child_table_element, ['fk_domain' => $this->id], '');
@@ -206,7 +206,7 @@ public function fetchAll(
206206
int $offset = 0
207207
) {
208208

209-
if (empty(PM_DISABLE_SYSLOG)) {
209+
if (empty(DISABLE_SYSLOG)) {
210210
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
211211
}
212212

@@ -256,7 +256,7 @@ public function fetch(
256256
int $offset = 0
257257
) {
258258

259-
if (empty(PM_DISABLE_SYSLOG)) {
259+
if (empty(DISABLE_SYSLOG)) {
260260
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
261261
}
262262

class/PassManDb.php

+22-21
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function __construct(string $host = '', string $user = '', string $pass =
131131
$this->connected = false;
132132
$this->ok = false;
133133
$this->error = $langs->trans('ErrorWrongHostParameter');
134-
if (empty(PM_DISABLE_SYSLOG)) {
134+
if (empty(DISABLE_SYSLOG)) {
135135
pm_syslog(get_class($this) . ': Connect error, wrong host parameters', PM_LOG_ERR);
136136
}
137137

@@ -149,7 +149,7 @@ public function __construct(string $host = '', string $user = '', string $pass =
149149
$this->error = $this->db->errorCode();
150150
}
151151

152-
if (empty(PM_DISABLE_SYSLOG)) {
152+
if (empty(DISABLE_SYSLOG)) {
153153
pm_syslog(get_class($this) . ': Connect error: ' . $this->error, PM_LOG_ERR);
154154
}
155155

@@ -179,7 +179,7 @@ public function __construct(string $host = '', string $user = '', string $pass =
179179
} elseif (isset($this->db) && $this->db->errorCode()) {
180180
$this->error = $this->db->errorCode();
181181
}
182-
if (empty(PM_DISABLE_SYSLOG)) {
182+
if (empty(DISABLE_SYSLOG)) {
183183
pm_syslog(get_class($this) . ': Select_db error ' . $this->error, PM_LOG_ERR);
184184
}
185185

@@ -209,7 +209,7 @@ public function connect(string $host, string $login, string $passwd, string $nam
209209
return $this->db;
210210
} catch (PDOException $e) {
211211
$this->error = 'Connection failed: ' . $e->getMessage();
212-
if (empty(PM_DISABLE_SYSLOG)) {
212+
if (empty(DISABLE_SYSLOG)) {
213213
pm_syslog('ERROR: ' . $this->error . ' for method ' . __METHOD__ . ' in class ' . get_class($this), PM_LOG_ERR);
214214
}
215215
}
@@ -232,7 +232,7 @@ public function connect(string $host, string $login, string $passwd, string $nam
232232
public function selectDb(string $host, string $login, string $passwd, string $name, string $charset, string $collation, int $port = 0)
233233
{
234234

235-
if (empty(PM_DISABLE_SYSLOG)) {
235+
if (empty(DISABLE_SYSLOG)) {
236236
pm_syslog(get_class($this) . '::select_db database=' . $name, PM_LOG_INFO);
237237
}
238238

@@ -243,7 +243,7 @@ public function selectDb(string $host, string $login, string $passwd, string $na
243243
return $this->db;
244244
} catch (PDOException $e) {
245245
$this->error = 'Connection failed: ' . $e->getMessage();
246-
if (empty(PM_DISABLE_SYSLOG)) {
246+
if (empty(DISABLE_SYSLOG)) {
247247
pm_syslog('ERROR: ' . $this->error . ' for method construct in class ' . get_class($this), PM_LOG_ERR);
248248
}
249249

@@ -274,7 +274,7 @@ public function create(array $array_of_fields, string $table_element)
274274
}
275275
$sql = preg_replace('/,\s*$/', '', $sql);
276276
$sql .= ')';
277-
if (empty(PM_DISABLE_SYSLOG)) {
277+
if (empty(DISABLE_SYSLOG)) {
278278
pm_syslog('query:: sql = ' . $sql, PM_LOG_DEBUG);
279279
}
280280
$query = $this->db->prepare($sql);
@@ -288,16 +288,17 @@ public function create(array $array_of_fields, string $table_element)
288288

289289
try {
290290
$result = $query->execute();
291+
$last_id = $this->db->lastInsertId();
291292
if ($result) {
292-
if (empty(PM_DISABLE_SYSLOG)) {
293+
if (empty(DISABLE_SYSLOG)) {
293294
pm_syslog(get_class($this) . ':: record with id=' . $this->db->lastInsertId() . ' inserted into ' . $table_element, PM_LOG_INFO);
294295
}
295296
$this->db->commit();
296297

297-
return 1;
298+
return $last_id;
298299
} else {
299300
$this->db->rollBack();
300-
if (empty(PM_DISABLE_SYSLOG)) {
301+
if (empty(DISABLE_SYSLOG)) {
301302
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
302303
}
303304

@@ -306,7 +307,7 @@ public function create(array $array_of_fields, string $table_element)
306307
} catch (PDOException $e) {
307308
$this->db->rollBack();
308309
$this->error = $e->getMessage();
309-
if (empty(PM_DISABLE_SYSLOG)) {
310+
if (empty(DISABLE_SYSLOG)) {
310311
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
311312
}
312313

@@ -333,7 +334,7 @@ public function update(array $filter, string $table_element, int $record_id)
333334
}
334335
$sql = preg_replace('/,\s*$/', '', $sql);
335336
$sql .= ' WHERE rowid = :id';
336-
if (empty(PM_DISABLE_SYSLOG)) {
337+
if (empty(DISABLE_SYSLOG)) {
337338
pm_syslog('query:: sql = ' . $sql, PM_LOG_DEBUG);
338339
}
339340
$query = $this->db->prepare($sql);
@@ -349,7 +350,7 @@ public function update(array $filter, string $table_element, int $record_id)
349350

350351
try {
351352
$query->execute();
352-
if (empty(PM_DISABLE_SYSLOG)) {
353+
if (empty(DISABLE_SYSLOG)) {
353354
pm_syslog(get_class($this) . ':: record with id=' . $this->db->lastInsertId() . ' from ' . $table_element . 'was updated', PM_LOG_INFO);
354355
}
355356
$this->db->commit();
@@ -358,7 +359,7 @@ public function update(array $filter, string $table_element, int $record_id)
358359
} catch (PDOException $e) {
359360
$this->db->rollBack();
360361
$this->error = $e->getMessage();
361-
if (empty(PM_DISABLE_SYSLOG)) {
362+
if (empty(DISABLE_SYSLOG)) {
362363
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
363364
}
364365

@@ -379,7 +380,7 @@ public function delete(string $table_element, int $record_id)
379380
{
380381

381382
$sql = 'DELETE FROM ' . PM_MAIN_DB_PREFIX . $table_element . ' WHERE rowid = :id';
382-
if (empty(PM_DISABLE_SYSLOG)) {
383+
if (empty(DISABLE_SYSLOG)) {
383384
pm_syslog('query:: sql = ' . $sql, PM_LOG_DEBUG);
384385
}
385386
$query = $this->db->prepare($sql);
@@ -390,7 +391,7 @@ public function delete(string $table_element, int $record_id)
390391

391392
try {
392393
$query->execute();
393-
if (empty(PM_DISABLE_SYSLOG)) {
394+
if (empty(DISABLE_SYSLOG)) {
394395
pm_syslog(get_class($this) . ':: record with id=' . $this->db->lastInsertId() . ' from ' . $table_element . 'was deleted', PM_LOG_INFO);
395396
}
396397
$this->db->commit();
@@ -399,7 +400,7 @@ public function delete(string $table_element, int $record_id)
399400
} catch (PDOException $e) {
400401
$this->db->rollBack();
401402
$this->error = $e->getMessage();
402-
if (empty(PM_DISABLE_SYSLOG)) {
403+
if (empty(DISABLE_SYSLOG)) {
403404
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
404405
}
405406

@@ -486,7 +487,7 @@ public function fetchAll(array $array_of_fields, string $table_element, $filter
486487
$sql .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
487488
}
488489

489-
if (empty(PM_DISABLE_SYSLOG)) {
490+
if (empty(DISABLE_SYSLOG)) {
490491
pm_syslog('query:: sql = ' . $sql, PM_LOG_DEBUG);
491492
}
492493
$query = $this->db->prepare($sql);
@@ -517,7 +518,7 @@ public function fetchAll(array $array_of_fields, string $table_element, $filter
517518
} catch (PDOException $e) {
518519
$this->db->rollBack();
519520
$this->error = $e->getMessage();
520-
if (empty(PM_DISABLE_SYSLOG)) {
521+
if (empty(DISABLE_SYSLOG)) {
521522
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
522523
}
523524

@@ -598,7 +599,7 @@ public function fetch($id = '', array $array_of_fields, string $table_element, $
598599
$sql .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
599600
}
600601

601-
if (empty(PM_DISABLE_SYSLOG)) {
602+
if (empty(DISABLE_SYSLOG)) {
602603
pm_syslog('query:: sql = ' . $sql, PM_LOG_DEBUG);
603604
}
604605
$query = $this->db->prepare($sql);
@@ -631,7 +632,7 @@ public function fetch($id = '', array $array_of_fields, string $table_element, $
631632
} catch (PDOException $e) {
632633
$this->db->rollBack();
633634
$this->error = $e->getMessage();
634-
if (empty(PM_DISABLE_SYSLOG)) {
635+
if (empty(DISABLE_SYSLOG)) {
635636
pm_syslog(get_class($this) . ':: ' . __METHOD__ . ' error: ' . $this->error, PM_LOG_ERR);
636637
}
637638

class/Records.php

+32-12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class Records
5050
* @var int
5151
*/
5252
public int $type;
53+
/**
54+
* @var int
55+
*/
56+
public int $old_type;
5357
/**
5458
* @var string
5559
*/
@@ -119,7 +123,7 @@ public function __construct(PassManDb $db)
119123
public function create()
120124
{
121125

122-
if (empty(PM_DISABLE_SYSLOG)) {
126+
if (empty(DISABLE_SYSLOG)) {
123127
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
124128
}
125129
$array = [];
@@ -132,9 +136,14 @@ public function create()
132136
$result = $this->db->create($array, $this->table_element);
133137

134138
if ($result > 0) {
135-
return 1;
139+
$res = $this->trigger->runTrigger('RECORD_INSERT', $this);
140+
if ($res > 0) {
141+
return 1;
142+
} else {
143+
return -1;
144+
}
136145
} else {
137-
return -1;
146+
return -2;
138147
}
139148
}
140149

@@ -147,7 +156,7 @@ public function create()
147156
public function update()
148157
{
149158

150-
if (empty(PM_DISABLE_SYSLOG)) {
159+
if (empty(DISABLE_SYSLOG)) {
151160
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
152161
}
153162
$array_to_update = [];
@@ -160,7 +169,12 @@ public function update()
160169
$result = $this->db->update($array_to_update, $this->table_element, $this->id);
161170

162171
if ($result > 0) {
163-
return 1;
172+
$res = $this->trigger->runTrigger('RECORD_UPDATE', $this);
173+
if ($res > 0) {
174+
return 1;
175+
} else {
176+
return -1;
177+
}
164178
} else {
165179
return -1;
166180
}
@@ -175,15 +189,21 @@ public function update()
175189
public function delete()
176190
{
177191

178-
if (empty(PM_DISABLE_SYSLOG)) {
192+
if (empty(DISABLE_SYSLOG)) {
179193
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
180194
}
181-
$result = $this->db->delete($this->table_element, $this->id);
182195

183-
if ($result > 0) {
184-
return 1;
196+
$res = $this->trigger->runTrigger('RECORD_DELETE', $this);
197+
198+
if ($res >= 0) {
199+
$result = $this->db->delete($this->table_element, $this->id);
200+
if ($result > 0) {
201+
return 1;
202+
} else {
203+
return -1;
204+
}
185205
} else {
186-
return -1;
206+
return -2;
187207
}
188208
}
189209

@@ -205,7 +225,7 @@ public function delete()
205225
public function fetchAll($filter = '', string $filter_mode = 'AND', string $sortfield = '', string $sortorder = '', string $group = '', int $limit = 0, int $offset = 0)
206226
{
207227

208-
if (empty(PM_DISABLE_SYSLOG)) {
228+
if (empty(DISABLE_SYSLOG)) {
209229
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
210230
}
211231

@@ -252,7 +272,7 @@ public function fetchAll($filter = '', string $filter_mode = 'AND', string $sort
252272
public function fetch($id, string $filter = '', string $filter_mode = 'AND', string $sortfield = '', string $sortorder = '', string $group = '', int $limit = 0, int $offset = 0)
253273
{
254274

255-
if (empty(PM_DISABLE_SYSLOG)) {
275+
if (empty(DISABLE_SYSLOG)) {
256276
pm_syslog(__METHOD__ . ' called from ' . get_class($this), PM_LOG_INFO);
257277
}
258278

0 commit comments

Comments
 (0)