@@ -15,22 +15,18 @@ public function copyIssueList($src_project_id,$dst_project_id){
1515 }
1616 public function copyIssue ( $ src_issue_id , $ dst_project_id ) {
1717 // ただし、コメント・課題の作成者はAPIの制限で変更が不可能。
18+ // TODO CreatedUserに応じてAPIキーを切り替える。
1819 $ src_issue = $ this ->src_cli ->getIssue ( $ src_issue_id );
19- // ユーザー・種別・マイルストーンを一致させる。
20- $ file_ids = $ this ->getIdMapping ( 'sharedFiles ' );
21- $ user_ids = $ this ->getIdMapping ( 'userIds ' );
22- $ type_ids = $ this ->getIdMapping ( 'typeIds ' );
23- $ version_ids = $ this ->getIdMapping ( 'versionIds ' );
24-
25-
20+ $ user_ids = $ this ->getIdMapping ( 'userIds ' );//TODO ユーザの一致
21+
22+
2623 // 課題をコピー
2724 $ data = $ this ->formatIssue ( $ src_issue );
28- $ data = $ this ->remapiId ( $ data , 'issueTypeId ' , $ type_ids );
29- $ data = $ this ->remapiId ( $ data , 'versionsId ' , $ version_ids );
3025 $ data ['projectId ' ] = $ dst_project_id ;
3126 $ dst_issue = $ this ->dst_cli ->addIssue ( $ data );
27+
3228 // 共有ファイルをリンクし直し
33- $ this ->copyLinkSharedFiles ( $ src_issue , $ dst_issue , $ file_ids );
29+ $ this ->copyLinkSharedFiles ( $ src_issue , $ dst_issue , $ this -> getIdMapping ( ' sharedFiles ' ) );
3430 // 添付ファイルをコピー
3531 $ this ->copyIssueAttachments ( $ src_issue , $ dst_issue );
3632 // 課題の状態を更新して合わせる。
@@ -47,12 +43,41 @@ public function getIdMapping ( $name ) {
4743 // TODO 変数依存を切る。メソッドを作ってメソッド内部で、API取得して比較する。
4844 return $ this ->id_mapping [$ name ];
4945 }
50-
51- protected function formatIssue ( object $ issue_api_result , $ add_user_name = true ,$ assignee ='' ) {
46+ public function remapCustomFieldKeys ($ issue ,$ idMap ){
47+ if (empty ($ issue ->customFields )){
48+ return [];
49+ }
50+ $ map = $ idMap ;
51+ $ custom_fields = $ issue ->customFields ;
52+ $ custom_fields = array_filter ($ custom_fields ,fn ($ c )=>!empty ($ c ->value ));
53+ $ data = [];
54+ foreach ( $ custom_fields as $ idx => $ cf ) {
55+ dump ($ map );
56+ dump ($ cf );
57+ $ data [$ idx ] = [];
58+ $ data [$ idx ]['id ' ] = $ map [$ cf ->id ];
59+ //$data[$idx]['value'] =match ($cf->fieldTypeId){
60+ // 1,2,3,4 => ,
61+ //};
62+ if (!empty ($ cf ->other_value )){
63+ $ data [$ idx ]['other_value ' ] = $ cf ->value ;
64+ }
65+
66+ }
67+ foreach ( $ data as $ id =>$ entry ) {
68+ $ id = $ entry ['id ' ];
69+ $ data ["customField_ {$ id }" ]=$ entry ['value ' ];
70+ if (!empty ($ entry ['other_value ' ])){
71+ $ data ["customField_ {$ id }_otherValue " ]=$ entry ['other_value ' ];
72+ }
73+ }
74+
75+ return $ data ;
76+ }
77+ protected function remapIssueKeys ( object $ issue_api_result , $ add_user_name = true ){
5278 if ( $ add_user_name ) {
5379 $ issue_api_result = $ this ->addUserInfoIntoBody ( $ issue_api_result );
5480 }
55-
5681 $ issue = (array )$ issue_api_result ;
5782 $ keys = [
5883 //'id',
@@ -103,10 +128,26 @@ protected function formatIssue ( object $issue_api_result, $add_user_name = true
103128 $ issue [$ new ] = $ issue [$ old ];
104129 unset( $ issue [$ old ] );
105130 } );
106- if (!empty ($ assignee )){
107- $ issue ->assignee = $ assignee ;
108- }
109131 return $ issue ;
132+
133+ }
134+ protected function formatIssue ( object $ issue_api_result , $ add_user_name = true ) {
135+ $ post_data = $ this ->remapIssueKeys ( $ issue_api_result , $ add_user_name = true );
136+
137+ // ユーザー・種別・マイルストーンを一致させる。
138+ $ type_ids = $ this ->getIdMapping ( 'typeIds ' );
139+ $ version_ids = $ this ->getIdMapping ( 'versionIds ' );
140+ //
141+ $ post_data = $ this ->remapiId ( $ post_data , 'issueTypeId ' , $ type_ids );
142+ $ post_data = $ this ->remapiId ( $ post_data , 'versionsId ' , $ version_ids );
143+ //
144+ $ cf = $ this ->remapCustomFieldKeys ($ issue_api_result ,$ this ->getIdMapping ( 'customFieldIds ' ));
145+ $ post_data = array_merge ($ post_data ,$ cf );
146+ //
147+ if (!empty ($ this ->assignee_user_id )){
148+ $ post_data ['assigneeId ' ] = $ this ->assignee_user_id ;
149+ }
150+ return $ post_data ;
110151 }
111152
112153 protected function addUserInfoIntoBody ( object $ issue_api_result ) {
@@ -185,7 +226,7 @@ protected function updateIssueAttributes ( object $src_issue, object $dst_issue
185226 $ params ['statusId ' ] = $ src_issue ->status ->id ;
186227 }
187228 if ( $ src_issue ->resolution ?->id != $ dst_issue ->resolution ?->id ) {
188- $ params ['resolution ' ] = $ src_issue ->resolution ->id ;
229+ $ params ['resolutionId ' ] = $ src_issue ->resolution ->id ;
189230 }
190231
191232 return !empty ( $ params ) ? $ this ->dst_cli ->updateIssue ( $ dst_issue ->id , $ params ) : $ dst_issue ;
0 commit comments