Files
Protocolbot 3386ac6542 feat: switch from MySQL to SQLite for zero-dependency deployment
- Rewrite db.php to use SQLite via PDO (no external DB server needed)
- Rewrite schema.sql for SQLite (AUTOINCREMENT, CHECK constraints,
  triggers for updated_at, ON CONFLICT instead of ON DUPLICATE KEY)
- Fix config.php upsert to use ON CONFLICT syntax
- Fix index.php: tag filter via json_each, vote upsert via ON CONFLICT,
  and fix protocol create route (was returning 405 for POST /api/protocols)
- Fix yaml.php seed import: replace invalid false callbacks with fn() => null,
  fix yaml_parse pos argument (-1 -> 0)
- Update Dockerfile: drop pdo_mysql/mysqli (pdo_sqlite is built in)
- Update CloudronManifest.json: remove mysql addon, bump to v0.3.0
- Update README for SQLite deployment
2026-07-06 14:42:45 -06:00

51 lines
1.5 KiB
PHP

<?php
/**
* Config helpers — read/write site configuration from the config table.
*/
function config_get(string $key, $default = null) {
$row = db_one("SELECT value FROM config WHERE key = ?", [$key]);
return $row ? $row['value'] : $default;
}
function config_set(string $key, string $value): void {
db_query(
"INSERT INTO config (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
[$key, $value]
);
}
function config_all(): array {
$rows = db_all("SELECT key, value FROM config");
$cfg = [];
foreach ($rows as $row) {
$cfg[$row['key']] = $row['value'];
}
return $cfg;
}
function site_config(): array {
return [
'name' => config_get('site_name', 'Protocol Droid'),
'tagline' => config_get('site_tagline', 'A commons of social protocols'),
'registration_enabled' => config_get('registration_enabled', 'true') === 'true',
'require_approval' => config_get('require_approval', 'false') === 'true',
];
}
/**
* Load a config.yaml file if present (for whitelabel customization).
* Merges with database config (database takes precedence).
*/
function load_yaml_config(): array {
$path = __DIR__ . '/../config.yaml';
if (!file_exists($path)) return [];
$yaml_text = file_get_contents($path);
return yaml_parse($yaml_text) ?: [];
}
function merged_config(): array {
$yaml_cfg = load_yaml_config();
$db_cfg = site_config();
return array_merge($yaml_cfg, $db_cfg);
}