mirror of
https://github.com/xevidos/codiad.git
synced 2024-11-10 21:26:35 +01:00
Added database update step in update process.
This commit is contained in:
parent
0912a19eb1
commit
1dd97f2e53
@ -5,11 +5,14 @@
|
|||||||
//error_reporting(E_ALL);
|
//error_reporting(E_ALL);
|
||||||
|
|
||||||
require_once('../../common.php');
|
require_once('../../common.php');
|
||||||
|
require_once('../settings/class.settings.php');
|
||||||
require_once('./class.update.php');
|
require_once('./class.update.php');
|
||||||
|
|
||||||
$user_settings_file = DATA . "/settings.php";
|
|
||||||
$projects_file = DATA . "/projects.php";
|
|
||||||
$users_file = DATA . "/users.php";
|
$user_settings_file = BASE_PATH . "/data/settings.php";
|
||||||
|
$projects_file = BASE_PATH . "/data/projects.php";
|
||||||
|
$users_file = BASE_PATH . "/data/users.php";
|
||||||
//checkSession();
|
//checkSession();
|
||||||
if ( ! checkAccess() ) {
|
if ( ! checkAccess() ) {
|
||||||
echo "Error, you do not have access to update Codiad.";
|
echo "Error, you do not have access to update Codiad.";
|
||||||
@ -102,8 +105,6 @@ class updater {
|
|||||||
mkdir( $backup, 00755 );
|
mkdir( $backup, 00755 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function copy_backup( $source, $dest ) {
|
function copy_backup( $source, $dest ) {
|
||||||
|
|
||||||
// Check for symlinks
|
// Check for symlinks
|
||||||
@ -173,8 +174,6 @@ class updater {
|
|||||||
|
|
||||||
function check_sql() {
|
function check_sql() {
|
||||||
|
|
||||||
require_once('../../common.php');
|
|
||||||
require_once('../sql/class.sql.php');
|
|
||||||
$sql = new sql();
|
$sql = new sql();
|
||||||
$connection = $sql->connect();
|
$connection = $sql->connect();
|
||||||
$result = $sql->create_default_tables();
|
$result = $sql->create_default_tables();
|
||||||
@ -211,9 +210,6 @@ class updater {
|
|||||||
|
|
||||||
function convert() {
|
function convert() {
|
||||||
|
|
||||||
require_once('../sql/class.sql.php');
|
|
||||||
require_once('../settings/class.settings.php');
|
|
||||||
|
|
||||||
$user_settings_file = DATA . "/settings.php";
|
$user_settings_file = DATA . "/settings.php";
|
||||||
$projects_file = DATA . "/projects.php";
|
$projects_file = DATA . "/projects.php";
|
||||||
$users_file = DATA . "/users.php";
|
$users_file = DATA . "/users.php";
|
||||||
@ -235,6 +231,9 @@ class updater {
|
|||||||
if( file_exists( $projects_file ) ) {
|
if( file_exists( $projects_file ) ) {
|
||||||
|
|
||||||
$projects = getJSON( 'projects.php' );
|
$projects = getJSON( 'projects.php' );
|
||||||
|
|
||||||
|
if( is_array( $projects ) ) {
|
||||||
|
|
||||||
foreach( $projects as $project => $data ) {
|
foreach( $projects as $project => $data ) {
|
||||||
|
|
||||||
$owner = 'nobody';
|
$owner = 'nobody';
|
||||||
@ -246,7 +245,8 @@ class updater {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
$this->restore();
|
$this->restore();
|
||||||
exit(formatJSEND( "error", "There was an error adding projects to database." ));
|
exit( formatJSEND( "error", "There was an error adding projects to database." ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlink( $projects_file );
|
unlink( $projects_file );
|
||||||
@ -255,6 +255,9 @@ class updater {
|
|||||||
if( file_exists( $users_file ) ) {
|
if( file_exists( $users_file ) ) {
|
||||||
|
|
||||||
$users = getJSON( 'users.php' );
|
$users = getJSON( 'users.php' );
|
||||||
|
|
||||||
|
if( is_array( $users ) ) {
|
||||||
|
|
||||||
foreach( $users as $user ) {
|
foreach( $users as $user ) {
|
||||||
|
|
||||||
if( $user["username"] === $_SESSION["user"] ) {
|
if( $user["username"] === $_SESSION["user"] ) {
|
||||||
@ -279,6 +282,7 @@ class updater {
|
|||||||
exit(formatJSEND( "error", "The Username is Already Taken" ));
|
exit(formatJSEND( "error", "The Username is Already Taken" ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
unlink( $users_file );
|
unlink( $users_file );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -415,10 +419,10 @@ class updater {
|
|||||||
|
|
||||||
function remove_directory( $path ) {
|
function remove_directory( $path ) {
|
||||||
|
|
||||||
$files = glob($path . '/*');
|
$files = glob( $path . '{,.}[!.,!..]*', GLOB_MARK|GLOB_BRACE );
|
||||||
foreach ($files as $file) {
|
foreach( $files as $file ) {
|
||||||
|
|
||||||
is_dir($file) ? $this->remove_directory($file) : unlink($file);
|
is_dir( $file ) ? $this->remove_directory( $file ) : unlink( $file );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( is_dir( $path ) ) {
|
if( is_dir( $path ) ) {
|
||||||
@ -524,8 +528,6 @@ class updater {
|
|||||||
|
|
||||||
$this->copyr( $src, $dest );
|
$this->copyr( $src, $dest );
|
||||||
$this->remove_directory( $src );
|
$this->remove_directory( $src );
|
||||||
$this->convert();
|
|
||||||
$this->check_sql();
|
|
||||||
return( "true" );
|
return( "true" );
|
||||||
} catch( Exception $e ) {
|
} catch( Exception $e ) {
|
||||||
|
|
||||||
@ -534,6 +536,21 @@ class updater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update_database() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$this->convert();
|
||||||
|
} catch( Exception $e ) {
|
||||||
|
|
||||||
|
//$this->restore();
|
||||||
|
return( $e );
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->check_sql();
|
||||||
|
return( "true" );
|
||||||
|
}
|
||||||
|
|
||||||
public function update_option( $option, $value, $user_setting = null ) {
|
public function update_option( $option, $value, $user_setting = null ) {
|
||||||
|
|
||||||
$sql = new sql();
|
$sql = new sql();
|
||||||
@ -619,6 +636,11 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
|
|
||||||
echo $updater->update();
|
echo $updater->update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case( "update_database" ):
|
||||||
|
|
||||||
|
echo $updater->update_database();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
@ -711,6 +733,35 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
apply_database: function() {
|
||||||
|
|
||||||
|
return jQuery.ajax({
|
||||||
|
|
||||||
|
url: "update.php",
|
||||||
|
type: "GET",
|
||||||
|
dataType: 'html',
|
||||||
|
data: {
|
||||||
|
action: 'update_database',
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function( result ) {
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function( jqXHR, textStatus, errorThrown ) {
|
||||||
|
|
||||||
|
console.log( 'jqXHR:' );
|
||||||
|
console.log( jqXHR );
|
||||||
|
console.log( 'textStatus:' );
|
||||||
|
console.log( textStatus);
|
||||||
|
console.log( 'errorThrown:' );
|
||||||
|
console.log( errorThrown );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
check_update: function() {
|
check_update: function() {
|
||||||
|
|
||||||
this.progress.innerText = "Checking for update ... ";
|
this.progress.innerText = "Checking for update ... ";
|
||||||
@ -809,6 +860,28 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
|
|
||||||
update: async function() {
|
update: async function() {
|
||||||
|
|
||||||
|
let GET = {};
|
||||||
|
let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function( m, key, value) {
|
||||||
|
|
||||||
|
GET[key] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
if( Object.keys( GET ).includes( "step" ) && GET.step === "database_update" ) {
|
||||||
|
|
||||||
|
progress.innerText = "Applying database update.";
|
||||||
|
let apply = await this.apply_database();
|
||||||
|
|
||||||
|
if( apply !== "true" ) {
|
||||||
|
|
||||||
|
console.log( apply );
|
||||||
|
progress.innerText = "Error applying update.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.innerText = "Successfully completed update. You may now return to Codiad.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let result = await this.check_update();
|
let result = await this.check_update();
|
||||||
|
|
||||||
console.log( result );
|
console.log( result );
|
||||||
@ -834,7 +907,7 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.innerText = "Applying update.";
|
progress.innerText = "Applying filesystem update.";
|
||||||
let apply = await this.apply();
|
let apply = await this.apply();
|
||||||
|
|
||||||
if( apply !== "true" ) {
|
if( apply !== "true" ) {
|
||||||
@ -844,7 +917,12 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.innerText = "Update Finished.";
|
progress.innerText = "Filesystem update finished. Please wait, your browser will now reload and start the datbase update.";
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
|
||||||
|
window.location.href = window.location.href + "?step=database_update"
|
||||||
|
}, 5000);
|
||||||
} else if( result === "false" ) {
|
} else if( result === "false" ) {
|
||||||
|
|
||||||
progress.innerText = "No update was found ...";
|
progress.innerText = "No update was found ...";
|
||||||
@ -856,6 +934,28 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
|
|
||||||
update_development: async function() {
|
update_development: async function() {
|
||||||
|
|
||||||
|
let GET = {};
|
||||||
|
let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function( m, key, value) {
|
||||||
|
|
||||||
|
GET[key] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
if( Object.keys( GET ).includes( "step" ) && GET.step === "database_update" ) {
|
||||||
|
|
||||||
|
progress.innerText = "Applying database update.";
|
||||||
|
let apply = await this.apply_database();
|
||||||
|
|
||||||
|
if( apply !== "true" ) {
|
||||||
|
|
||||||
|
console.log( apply );
|
||||||
|
progress.innerText = "Error applying update.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.innerText = "Successfully completed update. You may now return to Codiad.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
progress.innerText = "An update was found. Downloading update.";
|
progress.innerText = "An update was found. Downloading update.";
|
||||||
let download = await this.download( true );
|
let download = await this.download( true );
|
||||||
|
|
||||||
@ -876,7 +976,7 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.innerText = "Applying update.";
|
progress.innerText = "Applying filesystem update.";
|
||||||
let apply = await this.apply();
|
let apply = await this.apply();
|
||||||
|
|
||||||
if( apply !== "true" ) {
|
if( apply !== "true" ) {
|
||||||
@ -886,7 +986,12 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.innerText = "Update Finished.";
|
progress.innerText = "Filesystem update finished. Please wait, your browser will now reload and start the datbase update.";
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
|
||||||
|
window.location.href = window.location.href + "?step=database_update"
|
||||||
|
}, 5000);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user