Db File saving, fix settings class with explicit writes
This commit is contained in:
parent
d4bd456cbc
commit
80091147a1
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
class Settings {
|
class Settings {
|
||||||
|
|
||||||
protected $current;
|
private $current;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the settings file
|
* Load the settings file
|
||||||
@ -49,16 +49,6 @@ class Settings {
|
|||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the settings file on close, just to be safe
|
|
||||||
*/
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
file_put_contents(BASE_DIR.'/settings.json', json_encode($this->current));
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Magic method to simplify isset checking for config options
|
* Magic method to simplify isset checking for config options
|
||||||
*
|
*
|
||||||
@ -67,7 +57,9 @@ class Settings {
|
|||||||
*/
|
*/
|
||||||
public function __get($key)
|
public function __get($key)
|
||||||
{
|
{
|
||||||
return (isset($this->current->{$key})) ? $this->current->{$key} : NULL;
|
return (isset($this->current->{$key}) && $key != "dbs")
|
||||||
|
? $this->current->{$key}
|
||||||
|
: NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -87,6 +79,7 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->current->{$key} = $val;
|
$this->current->{$key} = $val;
|
||||||
|
$this->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -103,6 +96,29 @@ class Settings {
|
|||||||
{
|
{
|
||||||
$this->current->dbs->{$name} = array();
|
$this->current->dbs->{$name} = array();
|
||||||
$this->current->dbs->{$name} = $params;
|
$this->current->dbs->{$name} = $params;
|
||||||
|
|
||||||
|
$this->write();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit a database connection
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $params
|
||||||
|
*/
|
||||||
|
public function edit_db($name, $params)
|
||||||
|
{
|
||||||
|
if(isset($this->current->dbs->{$name}))
|
||||||
|
{
|
||||||
|
$this->current->dbs->{$name} = $params;
|
||||||
|
$this->write();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -126,6 +142,7 @@ class Settings {
|
|||||||
|
|
||||||
// Remove the db name from the object
|
// Remove the db name from the object
|
||||||
unset($this->current->dbs->{$name});
|
unset($this->current->dbs->{$name});
|
||||||
|
$this->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -139,5 +156,15 @@ class Settings {
|
|||||||
{
|
{
|
||||||
return $this->current->dbs;
|
return $this->current->dbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the settings to the file
|
||||||
|
*/
|
||||||
|
public function write()
|
||||||
|
{
|
||||||
|
file_put_contents(BASE_DIR . '/settings.json', json_encode($this->current));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// End of settings.php
|
// End of settings.php
|
@ -254,6 +254,7 @@ SQL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a prepared statement query
|
* Run a prepared statement query
|
||||||
|
*
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*
|
*
|
||||||
* PDO-firebird isn't stable, so this is a wrapper of the ibase_ public functions.
|
* PDO-firebird isn't stable, so this is a wrapper of the ibase_ public functions.
|
||||||
*/
|
*/
|
||||||
class firebird_manip extends db_manip{
|
class firebird_manip extends db_manip {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convienience public function to generate sql for creating a db table
|
* Convienience public function to generate sql for creating a db table
|
||||||
|
@ -77,13 +77,13 @@ class Add_DB extends GtkWindow {
|
|||||||
// DB File
|
// DB File
|
||||||
{
|
{
|
||||||
$filelbl = new GtkLabel("Database file");
|
$filelbl = new GtkLabel("Database file");
|
||||||
$this->dbfile = new GtkFileChooserButton("Select a database file",
|
$this->db_file = new GtkFileChooserButton("Select a database file",
|
||||||
Gtk::FILE_CHOOSER_ACTION_OPEN);
|
Gtk::FILE_CHOOSER_ACTION_OPEN);
|
||||||
$filealign = new GtkAlignment(0, 0.5, 0, 0);
|
$filealign = new GtkAlignment(0, 0.5, 0, 0);
|
||||||
$filealign->add($filelbl);
|
$filealign->add($filelbl);
|
||||||
|
|
||||||
$table->attach($filealign, 0, 1, ++$y1, ++$y2);
|
$table->attach($filealign, 0, 1, ++$y1, ++$y2);
|
||||||
$table->attach($this->dbfile, 1, 2, $y1, $y2);
|
$table->attach($this->db_file, 1, 2, $y1, $y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host
|
// Host
|
||||||
@ -185,10 +185,11 @@ class Add_DB extends GtkWindow {
|
|||||||
public function db_add()
|
public function db_add()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
'type' => $this->dbtype->get_active_text(),
|
'type' => strtolower($this->dbtype->get_active_text()),
|
||||||
'host' => $this->host->get_text(),
|
'host' => $this->host->get_text(),
|
||||||
'user' => $this->user->get_text(),
|
'user' => $this->user->get_text(),
|
||||||
'pass' => $this->pass->get_text(),
|
'pass' => $this->pass->get_text(),
|
||||||
|
'file' => $this->db_file->get_uri(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->settings->add_db($this->conn->get_text(), $data);
|
$this->settings->add_db($this->conn->get_text(), $data);
|
||||||
|
Reference in New Issue
Block a user