Esempio n. 1
0
 function load_settings()
 {
     global $Now;
     // load settings from database
     $this->settings = array();
     $this->settingTexts = array();
     foreach ($this->opt_override ?: [] as $k => $v) {
         if ($v === null) {
             unset($this->opt[$k]);
         } else {
             $this->opt[$k] = $v;
         }
     }
     $this->opt_override = [];
     $this->_pc_seeall_cache = null;
     $this->deadlineCache = null;
     $result = $this->q_raw("select name, value, data from Settings");
     while ($result && ($row = $result->fetch_row())) {
         $this->settings[$row[0]] = (int) $row[1];
         if ($row[2] !== null) {
             $this->settingTexts[$row[0]] = $row[2];
         }
         if (substr($row[0], 0, 4) == "opt.") {
             $okey = substr($row[0], 4);
             $this->opt_override[$okey] = get($this->opt, $okey);
             $this->opt[$okey] = $row[2] === null ? (int) $row[1] : $row[2];
         }
     }
     Dbl::free($result);
     // update schema
     $this->sversion = $this->settings["allowPaperOption"];
     if ($this->sversion < 108) {
         require_once "updateschema.php";
         $old_nerrors = Dbl::$nerrors;
         updateSchema($this);
         Dbl::$nerrors = $old_nerrors;
     }
     // invalidate all caches after loading from backup
     if (isset($this->settings["frombackup"]) && $this->invalidate_caches()) {
         $this->qe_raw("delete from Settings where name='frombackup' and value=" . $this->settings["frombackup"]);
         unset($this->settings["frombackup"]);
     } else {
         $this->invalidate_caches(["rf" => true]);
     }
     // update options
     if (isset($this->opt["ldapLogin"]) && !$this->opt["ldapLogin"]) {
         unset($this->opt["ldapLogin"]);
     }
     if (isset($this->opt["httpAuthLogin"]) && !$this->opt["httpAuthLogin"]) {
         unset($this->opt["httpAuthLogin"]);
     }
     // set conferenceKey
     if (!isset($this->opt["conferenceKey"])) {
         if (!isset($this->settingTexts["conf_key"]) && ($key = hotcrp_random_bytes(32)) !== false) {
             $this->save_setting("conf_key", 1, $key);
         }
         $this->opt["conferenceKey"] = get($this->settingTexts, "conf_key", "");
     }
     // set capability key
     if (!get($this->settings, "cap_key") && !get($this->opt, "disableCapabilities") && !(($key = hotcrp_random_bytes(16)) !== false && ($key = base64_encode($key)) && $this->save_setting("cap_key", 1, $key))) {
         $this->opt["disableCapabilities"] = true;
     }
     // GC old capabilities
     if (defval($this->settings, "__capability_gc", 0) < $Now - 86400) {
         foreach (array($this->dblink, Contact::contactdb()) as $db) {
             if ($db) {
                 Dbl::ql($db, "delete from Capability where timeExpires>0 and timeExpires<{$Now}");
             }
         }
         $this->q_raw("insert into Settings (name, value) values ('__capability_gc', {$Now}) on duplicate key update value=values(value)");
         $this->settings["__capability_gc"] = $Now;
     }
     $this->crosscheck_settings();
     $this->crosscheck_options();
 }