aboutsummaryrefslogtreecommitdiffstats
path: root/php/database.php
diff options
context:
space:
mode:
authorAlex Vitkov <alexvitkov98@gmail.com>2021-02-12 20:58:46 +0200
committerAlex Vitkov <alexvitkov98@gmail.com>2021-02-12 20:58:46 +0200
commit97e8088dbc74d958e7f427abf24a84d5938b42c1 (patch)
treeef6aa537d39b861d0c8f58a4880bc685e5ebe345 /php/database.php
parent1813442cb9d565641ee0a67f6491b47327cef69b (diff)
parent022e478554fdb7110f3029fab49f706ba1d893ad (diff)
downloadfileup-97e8088dbc74d958e7f427abf24a84d5938b42c1.tar.gz
Merge branch 'master' of https://github.com/alexvitkov/india
Diffstat (limited to 'php/database.php')
-rw-r--r--php/database.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/php/database.php b/php/database.php
index 789ea86..23ff602 100644
--- a/php/database.php
+++ b/php/database.php
@@ -135,12 +135,15 @@ require_once "node.php";
}
/*if both are not null returns the id of the node with the name name in the directory_id node*/
- function get_node_id($name,$directory_id)
+ function get_node_id(string $name,int $directory_id)
{
- $statement=$this->pdo->prepare(
- "select nl.node_id as id from node_links nl
- inner join nodes n on n.node_id=nl.node_id
- where name=:name and directory_id=:directory_id)");
+ $statement=$this->pdo->prepare("
+ select node_links.node_id as id
+ from node_links
+ inner join nodes on
+ nodes.node_id=node_links.node_id
+ where node_links.name=:name and node_links.directory_id=:directory_id
+ ");
$statement->bindParam(':name',$name);
$statement->bindParam(':directory_id',$directory_id);
if($statement->execute()==false)
@@ -149,7 +152,7 @@ require_once "node.php";
return NULL;
}
$hold=$statement->fetch(PDO::FETCH_ASSOC);
- if($hold==false)
+ if(gettype($hold)!="array")
{
return NULL;
}else
@@ -344,6 +347,12 @@ require_once "node.php";
return "error";
}
+ /*check if node with given name exists*/
+ if($this->get_node_id($filename,$dir_id)!=NULL)
+ {
+ error_log("filename taken");
+ return "filename taken";
+ }
/*generate the node*/
$code=$this->get_random_node_name("");
if($filename==NULL)return "error";