aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradam <adam@>2021-02-13 12:44:19 +0200
committeradam <adam@>2021-02-13 12:44:19 +0200
commitcfc5bf135b131827f8b269f2daebe614f8baa56e (patch)
treea396746d7ced1ddac4fb506f606966fd05979f92
parente4c0f4eeaa3f1a0707d6bf668619bb48b77c43ce (diff)
downloadfileup-cfc5bf135b131827f8b269f2daebe614f8baa56e.tar.gz
stuff
-rw-r--r--php/node.php19
-rw-r--r--sql/fileshare.sql10
2 files changed, 17 insertions, 12 deletions
diff --git a/php/node.php b/php/node.php
index d7c2a6c..a9a6f9b 100644
--- a/php/node.php
+++ b/php/node.php
@@ -6,20 +6,24 @@ 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] != "/") {
+ 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*/
@@ -39,6 +43,7 @@ require_once "user.php";
global $database;
$parent_dir_id=get_directory($abstract_path,$user);
+
if($database->check_if_name_is_taken($directory_name,$parent_dir_id))
{
return NULL;
diff --git a/sql/fileshare.sql b/sql/fileshare.sql
index 010b35d..8e69881 100644
--- a/sql/fileshare.sql
+++ b/sql/fileshare.sql
@@ -24,7 +24,7 @@ create table users (
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 (
@@ -33,8 +33,8 @@ 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 (
@@ -43,8 +43,8 @@ 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
);