F diff --git a/php/database.php b/php/database.php --- a/php/database.php +++ b/php/database.phpfunction unlink_nodes(int $dir_id, string $filename){+ /*TODO delet this*/+ error_log("in unlink nodes");$prep=$this->pdo->prepare("delete from node_linkswhere directory_id=:dir_id and name=:name");error_log("there was an error with the first statement in unlink_nodes");return;}+ error_log("in pre stuff in unlink nodes");+ $prep=$this->pdo->prepare("select count(1) as count from trash");+ $prep->execute() or die(1);do{- $prep=$this->pdo->prepare("select count(1) as count from trash");+++ $prep=$this->pdo->prepare("select count(1) as count from super_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");+ $super_trash_count=$prep->fetch(PDO::FETCH_ASSOC);+ $prep=$this->pdo->prepare("delete from super_trash");$prep->execute() or die(1);- $prep=$this->pdo->prepare("delete from trash");++++ $prep=$this->pdo->prepare("select count(1) as count from trash");$prep->execute() or die(1);- $prep=$this->pdo->prepare("delete from links- where directory_id in- (select node_id from super_trash)- ");+ $trash_count=$prep->fetch(PDO::FETCH_ASSOC);+ $prep=$this->pdo->prepare("delete from trash");$prep->execute() or die(1);- }while($res["count"]!=0);+ error_log("asdf: ".$trash_count["count"]." ".$super_trash_count["count"]);+ }while($trash_count["count"]!=$super_trash_count["count"]);+$prep=$this->pdo->prepare("select code from nodes where node_id in(select node_id from super_trash)");$prep->execute() or die(1);unlink($storage_root,"/".$node["code"]);}$prep=$this->pdo->prepare("delete from nodes where node_id in- (select node_id from super_trash");+ (select node_id from super_trash)");$prep->execute() or die(1);$prep=$this->pdo->prepare("delete from super_trash");+ $prep->execute() or die(1);}F diff --git a/php/delete.php b/php/delete.php --- a/php/delete.php +++ b/php/delete.php<?php---+ require_once "database.php";+ require_once "user.php";+ require_once "node.php";++ session_start();+ $folder=$_POST["folder"];+ $filename=$_POST["filename"];+ $user=$_SESSION["user_object"];++ error_log("someone is trying to delete".$filename);+ unlink_from_folder($folder,$filename,$user);+ error_log("someone is trying to delete".$filename);?>F diff --git a/php/node.php b/php/node.php --- a/php/node.php +++ b/php/node.phpreturn $dir_id;}}+ function unlink_from_folder(string $abstract_path,string $filename,User $user)+ {+ global $database;+ $parent_dir_id=get_directory($abstract_path,$user);+ $database->unlink_nodes($parent_dir_id,$filename);+ }?>F diff --git a/sql/fileshare.sql b/sql/fileshare.sql --- a/sql/fileshare.sql +++ b/sql/fileshare.sqldrop table if exists node_links;drop table if exists trash;drop table if exists super_trash;+ drop table if exists nodes;+++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;+ drop trigger if exists supper_del_node;+);create table trash (- node_id int not null,- foreign key (node_id) references nodes(node_id)+ node_id int not null);create table super_trash (- node_id int not null,- foreign key (node_id) references nodes(node_id)- );+ node_id int not null+ );create trigger delete_on_zero_linksinsert into trashselect nodes.node_idfrom 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 node_links where directory_id=old.node_id;- /*create trigger del_node- after insert+ after deleteon trashfor each row- delete from nodes where node_id=new.node_id;- */+ insert into super_trash(node_id)+ select node_id+ from nodes+ where nodes.node_id=old.node_id;+++ create trigger supper_del_node+ after delete+ on super_trash+ for each row+ insert into trash+ select node_id+ from nodes+ where nodes.node_id=old.node_id;++ create trigger delete_links+ before delete+ on super_trash+ for each row+ delete from node_links+ where directory_id=old.node_id;