FILEUP



LOG | FILES | OVERVIEW


F diff --git a/php/configuration.php b/php/configuration.php --- a/php/configuration.php +++ b/php/configuration.php
$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;
F diff --git a/php/database.php b/php/database.php --- a/php/database.php +++ b/php/database.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
return $id["id"];
}
+
/*links source to target*/
function link_nodes(int $target_id,int $source_id,string $name,string $note)
{
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)
}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);
F diff --git a/php/delete.php b/php/delete.php new file mode 100644 --- /dev/null +++ b/php/delete.php
+ <?php
+
+
+
+
+ ?>
F diff --git a/php/node.php b/php/node.php --- a/php/node.php +++ b/php/node.php
<?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)
{
+
global $database;
- if($abstract_path[0] != "/") {
+ if($abstract_path[0] != "/")
+ {
return NULL;
}
- $component = strtok($abstract_path,"/");
- $current_dir = $user->home_directory;
+ $component = strtok($abstract_path,"/");
+ $current_dir = $user->home_directory;
- while ($component) {
+ while($component)
+ {
$current_dir = $database->get_node_id($component, $current_dir);
- $component = strtok("/");
- };
+ $component = strtok("/");
+ }
- return $current_dir;
+ return $current_dir;
}
/*returns an assoc arrat of Node-s*/
global $database;
$parent_dir_id=get_directory($abstract_path,$user);
+
if($database->check_if_name_is_taken($directory_name,$parent_dir_id))
{
return NULL;
F diff --git a/sql/fileshare.sql b/sql/fileshare.sql --- a/sql/fileshare.sql +++ b/sql/fileshare.sql
email varchar(50),
home_directory int not null,
primary key (user_id),
- foreign key (home_directory) references nodes(node_id)
+ foreign key (home_directory) references nodes(node_id) on delete cascade
);
create table node_access (
can_view boolean not null default true,
can_edit boolean not null default false,
- foreign key (node_id) references nodes(node_id),
- foreign key (user_id) references users(user_id)
+ foreign key (node_id) references nodes(node_id) on delete cascade,
+ foreign key (user_id) references users(user_id) on delete cascade
);
/*we can name a node in many different ways */
create table node_links (
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),
- foreign key (node_id) references nodes(node_id)
+ foreign key (directory_id) references nodes(node_id) on delete cascade,
+ foreign key (node_id) references nodes(node_id) on delete cascade
);