From a346874ea858d43ee2336e315dba056fb81b6439 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 13 Feb 2021 14:51:35 +0200 Subject: nothing done --- php/database.php | 32 ++++++++++++++++++++++++++++++++ sql/fileshare.sql | 21 ++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/php/database.php b/php/database.php index 668490a..74210eb 100644 --- a/php/database.php +++ b/php/database.php @@ -291,6 +291,7 @@ 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) @@ -375,6 +376,37 @@ require_once "node.php"; } } + + function unlink_nodes(int $dir_id, int $node_id) + { + $prep=$this->pdo->prepare("delete from node_links + where directory_id=:dir_id and node_id=:node_id + "); + $prep->bindParam(':dir_id',$dir_id); + $prep->bindParam(':node_id',$node_id); + 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); + } + + + } + function create_home_directory():int { $ret=$this->create_dangling_directory(); diff --git a/sql/fileshare.sql b/sql/fileshare.sql index 8e69881..4eb60f7 100644 --- a/sql/fileshare.sql +++ b/sql/fileshare.sql @@ -2,6 +2,8 @@ drop table if exists node_access; drop table if exists users; drop table if exists node_links; +drop table if exists trash; +drop trigger if exists delete_on_zero_links; drop table if exists nodes; @@ -42,9 +44,26 @@ create table node_links ( node_id int not null, name varchar(100) not null default 'no name', note varchar(200) not null default "", - check (directory_id != node_id), foreign key (directory_id) references nodes(node_id) on delete cascade, foreign key (node_id) references nodes(node_id) on delete cascade ); +create table trash ( + node_id int not null, + foreign key (node_id) references nodes(node_id) on delete cascade +); + +/* +create trigger delete_on_zero_links + after delete + on node_links + for each row + insert into trash(node_id) + select + if(old.node_id not in (select node_id from node_links), + old.node_id, + select node_id from nodes where 1=0 + ); + +*/ -- cgit v1.2.3 From 0abc4c6de856c5c1d678d82bb464758c934fae0c Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 13 Feb 2021 15:40:53 +0200 Subject: triggers are kinda ok --- sql/fileshare.sql | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sql/fileshare.sql b/sql/fileshare.sql index 4eb60f7..b0c28a5 100644 --- a/sql/fileshare.sql +++ b/sql/fileshare.sql @@ -54,16 +54,19 @@ create table trash ( ); -/* create trigger delete_on_zero_links after delete on node_links - for each row - insert into trash(node_id) - select - if(old.node_id not in (select node_id from node_links), - old.node_id, - select node_id from nodes where 1=0 - ); + for each row + 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; -*/ + /* +create trigger delete_links + after delete + on nodes + for each row + delete from + */ -- cgit v1.2.3