Fossil SCM
Break out the forum thread artificate finder into a separate subroutine where it can be reused.
Commit
96004cd024a30b892aed9a854b3f7b26a09954461016c34d2ee3a99a3ac8ea39
Parent
08ce190f39d8f9f…
1 file changed
+125
-80
+125
-80
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -826,10 +826,134 @@ | ||
| 826 | 826 | } |
| 827 | 827 | fossil_print("\n"); |
| 828 | 828 | } |
| 829 | 829 | forumthread_delete(pThread); |
| 830 | 830 | } |
| 831 | + | |
| 832 | +/* | |
| 833 | +** Fill the TEMP table zTab with the RID of every artifact associated | |
| 834 | +** with the forum thread whose root post is froot. That is the forum | |
| 835 | +** posts themselves, plus any control artifacts that tag those posts, | |
| 836 | +** such as to close or reopen a post or to change the status of the | |
| 837 | +** thread. The table is created if it does not already exist, with | |
| 838 | +** this schema: | |
| 839 | +** | |
| 840 | +** CREATE TEMP TABLE zTab(rid INTEGER PRIMARY KEY, | |
| 841 | +** isCtrl BOOLEAN, zDesc TEXT); | |
| 842 | +** | |
| 843 | +** isCtrl is true for control artifacts. If bDesc is true, then zDesc | |
| 844 | +** is set to an HTML description of the tags that each control artifact | |
| 845 | +** applies to posts in the thread. Otherwise zDesc is left NULL. zDesc | |
| 846 | +** is always NULL for the forum posts themselves. | |
| 847 | +** | |
| 848 | +** If bClear is true, any prior content of zTab is deleted first. | |
| 849 | +** Otherwise, new rows are added to whatever zTab already contains, | |
| 850 | +** and RIDs that are already present are left unchanged. | |
| 851 | +** | |
| 852 | +** Candidate control artifacts come from tagxref.srcid, which only | |
| 853 | +** remembers the most recent tag of each name on each post, and from | |
| 854 | +** the event.comment that manifest_crosslink() generates for each | |
| 855 | +** control artifact, which also finds tags that have since been | |
| 856 | +** superseded. That comment includes a hash prefix of at least 12 | |
| 857 | +** characters for each tagged artifact. Each candidate is then | |
| 858 | +** parsed to verify that it really does tag a post in this thread. | |
| 859 | +** | |
| 860 | +** zTab is inserted into the SQL as-is, so it must be a trusted | |
| 861 | +** identifier, not user input. | |
| 862 | +*/ | |
| 863 | +void forum_thread_artifacts( | |
| 864 | + const char *zTab, /* Name of the TEMP table to fill */ | |
| 865 | + int froot, /* RID of the root post of the thread */ | |
| 866 | + int bClear, /* True to delete prior content of zTab first */ | |
| 867 | + int bDesc /* True to fill in zDesc for control artifacts */ | |
| 868 | +){ | |
| 869 | + Stmt q; | |
| 870 | + db_multi_exec( | |
| 871 | + "CREATE TEMP TABLE IF NOT EXISTS \"%w\"(" | |
| 872 | + " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);", | |
| 873 | + zTab | |
| 874 | + ); | |
| 875 | + if( bClear ){ | |
| 876 | + db_multi_exec("DELETE FROM \"%w\";", zTab); | |
| 877 | + } | |
| 878 | + db_multi_exec( | |
| 879 | + "INSERT OR IGNORE INTO \"%w\"(rid,isCtrl)" | |
| 880 | + " SELECT fpid, 0 FROM forumpost WHERE froot=%d;", | |
| 881 | + zTab, froot | |
| 882 | + ); | |
| 883 | + | |
| 884 | + /* Find candidate control artifacts. Each one is verified before | |
| 885 | + ** being added, and candidates already in zTab are skipped, so that | |
| 886 | + ** when bClear is false, rows that were already in zTab are not | |
| 887 | + ** disturbed. */ | |
| 888 | + db_prepare(&q, | |
| 889 | + "SELECT srcid FROM tagxref" | |
| 890 | + " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)" | |
| 891 | + " AND srcid>0 AND srcid!=rid" | |
| 892 | + " UNION " | |
| 893 | + "SELECT event.objid FROM event, forumpost, blob" | |
| 894 | + " WHERE forumpost.froot=%d" | |
| 895 | + " AND blob.rid=forumpost.fpid" | |
| 896 | + " AND event.type='g'" | |
| 897 | + " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0" | |
| 898 | + " AND event.mtime >= forumpost.fmtime-0.01" | |
| 899 | + " AND event.mtime <= (SELECT max(mtime) FROM tagxref" | |
| 900 | + " WHERE rid=%d)", | |
| 901 | + froot, froot, froot | |
| 902 | + ); | |
| 903 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 904 | + int rid = db_column_int(&q, 0); | |
| 905 | + Manifest *pCtrl; | |
| 906 | + Blob desc = BLOB_INITIALIZER; | |
| 907 | + int nMatch = 0; | |
| 908 | + int i; | |
| 909 | + if( db_exists("SELECT 1 FROM \"%w\" WHERE rid=%d", zTab, rid) ){ | |
| 910 | + continue; | |
| 911 | + } | |
| 912 | + pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0); | |
| 913 | + for(i=0; pCtrl && i<pCtrl->nTag; i++){ | |
| 914 | + const char *zTag = pCtrl->aTag[i].zName; | |
| 915 | + const char *zVal = pCtrl->aTag[i].zValue; | |
| 916 | + const char *zTarget = pCtrl->aTag[i].zUuid; | |
| 917 | + int isCancel = zTag[0]=='-'; | |
| 918 | + if( zTarget==0 | |
| 919 | + || !db_exists("SELECT 1 FROM forumpost, blob" | |
| 920 | + " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid" | |
| 921 | + " AND blob.uuid=%Q", froot, zTarget) | |
| 922 | + ){ | |
| 923 | + continue; | |
| 924 | + } | |
| 925 | + nMatch++; | |
| 926 | + if( !bDesc ) break; | |
| 927 | + if( blob_size(&desc) ) blob_append(&desc, "; ", 2); | |
| 928 | + if( fossil_strcmp(&zTag[1], "closed")==0 ){ | |
| 929 | + blob_append(&desc, isCancel ? "reopen" : "close", -1); | |
| 930 | + }else if( fossil_strcmp(&zTag[1], "status")==0 ){ | |
| 931 | + if( isCancel || zVal==0 || zVal[0]==0 ){ | |
| 932 | + blob_append(&desc, "clear status of", -1); | |
| 933 | + }else{ | |
| 934 | + blob_appendf(&desc, "set status \"%h\" on", zVal); | |
| 935 | + } | |
| 936 | + }else if( zVal && zVal[0] ){ | |
| 937 | + blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal); | |
| 938 | + }else{ | |
| 939 | + blob_appendf(&desc, "tag %h on", zTag); | |
| 940 | + } | |
| 941 | + blob_appendf(&desc, " post %z%S</a>", | |
| 942 | + href("%R/forumpost/%!S", zTarget), zTarget); | |
| 943 | + } | |
| 944 | + manifest_destroy(pCtrl); | |
| 945 | + if( nMatch ){ | |
| 946 | + db_multi_exec( | |
| 947 | + "INSERT INTO \"%w\"(rid,isCtrl,zDesc) VALUES(%d,1,%Q)", | |
| 948 | + zTab, rid, bDesc ? blob_str(&desc) : 0 | |
| 949 | + ); | |
| 950 | + } | |
| 951 | + blob_reset(&desc); | |
| 952 | + } | |
| 953 | + db_finalize(&q); | |
| 954 | +} | |
| 831 | 955 | |
| 832 | 956 | /* |
| 833 | 957 | ** WEBPAGE: forumthreadhashlist |
| 834 | 958 | ** |
| 835 | 959 | ** Usage: /forumthreadhashlist/HASH-OF-ROOT |
| @@ -869,90 +993,11 @@ | ||
| 869 | 993 | } |
| 870 | 994 | fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot); |
| 871 | 995 | style_set_current_feature("forum"); |
| 872 | 996 | style_header("Artifacts Of Forum Thread"); |
| 873 | 997 | |
| 874 | - /* The fthread table holds the RID of every artifact associated with | |
| 875 | - ** the thread. That is the forum posts themselves, plus any control | |
| 876 | - ** artifacts that tag those posts, such as to close or reopen a post | |
| 877 | - ** or to change the status of the thread. For control artifacts, | |
| 878 | - ** zDesc is an HTML description of the tags applied. | |
| 879 | - ** | |
| 880 | - ** Candidate control artifacts come from tagxref.srcid, which only | |
| 881 | - ** remembers the most recent tag of each name on each post, and from | |
| 882 | - ** the event.comment that manifest_crosslink() generates for each | |
| 883 | - ** control artifact, which also finds tags that have since been | |
| 884 | - ** superseded. That comment includes a hash prefix of at least 12 | |
| 885 | - ** characters for each tagged artifact. Each candidate is then | |
| 886 | - ** parsed to verify that it really does tag a post in this thread. | |
| 887 | - */ | |
| 888 | - db_multi_exec( | |
| 889 | - "CREATE TEMP TABLE IF NOT EXISTS fthread(" | |
| 890 | - " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);" | |
| 891 | - "DELETE FROM fthread;" | |
| 892 | - "INSERT OR IGNORE INTO fthread(rid,isCtrl)" | |
| 893 | - " SELECT fpid, 0 FROM forumpost WHERE froot=%d;" | |
| 894 | - "INSERT OR IGNORE INTO fthread(rid,isCtrl)" | |
| 895 | - " SELECT srcid, 1 FROM tagxref" | |
| 896 | - " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)" | |
| 897 | - " AND srcid>0 AND srcid!=rid;" | |
| 898 | - "INSERT OR IGNORE INTO fthread(rid,isCtrl)" | |
| 899 | - " SELECT event.objid, 1 FROM event, forumpost, blob" | |
| 900 | - " WHERE forumpost.froot=%d" | |
| 901 | - " AND blob.rid=forumpost.fpid" | |
| 902 | - " AND event.type='g'" | |
| 903 | - " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0" | |
| 904 | - " AND event.mtime >= forumpost.fmtime-0.01" | |
| 905 | - " AND event.mtime <= (SELECT max(mtime) FROM tagxref" | |
| 906 | - " WHERE rid=%d);", | |
| 907 | - froot, froot, froot, froot | |
| 908 | - ); | |
| 909 | - db_prepare(&q, "SELECT rid FROM fthread WHERE isCtrl"); | |
| 910 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 911 | - int rid = db_column_int(&q, 0); | |
| 912 | - Manifest *pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0); | |
| 913 | - Blob desc = BLOB_INITIALIZER; | |
| 914 | - int i; | |
| 915 | - for(i=0; pCtrl && i<pCtrl->nTag; i++){ | |
| 916 | - const char *zTag = pCtrl->aTag[i].zName; | |
| 917 | - const char *zVal = pCtrl->aTag[i].zValue; | |
| 918 | - const char *zTarget = pCtrl->aTag[i].zUuid; | |
| 919 | - int isCancel = zTag[0]=='-'; | |
| 920 | - if( zTarget==0 | |
| 921 | - || !db_exists("SELECT 1 FROM forumpost, blob" | |
| 922 | - " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid" | |
| 923 | - " AND blob.uuid=%Q", froot, zTarget) | |
| 924 | - ){ | |
| 925 | - continue; | |
| 926 | - } | |
| 927 | - if( blob_size(&desc) ) blob_append(&desc, "; ", 2); | |
| 928 | - if( fossil_strcmp(&zTag[1], "closed")==0 ){ | |
| 929 | - blob_append(&desc, isCancel ? "reopen" : "close", -1); | |
| 930 | - }else if( fossil_strcmp(&zTag[1], "status")==0 ){ | |
| 931 | - if( isCancel || zVal==0 || zVal[0]==0 ){ | |
| 932 | - blob_append(&desc, "clear status of", -1); | |
| 933 | - }else{ | |
| 934 | - blob_appendf(&desc, "set status \"%h\" on", zVal); | |
| 935 | - } | |
| 936 | - }else if( zVal && zVal[0] ){ | |
| 937 | - blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal); | |
| 938 | - }else{ | |
| 939 | - blob_appendf(&desc, "tag %h on", zTag); | |
| 940 | - } | |
| 941 | - blob_appendf(&desc, " post %z%S</a>", | |
| 942 | - href("%R/forumpost/%!S", zTarget), zTarget); | |
| 943 | - } | |
| 944 | - manifest_destroy(pCtrl); | |
| 945 | - if( blob_size(&desc)==0 ){ | |
| 946 | - db_multi_exec("DELETE FROM fthread WHERE rid=%d", rid); | |
| 947 | - }else{ | |
| 948 | - db_multi_exec("UPDATE fthread SET zDesc=%Q WHERE rid=%d", | |
| 949 | - blob_str(&desc), rid); | |
| 950 | - } | |
| 951 | - blob_reset(&desc); | |
| 952 | - } | |
| 953 | - db_finalize(&q); | |
| 998 | + forum_thread_artifacts("fthread", froot, 1, 1); | |
| 954 | 999 | describe_artifacts("IN (SELECT rid FROM fthread)"); |
| 955 | 1000 | |
| 956 | 1001 | @ <h2> |
| 957 | 1002 | @ Artifacts associated with the forum thread |
| 958 | 1003 | @ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2> |
| 959 | 1004 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -826,10 +826,134 @@ | |
| 826 | } |
| 827 | fossil_print("\n"); |
| 828 | } |
| 829 | forumthread_delete(pThread); |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | ** WEBPAGE: forumthreadhashlist |
| 834 | ** |
| 835 | ** Usage: /forumthreadhashlist/HASH-OF-ROOT |
| @@ -869,90 +993,11 @@ | |
| 869 | } |
| 870 | fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot); |
| 871 | style_set_current_feature("forum"); |
| 872 | style_header("Artifacts Of Forum Thread"); |
| 873 | |
| 874 | /* The fthread table holds the RID of every artifact associated with |
| 875 | ** the thread. That is the forum posts themselves, plus any control |
| 876 | ** artifacts that tag those posts, such as to close or reopen a post |
| 877 | ** or to change the status of the thread. For control artifacts, |
| 878 | ** zDesc is an HTML description of the tags applied. |
| 879 | ** |
| 880 | ** Candidate control artifacts come from tagxref.srcid, which only |
| 881 | ** remembers the most recent tag of each name on each post, and from |
| 882 | ** the event.comment that manifest_crosslink() generates for each |
| 883 | ** control artifact, which also finds tags that have since been |
| 884 | ** superseded. That comment includes a hash prefix of at least 12 |
| 885 | ** characters for each tagged artifact. Each candidate is then |
| 886 | ** parsed to verify that it really does tag a post in this thread. |
| 887 | */ |
| 888 | db_multi_exec( |
| 889 | "CREATE TEMP TABLE IF NOT EXISTS fthread(" |
| 890 | " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);" |
| 891 | "DELETE FROM fthread;" |
| 892 | "INSERT OR IGNORE INTO fthread(rid,isCtrl)" |
| 893 | " SELECT fpid, 0 FROM forumpost WHERE froot=%d;" |
| 894 | "INSERT OR IGNORE INTO fthread(rid,isCtrl)" |
| 895 | " SELECT srcid, 1 FROM tagxref" |
| 896 | " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)" |
| 897 | " AND srcid>0 AND srcid!=rid;" |
| 898 | "INSERT OR IGNORE INTO fthread(rid,isCtrl)" |
| 899 | " SELECT event.objid, 1 FROM event, forumpost, blob" |
| 900 | " WHERE forumpost.froot=%d" |
| 901 | " AND blob.rid=forumpost.fpid" |
| 902 | " AND event.type='g'" |
| 903 | " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0" |
| 904 | " AND event.mtime >= forumpost.fmtime-0.01" |
| 905 | " AND event.mtime <= (SELECT max(mtime) FROM tagxref" |
| 906 | " WHERE rid=%d);", |
| 907 | froot, froot, froot, froot |
| 908 | ); |
| 909 | db_prepare(&q, "SELECT rid FROM fthread WHERE isCtrl"); |
| 910 | while( db_step(&q)==SQLITE_ROW ){ |
| 911 | int rid = db_column_int(&q, 0); |
| 912 | Manifest *pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0); |
| 913 | Blob desc = BLOB_INITIALIZER; |
| 914 | int i; |
| 915 | for(i=0; pCtrl && i<pCtrl->nTag; i++){ |
| 916 | const char *zTag = pCtrl->aTag[i].zName; |
| 917 | const char *zVal = pCtrl->aTag[i].zValue; |
| 918 | const char *zTarget = pCtrl->aTag[i].zUuid; |
| 919 | int isCancel = zTag[0]=='-'; |
| 920 | if( zTarget==0 |
| 921 | || !db_exists("SELECT 1 FROM forumpost, blob" |
| 922 | " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid" |
| 923 | " AND blob.uuid=%Q", froot, zTarget) |
| 924 | ){ |
| 925 | continue; |
| 926 | } |
| 927 | if( blob_size(&desc) ) blob_append(&desc, "; ", 2); |
| 928 | if( fossil_strcmp(&zTag[1], "closed")==0 ){ |
| 929 | blob_append(&desc, isCancel ? "reopen" : "close", -1); |
| 930 | }else if( fossil_strcmp(&zTag[1], "status")==0 ){ |
| 931 | if( isCancel || zVal==0 || zVal[0]==0 ){ |
| 932 | blob_append(&desc, "clear status of", -1); |
| 933 | }else{ |
| 934 | blob_appendf(&desc, "set status \"%h\" on", zVal); |
| 935 | } |
| 936 | }else if( zVal && zVal[0] ){ |
| 937 | blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal); |
| 938 | }else{ |
| 939 | blob_appendf(&desc, "tag %h on", zTag); |
| 940 | } |
| 941 | blob_appendf(&desc, " post %z%S</a>", |
| 942 | href("%R/forumpost/%!S", zTarget), zTarget); |
| 943 | } |
| 944 | manifest_destroy(pCtrl); |
| 945 | if( blob_size(&desc)==0 ){ |
| 946 | db_multi_exec("DELETE FROM fthread WHERE rid=%d", rid); |
| 947 | }else{ |
| 948 | db_multi_exec("UPDATE fthread SET zDesc=%Q WHERE rid=%d", |
| 949 | blob_str(&desc), rid); |
| 950 | } |
| 951 | blob_reset(&desc); |
| 952 | } |
| 953 | db_finalize(&q); |
| 954 | describe_artifacts("IN (SELECT rid FROM fthread)"); |
| 955 | |
| 956 | @ <h2> |
| 957 | @ Artifacts associated with the forum thread |
| 958 | @ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2> |
| 959 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -826,10 +826,134 @@ | |
| 826 | } |
| 827 | fossil_print("\n"); |
| 828 | } |
| 829 | forumthread_delete(pThread); |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | ** Fill the TEMP table zTab with the RID of every artifact associated |
| 834 | ** with the forum thread whose root post is froot. That is the forum |
| 835 | ** posts themselves, plus any control artifacts that tag those posts, |
| 836 | ** such as to close or reopen a post or to change the status of the |
| 837 | ** thread. The table is created if it does not already exist, with |
| 838 | ** this schema: |
| 839 | ** |
| 840 | ** CREATE TEMP TABLE zTab(rid INTEGER PRIMARY KEY, |
| 841 | ** isCtrl BOOLEAN, zDesc TEXT); |
| 842 | ** |
| 843 | ** isCtrl is true for control artifacts. If bDesc is true, then zDesc |
| 844 | ** is set to an HTML description of the tags that each control artifact |
| 845 | ** applies to posts in the thread. Otherwise zDesc is left NULL. zDesc |
| 846 | ** is always NULL for the forum posts themselves. |
| 847 | ** |
| 848 | ** If bClear is true, any prior content of zTab is deleted first. |
| 849 | ** Otherwise, new rows are added to whatever zTab already contains, |
| 850 | ** and RIDs that are already present are left unchanged. |
| 851 | ** |
| 852 | ** Candidate control artifacts come from tagxref.srcid, which only |
| 853 | ** remembers the most recent tag of each name on each post, and from |
| 854 | ** the event.comment that manifest_crosslink() generates for each |
| 855 | ** control artifact, which also finds tags that have since been |
| 856 | ** superseded. That comment includes a hash prefix of at least 12 |
| 857 | ** characters for each tagged artifact. Each candidate is then |
| 858 | ** parsed to verify that it really does tag a post in this thread. |
| 859 | ** |
| 860 | ** zTab is inserted into the SQL as-is, so it must be a trusted |
| 861 | ** identifier, not user input. |
| 862 | */ |
| 863 | void forum_thread_artifacts( |
| 864 | const char *zTab, /* Name of the TEMP table to fill */ |
| 865 | int froot, /* RID of the root post of the thread */ |
| 866 | int bClear, /* True to delete prior content of zTab first */ |
| 867 | int bDesc /* True to fill in zDesc for control artifacts */ |
| 868 | ){ |
| 869 | Stmt q; |
| 870 | db_multi_exec( |
| 871 | "CREATE TEMP TABLE IF NOT EXISTS \"%w\"(" |
| 872 | " rid INTEGER PRIMARY KEY, isCtrl BOOLEAN, zDesc TEXT);", |
| 873 | zTab |
| 874 | ); |
| 875 | if( bClear ){ |
| 876 | db_multi_exec("DELETE FROM \"%w\";", zTab); |
| 877 | } |
| 878 | db_multi_exec( |
| 879 | "INSERT OR IGNORE INTO \"%w\"(rid,isCtrl)" |
| 880 | " SELECT fpid, 0 FROM forumpost WHERE froot=%d;", |
| 881 | zTab, froot |
| 882 | ); |
| 883 | |
| 884 | /* Find candidate control artifacts. Each one is verified before |
| 885 | ** being added, and candidates already in zTab are skipped, so that |
| 886 | ** when bClear is false, rows that were already in zTab are not |
| 887 | ** disturbed. */ |
| 888 | db_prepare(&q, |
| 889 | "SELECT srcid FROM tagxref" |
| 890 | " WHERE rid IN (SELECT fpid FROM forumpost WHERE froot=%d)" |
| 891 | " AND srcid>0 AND srcid!=rid" |
| 892 | " UNION " |
| 893 | "SELECT event.objid FROM event, forumpost, blob" |
| 894 | " WHERE forumpost.froot=%d" |
| 895 | " AND blob.rid=forumpost.fpid" |
| 896 | " AND event.type='g'" |
| 897 | " AND instr(event.comment, '['||substr(blob.uuid,1,12))>0" |
| 898 | " AND event.mtime >= forumpost.fmtime-0.01" |
| 899 | " AND event.mtime <= (SELECT max(mtime) FROM tagxref" |
| 900 | " WHERE rid=%d)", |
| 901 | froot, froot, froot |
| 902 | ); |
| 903 | while( db_step(&q)==SQLITE_ROW ){ |
| 904 | int rid = db_column_int(&q, 0); |
| 905 | Manifest *pCtrl; |
| 906 | Blob desc = BLOB_INITIALIZER; |
| 907 | int nMatch = 0; |
| 908 | int i; |
| 909 | if( db_exists("SELECT 1 FROM \"%w\" WHERE rid=%d", zTab, rid) ){ |
| 910 | continue; |
| 911 | } |
| 912 | pCtrl = manifest_get(rid, CFTYPE_CONTROL, 0); |
| 913 | for(i=0; pCtrl && i<pCtrl->nTag; i++){ |
| 914 | const char *zTag = pCtrl->aTag[i].zName; |
| 915 | const char *zVal = pCtrl->aTag[i].zValue; |
| 916 | const char *zTarget = pCtrl->aTag[i].zUuid; |
| 917 | int isCancel = zTag[0]=='-'; |
| 918 | if( zTarget==0 |
| 919 | || !db_exists("SELECT 1 FROM forumpost, blob" |
| 920 | " WHERE forumpost.froot=%d AND blob.rid=forumpost.fpid" |
| 921 | " AND blob.uuid=%Q", froot, zTarget) |
| 922 | ){ |
| 923 | continue; |
| 924 | } |
| 925 | nMatch++; |
| 926 | if( !bDesc ) break; |
| 927 | if( blob_size(&desc) ) blob_append(&desc, "; ", 2); |
| 928 | if( fossil_strcmp(&zTag[1], "closed")==0 ){ |
| 929 | blob_append(&desc, isCancel ? "reopen" : "close", -1); |
| 930 | }else if( fossil_strcmp(&zTag[1], "status")==0 ){ |
| 931 | if( isCancel || zVal==0 || zVal[0]==0 ){ |
| 932 | blob_append(&desc, "clear status of", -1); |
| 933 | }else{ |
| 934 | blob_appendf(&desc, "set status \"%h\" on", zVal); |
| 935 | } |
| 936 | }else if( zVal && zVal[0] ){ |
| 937 | blob_appendf(&desc, "tag %h=\"%h\" on", zTag, zVal); |
| 938 | }else{ |
| 939 | blob_appendf(&desc, "tag %h on", zTag); |
| 940 | } |
| 941 | blob_appendf(&desc, " post %z%S</a>", |
| 942 | href("%R/forumpost/%!S", zTarget), zTarget); |
| 943 | } |
| 944 | manifest_destroy(pCtrl); |
| 945 | if( nMatch ){ |
| 946 | db_multi_exec( |
| 947 | "INSERT INTO \"%w\"(rid,isCtrl,zDesc) VALUES(%d,1,%Q)", |
| 948 | zTab, rid, bDesc ? blob_str(&desc) : 0 |
| 949 | ); |
| 950 | } |
| 951 | blob_reset(&desc); |
| 952 | } |
| 953 | db_finalize(&q); |
| 954 | } |
| 955 | |
| 956 | /* |
| 957 | ** WEBPAGE: forumthreadhashlist |
| 958 | ** |
| 959 | ** Usage: /forumthreadhashlist/HASH-OF-ROOT |
| @@ -869,90 +993,11 @@ | |
| 993 | } |
| 994 | fuuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", froot); |
| 995 | style_set_current_feature("forum"); |
| 996 | style_header("Artifacts Of Forum Thread"); |
| 997 | |
| 998 | forum_thread_artifacts("fthread", froot, 1, 1); |
| 999 | describe_artifacts("IN (SELECT rid FROM fthread)"); |
| 1000 | |
| 1001 | @ <h2> |
| 1002 | @ Artifacts associated with the forum thread |
| 1003 | @ <a href="%R/forumthread/%S(fuuid)">%S(fuuid)</a>:</h2> |
| 1004 |