#!/usr/bin/env php query('SELECT 1 FROM plugin_mobilize_feeds'); // reached this point => table found, assume db is complete } catch (PDOException $e) { echo 'Database table for mobilize plugin not found, applying schema... ' . PHP_EOL; $schema = file_get_contents('plugins/mobilize/ttrss-plugin-mobilize.pgsql'); $schema = preg_replace('/--(.*?);/', '', $schema); $schema = preg_replace('/[\r\n]/', ' ', $schema); $schema = trim($schema, ' ;'); foreach (explode(';', $schema) as $stm) { $pdo->exec($stm); } unset($pdo); } $contents = file_get_contents($confpath); foreach ($config as $name => $value) { $contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents); } file_put_contents($confpath, $contents);