<?php
/**
 * Imports a json configuration into a sqlite database.
 *
 * Usage:
 *   php bin/import_config.php /path/to/config.json /path/to/owncloud.db
 */

$configFile = $argv[1];
$databaseFile = $argv[2];

$content = file_get_contents($configFile);
$config = json_decode($content, true);

$pdo = new \Pdo(sprintf('sqlite:%s', $databaseFile));
$stmt = $pdo->prepare('UPDATE oc_appconfig SET configvalue=:value WHERE configkey=:key and appid=:appId');

foreach ($config as $key => $value) {
    $stmt->execute([
        'appId' => 'side_menu',
        'key' => $key,
        'value' => $value,
    ]);
}
