FileApi start
This commit is contained in:
@@ -6,7 +6,7 @@ use Driver\SQL\SQL;
|
||||
use \Driver\SQL\Strategy\SetNullStrategy;
|
||||
use \Driver\SQL\Strategy\CascadeStrategy;
|
||||
|
||||
class CreateDatabase {
|
||||
class CreateDatabase extends DatabaseScript {
|
||||
|
||||
// NOTE:
|
||||
// explicit serial ids removed due to postgres' serial implementation
|
||||
@@ -192,7 +192,10 @@ class CreateDatabase {
|
||||
->addRow("User/edit", array(USER_GROUP_ADMIN), "Allows users to edit details and group memberships of any user")
|
||||
->addRow("User/delete", array(USER_GROUP_ADMIN), "Allows users to delete any other user")
|
||||
->addRow("Permission/fetch", array(USER_GROUP_ADMIN), "Allows users to list all API permissions")
|
||||
->addRow("Visitors/stats", array(USER_GROUP_ADMIN, USER_GROUP_SUPPORT), "Allows users to see visitor statistics");
|
||||
->addRow("Visitors/stats", array(USER_GROUP_ADMIN, USER_GROUP_SUPPORT), "Allows users to see visitor statistics")
|
||||
->addRow("PatchSQL", array(USER_GROUP_ADMIN), "Allows users to import database patches");
|
||||
|
||||
self::loadPatches($queries, $sql);
|
||||
|
||||
return $queries;
|
||||
}
|
||||
@@ -225,4 +228,22 @@ class CreateDatabase {
|
||||
"Best Regards<br>" .
|
||||
"{{site_name}} Administration";
|
||||
}
|
||||
|
||||
private static function loadPatches(&$queries, $sql) {
|
||||
$patchDirectory = './core/Configuration/Patch/';
|
||||
if (file_exists($patchDirectory) && is_dir($patchDirectory)) {
|
||||
$scan_arr = scandir($patchDirectory);
|
||||
$files_arr = array_diff($scan_arr, array('.','..'));
|
||||
foreach ($files_arr as $file) {
|
||||
$suffix = ".class.php";
|
||||
if (endsWith($file, $suffix)) {
|
||||
$className = substr($file, 0, strlen($file) - strlen($suffix));
|
||||
$className = "\\Configuration\\Patch\\$className";
|
||||
$method = "$className::createQueries";
|
||||
$patchQueries = call_user_func($method, $sql);
|
||||
foreach($patchQueries as $query) $queries[] = $query;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
core/Configuration/DatabaseScript.class.php
Normal file
9
core/Configuration/DatabaseScript.class.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Configuration;
|
||||
|
||||
use Driver\SQL\SQL;
|
||||
|
||||
abstract class DatabaseScript {
|
||||
public static abstract function createQueries(SQL $sql);
|
||||
}
|
||||
72
core/Configuration/Patch/file_api.class.php
Normal file
72
core/Configuration/Patch/file_api.class.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Configuration\Patch;
|
||||
|
||||
use Configuration\DatabaseScript;
|
||||
use Driver\SQL\SQL;
|
||||
use Driver\SQL\Column\Column;
|
||||
use Driver\SQL\Strategy\CascadeStrategy;
|
||||
use Driver\SQL\Strategy\UpdateStrategy;
|
||||
|
||||
class file_api extends DatabaseScript {
|
||||
|
||||
public static function createQueries(SQL $sql) {
|
||||
|
||||
$queries = array();
|
||||
|
||||
$queries[] = $sql->insert("ApiPermission", array("method", "groups", "description"))
|
||||
->onDuplicateKeyStrategy(new UpdateStrategy(array("method"), array("method" => new Column("method"))))
|
||||
->addRow("File/Download", array(), "Allows users to download files when logged in, or using a given token")
|
||||
->addRow("File/Upload", array(), "Allows users to upload files when logged in, or using a given token")
|
||||
->addRow("File/ValidateToken", array(), "Allows users to validate a given token")
|
||||
->addRow("File/RevokeToken", array(USER_GROUP_ADMIN), "Allows users to revoke a token")
|
||||
->addRow("File/ListFiles", array(), "Allows users to list all files assigned to an account")
|
||||
->addRow("File/ListTokens", array(USER_GROUP_ADMIN), "Allows users to list all tokens assigned to the virtual filesystem of an account")
|
||||
->addRow("File/CreateDirectory", array(), "Allows users to create a virtual directory")
|
||||
->addRow("File/Rename", array(), "Allows users to rename files in the virtual filesystem")
|
||||
->addRow("File/Move", array(), "Allows users to move files in the virtual filesystem")
|
||||
->addRow("File/Delete", array(), "Allows users to delete files in the virtual filesystem")
|
||||
->addRow("File/CreateUploadToken", array(USER_GROUP_ADMIN), "Allows users to create a token to upload files to the virtual filesystem assigned to the users account")
|
||||
->addRow("File/CreateDownloadToken", array(USER_GROUP_ADMIN), "Allows users to create a token to download files from the virtual filesystem assigned to the users account");
|
||||
|
||||
$queries[] = $sql->, array("request", "action", "target", "extra"))
|
||||
->onDuplicateKeyStrategy(new UpdateStrategy(array("request"), array("request" => new Column("request"))))
|
||||
->addRow("^/files(/.*)?$", "dynamic", "\\Documents\\Files", NULL);
|
||||
|
||||
$queries[] = $sql->createTable("UserFile")
|
||||
->onlyIfNotExists()
|
||||
->addSerial("uid")
|
||||
->addBool("directory")
|
||||
->addString("name", 64, false)
|
||||
->addString("path", 512, true)
|
||||
->addInt("parent_id", true)
|
||||
->addInt("user_id", true)
|
||||
->primaryKey("uid")
|
||||
->unique("parent_id", "name")
|
||||
->foreignKey("parent_id", "UserFile", "uid", new CascadeStrategy())
|
||||
->foreignKey("user_id", "User", "uid", new CascadeStrategy());
|
||||
|
||||
$queries[] = $sql->createTable("UserFileToken")
|
||||
->onlyIfNotExists()
|
||||
->addSerial("uid")
|
||||
->addString("token", 36, false)
|
||||
->addDateTime("valid_until", true)
|
||||
->addEnum("token_type", array("download", "upload"))
|
||||
->addInt("user_id")
|
||||
# upload only:
|
||||
->addInt("maxFiles", true)
|
||||
->addInt("maxSize", true)
|
||||
->addString("extensions", 64, true)
|
||||
->primaryKey("uid")
|
||||
->foreignKey("user_id", "User", "uid");
|
||||
|
||||
$queries[] = $sql->createTable("UserFileTokenFile")
|
||||
->addInt("file_id")
|
||||
->addInt("token_id")
|
||||
->unique("file_id", "token_id")
|
||||
->foreignKey("file_id", "UserFile", "uid")
|
||||
->foreignKey("token_id", "UserFileToken", "uid");
|
||||
|
||||
return $queries;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user