Skip to content

Commit 09f40cb

Browse files
committed
Add a util function running_on_master() to improve code readablility
1 parent 8271e11 commit 09f40cb

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

server/lib/app.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ function error($msg) {
354354
$this->log($msg, 3); // isn't this supposed to be error code 2? (gwyneth 20220315)
355355
die($msg);
356356
}
357+
358+
/**
359+
* Determin if the current process is running on the master or a slave server.
360+
*
361+
* @return boolean
362+
*/
363+
function running_on_master() {
364+
365+
return $this->dbmaster == $this->db;
366+
}
357367
}
358368

359369
/**

server/lib/classes/cron.d/200-logfiles.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function onRunJob() {
226226
// Cleanup logs in master database (only the "master-server")
227227
//######################################################################################################
228228

229-
if ($app->dbmaster == $app->db) {
229+
if ($app->running_on_master()) {
230230
/** 7 days */
231231

232232

server/lib/classes/cron.d/300-quota_notify.inc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function onRunJob() {
7575
// enforce traffic quota (run only on the "master-server")
7676
//######################################################################################################
7777

78-
if ($app->dbmaster == $app->db) {
78+
if ($app->running_on_master()) {
7979

8080
$global_config = $app->getconf->get_global_config('mail');
8181

@@ -159,7 +159,7 @@ public function onRunJob() {
159159
// send website quota warnings by email
160160
//######################################################################################################
161161

162-
if ($app->dbmaster == $app->db) {
162+
if ($app->running_on_master()) {
163163

164164
$global_config = $app->getconf->get_global_config('mail');
165165

@@ -315,7 +315,7 @@ public function onRunJob() {
315315
// send mail quota warnings by email
316316
//######################################################################################################
317317

318-
if ($app->dbmaster == $app->db) {
318+
if ($app->running_on_master()) {
319319

320320
$global_config = $app->getconf->get_global_config('mail');
321321
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
@@ -453,7 +453,7 @@ public function onRunJob() {
453453
// send database quota warnings by email
454454
//######################################################################################################
455455

456-
if ($app->dbmaster == $app->db) {
456+
if ($app->running_on_master()) {
457457

458458
$global_config = $app->getconf->get_global_config('mail');
459459

server/lib/classes/cron.d/400-openvz.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function onRunJob() {
5454
// deactivate virtual servers (run only on the "master-server")
5555
//######################################################################################################
5656

57-
if ($app->dbmaster == $app->db) {
57+
if ($app->running_on_master()) {
5858
//* Check which virtual machines have to be deactivated
5959
$sql = "SELECT * FROM openvz_vm WHERE active = 'y' AND active_until_date IS NOT NULL AND active_until_date < CURDATE()";
6060
$records = $app->db->queryAllRecords($sql);

server/plugins-available/bind_plugin.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function soa_dnssec_sign(&$data) {
189189
}
190190
}
191191

192-
if ($app->dbmaster !== $app->db) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=\'Y\', dnssec_last_signed=? WHERE id=?', $dnssecdata, intval(time()), intval($data['new']['id']));
192+
if (!$app->running_on_master()) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=\'Y\', dnssec_last_signed=? WHERE id=?', $dnssecdata, intval(time()), intval($data['new']['id']));
193193
$app->db->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=\'Y\', dnssec_last_signed=? WHERE id=?', $dnssecdata, intval(time()), intval($data['new']['id']));
194194
}
195195

@@ -244,7 +244,7 @@ function soa_dnssec_delete(&$data) {
244244
unlink($dns_config['bind_zonefiles_dir'].'/'.$dns_config['bind_zonefiles_masterprefix'].$domain.'.signed');
245245
unlink($dns_config['bind_keyfiles_dir'].'/dsset-'.$domain.'.');
246246

247-
if ($app->dbmaster !== $app->db) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
247+
if (!$app->running_on_master()) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
248248
$app->db->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
249249
}
250250

server/plugins-available/powerdns_plugin.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ function soa_dnssec_create($data) {
546546
$dnssec_info = array_merge($this->format_dnssec_pubkeys($pubkeys), array('', '== Raw log ============================'), $log);
547547
$dnssec_info = implode("\r\n", $dnssec_info);
548548

549-
if ($app->dbmaster !== $app->db) {
549+
if (!$app->running_on_master()) {
550550
$app->dbmaster->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=? WHERE id=?', $dnssec_info, 'Y', intval($data['new']['id']));
551551
}
552552
$app->db->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=? WHERE id=?', $dnssec_info, 'Y', intval($data['new']['id']));

0 commit comments

Comments
 (0)