Skip to content

Commit

Permalink
Merge pull request #10 from HeuristNetwork/fixes
Browse files Browse the repository at this point in the history
Fixes 30 Nov - 10 Dec 2016
  • Loading branch information
ijohnson222 authored Dec 10, 2016
2 parents 88e8a19 + d65031a commit 4a2c0a8
Show file tree
Hide file tree
Showing 49 changed files with 2,939 additions and 872 deletions.
4 changes: 3 additions & 1 deletion admin/adminMenuStandalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ function menuEntry($separator,$action,$actionFile,$actionLabel) {
*/

if (is_admin()) {
menuEntry('---','Clone database','setup/dboperations/cloneDatabase.php?db='.HEURIST_DBNAME,
'Clones an identical database from the currrent database with all data, users, attached files, templates etc.');
menuEntry('','Delete entire database','setup/dboperations/deleteCurrentDB.php?db='.HEURIST_DBNAME,
'Delete the current database completely - cannot be undone, although data is copied '.
'to a backup which could be reloaded by a system administrator');
Expand Down Expand Up @@ -330,9 +332,9 @@ function menuEntry($separator,$action,$actionFile,$actionLabel) {
// DATA QUALITY

/* Deprecated 27/10/16, now in main search page menus
*/
menuEntry('---','Verify structure and data consistency','verification/listDatabaseErrors.php?db='.HEURIST_DBNAME,
'Find errors in database structure (invalid record type, field and term codes) and records with wrong structure and inconsistent values (invalid pointer, missed data etc)');
*/

menuEntry('','Verify wysiwyg texts','verification/checkXHTML.php?db='.HEURIST_DBNAME.'',
'Check the wysiwyg text fields in records/blog entries for structural errors');
Expand Down
370 changes: 189 additions & 181 deletions admin/describe/dbStatistics.php

Large diffs are not rendered by default.

48 changes: 43 additions & 5 deletions admin/setup/dboperations/cloneDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<body class="popup">

<script type="text/javascript">
//
// allow only alphanum chars for database name
//
function onKeyPress(event){

event = event || window.event;
Expand Down Expand Up @@ -197,7 +200,14 @@ function arraytolower($item)
return false;
}

cloneDatabase($targetdbname);
$res = cloneDatabase($targetdbname);

if(!$res){
echo_flush ('<p style="padding-left:20px;"><h2 style="color:red">WARNING: Your database has not been cloned.</h2>'
.'Please contact your system administrator or the Heurist developers (support at HeuristNetwork dot org) for assistance with cloning of your database.');
}



print "</div></body></html>";
}
Expand All @@ -216,7 +226,7 @@ function cloneDatabase($targetdbname) {

$newname = HEURIST_DB_PREFIX.$targetdbname;

//create new database
//create new empty database
if(!db_create($newname)){
return false;
}
Expand All @@ -229,7 +239,7 @@ function cloneDatabase($targetdbname) {
return false;
}

// Remove chatac
// Remove initial values from empty database
mysql_connection_insert($newname);
mysql_query('delete from sysIdentification where 1');
mysql_query('delete from sysTableLastUpdated where 1');
Expand All @@ -244,16 +254,42 @@ function cloneDatabase($targetdbname) {
echo_flush ('<p style="padding-left:20px">SUCCESS</p>');
}else{
db_drop($newname);

return false;
}

//TODO: need to check for successful addition of constraints
//cleanup database to avoid issues with addition of constraints

//1. cleanup missed trm_InverseTermId
mysql_query('update defTerms t1 left join defTerms t2 on t1.trm_InverseTermId=t2.trm_ID
set t1.trm_InverseTermId=null
where t1.trm_ID>0 and t2.trm_ID is NULL');

//2. remove missed recent records
mysql_query('delete FROM usrRecentRecords
where rre_RecID>0
where rre_RecID is not null
and rre_RecID not in (select rec_ID from Records)');

//3. remove missed rrc_SourceRecID and rrc_TargetRecID
mysql_query('delete FROM recRelationshipsCache
where rrc_SourceRecID is not null
and rrc_SourceRecID not in (select rec_ID from Records)');

mysql_query('delete FROM recRelationshipsCache
where rrc_TargetRecID is not null
and rrc_TargetRecID not in (select rec_ID from Records)');

//4. cleanup orphaned details
mysql_query('delete FROM recDetails
where dtl_RecID is not null
and dtl_RecID not in (select rec_ID from Records)');

//5. cleanup missed references to uploaded files
mysql_query('delete FROM recDetails
where dtl_UploadedFileID is not null
and dtl_UploadedFileID not in (select ulf_ID from recUploadedFiles)');



$sHighLoadWarning = "<p><h4>Note: </h4>Failure to clone a database may result from high server load. Please try again, and if the problem continues contact the Heurist developers at info heuristnetwork dot org</p>";

Expand Down Expand Up @@ -319,5 +355,7 @@ function cloneDatabase($targetdbname) {
echo "<hr><p>&nbsp;</p><h2>New database '$targetdbname' created successfully</h2>";
print "<p>Please access your new database through this link: <a href='".HEURIST_BASE_URL."?db=".$targetdbname.
"' title='' target=\"_new\"><strong>".$targetdbname."</strong></a></p>";

return true;
} // straightCopyNewDatabase
?>
175 changes: 88 additions & 87 deletions admin/setup/dboperations/deleteCurrentDB.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
<?php

/**
* File: deleteCurrentDB.php Deletes the current database (owner group admins only)
*
* @package Heurist academic knowledge management system
* @link http://HeuristNetwork.org
* @copyright (C) 2005-2016 University of Sydney
* @author Ian Johnson <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @version 3.0
*/

/*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.txt
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
* See the License for the specific language governing permissions and limitations under the License.
*/


require_once(dirname(__FILE__).'/../../../common/connect/applyCredentials.php');
require_once(dirname(__FILE__).'/../../../records/index/elasticSearchFunctions.php');
require_once(dirname(__FILE__).'/../../../common/php/dbUtils.php');

if(isForOwnerOnly("to delete a database")){
return;
}
/**
* deleteCurrentDB.php Deletes the current database (owner group admins only)
* Note that deletion of multiple DBs in dbStatistics.php uses deleteDB.php
*
* @package Heurist academic knowledge management system
* @link http://HeuristNetwork.org
* @copyright (C) 2005-2016 University of Sydney
* @author Ian Johnson <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @version 3.0
*/

/*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.txt
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
* See the License for the specific language governing permissions and limitations under the License.
*/


require_once(dirname(__FILE__).'/../../../common/connect/applyCredentials.php');
require_once(dirname(__FILE__).'/../../../records/index/elasticSearchFunctions.php');
require_once(dirname(__FILE__).'/../../../common/php/dbUtils.php');

if(isForOwnerOnly("to delete a database")){
return;
}
?>
<html>
<head>
Expand All @@ -39,68 +40,68 @@
<body class='popup'>
<div class='banner'><h2>Delete Current Heurist Database</h2></div>
<div id='page-inner' style='overflow:auto'>
<?php
$dbname = $_REQUEST['db'];


if(!@$_REQUEST['mode']) {
?>
<h4 style='display:inline-block; margin:0 5px 0 0'><span><img src='../../../common/images/url_error.png' />
DANGER <img src='../../../common/images/url_error.png' /></span></h4>
<h1 style='display:inline-block'>DELETION OF CURRENT DATABASE</h1><br>
<h3>This will PERMANENTLY AND IRREVOCABLY delete the current database: </h3>
<h2>About to delete database: <?=$dbname?></h2>
<form name='deletion' action='deleteCurrentDB.php' method='get'>
<p>Enter the words DELETE MY DATABASE below in ALL-CAPITALS to confirm that you want to delete the current database
<p>Type the words above to confirm deletion <input type='input' maxlength='20' size='20' name='del' id='del'>
&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='OK to Delete' style='font-weight: bold;' >
<input name='mode' value='2' type='hidden'>
<input name='db' value='<?=$dbname?>' type='hidden'>
</form>
<?php
}else if(@$_REQUEST['mode']=='2') {

if (@$_REQUEST['del']=='DELETE MY DATABASE') {
print "<br/><br/><hr>";
if ($dbname=='') {
print "<p class='error'>Undefined database name</p>"; // shouldn't get here
} else {
// It's too risky to delete data with "rm -Rf .$uploadPath", could end up trashing stuff needed elsewhere, so we move it
$uploadPath = HEURIST_UPLOAD_ROOT.$dbname; // individual deletio nto avoid risk of unintended disaster with -Rf
$cmdline = "mv ".$uploadPath." ".HEURIST_UPLOAD_ROOT."deleted_databases";
$output2 = exec($cmdline . ' 2>&1', $output, $res2);
if ($res2 != 0 ) {
echo ("<h2>Warning:</h2> Unable to move <b>$uploadPath</b> to the deleted files folder, perhaps a permissions problem or previously deleted.");
echo ("<p>Please ask your system adminstrator to delete this folder if it exists.<br></p>");
echo($output2);
}


//$cmdline = "mysql -h".HEURIST_DBSERVER_NAME." -u".ADMIN_DBUSERNAME." -p".ADMIN_DBUSERPSWD." -e'drop database ".HEURIST_DB_PREFIX."$dbname'";
//$output2 = exec($cmdline . ' 2>&1', $output, $res2); // this is the one we really care about

if (!db_drop(HEURIST_DB_PREFIX.$dbname, false)) {
echo ("<h2>Warning:</h2> Unable to delete <b>".HEURIST_DB_PREFIX.$dbname."</b>");
echo ("<p>Check that the database still exists. Consult Heurist helpdesk if needed<br></p>");
//echo($output2);
} else {
// Remove from Elasticsearch
print "<p>Removing indexes, calling deleteIndexForDatabase with parameter $dbname<br /><br /></p>";
deleteIndexForDatabase($dbname); //Deleting all Elasticsearch indexes
?>
<h2>Database <b><?=$dbname?></b> has been deleted</h2>
<p>Associated files stored in upload subdirectories <b><?=$uploadPath?></b> <br/> have ben moved to <?=HEURIST_UPLOAD_ROOT?>deleted_databases.</p>
<p>If you delete databases with a large volume of data, please ask your system administrator to empty this folder.</p>
<p><a href='#' onclick='{top.location.href="<?=HEURIST_BASE_URL?>index.php" }' >Return to Heurist</a></p>
<?php
<?php
$dbname = $_REQUEST['db'];


if(!@$_REQUEST['mode']) {
?>
<h4 style='display:inline-block; margin:0 5px 0 0'><span><img src='../../../common/images/url_error.png' />
DANGER <img src='../../../common/images/url_error.png' /></span></h4>
<h1 style='display:inline-block'>DELETION OF CURRENT DATABASE</h1><br>
<h3>This will PERMANENTLY AND IRREVOCABLY delete the current database: </h3>
<h2>About to delete database: <?=$dbname?></h2>
<form name='deletion' action='deleteCurrentDB.php' method='get'>
<p>Enter the words DELETE MY DATABASE below in ALL-CAPITALS to confirm that you want to delete the current database
<p>Type the words above to confirm deletion <input type='input' maxlength='20' size='20' name='del' id='del'>
&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='OK to Delete' style='font-weight: bold;' >
<input name='mode' value='2' type='hidden'>
<input name='db' value='<?=$dbname?>' type='hidden'>
</form>
<?php
}else if(@$_REQUEST['mode']=='2') {

if (@$_REQUEST['del']=='DELETE MY DATABASE') {
print "<br/><br/><hr>";
if ($dbname=='') {
print "<p class='error'>Undefined database name</p>"; // shouldn't get here
} else {
// It's too risky to delete data with "rm -Rf .$uploadPath", could end up trashing stuff needed elsewhere, so we move it
$uploadPath = HEURIST_UPLOAD_ROOT.$dbname; // individual deletio nto avoid risk of unintended disaster with -Rf
$cmdline = "mv ".$uploadPath." ".HEURIST_UPLOAD_ROOT."DELETED_DATABASES";
$output2 = exec($cmdline . ' 2>&1', $output, $res2);
if ($res2 != 0 ) {
echo ("<h2>Warning:</h2> Unable to move <b>$uploadPath</b> to the deleted files folder, perhaps a permissions problem or previously deleted.");
echo ("<p>Please ask your system adminstrator to delete this folder if it exists.<br></p>");
echo($output2);
}


//$cmdline = "mysql -h".HEURIST_DBSERVER_NAME." -u".ADMIN_DBUSERNAME." -p".ADMIN_DBUSERPSWD." -e'drop database ".HEURIST_DB_PREFIX."$dbname'";
//$output2 = exec($cmdline . ' 2>&1', $output, $res2); // this is the one we really care about

if (!db_drop(HEURIST_DB_PREFIX.$dbname, false)) {
echo ("<h2>Warning:</h2> Unable to delete <b>".HEURIST_DB_PREFIX.$dbname."</b>");
echo ("<p>Check that the database still exists. Consult Heurist helpdesk if needed<br></p>");
//echo($output2);
} else {
// Remove from Elasticsearch
print "<p>Removing indexes, calling deleteIndexForDatabase with parameter $dbname<br /><br /></p>";
deleteIndexForDatabase($dbname); //Deleting all Elasticsearch indexes
?>
<h2>Database <b><?=$dbname?></b> has been deleted</h2>
<p>Associated files stored in upload subdirectories <b><?=$uploadPath?></b> <br/> have ben moved to <?=HEURIST_UPLOAD_ROOT?>DELETED_DATABASES.</p>
<p>If you delete databases with a large volume of data, please ask your system administrator to empty this folder.</p>
<p><a href='#' onclick='{top.location.href="<?=HEURIST_BASE_URL?>index.php" }' >Return to Heurist</a></p>
<?php
}
}
} else { // didn't request properly
print "<p><h2>Request disallowed</h2>Incorrect challenge words entered. Database <b>$dbname</b> was not deleted</p>";
}
}
} else { // didn't request properly
print "<p><h2>Request disallowed</h2>Incorrect challenge words entered. Database <b>$dbname</b> was not deleted</p>";
}
}
?>
</div>
?>
</div>
</body>
</html>

Expand Down
3 changes: 2 additions & 1 deletion admin/structure/fields/editDetailType.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function DetailTypeEditor() {

Hul.addoption(el_sel, 0, 'Individual selection (advanced)');
if(sel_index<0) {
sel_index = (Dom.get("dty_JsonTermIDTree").value!="" && vocabId==0)?el_sel.length-1:0;
sel_index = (Dom.get("dty_JsonTermIDTree").value!='' && vocabId==0)?el_sel.length-1:0;
}
el_sel.selectedIndex = sel_index;

Expand Down Expand Up @@ -628,6 +628,7 @@ function DetailTypeEditor() {
}

//to trigger setting visibilty for div with terms tree and record pointer
that.keepType = Dom.get("dty_Type").value;
_onChangeType(null);

// create preview for Terms Tree and record pointer
Expand Down
10 changes: 3 additions & 7 deletions admin/structure/terms/editTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@
<div id="divBanner" class="banner">
<h2>Manage terms for term list fields and relationship type</h2>
</div>
<div><br/></div>
<div style="margin-left:10px; padding-top:15px;">
<div style="margin-left:10px; padding-top:35px;">
<input id="btnAddChild" type="button"
value="Add Vocabulary" onClick="{editTerms.doAddChild(true)}"/>
<span style="margin-top:5px; margin-left:10px;"> Adds a new root to the tree</span>
</div>


<div id="page-inner">
<div><br/><br/><br/></div>
<div>&nbsp;&nbsp;&nbsp;&#129155;</div>
<div><br/></div>
<div id="page-inner" style="top:75px">
<div id="pnlLeft" style="height:100%; width:300; max-width:300; float: left; padding-right:5px; overflow: hidden;">

<!-- Container for tab control component, each tab contains tree view, one for enums, one for relationship types-->
Expand Down Expand Up @@ -139,7 +135,7 @@ class="yui-navset yui-navset-top" style="y:138; height:70%; width:300; max-width
</div>

<!-- Edit form for modifying characteristics of terms, including insertion of child terms and deletion -->
<div id="formEditor" style="display:none;width:600px;">
<div id="formEditor" style="display:none;width:600px;margin-top:-35px;">
<h3 style="margin-left:10px; margin-top:0px; border-style:none;display:inline-block"><br/><br/>Edit selected term / vocabulary</h3>
<div id="div_SaveMessage" style="text-align: center; display:none;color:#0000ff;width:140px;">
<b>term saved</b>
Expand Down
Loading

0 comments on commit 4a2c0a8

Please sign in to comment.