diff options
-rw-r--r-- | php/database.php | 46 | ||||
-rw-r--r-- | sql/fileshare.sql | 20 |
2 files changed, 45 insertions, 21 deletions
diff --git a/php/database.php b/php/database.php index 74210eb..ba02fc7 100644 --- a/php/database.php +++ b/php/database.php @@ -291,7 +291,6 @@ require_once "node.php"; we remove the node and 1. move the file represented by the node to the trash folder 2. remove the file - 3. if node is a directory - delete all children nodes depends on the conf file */ function delete_node_by_id(int $node_id) @@ -377,32 +376,45 @@ require_once "node.php"; } - function unlink_nodes(int $dir_id, int $node_id) + function unlink_nodes(int $dir_id, string $filename) { $prep=$this->pdo->prepare("delete from node_links - where directory_id=:dir_id and node_id=:node_id + where directory_id=:dir_id and name=:name "); $prep->bindParam(':dir_id',$dir_id); - $prep->bindParam(':node_id',$node_id); + $prep->bindParam(':name',$filename); if($prep->execute()==false) { error_log("there was an error with the first statement in unlink_nodes"); return; } - $prep=$this->pdo->prepare("select node_id - from node_links - where node_id=:id - "); - $prep->bindParam(':id',$node_id); - if($prep->execute()==false) - { - error_log("there was an error with the second statement in unlink_nodes"); - return; - } - if(count($prep->fetchALL(PDO::FETCH_ASSOC))==0) - { - delete_node_by_id($node_id); + do{ + $prep=$this->pdo->prepare("select count(1) as count from trash"); + $prep->execute() or die(1); + $res=$prep->fetch(PDO::FETCH_ASSOC); + $prep=$this->pdo->prepare("insert into super_trash select node_id from trash"); + $prep->execute() or die(1); + $prep=$this->pdo->prepare("delete from trash"); + $prep->execute() or die(1); + $prep=$this->pdo->prepare("delete from links + where directory_id in + (select node_id from super_trash) + "); + $prep->execute() or die(1); + + }while($res["count"]!=0); + $prep=$this->pdo->prepare("select code from nodes where node_id in + (select node_id from super_trash)"); + $prep->execute() or die(1); + $res=$prep->fetchAll(PDO::FETCH_ASSOC); + foreach($res as $node) + { + unlink($storage_root,"/".$node["code"]); } + $prep=$this->pdo->prepare("delete from nodes where node_id in + (select node_id from super_trash"); + $prep->execute() or die(1); + $prep=$this->pdo->prepare("delete from super_trash"); } diff --git a/sql/fileshare.sql b/sql/fileshare.sql index b0c28a5..7dae888 100644 --- a/sql/fileshare.sql +++ b/sql/fileshare.sql @@ -3,7 +3,10 @@ drop table if exists node_access; drop table if exists users; drop table if exists node_links; drop table if exists trash; +drop table if exists super_trash; drop trigger if exists delete_on_zero_links; +drop trigger if exists delete_links; +drop trigger if exists del_node; drop table if exists nodes; @@ -50,8 +53,12 @@ create table node_links ( create table trash ( node_id int not null, - foreign key (node_id) references nodes(node_id) on delete cascade + foreign key (node_id) references nodes(node_id) ); +create table super_trash ( + node_id int not null, + foreign key (node_id) references nodes(node_id) + ); create trigger delete_on_zero_links @@ -61,12 +68,17 @@ create trigger delete_on_zero_links insert into trash select nodes.node_id from nodes - where nodes.node_id not in (select node_id from node_links) and nodes.node_id=old.node_id; + where nodes.node_id not in (select node_id from node_links) and nodes.node_id=old.node_id ; - /* create trigger delete_links after delete on nodes for each row - delete from + delete from node_links where directory_id=old.node_id; +/* +create trigger del_node + after insert + on trash + for each row + delete from nodes where node_id=new.node_id; */ |