Moving tasks - Internal dependencies fix

Moving tasks with internal dependencies from a logical container to
another will now work, as the dependencies will be re-added
automatically.
This commit is contained in:
Emmanuel BENOîT 2016-01-04 11:29:48 +01:00
parent f23e1e94eb
commit c69abbe2b3

View file

@ -94,7 +94,9 @@ BEGIN
END IF;
-- If we're changing the LTC, handle dependencies.
IF _ltc_source <> _ltc_dest AND NOT _force THEN
IF _ltc_source <> _ltc_dest THEN
-- Start with external dependencies
IF NOT _force THEN
-- Check them if we're not forcing the move.
PERFORM _tdn.task_id
FROM taskdep_nodes _tdn
@ -106,7 +108,7 @@ BEGIN
IF FOUND THEN
RETURN 5;
END IF;
ELSIF _ltc_source <> _ltc_dest AND _force THEN
ELSE
-- Otherwise, break them.
DELETE FROM task_dependencies
WHERE taskdep_id IN (
@ -120,6 +122,23 @@ BEGIN
);
END IF;
-- Store all internal dependencies, we'll recreate them after
-- the tasks have been moved.
SET LOCAL client_min_messages=warning;
DROP TABLE IF EXISTS _tm_deps;
RESET client_min_messages;
CREATE TEMPORARY TABLE _tm_deps(
task_id INT ,
task_id_depends INT
) ON COMMIT DROP;
INSERT INTO _tm_deps ( task_id , task_id_depends )
SELECT task_id , task_id_depends
FROM task_dependencies
INNER JOIN _tm_tasks USING ( task_id );
DELETE FROM task_dependencies
WHERE task_id IN ( SELECT task_id FROM _tm_tasks );
END IF;
-- We're ready to move the tasks themselves.
IF _toTask THEN
SELECT INTO _i item_id FROM tasks WHERE task_id = _toId;
@ -131,6 +150,13 @@ BEGIN
SELECT task_id FROM _tm_tasks
);
-- Restore deleted dependencies
IF _ltc_dest <> _ltc_source THEN
INSERT INTO task_dependencies ( task_id , task_id_depends , ltc_id )
SELECT task_id , task_id_depends , _ltc_dest
FROM _tm_deps;
END IF;
RETURN 0;
END;
$tasks_move$;