diff options
author | adam <adam@> | 2021-02-13 13:26:36 +0200 |
---|---|---|
committer | adam <adam@> | 2021-02-13 13:26:36 +0200 |
commit | 8f8d22109484308255d16f318cb488b3c8519885 (patch) | |
tree | fe6973ac7ab727e12a948dce116723e9306be93b /php | |
parent | 212043453286cbd1c1840b1ae13f1516f90870d4 (diff) | |
download | fileup-8f8d22109484308255d16f318cb488b3c8519885.tar.gz |
added trash folder on user creation
Diffstat (limited to 'php')
-rw-r--r-- | php/configuration.php | 3 | ||||
-rw-r--r-- | php/database.php | 78 | ||||
-rw-r--r-- | php/delete.php | 6 | ||||
-rw-r--r-- | php/node.php | 2 |
4 files changed, 85 insertions, 4 deletions
diff --git a/php/configuration.php b/php/configuration.php index 313f0ad..09d1a06 100644 --- a/php/configuration.php +++ b/php/configuration.php @@ -21,7 +21,8 @@ $database_location="localhost"; $storage_root = "/srv/apache/testing/project/files/"; } - +/*if we save deleted files just in case of an error*/ +$has_trash=true; $password_hash_algo=PASSWORD_BCRYPT; $has_email_verification=false; diff --git a/php/database.php b/php/database.php index cb2697f..668490a 100644 --- a/php/database.php +++ b/php/database.php @@ -262,6 +262,72 @@ require_once "node.php"; } } + /*returns NULL if directory or error*/ + function get_code_of_node(int $node_id) + { + global $storage_root; + + $prep=$this->pdo->prepare("select code + from nodes + where node_id=:id + "); + $prep->bindParam(':id',$node_id); + if($prep->execute()==false) + { + error_log("could not execute sql statement in get_file_location_of_node"); + return NULL; + } + $hold=$prep->fetch(PDO::FETCH_ASSOC); + if(count($hold)!=1) + { + return NULL; + }else + { + /*BEWARE*/ + return $hold["code"]; + } + } + /* + we remove the node and + 1. move the file represented by the node to the trash folder + 2. remove the file + depends on the conf file + */ + function delete_node_by_id(int $node_id) + { + global $has_trash; + global $storage_root; + + $location=get_file_location_of_node($node_id); + + /*actually delete the file*/ + if($has_trash) + { + /*BEWARE*/ + if(!copy($storage_root."/".$location,$storage_root."/trash/".$location)) + { + error_log("could not copy file aborting node deletion in delete_node_by_id"); + return; + } + } + unlink($storage_root,"/".$location); + + if($location==NULL) + { + error_log("trying to delete a node that does not exist in delete_node_by_id!"); + return; + } + $prep=$this->pdo->prepare("delete + from nodes + where node_id=:id + "); + $prep->bindParam(':id',$node_id); + if($prep->execute()==false) + { + error_log("sql statement in delete_node_by_id could not execute"); + return NULL; + } + } /*this is used to create seperate roots for the users*/ function create_dangling_directory(): int @@ -291,6 +357,7 @@ require_once "node.php"; return $id["id"]; } + /*links source to target*/ function link_nodes(int $target_id,int $source_id,string $name,string $note) { @@ -307,6 +374,15 @@ require_once "node.php"; error_log("there was an error with the statement ni link_nodes"); } } + + function create_home_directory():int + { + $ret=$this->create_dangling_directory(); + $trash_folder_id=$this->create_dangling_directory(); + $this->link_nodes($ret,$trash_folder_id,"trash","trash folder"); + return $ret; + } + function check_if_name_is_taken(string $filename,int $dir_id):bool { if($this->get_node_id($filename,$dir_id)!=NULL) @@ -434,7 +510,7 @@ require_once "node.php"; }else { $hashed_pass=password_hash($password,$password_hash_algo); - $home_dir=$this->create_dangling_directory(); + $home_dir=$this->create_home_directory(); $prep=$this->pdo->prepare("insert into users(username,password,email,home_directory) values(:username,:password,:email,:dir)"); $prep->bindParam(':username',$user); $prep->bindParam(':password',$hashed_pass); diff --git a/php/delete.php b/php/delete.php new file mode 100644 index 0000000..b50dbad --- /dev/null +++ b/php/delete.php @@ -0,0 +1,6 @@ +<?php + + + + +?> diff --git a/php/node.php b/php/node.php index a9a6f9b..5074082 100644 --- a/php/node.php +++ b/php/node.php @@ -1,12 +1,10 @@ <?php require_once "database.php"; require_once "user.php"; - /*path is in terms of the simulated filesystem*/ function get_directory(string $abstract_path,User $user) { - error_log("getting directory".$abstract_path." for ".$user->username); global $database; if($abstract_path[0] != "/") |