Started updating update script, Removed unneeded Update calls, Fixed issue with selecting all user options not applying, Added error checking to creation of tables

This commit is contained in:
xevidos 2019-04-11 18:26:55 -04:00
parent 373c281111
commit c833bb72de
7 changed files with 65 additions and 156 deletions

View file

@ -347,6 +347,8 @@
let user_settings = await codiad.settings.get_options();
//console.log( user_settings );
$.each( options, function( idx, key ) {
let localValue = user_settings['codiad.' + key];
@ -853,7 +855,7 @@
}
}
//Database
codiad.settings.update_option( 'codiad.editor.theme', t );
//codiad.settings.update_option( 'codiad.editor.theme', t );
},
/////////////////////////////////////////////////////////////////
@ -895,7 +897,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.fontSize', s );
//codiad.settings.update_option( 'codiad.editor.fontSize', s );
},
@ -920,7 +922,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.highlightLine', h );
//codiad.settings.update_option( 'codiad.editor.highlightLine', h );
},
//////////////////////////////////////////////////////////////////
@ -943,7 +945,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.printMargin', p );
//codiad.settings.update_option( 'codiad.editor.printMargin', p );
},
//////////////////////////////////////////////////////////////////
@ -966,7 +968,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.printMarginColumn', p );
//codiad.settings.update_option( 'codiad.editor.printMarginColumn', p );
},
//////////////////////////////////////////////////////////////////
@ -989,7 +991,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.indentGuides', g );
//codiad.settings.update_option( 'codiad.editor.indentGuides', g );
},
//////////////////////////////////////////////////////////////////
@ -1031,7 +1033,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.wrapMode', w );
//codiad.settings.update_option( 'codiad.editor.wrapMode', w );
},
//////////////////////////////////////////////////////////////////
@ -1047,7 +1049,7 @@
setPersistentModal: function(t, i) {
this.settings.persistentModal = t;
//Database
codiad.settings.update_option( 'codiad.editor.persistentModal', t );
//codiad.settings.update_option( 'codiad.editor.persistentModal', t );
},
//////////////////////////////////////////////////////////////////
@ -1063,7 +1065,7 @@
setRightSidebarTrigger: function(t, i) {
this.settings.rightSidebarTrigger = t;
//Database
codiad.settings.update_option( 'codiad.editor.rightSidebarTrigger', t );
//codiad.settings.update_option( 'codiad.editor.rightSidebarTrigger', t );
},
//////////////////////////////////////////////////////////////////
@ -1079,7 +1081,7 @@
setFileManagerTrigger: function(t, i) {
this.settings.fileManagerTrigger = t;
//Database
codiad.settings.update_option( 'codiad.editor.fileManagerTrigger', t );
//codiad.settings.update_option( 'codiad.editor.fileManagerTrigger', t );
codiad.project.loadSide();
},
@ -1103,7 +1105,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.tabSize', s );
//codiad.settings.update_option( 'codiad.editor.tabSize', s );
},
@ -1126,7 +1128,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.softTabs', t );
//codiad.settings.update_option( 'codiad.editor.softTabs', t );
},
@ -1458,7 +1460,7 @@
//////////////////////////////////////////////////////////////////
setOverScroll: function( s, i ) {
if (i) {
i.setOption( "scrollPastEnd", s );
} else {
@ -1468,7 +1470,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.overScroll', s );
//codiad.settings.update_option( 'codiad.editor.overScroll', s );
},
setLiveAutocomplete: function( s, i ) {
@ -1486,7 +1488,7 @@
});
}
//Database
codiad.settings.update_option( 'codiad.editor.autocomplete', s );
//codiad.settings.update_option( 'codiad.editor.autocomplete', s );
},
toggleMultiLine: function( e ) {

View file

@ -207,85 +207,13 @@ define("WSURL", BASE_URL . "/workspace");
function create_tables() {
$this->sql->create_tables(
array(
"active" => array(
"fields" => array(
"username" => "string",
"path" => "text",
"focused" => "string"
),
"attributes" => array(
"username" => array( "not null", "unique" ),
"path" => array( "not null", "unique" ),
"focused" => array( "not null" ),
)
),
"options" => array(
"fields" => array(
"id" => "int",
"name" => "string",
"value" => "text",
),
"attributes" => array(
"id" => array( "id" ),
"name" => array( "not null", "unique" ),
"value" => array( "not null" ),
)
),
"projects" => array(
"fields" => array(
"id" => "int",
"name" => "string",
"path" => "text",
"owner" => "string",
"access" => "string",
),
"attributes" => array(
"id" => array( "id" ),
"name" => array( "not null" ),
"path" => array( "not null", "unique" ),
"owner" => array( "not null", "unique" ),
"access" => array(),
)
),
"users" => array(
"fields" => array(
"id" => "int",
"first_name" => "string",
"last_name" => "string",
"username" => "string",
"password" => "text",
"email" => "string",
"project" => "string",
"access" => "string",
"groups" => "string",
"token" => "string",
),
"attributes" => array(
"id" => array( "id" ),
"username" => array( "not null", "unique" ),
"password" => array( "not null" ),
"access" => array( "not null" ),
)
),
"user_options" => array(
"fields" => array(
"id" => "int",
"name" => "string",
"username" => "string",
"value" => "text",
),
"attributes" => array(
"id" => array( "id" ),
"name" => array( "not null", "unique" ),
"username" => array( "not null", "unique" ),
"value" => array( "not null" ),
)
),
)
);
$result = $this->sql->create_default_tables();
if ( ! $result === true ) {
$this->restore();
die( '{"message":"Could not tables in database.","error":"' . json_encode( $error ) .'"}' );
}
}
function create_user() {

View file

@ -173,7 +173,7 @@ class Settings {
global $sql;
$query = "SELECT name, value FROM user_options WHERE username=?;";
$bind_variables = array( $option, $this->username );
$bind_variables = array( $this->username );
$return = $sql->query( $query, $bind_variables, array() );
$options = array();
@ -184,6 +184,8 @@ class Settings {
$options = json_encode( $options );
//echo var_dump( $options, $return );
switch( $action ) {
case( "exit" ):

View file

@ -14,6 +14,7 @@
codiad.settings = {
controller: 'components/settings/controller.php',
settings: null,
init: function() {
@ -59,17 +60,25 @@
get_options: async function() {
let result;
let _self = codiad.settings;
try {
result = await $.ajax({
if( _self.settings == null ) {
url: this.controller + '?action=get_options',
type: "POST",
dataType: 'html',
data: {
},
});
result = await $.ajax({
url: this.controller + '?action=get_options',
type: "POST",
dataType: 'html',
data: {
},
});
result = JSON.parse( result );
} else {
result = _self.settings
}
return result;
} catch (error) {
@ -154,6 +163,8 @@
return false;
}
let _self = codiad.settings;
jQuery.ajax({
url: this.controller + '?action=update_option',
@ -165,7 +176,8 @@
},
success: function( data ) {
console.log( `Update Option ( ${option} ): ` + data )
console.log( `Update Option ( ${option} ): ` + data );
_self.settings = null;
},
error: function(jqXHR, textStatus, errorThrown) {

View file

@ -86,7 +86,13 @@ class sql {
$query = $this->conversions->tables( $table );
$connection = $this->connect();
$result = $connection->exec( $query );
$error = $connection->errorInfo();
//echo var_dump( $query, $result, $connection->errorInfo() ) . "<br>";
if ( $result === false || ! $error[0] == "00000" ) {
return false;
}
}
public static function escape_identifier( $i ) {

View file

@ -96,19 +96,23 @@ class updater {
}
function copy_backup( $source, $dest ) {
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
if ( is_link( $source ) ) {
return symlink( readlink( $source ), $dest );
}
// Simple copy for a file
if (is_file($source)) {
if ( is_file( $source ) ) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
if ( ! is_dir( $dest ) ) {
mkdir( $dest );
}
$invalid_files = array(
@ -122,7 +126,7 @@ class updater {
// Loop through the folder
$dir = dir( $source );
while (false !== $entry = $dir->read()) {
while ( false !== $entry = $dir->read() ) {
// Skip pointers
if( in_array( $entry, $invalid_files ) ) {
@ -197,54 +201,9 @@ class updater {
$users_file = DATA . "/users.php";
global $sql;
$connection = $sql->connect();
$result = $sql->create_default_tables();
$query = "
CREATE TABLE IF NOT EXISTS options(
id INT(11) NOT NULL,
name VARCHAR(255) NOT NULL,
value TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS projects(
id INT(11) NOT NULL,
name VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
owner VARCHAR(255) NOT NULL,
access TEXT
);
CREATE TABLE IF NOT EXISTS users(
id INT(11) NOT NULL,
first_name VARCHAR(255) DEFAULT NULL,
last_name VARCHAR(255) DEFAULT NULL,
username VARCHAR(255) NOT NULL,
password TEXT NOT NULL,
email VARCHAR(255) DEFAULT NULL,
project VARCHAR(255) DEFAULT NULL,
access VARCHAR(255) NOT NULL,
groups TEXT,
token TEXT
);
CREATE TABLE IF NOT EXISTS user_options(
id INT(11) NOT NULL,
name VARCHAR(255) NOT NULL,
username VARCHAR(255) NOT NULL,
value TEXT NOT NULL
);
ALTER TABLE options ADD PRIMARY KEY(id), ADD UNIQUE KEY option_name(name);
ALTER TABLE projects ADD PRIMARY KEY(id), ADD UNIQUE KEY project_path(path, owner);
ALTER TABLE users ADD PRIMARY KEY(id), ADD UNIQUE KEY username(username);
ALTER TABLE user_options ADD PRIMARY KEY(id), ADD UNIQUE KEY option_name(name, username);
ALTER TABLE options MODIFY id INT(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE projects MODIFY id INT(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE users MODIFY id INT(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE user_options MODIFY id INT(11) NOT NULL AUTO_INCREMENT;
DELETE FROM options;
DELETE FROM projects;
DELETE FROM users;
DELETE FROM user_options;
";
if ( $connection->exec( $query ) === false ) {
if ( $result === false ) {
$this->restore();
exit( $connection->errorInfo() );