@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Overseer module.
5 *
6 * The primary purpose of this overseer module is to poll for configuration
7 * changes and reload daemons when the configuration changes.
8 */
9final class PhabricatorDaemonOverseerModule
10 extends PhutilDaemonOverseerModule {
11
12 private $configVersion;
13
14 public function shouldReloadDaemons() {
15 if ($this->shouldThrottle('reload', 10)) {
16 return false;
17 }
18
19 return $this->updateConfigVersion();
20 }
21
22 /**
23 * Calculate a version number for the current Phabricator configuration.
24 *
25 * The version number has no real meaning and does not provide any real
26 * indication of whether a configuration entry has been changed. The config
27 * version is intended to be a rough indicator that "something has changed",
28 * which indicates to the overseer that the daemons should be reloaded.
29 *
30 * @return int
31 */
32 private function loadConfigVersion() {
33 $conn_r = id(new PhabricatorConfigEntry())->establishConnection('r');
34 return head(queryfx_one(
35 $conn_r,
36 'SELECT MAX(id) FROM %T',
37 id(new PhabricatorConfigTransaction())->getTableName()));
38 }
39
40 /**
41 * Check and update the configuration version.
42 *
43 * @return bool True if the daemons should restart, otherwise false.
44 */
45 private function updateConfigVersion() {
46 $old_version = $this->configVersion;
47 $new_version = $this->loadConfigVersion();
48
49 $this->configVersion = $new_version;
50
51 // Don't trigger a reload if we're loading the config for the very
52 // first time.
53 if ($old_version === null) {
54 return false;
55 }
56
57 return ($old_version != $new_version);
58 }
59
60}