-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete feature for DQT Add tools/dqt_delete_saved_query.php
- Loading branch information
1 parent
69c2610
commit ae89857
Showing
9 changed files
with
191 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Data Querying Module | ||
* | ||
* PHP Version 5 | ||
* | ||
* @category Data_Querying_Module | ||
* @package Loris | ||
* @author Loris Team <loris-dev@bic.mni.mcgill.ca> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://www.github.com/aces/Loris/ | ||
*/ | ||
header("Content-Type: application/json"); | ||
$config = \NDB_Config::singleton(); | ||
$couchConfig = $config->getSetting('CouchDB'); | ||
$cdb = \NDB_Factory::singleton()->couchDB( | ||
$couchConfig['dbName'], | ||
$couchConfig['hostname'], | ||
intval($couchConfig['port']), | ||
$couchConfig['admin'], | ||
$couchConfig['adminpass'] | ||
); | ||
$is_author = false; | ||
$docID = urlencode($_REQUEST['DocID']); | ||
$user = User::singleton(); | ||
$tmp_author = explode("_", $docID); | ||
$doc_author = str_replace("global:", '', $tmp_author[0]); | ||
if ($doc_author == $user->getUsername()) { | ||
$is_author = true; | ||
} | ||
|
||
if ($user->hasPermission('superuser') || $is_author) { | ||
$results = $cdb->deleteDoc($docID); | ||
print json_encode($results); | ||
} else { | ||
header("HTTP/1.1 403 Forbidden"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Data Querying Module | ||
* | ||
* PHP Version 7.4 | ||
* | ||
* @category Data_Querying_Module | ||
* @package Loris | ||
* @author Loris Team <loris-dev@bic.mni.mcgill.ca> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://www.github.com/aces/Loris/ | ||
*/ | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
header("Content-Type: application/json"); | ||
$config = \NDB_Config::singleton(); | ||
$couchConfig = $config->getSetting('CouchDB'); | ||
$cdb = \NDB_Factory::singleton()->couchDB( | ||
$couchConfig['dbName'], | ||
$couchConfig['hostname'], | ||
intval($couchConfig['port']), | ||
$couchConfig['admin'], | ||
$couchConfig['adminpass'] | ||
); | ||
echo "Deleting a saved query in DQT.\n"; | ||
|
||
$user = readline("Please input the author of the saved query:"); | ||
$name = readline("Please input the name of the saved query:"); | ||
$global = readline("If the saved query is global then input 'y':"); | ||
if ($global) { | ||
$docID = urlencode("global:".$user."_".$name); | ||
} else { | ||
$docID = urlencode($user."_".$name); | ||
} | ||
$results = $cdb->deleteDoc( | ||
$docID | ||
); | ||
|
||
|
||
if (json_encode($results) == "true") { | ||
echo $name." has been deleted in DQT.\n"; | ||
} else { | ||
echo "There is no query named ".$name." in DQT.\n"; | ||
}; |