Skip to content

Commit

Permalink
Fix workspace (not showing folders)
Browse files Browse the repository at this point in the history
  • Loading branch information
torinfo committed Jun 15, 2022
1 parent ab6ee18 commit 226180b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
8 changes: 4 additions & 4 deletions setup/basic.sql
Expand Up @@ -297,10 +297,10 @@ CREATE TABLE `template_group_rights` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `folderrights` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`folder_id` bigint(20) NOT NULL,
`login_id` bigint(20) NOT NULL,
`folder_parent` bigint(20) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`folder_id` int(11) NOT NULL,
`login_id` int(11) NOT NULL,
`folder_parent` int(11) NOT NULL,
`role` char(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Expand Down
54 changes: 47 additions & 7 deletions upgrade.php
Expand Up @@ -122,6 +122,12 @@ function printdebug($text) {
$r = db_query_one($sql);
if(!empty($r)) {
$version = $r['value'];
// Fix jump if we are not already past 32
// Previously the messages were a bit strange with the counters.
if ($version <= 32)
{
$version -= 1;
}
echo "Starting from $version\n";
} else {
db_query("INSERT INTO $config_table (name, value) VALUES ('version', '0')");
Expand All @@ -133,9 +139,7 @@ function printdebug($text) {
_do_cleanup();

function _do_upgrade($current_version) {
$target_version = $current_version + 0; // changed this to add 0 not 1 as this looks like it causes issues as when done an upgrade you had to add an extra 1 to the upgrade_function
if($target_version ==0 ) $target_version=1; // fixed this for when the variable didnt exist;

$target_version = $current_version + 1;

echo "<p>Current database version - $current_version</p>";
if(!function_exists('upgrade_' . $target_version)) {
Expand All @@ -158,6 +162,8 @@ function _do_upgrade($current_version) {
$target_version += 1;
}
echo "<p><b>Upgrade complete</b></p>\n";
// Last version is actually used is one less
$target_version -= 1;
// Update config table so we don't run the same query twice in the future.
$table = table_by_key('config');
$sql = "UPDATE $table SET value = $target_version WHERE name = 'version'";
Expand Down Expand Up @@ -1095,10 +1101,9 @@ function upgrade_27()
{
$table = table_by_key('folderrights');
$ok = _upgrade_db_query("CREATE TABLE IF NOT EXISTS `$table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`folder_id` bigint(20) NOT NULL,
`user_id` bigint(20) NOT NULL,
`folder_parent` bigint(20) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`folder_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`role` char(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
Expand Down Expand Up @@ -1200,3 +1205,38 @@ function upgrade_31()
}
}

function upgrade_32()
{
// Fix corrupt or wrong folderrights table;
$frtable = table_by_key('folderrights');
if (_db_field_exists('folderrights', 'user_id')) {
// change this to login_id
$ok = db_query("alter table `$frtable` change user_id login_id int");
}
if (!_db_field_exists('folderrights', 'folder_parent')) {
$error = _db_add_field('folderrights', 'folder_parent', 'int', '-1', 'login_id');

if ($error !== false) {
// Fill folderrights table based on folderdetails
$fdtable = table_by_key('folderdetails');
$folders = db_query("select * from `$fdtable`;");
if ($folders !== false) {
foreach ($folders as $folder) {
$ok = db_query("insert into `$frtable` set login_id=?, folder_id=?, folder_parent=?, role='creator'",
array($folder['login_id'], $folder['folder_id'], $folder['folder_parent']));
if ($ok === false) {
return "Something went wrong with migrating folderrights table!";
}
}
}
}
return "Creating folder_parent field in folderrights - ok ? " . ($error === false ? 'true' : 'false'). "<br>";
}
else
{
return "Creating folder_parent field in folderrights already present - ok ? ". "<br>";
}


}

6 changes: 6 additions & 0 deletions website_code/php/folder_library.php
Expand Up @@ -179,6 +179,12 @@ function move_folder($folder_id,$destination)
$params = array($destination, $folder_id);

$ok = db_query($query_folder, $params);

$query_folder = "UPDATE {$prefix}folderrights SET folder_parent = ? WHERE (folder_id = ? )";
$params = array($destination, $folder_id);

$ok = $ok && db_query($query_folder, $params);

if ($ok) {
receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "Folder " . $folder_id . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username'], "File " . $new_files_array[$x] . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username']);
} else {
Expand Down

0 comments on commit 226180b

Please sign in to comment.