DocSpace-buildtools/common/ASC.Data.Backup.Core/Tasks/Modules/ProjectsModuleSpecifics.cs

205 lines
11 KiB
C#
Raw Normal View History

2022-03-15 18:00:53 +00:00
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
namespace ASC.Data.Backup.Tasks.Modules;
public class ProjectsModuleSpecifics : ModuleSpecificsBase
2020-05-20 15:14:44 +00:00
{
public override ModuleName ModuleName => ModuleName.Projects;
public override IEnumerable<TableInfo> Tables => _tables;
public override IEnumerable<RelationInfo> TableRelations => _tableRelations;
2020-05-26 08:52:47 +00:00
private readonly TableInfo[] _tables = new[]
{
2022-02-09 18:33:50 +00:00
new TableInfo("projects_comments", "tenant_id", "comment_id", IdType.Autoincrement) {UserIDColumns = new[] {"create_by"}},
new TableInfo("projects_following_project_participant") {UserIDColumns = new[] {"participant_id"}},
new TableInfo("projects_messages", "tenant_id", "id")
2020-05-20 15:14:44 +00:00
{
2022-02-09 18:33:50 +00:00
UserIDColumns = new[] {"create_by", "last_modified_by"},
DateColumns = new Dictionary<string, bool> {{"create_on", false}, {"last_modified_on", false}}
},
new TableInfo("projects_milestones", "tenant_id", "id")
2020-05-20 15:14:44 +00:00
{
2022-02-09 18:33:50 +00:00
UserIDColumns = new[] {"create_by", "last_modified_by", "responsible_id"},
DateColumns = new Dictionary<string, bool> {{"deadline", true}, {"status_changed", false}, {"create_on", false}, {"last_modified_on", false}}
},
new TableInfo("projects_projects", "tenant_id", "id")
{
UserIDColumns = new[] {"create_by", "last_modified_by", "responsible_id"},
DateColumns = new Dictionary<string, bool> {{"status_changed", false}, {"create_on", false}, {"last_modified_on", false}}
},
new TableInfo("projects_project_participant", "tenant") {UserIDColumns = new[] {"participant_id"}},
new TableInfo("projects_project_tag"),
new TableInfo("projects_report_template", "tenant_id", "id") {UserIDColumns = new[] {"create_by"}},
new TableInfo("projects_subtasks", "tenant_id", "id")
{
UserIDColumns = new[] {"create_by", "last_modified_by", "responsible_id"},
DateColumns = new Dictionary<string, bool> {{"status_changed", false}, {"create_on", false}, {"last_modified_on", false}}
},
new TableInfo("projects_tags", "tenant_id", "id"),
new TableInfo("projects_tasks", "tenant_id", "id")
{
UserIDColumns = new[] {"create_by", "last_modified_by", "responsible_id"},
DateColumns = new Dictionary<string, bool> {{"status_changed", true}, {"deadline", true}, {"create_on", false}, {"last_modified_on", true}, {"start_date", true}}
},
new TableInfo("projects_tasks_responsible", "tenant_id") {UserIDColumns = new[] {"responsible_id"}},
new TableInfo("projects_templates", "tenant_id", "id") {UserIDColumns = new[] {"create_by", "last_modified_by"}},
new TableInfo("projects_time_tracking", "tenant_id", "id")
{
UserIDColumns = new[] {"create_by", "person_id"},
DateColumns = new Dictionary<string, bool> {{"date", true}, {"create_on", false}, {"status_changed", true}}
},
new TableInfo("projects_tasks_links", "tenant_id"),
new TableInfo("projects_tasks_order", "tenant_id")
};
2020-05-20 15:14:44 +00:00
private readonly RelationInfo[] _tableRelations = new[]
{
2022-02-09 18:33:50 +00:00
new RelationInfo("projects_comments", "id", "projects_comments", "parent_id"),
new RelationInfo("projects_messages", "id", "projects_comments", "target_uniq_id", x => Convert.ToString(x["target_uniq_id"]).StartsWith("Message_", StringComparison.InvariantCultureIgnoreCase)),
new RelationInfo("projects_tasks", "id", "projects_comments", "target_uniq_id", x => Convert.ToString(x["target_uniq_id"]).StartsWith("Task_", StringComparison.InvariantCultureIgnoreCase)),
new RelationInfo("projects_milestones", "id", "projects_comments", "target_uniq_id", x => Convert.ToString(x["target_uniq_id"]).StartsWith("Milestone_", StringComparison.InvariantCultureIgnoreCase)),
new RelationInfo("projects_projects", "id", "projects_following_project_participant", "project_id"),
new RelationInfo("projects_projects", "id", "projects_messages", "project_id"),
new RelationInfo("projects_projects", "id", "projects_milestones", "project_id"),
new RelationInfo("projects_projects", "id", "projects_project_participant", "project_id"),
new RelationInfo("projects_projects", "id", "projects_project_tag", "project_id"),
new RelationInfo("projects_tags", "id", "projects_project_tag", "tag_id"),
new RelationInfo("projects_tasks", "id", "projects_subtasks", "task_id"),
new RelationInfo("projects_projects", "id", "projects_tasks", "project_id"),
new RelationInfo("projects_milestones", "id", "projects_tasks", "milestone_id"),
new RelationInfo("projects_tasks", "id", "projects_tasks_responsible", "task_id"),
new RelationInfo("projects_projects", "id", "projects_time_tracking", "project_id"),
new RelationInfo("projects_tasks", "id", "projects_time_tracking", "relative_task_id"),
new RelationInfo("projects_tasks", "id", "projects_tasks_links", "task_id"),
new RelationInfo("projects_tasks", "id", "projects_tasks_links", "parent_id"),
new RelationInfo("projects_projects", "id", "projects_tasks_order", "project_id"),
new RelationInfo("projects_tasks", "id", "projects_tasks_order", "task_order"),
new RelationInfo("projects_milestones", "id", "projects_tasks_order", "task_order")
};
public ProjectsModuleSpecifics(Helpers helpers) : base(helpers) { }
2020-05-20 15:14:44 +00:00
public override bool TryAdjustFilePath(bool dump, ColumnMapper columnMapper, ref string filePath)
{
var match = Regex.Match(filePath, @"^thumbs/\d+/\d+/\d+/(?'fileId'\d+)\.jpg$");
if (match.Success)
2020-05-20 15:14:44 +00:00
{
var fileId = columnMapper.GetMapping("files_file", "id", match.Groups["fileId"].Value);
if (fileId == null)
2020-05-20 15:14:44 +00:00
{
if (!dump)
2020-05-20 15:14:44 +00:00
{
return false;
2020-05-20 15:14:44 +00:00
}
fileId = match.Groups["fileId"].Value;
2020-05-20 15:14:44 +00:00
}
var s = fileId.ToString().PadRight(6, '0');
filePath = string.Format("thumbs/{0}/{1}/{2}/{3}.jpg", s.Substring(0, 2), s.Substring(2, 2), s.Substring(4), fileId);
return true;
2020-05-20 15:14:44 +00:00
}
return false;
}
protected override string GetSelectCommandConditionText(int tenantId, TableInfo table)
{
if (table.Name == "projects_project_tag" || table.Name == "projects_following_project_participant")
2020-05-20 15:14:44 +00:00
{
return "inner join projects_projects as t1 on t1.id = t.project_id where t1.tenant_id = " + tenantId;
}
2020-05-20 15:14:44 +00:00
return base.GetSelectCommandConditionText(tenantId, table);
}
protected override bool TryPrepareValue(DbConnection connection, ColumnMapper columnMapper, TableInfo table, string columnName, ref object value)
{
if (table.Name == "projects_comments" && columnName == "content" ||
table.Name == "projects_messages" && columnName == "content")
{
value = FCKEditorPathUtility.CorrectStoragePath(value as string, columnMapper.GetTenantMapping());
return true;
2020-05-20 15:14:44 +00:00
}
return base.TryPrepareValue(connection, columnMapper, table, columnName, ref value);
}
protected override bool TryPrepareValue(DbConnection connection, ColumnMapper columnMapper, RelationInfo relation, ref object value)
{
if (relation.ChildTable == "projects_comments" && relation.ChildColumn == "target_uniq_id")
2020-05-20 15:14:44 +00:00
{
var valParts = value.ToString().Split('_');
2020-05-20 15:14:44 +00:00
var entityId = columnMapper.GetMapping(relation.ParentTable, relation.ParentColumn, valParts[1]);
if (entityId == null)
2020-05-20 15:14:44 +00:00
{
return false;
2020-05-20 15:14:44 +00:00
}
2022-02-09 18:33:50 +00:00
value = string.Format("{0}_{1}", valParts[0], entityId);
return true;
2020-05-20 15:14:44 +00:00
}
return base.TryPrepareValue(connection, columnMapper, relation, ref value);
}
2020-05-20 15:14:44 +00:00
protected override bool TryPrepareValue(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, string columnName, IEnumerable<RelationInfo> relations, ref object value)
{
if (table.Name == "projects_tasks_order" && columnName == "task_order")
{
value = Regex.Replace(
Convert.ToString(value),
@"(?<=""tasks"":\[(\d+,)*)\d+,?",
match =>
2022-02-09 16:46:09 +00:00
{
var mappedId = Convert.ToString(columnMapper.GetMapping("projects_tasks", "id", match.Value.TrimEnd(',')));
2022-01-18 12:40:28 +00:00
return !string.IsNullOrEmpty(mappedId) && match.Value.EndsWith(',') ? mappedId + "," : mappedId;
},
RegexOptions.Compiled);
2022-02-09 18:33:50 +00:00
value = Regex.Replace(
Convert.ToString(value),
@"(?<=""milestones"":\[(\d+,)*)\d+,?",
match =>
{
var mappedId = Convert.ToString(columnMapper.GetMapping("projects_milestones", "id", match.Value.TrimEnd(',')));
Merge branch 'feature/backend-refactor' into feature/asc-backup-core-refactor # Conflicts: # common/ASC.Data.Backup.Core/ActionInvoker.cs # common/ASC.Data.Backup.Core/BackupAjaxHandler.cs # common/ASC.Data.Backup.Core/Core/DbBackupProvider.cs # common/ASC.Data.Backup.Core/Core/DbHelper.cs # common/ASC.Data.Backup.Core/Core/FileBackupProvider.cs # common/ASC.Data.Backup.Core/Core/NotifyHelper.cs # common/ASC.Data.Backup.Core/Core/ZipOperator.cs # common/ASC.Data.Backup.Core/Exceptions/ThrowHelper.cs # common/ASC.Data.Backup.Core/Extensions/EnumerableExtensions.cs # common/ASC.Data.Backup.Core/Service/BackupWorker.cs # common/ASC.Data.Backup.Core/Storage/DocumentsBackupStorage.cs # common/ASC.Data.Backup.Core/Tasks/BackupPortalTask.cs # common/ASC.Data.Backup.Core/Tasks/ColumnMapper.cs # common/ASC.Data.Backup.Core/Tasks/Data/DataRowInfo.cs # common/ASC.Data.Backup.Core/Tasks/Data/TableInfo.cs # common/ASC.Data.Backup.Core/Tasks/DeletePortalTask.cs # common/ASC.Data.Backup.Core/Tasks/KeyHelper.cs # common/ASC.Data.Backup.Core/Tasks/Modules/MailModuleSpecifics.cs # common/ASC.Data.Backup.Core/Tasks/Modules/ModuleProvider.cs # common/ASC.Data.Backup.Core/Tasks/Modules/ModuleSpecificsBase.cs # common/ASC.Data.Backup.Core/Tasks/Modules/ProjectsModuleSpecifics.cs # common/ASC.Data.Backup.Core/Tasks/PortalTaskBase.cs # common/ASC.Data.Backup.Core/Tasks/RestoreDbModuleTask.cs # common/ASC.Data.Backup.Core/Tasks/RestorePortalTask.cs # common/ASC.Data.Backup.Core/Tasks/TransferPortalTask.cs
2022-02-15 16:56:43 +00:00
return !string.IsNullOrEmpty(mappedId) && match.Value.EndsWith(',') ? mappedId + "," : mappedId;
},
RegexOptions.Compiled);
2020-05-20 15:14:44 +00:00
return true;
2020-05-20 15:14:44 +00:00
}
return base.TryPrepareValue(dump, connection, columnMapper, table, columnName, relations, ref value);
2020-05-20 15:14:44 +00:00
}
}