Skip to content

Commit 570fa4a

Browse files
committed
fbdoc: getpage can use CWikiConSql
1 parent 1daaa13 commit 570fa4a

File tree

5 files changed

+78
-20
lines changed

5 files changed

+78
-20
lines changed

doc/fbchkdoc/getindex.bas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
'' fbdoc headers
2323
#include once "CWikiConUrl.bi"
2424
#include once "CWikiConDir.bi"
25+
26+
#if defined(HAVE_MYSQL)
2527
#include once "CWikiConSql.bi"
28+
#endif
2629

2730
'' fbchkdoc headers
2831
#include once "fbchkdoc.bi"
@@ -113,7 +116,7 @@ sPage = "PageIndex"
113116

114117
dim as CWikiCon ptr wikicon = NULL
115118

116-
'' connect to the wiki and get PageIndex as HTML
119+
'' connect to the wiki and get PageIndex (list of all pages)
117120

118121
if( bLocal ) then
119122

@@ -146,7 +149,6 @@ elseif( bUseSql ) then
146149

147150
#endif
148151
else
149-
150152
cmd_opts_check_url()
151153

152154
if( len( app_opt.wiki_url ) = 0 ) then

doc/fbchkdoc/getpage.bas

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include once "fbdoc_loader.bi"
2525
#include once "fbdoc_loader_web.bi"
2626

27+
#if defined(HAVE_MYSQL)
28+
#include once "CWikiConSql.bi"
29+
#endif
30+
2731
'' fbchkdoc headers
2832
#include once "fbchkdoc.bi"
2933
#include once "funcs.bi"
@@ -42,9 +46,14 @@ using fbdoc
4246

4347
'' private options
4448
dim allow_retry as boolean = true
49+
dim as boolean bUseSql = false '' -usesql given on command line
4550

4651
'' enable url and cache
52+
#if defined(HAVE_MYSQL)
53+
cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_PAGELIST or CMD_OPTS_ENABLE_DATABASE )
54+
#else
4755
cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_PAGELIST )
56+
#endif
4857

4958
dim i as integer = 1
5059
while( command(i) > "" )
@@ -54,6 +63,10 @@ while( command(i) > "" )
5463
select case lcase(command(i))
5564
case "-auto"
5665
allow_retry = false
66+
#if defined(HAVE_MYSQL)
67+
case "-usesql"
68+
bUseSql = true
69+
#endif
5770
case else
5871
cmd_opts_unrecognized_die( i )
5972
end select
@@ -73,14 +86,23 @@ if( app_opt.help ) then
7386
print " -dev+ get pages from the development server in to dev_cache_dir"
7487
print
7588
cmd_opts_show_help( "get page from", false )
89+
#if defined(HAVE_MYSQL)
90+
print " -usesql use MySQL connection to read index"
91+
#endif
7692
print
7793
end 1
7894
end if
7995

8096
cmd_opts_resolve()
8197
cmd_opts_check_cache()
8298
cmd_opts_check_url()
83-
99+
if( len( app_opt.wiki_url ) = 0 ) then
100+
print "wiki_url not set. use -url, -web, -web+, -dev, or -dev+"
101+
end 1
102+
end if
103+
if( bUseSql ) then
104+
cmd_opts_check_database()
105+
end if
84106

85107
'' no pages? nothing to do...
86108
if( app_opt.pageCount = 0 ) then
@@ -96,35 +118,68 @@ redim failedpages(1 to 1) as string
96118
'' main loop - has option to retry/list failed pages
97119
do
98120

121+
dim as CWikiCon ptr wikicon = NULL
122+
99123
'' Initialize the cache
100124
if LocalCache_Create( app_opt.cache_dir, CWikiCache.CACHE_REFRESH_ALL ) = FALSE then
101125
print "Unable to use local cache dir " + app_opt.cache_dir
102126
end 1
103127
end if
104128

105-
'' Initialize the wiki connection
106-
Connection_SetUrl( app_opt.wiki_url, app_opt.ca_file )
107-
108-
print "URL: "; app_opt.wiki_url
109-
if( app_opt.ca_file > "" ) then
110-
print "Certificate: "; app_opt.ca_file
129+
if( bUseSql ) then
130+
#if defined(HAVE_MYSQL)
131+
cmd_opts_check_database()
132+
133+
wikicon = new CWikiConSql( app_opt.db_host, app_opt.db_user, app_opt.db_pass, app_opt.db_name, app_opt.db_port )
134+
if wikicon = NULL then
135+
print "Unable to create connection " + app_opt.cache_dir
136+
end 1
137+
end if
138+
139+
dim as CWikiConSql ptr o = cast( CWikiConSql ptr, wikicon )
140+
if( o->Connect() = FALSE ) then
141+
print "Error"
142+
end 1
143+
end if
144+
#endif
111145
else
112-
print "Certificate: none"
146+
print "URL: "; app_opt.wiki_url
147+
148+
wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file )
149+
if wikicon = NULL then
150+
print "Unable to create connection " + app_opt.wiki_url
151+
end 1
152+
end if
153+
154+
if( app_opt.ca_file > "" ) then
155+
print "Certificate: "; app_opt.ca_file
156+
else
157+
print "Certificate: none"
158+
end if
159+
160+
print "cache: "; app_opt.cache_dir
113161
end if
114-
print "cache: "; app_opt.cache_dir
115162

116163
nfailedpages = 0
117164

118165
if( app_opt.pageCount > 0 ) then
119166
dim as integer i, j
120167
dim as string ret
121168
for i = 1 to app_opt.pageCount
122-
ret = LoadPage( app_opt.pageList(i), FALSE, TRUE )
123-
if( ret = "" ) then
169+
dim sBody as string = ""
170+
print "Loading '" + app_opt.pageList(i) + "'"
171+
if( wikicon->LoadPage( app_opt.pageList(i), sBody ) = FALSE ) then
124172
print "Failed to load '" & app_opt.pageList(i) & "'"
125173
nfailedpages += 1
126174
redim preserve failedpages( 1 to nfailedpages )
127175
failedpages(nfailedpages) = app_opt.pageList(i)
176+
else
177+
if( wikicon->GetPageID() > 0 ) then
178+
if( len(sBody) > 0 ) then
179+
dim as CWikiCache ptr wikicache = LocalCache_Get()
180+
wikicache->SavePage( app_opt.pageList(i), sBody )
181+
end if
182+
end if
128183
end if
129184

130185
if( inkey = chr(27) ) then
@@ -142,7 +197,8 @@ do
142197
next
143198
end if
144199

145-
Connection_Destroy()
200+
delete wikicon
201+
146202
LocalCache_Destroy()
147203

148204
'' Check for failed pages

doc/libfbdoc/CWikiConSql.bas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ namespace fb.fbdoc
289289
return FALSE
290290
end if
291291

292-
sql = "SELECT tag, body FROM wikka_pages WHERE ( latest = 'Y' AND tag = '" & *pagename & "' )"
292+
sql = "SELECT id, tag, CAST(CONVERT(body USING utf8) AS binary) FROM wikka_pages WHERE ( latest = 'Y' AND tag = '" & *pagename & "' )"
293293

294294
if( 0 <> mysql_real_query( ctx->db_conn->db, sql, len(sql)) ) then
295295
return FALSE
@@ -305,7 +305,8 @@ namespace fb.fbdoc
305305
return FALSE
306306
end if
307307

308-
body = *row[1]
308+
ctx->pageid = cint( *row[0] )
309+
body = *row[2]
309310

310311
mysql_free_result( res )
311312

doc/libfbdoc/CWikiConUrl.bas

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ namespace fb.fbdoc
549549

550550
ctx->pageid = get_pageid( ctx )
551551

552-
function = TRUE
552+
function = cbool( ctx->pageid > 0 )
553553

554554
end function
555555

@@ -585,14 +585,13 @@ namespace fb.fbdoc
585585
remove_http_headers( body )
586586
remove_html_tags( body )
587587
extract_page_names( body )
588+
function = TRUE
588589
end if
589590

590591
delete stream
591592

592593
ctx->pageid = -1
593594

594-
function = TRUE
595-
596595
end function
597596

598597
'':::::

doc/libfbdoc/fbdoc_loader_sql.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace fb.fbdoc
7272
return FALSE
7373
end if
7474

75-
sql = "SELECT tag, body FROM wikka_pages WHERE ( latest = 'Y' )"
75+
sql = "SELECT tag, CAST(CONVERT(body USING utf8) AS binary) FROM wikka_pages WHERE ( latest = 'Y' )"
7676

7777
if( 0 <> mysql_real_query( @db, sql, len(sql)) ) then
7878
printlog "Unable to query wikka_pages"

0 commit comments

Comments
 (0)