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
4448dim 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
4755cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_PAGELIST )
56+ # endif
4857
4958dim i as integer = 1
5059while ( 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
7894end if
7995
8096cmd_opts_resolve()
8197cmd_opts_check_cache()
8298cmd_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...
86108if ( 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
97119do
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
142197 next
143198 end if
144199
145- Connection_Destroy()
200+ delete wikicon
201+
146202 LocalCache_Destroy()
147203
148204 '' Check for failed pages
0 commit comments