| | @@ -881,10 +881,109 @@ |
| 881 | 881 | } |
| 882 | 882 | j++; |
| 883 | 883 | } |
| 884 | 884 | manifest_clear(&other); |
| 885 | 885 | } |
| 886 | + |
| 887 | +/* |
| 888 | +** True if manifest_crosslink_begin() has been called but |
| 889 | +** manifest_crosslink_end() is still pending. |
| 890 | +*/ |
| 891 | +static int manifest_crosslink_busy = 0; |
| 892 | + |
| 893 | +/* |
| 894 | +** Setup to do multiple manifest_crosslink() calls. |
| 895 | +** This is only required if processing ticket changes. |
| 896 | +*/ |
| 897 | +void manifest_crosslink_begin(void){ |
| 898 | + assert( manifest_crosslink_busy==0 ); |
| 899 | + manifest_crosslink_busy = 1; |
| 900 | + db_begin_transaction(); |
| 901 | + db_multi_exec("CREATE TEMP TABLE pending_tkt(uuid TEXT UNIQUE)"); |
| 902 | +} |
| 903 | + |
| 904 | +/* |
| 905 | +** Finish up a sequence of manifest_crosslink calls. |
| 906 | +*/ |
| 907 | +void manifest_crosslink_end(void){ |
| 908 | + Stmt q; |
| 909 | + assert( manifest_crosslink_busy==1 ); |
| 910 | + db_prepare(&q, "SELECT uuid FROM pending_tkt"); |
| 911 | + while( db_step(&q)==SQLITE_ROW ){ |
| 912 | + const char *zUuid = db_column_text(&q, 0); |
| 913 | + ticket_rebuild_entry(zUuid); |
| 914 | + } |
| 915 | + db_finalize(&q); |
| 916 | + db_end_transaction(0); |
| 917 | + manifest_crosslink_busy = 0; |
| 918 | +} |
| 919 | + |
| 920 | +/* |
| 921 | +** Make an entry in the event table for a ticket change artifact. |
| 922 | +*/ |
| 923 | +void manifest_ticket_event( |
| 924 | + int rid, /* Artifact ID of the change ticket artifact */ |
| 925 | + const Manifest *pManifest, /* Parsed content of the artifact */ |
| 926 | + int isNew /* True if this is the first event */ |
| 927 | +){ |
| 928 | + int i; |
| 929 | + char *zTitle; |
| 930 | + Blob comment; |
| 931 | + char *zNewStatus = 0; |
| 932 | + static char *zTitleExpr = 0; |
| 933 | + static char *zStatusColumn = 0; |
| 934 | + static int once = 1; |
| 935 | + |
| 936 | + blob_zero(&comment); |
| 937 | + if( once ){ |
| 938 | + once = 0; |
| 939 | + zTitleExpr = db_get("ticket-title-expr", "title"); |
| 940 | + zStatusColumn = db_get("ticket-status-column", "status"); |
| 941 | + } |
| 942 | + zTitle = db_text("unknown", |
| 943 | + "SELECT %s FROM ticket WHERE tkt_uuid='%s'", |
| 944 | + zTitleExpr, pManifest->zTicketUuid |
| 945 | + ); |
| 946 | + if( !isNew ){ |
| 947 | + for(i=0; i<pManifest->nField; i++){ |
| 948 | + if( strcmp(pManifest->aField[i].zName, zStatusColumn)==0 ){ |
| 949 | + zNewStatus = pManifest->aField[i].zValue; |
| 950 | + } |
| 951 | + } |
| 952 | + if( zNewStatus ){ |
| 953 | + blob_appendf(&comment, "%h ticket [%.10s]: <i>%h</i>", |
| 954 | + zNewStatus, pManifest->zTicketUuid, zTitle |
| 955 | + ); |
| 956 | + if( pManifest->nField>1 ){ |
| 957 | + blob_appendf(&comment, " plus %d other change%s", |
| 958 | + pManifest->nField-1, pManifest->nField==2 ? "" : "s"); |
| 959 | + } |
| 960 | + }else{ |
| 961 | + zNewStatus = db_text("unknown", |
| 962 | + "SELECT %s FROM ticket WHERE tkt_uuid='%s'", |
| 963 | + zStatusColumn, pManifest->zTicketUuid |
| 964 | + ); |
| 965 | + blob_appendf(&comment, "Ticket [%.10s] <i>%h</i> status still %h with " |
| 966 | + "%d other change%s", |
| 967 | + pManifest->zTicketUuid, zTitle, zNewStatus, pManifest->nField, |
| 968 | + pManifest->nField==1 ? "" : "s" |
| 969 | + ); |
| 970 | + free(zNewStatus); |
| 971 | + } |
| 972 | + }else{ |
| 973 | + blob_appendf(&comment, "New ticket [%.10s] <i>%h</i>.", |
| 974 | + pManifest->zTicketUuid, zTitle |
| 975 | + ); |
| 976 | + } |
| 977 | + free(zTitle); |
| 978 | + db_multi_exec( |
| 979 | + "REPLACE INTO event(type,mtime,objid,user,comment)" |
| 980 | + "VALUES('t',%.17g,%d,%Q,%Q)", |
| 981 | + pManifest->rDate, rid, pManifest->zUser, blob_str(&comment) |
| 982 | + ); |
| 983 | + blob_reset(&comment); |
| 984 | +} |
| 886 | 985 | |
| 887 | 986 | /* |
| 888 | 987 | ** Scan artifact rid/pContent to see if it is a control artifact of |
| 889 | 988 | ** any key: |
| 890 | 989 | ** |
| | @@ -1024,72 +1123,18 @@ |
| 1024 | 1123 | TAG_COMMENT, rid |
| 1025 | 1124 | ); |
| 1026 | 1125 | free(zComment); |
| 1027 | 1126 | } |
| 1028 | 1127 | if( m.type==CFTYPE_TICKET ){ |
| 1029 | | - int i; |
| 1030 | | - char *zTitle; |
| 1031 | 1128 | char *zTag; |
| 1032 | | - Blob comment; |
| 1033 | | - char *zNewStatus = 0; |
| 1034 | | - static char *zTitleExpr = 0; |
| 1035 | | - static char *zStatusColumn = 0; |
| 1036 | | - static int once = 1; |
| 1037 | | - int isNew; |
| 1038 | | - |
| 1039 | | - isNew = ticket_insert(&m, 1, 1); |
| 1129 | + |
| 1130 | + assert( manifest_crosslink_busy==1 ); |
| 1040 | 1131 | zTag = mprintf("tkt-%s", m.zTicketUuid); |
| 1041 | 1132 | tag_insert(zTag, 1, 0, rid, m.rDate, rid); |
| 1042 | 1133 | free(zTag); |
| 1043 | | - blob_zero(&comment); |
| 1044 | | - if( once ){ |
| 1045 | | - once = 0; |
| 1046 | | - zTitleExpr = db_get("ticket-title-expr", "title"); |
| 1047 | | - zStatusColumn = db_get("ticket-status-column", "status"); |
| 1048 | | - } |
| 1049 | | - zTitle = db_text("unknown", |
| 1050 | | - "SELECT %s FROM ticket WHERE tkt_uuid='%s'", |
| 1051 | | - zTitleExpr, m.zTicketUuid |
| 1052 | | - ); |
| 1053 | | - if( !isNew ){ |
| 1054 | | - for(i=0; i<m.nField; i++){ |
| 1055 | | - if( strcmp(m.aField[i].zName, zStatusColumn)==0 ){ |
| 1056 | | - zNewStatus = m.aField[i].zValue; |
| 1057 | | - } |
| 1058 | | - } |
| 1059 | | - if( zNewStatus ){ |
| 1060 | | - blob_appendf(&comment, "%h ticket [%.10s]: <i>%h</i>", |
| 1061 | | - zNewStatus, m.zTicketUuid, zTitle |
| 1062 | | - ); |
| 1063 | | - if( m.nField>1 ){ |
| 1064 | | - blob_appendf(&comment, " plus %d other change%s", |
| 1065 | | - m.nField-1, m.nField==2 ? "" : "s"); |
| 1066 | | - } |
| 1067 | | - }else{ |
| 1068 | | - zNewStatus = db_text("unknown", |
| 1069 | | - "SELECT %s FROM ticket WHERE tkt_uuid='%s'", |
| 1070 | | - zStatusColumn, m.zTicketUuid |
| 1071 | | - ); |
| 1072 | | - blob_appendf(&comment, "Ticket [%.10s] <i>%h</i> status still %h with " |
| 1073 | | - "%d other change%s", |
| 1074 | | - m.zTicketUuid, zTitle, zNewStatus, m.nField, |
| 1075 | | - m.nField==1 ? "" : "s" |
| 1076 | | - ); |
| 1077 | | - free(zNewStatus); |
| 1078 | | - } |
| 1079 | | - }else{ |
| 1080 | | - blob_appendf(&comment, "New ticket [%.10s] <i>%h</i>.", |
| 1081 | | - m.zTicketUuid, zTitle |
| 1082 | | - ); |
| 1083 | | - } |
| 1084 | | - free(zTitle); |
| 1085 | | - db_multi_exec( |
| 1086 | | - "REPLACE INTO event(type,mtime,objid,user,comment)" |
| 1087 | | - "VALUES('t',%.17g,%d,%Q,%Q)", |
| 1088 | | - m.rDate, rid, m.zUser, blob_str(&comment) |
| 1089 | | - ); |
| 1090 | | - blob_reset(&comment); |
| 1134 | + db_multi_exec("INSERT OR IGNORE INTO pending_tkt VALUES(%Q)", |
| 1135 | + m.zTicketUuid); |
| 1091 | 1136 | } |
| 1092 | 1137 | db_end_transaction(0); |
| 1093 | 1138 | manifest_clear(&m); |
| 1094 | 1139 | return 1; |
| 1095 | 1140 | } |
| 1096 | 1141 | |