-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
370 changed files
with
4,076 additions
and
3,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/workers/work_packages/progress/apply_statuses_p_complete_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
class WorkPackages::Progress::ApplyStatusesPCompleteJob < WorkPackages::Progress::Job | ||
VALID_CAUSE_TYPES = %w[ | ||
progress_mode_changed_to_status_based | ||
status_p_complete_changed | ||
].freeze | ||
|
||
# Updates % complete and remaining work of all work packages after a status % | ||
# complete value has been changed or the progress calculation mode was set to | ||
# status-based. | ||
# | ||
# It creates a journal entry with the System user describing the change. | ||
# | ||
# @param status_name [String] The cause of the update to be put in the journal | ||
# entry. Must be one of `VALID_CAUSE_TYPES`. | ||
# @param status_name [String] The name of the status to apply. | ||
# @param status_id [Integer] The ID of the status to apply. Not used | ||
# currently, but here in case we need it in a later version. | ||
# @param change [Object] The change object containing an array of [old, new] | ||
# values of the change. | ||
# @return [void] | ||
def perform(cause_type:, status_name: nil, status_id: nil, change: nil) | ||
return if WorkPackage.use_field_for_done_ratio? | ||
|
||
journal_cause = journal_cause_from(cause_type, status_name:, status_id:, change:) | ||
|
||
with_temporary_progress_table do | ||
set_p_complete_from_status | ||
derive_remaining_work_from_work_and_p_complete | ||
update_totals | ||
|
||
copy_progress_values_to_work_packages_and_update_journals(journal_cause) | ||
end | ||
end | ||
|
||
private | ||
|
||
def journal_cause_from(cause_type, status_name:, status_id:, change:) | ||
if VALID_CAUSE_TYPES.exclude?(cause_type) | ||
raise ArgumentError, "Invalid cause type #{cause_type.inspect}. " \ | ||
"Valid values are #{VALID_CAUSE_TYPES.inspect}" | ||
end | ||
|
||
case cause_type | ||
when "progress_mode_changed_to_status_based" | ||
{ type: cause_type } | ||
when "status_p_complete_changed" | ||
raise ArgumentError, "status_name must be provided" if status_name.blank? | ||
raise ArgumentError, "status_id must be provided" if status_id.nil? | ||
raise ArgumentError, "change must be provided" if change.nil? | ||
|
||
{ type: cause_type, status_name:, status_id:, status_p_complete_change: change } | ||
else | ||
raise "Unable to handle cause type #{cause_type.inspect}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
# Base class for jobs updating work packages progress values. | ||
# | ||
# Handles concurrency so that only one progress job is performed at a time. | ||
class WorkPackages::Progress::Job < ApplicationJob | ||
include GoodJob::ActiveJobExtensions::Concurrency | ||
include WorkPackages::Progress::SqlCommands | ||
|
||
queue_with_priority :default | ||
|
||
good_job_control_concurrency_with( | ||
perform_limit: 1, | ||
key: -> { "WorkPackagesProgressJob" } | ||
) | ||
end |
62 changes: 62 additions & 0 deletions
62
app/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
class WorkPackages::Progress::MigrateRemoveTotalsFromChildlessWorkPackagesJob < WorkPackages::Progress::Job | ||
def perform | ||
updated_work_package_ids = remove_totals_from_childless_work_packages | ||
create_journals_for_updated_work_packages(updated_work_package_ids, cause: journal_cause) | ||
end | ||
|
||
private | ||
|
||
def journal_cause | ||
{ type: "system_update", feature: "totals_removed_from_childless_work_packages" } | ||
end | ||
|
||
def remove_totals_from_childless_work_packages | ||
results = execute(<<~SQL.squish) | ||
UPDATE work_packages | ||
SET derived_estimated_hours = NULL, | ||
derived_remaining_hours = NULL, | ||
derived_done_ratio = NULL | ||
WHERE work_packages.id IN ( | ||
SELECT ancestor_id AS id | ||
FROM work_package_hierarchies | ||
GROUP BY id | ||
HAVING MAX(generations) = 0 | ||
) | ||
AND ( | ||
work_packages.derived_estimated_hours IS NOT NULL | ||
OR work_packages.derived_remaining_hours IS NOT NULL | ||
OR work_packages.derived_done_ratio IS NOT NULL | ||
) | ||
RETURNING work_packages.id | ||
SQL | ||
results.column_values(0) | ||
end | ||
end |
Oops, something went wrong.