Permalink
Browse files

added nusystemupdate

  • Loading branch information...
steven-copley
steven-copley committed Oct 4, 2017
1 parent b8320cf commit 9374e93c6b8edd3d9621a7a27f6b071a8e11a10b
Showing with 361 additions and 456 deletions.
  1. +30 −0 nuajax.js
  2. +4 −2 nuapi.php
  3. +25 −3 nucommon.php
  4. +0 −212 nudata.php
  5. +0 −238 nuevalphpclass.php
  6. +0 −1 nurunphp.php
  7. +24 −0 nurunsystemupdate.php
  8. +278 −0 nusystemupdate.php
@@ -178,6 +178,7 @@ function nuGetPHP(f, r){
}
function nuRunPHP(pCode, iframe){
if(window.nuBeforeSave){
@@ -249,6 +250,35 @@ function nuRunPHPHidden(i, h){
}
function nuSystemUpdate(){
var last = nuFORM.addBreadcrumb();
last.session_id = nuSESSION;
last.call_type = 'systemupdate';
last.form_id = 'systemupdate';
last.nuFORMdata = nuFORM.data();
last.hash = nuHashFromEditForm();
var successCallback = function(data,textStatus,jqXHR){
var fm = data;
if(!nuDisplayError(fm)){
var pdfUrl = 'nurunsystemupdate.php?i=' + fm.id;
window.open(pdfUrl);
}
};
nuAjax(last,successCallback);
}
function nuAttachImage(i, c){
@@ -6,6 +6,7 @@
require_once('nuform.php');
require_once('nudata.php');
require_once('nudrag.php');
require_once('nusystemupdate.php');
$_POST['nuCounter'] = rand(0, 999);
$_POST['nuErrors'] = array();
@@ -46,12 +47,13 @@
if($CT == 'runhtml') {$f->forms[0]->id = nuRunHTML();}
if($CT == 'update') {$f->forms[0]->record_id = nuUpdateDatabase();}
if($CT == 'nudragsave') {$f->forms[0] = nuDragSave($P);}
if($CT == 'systemupdate') {$f->forms[0]->id = nuRunSystemUpdate();}
}
$f->forms[0]->user_id = $U['USER_ID'];
$f->forms[0]->dimensions = $formAndSessionData->dimensions;
$f->forms[0]->tableSchema = nuUpdateTableSchema();//$formAndSessionData->tableSchema;
$f->forms[0]->tableSchema = nuUpdateTableSchema();
$f->forms[0]->formSchema = $formAndSessionData->formSchema;
$f->forms[0]->translation = $formAndSessionData->translation;
$f->forms[0]->session_id = $_SESSION['SESSION_ID'];
@@ -4,8 +4,6 @@
require_once('nuconfig.php');
require_once('nubuilders.php');
//require_once('nuexception.php');
//require_once('nuevalphpclass.php');
require_once dirname(__FILE__) . '/nusqlclass.php';
require_once dirname(__FILE__) . '/nusearchclass.php';
require_once('nudatabase.php');
@@ -369,6 +367,7 @@ function nuRunReport($report_id){
$_POST['nuHash']['description'] = $ob->sre_description;
$_POST['nuHash']['sre_layout'] = nuReplaceHashVariables($ob->sre_layout);
$_POST['nuHash']['parentID'] = $ob->sre_zzzzsys_php_id;
$_POST['nuHash']['nuInstall'] = '0';
$j = json_encode($_POST['nuHash']);
nuSetJSONData($id, $j);
@@ -378,6 +377,28 @@ function nuRunReport($report_id){
}
function nuInstall(){
$id = nuID();
$s = "SELECT * FROM zzzzsys_php WHERE sph_code = '$procedure_code'";
$t = nuRunQuery($s);
$ob = db_fetch_object($t);
$_POST['nuHash']['code'] = $ob->sph_code;
$_POST['nuHash']['description'] = $ob->sph_description;
$_POST['nuHash']['parentID'] = $ob->zzzzsys_php_id;
$_POST['nuHash']['nuInstall'] = '1';
$j = json_encode($_POST['nuHash']);
nuSetJSONData($id, $j);
return $id;
}
function nuRunPHP($procedure_code){
$id = nuID();
@@ -396,13 +417,14 @@ function nuRunPHP($procedure_code){
return $id;
}
function nuRunPHPHidden($nuCode){
$s = "SELECT * FROM zzzzsys_php WHERE sph_code = ? ";
$t = nuRunQuery($s, [$nuCode]);
$r = db_fetch_object($t);
// $evalPHP = new nuEvalPHPClass($r->zzzzsys_php_id);
nuEval($r->zzzzsys_php_id);
$f = new stdClass;
@@ -593,216 +593,4 @@ function nuGetFile(){
}
function nuSystemList(){
$t = [];
$t[] = 'zzzzsys_access';
$t[] = 'zzzzsys_access_form';
$t[] = 'zzzzsys_access_php';
$t[] = 'zzzzsys_access_report';
$t[] = 'zzzzsys_browse';
$t[] = 'zzzzsys_debug';
$t[] = 'zzzzsys_event';
$t[] = 'zzzzsys_file';
$t[] = 'zzzzsys_form';
$t[] = 'zzzzsys_format';
$t[] = 'zzzzsys_object';
$t[] = 'zzzzsys_phinxlog';
$t[] = 'zzzzsys_php';
$t[] = 'zzzzsys_report';
$t[] = 'zzzzsys_select';
$t[] = 'zzzzsys_select_clause';
$t[] = 'zzzzsys_session';
$t[] = 'zzzzsys_setup';
$t[] = 'zzzzsys_tab';
$t[] = 'zzzzsys_table';
$t[] = 'zzzzsys_timezone';
$t[] = 'zzzzsys_translate';
$t[] = 'zzzzsys_user';
return $t;
}
function nuRenameSystemFiles(){
$t = nuSystemList();
for($i = 0 ; $i < count($t) ; $i++){
print "$table<br>";
$table = $t[$i];
nuRunQuery("DROP TABLE IF EXISTS sys_$table");
nuRunQuery("CREATE TABLE sys_$table SELECT * FROM $table");
nuRunQuery("DROP TABLE IF EXISTS $table");
}
nuRunQuery("DROP VIEW IF EXISTS zzzzsys_report_data");
nuRunQuery("DROP VIEW IF EXISTS zzzzsys_run_list");
print 'Done!';
}
function nuUpdateSystemRecords(){ //-- after zzzzsys files have been imported
nuAddNewSystemTables();
$ts = nuBuildTableSchema();
$t = nuListSystemTables();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
$new = $ts["$table"]['names'];
$old = $ts["sys_$table"]['names'];
for($c = 0 ; $c < count($old) ; $c++){ //-- remove unused fields from old
$field = $old[$c];
if(!in_array($field, $new)){
$sql= "ALTER TABLE sys_$table DROP COLUMN $field";
nuRunQuery($sql);
print "$sql<br>";
}
}
}
$ts = nuBuildTableSchema();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
$lfield = 'FIRST';
for($c = 0 ; $c < count($new) ; $c++){ //-- insert extra new fields into old
$new = $ts["$table"]['names'];
$old = $ts["sys_$table"]['names'];
$newt = $ts["$table"]['types'];
$oldt = $ts["sys_$table"]['types'];
$ofield = $old[$c];
$nfield = $new[$c];
$otype = $oldt[$c];
$ntype = $newt[$c];
if($ofield != $nfield){
$sql= "ALTER TABLE sys_$table ADD COLUMN $nfield $ntype $lfield";
nuRunQuery($sql);
print "$sql<br>";
$ts = nuBuildTableSchema();
$c = -1; //-- start from the beginning again
}else if($otype != $ntype){
$sql= "ALTER TABLE sys_$table MODIFY COLUMN $nfield $ntype";
nuRunQuery($sql);
print "$sql<br>";
}
if($ofield == ''){
$lfield = '';
}else{
$lfield = "AFTER $ofield";
}
}
}
nuRemoveSystemRecords();
nuAppendToSystemTables();
print 'Done!';
}
function nuAddNewSystemTables(){
$ts = nuBuildTableSchema();
foreach ($ts as $k => $v) {
if(substr($k,0,8) == 'zzzzsys_'){
$v = $ts["sys_$k"]['valid'];
if($v == ''){
nuRunQuery("CREATE TABLE sys_$k SELECT * FROM $k");
}
}
}
}
function nuRemoveSystemRecords(){
$s = "DELETE FROM sys_zzzzsys_form WHERE zzzzsys_form_id NOT LIKE 'nu%' "; //-- KEEP FORM with ids that start with 'nu'
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_tab WHERE syt_zzzzsys_form_id NOT IN (SELECT zzzzsys_form_id FROM sys_zzzzsys_form)"; //-- KEEP TABs from FORMs with ids that start with 'nu'
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_object WHERE sob_all_zzzzsys_tab_id NOT IN (SELECT zzzzsys_tab_id FROM sys_zzzzsys_tab)"; //-- KEEP OBJECTs from TABs where FORMs with ids that start with 'nu'
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_php WHERE sph_zzzzsys_form_id NOT LIKE 'nu%' AND sph_zzzzsys_form_id NOT IN (SELECT zzzzsys_object_id FROM sys_zzzzsys_object)"; //-- KEEP PHP with ids that start with 'nu' or match the above OBJECT list.
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_php WHERE sph_zzzzsys_form_id NOT LIKE 'nu%' AND sph_zzzzsys_form_id NOT IN (SELECT zzzzsys_object_id FROM sys_zzzzsys_object)"; //-- ADD PHP_LIBRARY records to PHP that links to ids that start with 'nu'.
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_browse WHERE sbr_zzzzsys_form_id NOT IN (SELECT zzzzsys_form_id FROM sys_zzzzsys_form)"; //-- KEEP BROWSEs from FORMs with ids that start with 'nu'
nuRunQuery($s);
$s = "DELETE FROM sys_zzzzsys_event WHERE sev_zzzzsys_object_id NOT IN (SELECT zzzzsys_object_id FROM sys_zzzzsys_object)"; //-- KEEP EVENTs, from OBJECTs, from FORMs with ids that start with 'nu'
nuRunQuery($s);
print 'Done!';
}
function nuAppendToSystemTables(){
$t = nuSystemList();
for($i = 0 ; $i < count($t) ; $i++){
$table = $t[$i];
nuRunQuery("INSERT INTO $table SELECT * FROM sys_$table");
}
print 'Appended to system tables!<br>';
}
?>
Oops, something went wrong.

0 comments on commit 9374e93

Please sign in to comment.