aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--php/database.php14
-rw-r--r--php/node.php12
-rw-r--r--php/readdir.php3
3 files changed, 24 insertions, 5 deletions
diff --git a/php/database.php b/php/database.php
index 23ff602..bb8cfa4 100644
--- a/php/database.php
+++ b/php/database.php
@@ -112,7 +112,6 @@ require_once "node.php";
/* returns assoc array of nodes*/
function get_links_of(int $node_id)
{
- error_log("in get_links_of with argument {$node_id}");
$statement=$this->pdo->prepare("
select node_links.node_id as id,
node_links.name as name,
@@ -308,6 +307,17 @@ require_once "node.php";
error_log("there was an error with the statement ni link_nodes");
}
}
+ function check_if_name_is_taken(string $filename,int $dir_id):bool
+ {
+ if($this->get_node_id($filename,$dir_id)!=NULL)
+ {
+ return true;
+ }else
+ {
+ return false;
+ }
+
+ }
/*returns the file name as it must be in the filesystem relative to the storage root*/
function create_file_node(string $filename,string $note,int $dir_id,string $mimetype,User $user): string
{
@@ -348,7 +358,7 @@ require_once "node.php";
}
/*check if node with given name exists*/
- if($this->get_node_id($filename,$dir_id)!=NULL)
+ if($this->check_if_name_is_taken($filename,$dir_id))
{
error_log("filename taken");
return "filename taken";
diff --git a/php/node.php b/php/node.php
index b3b2c3f..c2ab5f1 100644
--- a/php/node.php
+++ b/php/node.php
@@ -43,9 +43,17 @@ require_once "user.php";
function create_directory(string $abstract_path,string $directory_name,string $note,User $user)
{
global $database;
- $dir_id=$database->create_dangling_directory();
+
$parent_dir_id=get_directory($abstract_path,$user);
- $database->link_nodes($parent_dir_id,$dir_id,$directory_name,$note);
+ if($database->check_if_name_is_taken($directory_name,$parent_dir_id))
+ {
+ return NULL;
+ }else
+ {
+ $dir_id=$database->create_dangling_directory();
+ $database->link_nodes($parent_dir_id,$dir_id,$directory_name,$note);
+ return $dir_id;
+ }
}
?>
diff --git a/php/readdir.php b/php/readdir.php
index 04587ee..8194580 100644
--- a/php/readdir.php
+++ b/php/readdir.php
@@ -2,9 +2,10 @@
require_once "node.php";
session_start();
$user=$_SESSION['user_object'];
+ $path=$_POST['path'];
//echo '[ { "name": "file1.txt", "mimetype": "text/plain", "is_directory": false }, { "name": "file2.pdf", "mimetype": "application/pdf", "is_directory": false }, { "name": "dir", "mimetype": "", "is_directory": true } ] ';
- $ret=get_directory_contents("/",$user);
+ $ret=get_directory_contents($path,$user);
$json=json_encode($ret);
echo $json;
?>