243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
manifest_clear(&manifest);
createFlag = 0;
}
db_finalize(&q);
}
/*
** Create the subscript interpreter and load the ticket configuration.
*/
void ticket_init(void){
char *zConfig;
Th_FossilInit();
zConfig = db_text((char*)zDefaultTicketConfig,
"SELECT value FROM config WHERE name='ticket-configuration'");
Th_Eval(g.interp, 0, (const uchar*)zConfig, -1);
}
/*
** Recreate the ticket table.
*/
void ticket_create_table(int separateConnection){
char *zSql;
int nSql;
db_multi_exec("DROP TABLE IF EXISTS ticket;");
ticket_init();
zSql = (char*)Th_Fetch("ticket_sql", &nSql);
if( zSql==0 ){
fossil_panic("no ticket_sql defined by ticket configuration");
}
if( separateConnection ){
zSql = mprintf("%.*s", nSql, zSql);
db_init_database(g.zRepositoryName, zSql, 0);
free(zSql);
}else{
db_multi_exec("%.*s", nSql, zSql);
}
}
/*
** Repopulate the ticket table
*/
void ticket_rebuild(void){
Stmt q;
db_begin_transaction();
db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'");
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
int len;
zName += 4;
len = strlen(zName);
|
|
|
|
<
|
<
|
<
<
<
<
<
<
|
>
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
manifest_clear(&manifest);
createFlag = 0;
}
db_finalize(&q);
}
/*
** Create the subscript interpreter and load the "common" code.
*/
void ticket_init(void){
const char *zConfig;
Th_FossilInit();
zConfig = ticket_common_code();
Th_Eval(g.interp, 0, (const uchar*)zConfig, -1);
}
/*
** Recreate the ticket table.
*/
void ticket_create_table(int separateConnection){
const char *zSql;
db_multi_exec("DROP TABLE IF EXISTS ticket;");
zSql = ticket_table_schema();
if( separateConnection ){
db_init_database(g.zRepositoryName, zSql, 0);
}else{
db_multi_exec("%s", zSql);
}
}
/*
** Repopulate the ticket table
*/
void ticket_rebuild(void){
Stmt q;
ticket_create_table(1);
db_begin_transaction();
db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'");
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
int len;
zName += 4;
len = strlen(zName);
|
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/*
** WEBPAGE: tktview
** URL: tktview?name=UUID
**
** View a ticket.
*/
void tktview_page(void){
char *zScript;
int nScript;
login_check_credentials();
if( !g.okRdTkt ){ login_needed(); return; }
if( g.okWrTkt ){
style_submenu_element("Edit", "Edit The Ticket", "%s/tktedit?name=%T",
g.zTop, PD("name",""));
}
style_header("View Ticket");
ticket_init();
initializeVariablesFromDb();
zScript = (char*)Th_Fetch("tktview_template", &nScript);
zScript = mprintf("%.*s", nScript, zScript);
Th_Render(zScript);
style_footer();
}
/*
** TH command: append_field FIELD STRING
**
|
|
<
<
|
|
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/*
** WEBPAGE: tktview
** URL: tktview?name=UUID
**
** View a ticket.
*/
void tktview_page(void){
const char *zScript;
login_check_credentials();
if( !g.okRdTkt ){ login_needed(); return; }
if( g.okWrTkt ){
style_submenu_element("Edit", "Edit The Ticket", "%s/tktedit?name=%T",
g.zTop, PD("name",""));
}
style_header("View Ticket");
ticket_init();
initializeVariablesFromDb();
zScript = ticket_viewpage_code();
Th_Render(zScript);
style_footer();
}
/*
** TH command: append_field FIELD STRING
**
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
** entry page. The /debug_tktnew page is used for debugging the
** tktnew_template in the ticket configuration. /debug_tktnew works
** just like /tktnew except that it does not really save the new ticket
** when you press submit - it just prints the ticket artifact at the
** top of the screen.
*/
void tktnew_page(void){
char *zScript;
int nScript;
char *zNewUuid = 0;
login_check_credentials();
if( !g.okNewTkt ){ login_needed(); return; }
style_header("New Ticket");
ticket_init();
getAllTicketFields();
initializeVariablesFromDb();
initializeVariablesFromCGI();
@ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
zScript = (char*)Th_Fetch("tktnew_template", &nScript);
zScript = mprintf("%.*s", nScript, zScript);
Th_Store("login", g.zLogin);
Th_Store("date", db_text(0, "SELECT datetime('now')"));
Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,
(void*)&zNewUuid, 0);
if( Th_Render(zScript)==TH_RETURN && zNewUuid ){
cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zNewUuid));
return;
|
|
<
<
|
|
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
** entry page. The /debug_tktnew page is used for debugging the
** tktnew_template in the ticket configuration. /debug_tktnew works
** just like /tktnew except that it does not really save the new ticket
** when you press submit - it just prints the ticket artifact at the
** top of the screen.
*/
void tktnew_page(void){
const char *zScript;
char *zNewUuid = 0;
login_check_credentials();
if( !g.okNewTkt ){ login_needed(); return; }
style_header("New Ticket");
ticket_init();
getAllTicketFields();
initializeVariablesFromDb();
initializeVariablesFromCGI();
@ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
zScript = ticket_newpage_code();
Th_Store("login", g.zLogin);
Th_Store("date", db_text(0, "SELECT datetime('now')"));
Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,
(void*)&zNewUuid, 0);
if( Th_Render(zScript)==TH_RETURN && zNewUuid ){
cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zNewUuid));
return;
|
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
}
ticket_init();
getAllTicketFields();
initializeVariablesFromCGI();
initializeVariablesFromDb();
@ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
@ <input type="hidden" name="name" value="%s(zName)">
zScript = (char*)Th_Fetch("tktedit_template", &nScript);
zScript = mprintf("%.*s", nScript, zScript);
Th_Store("login", g.zLogin);
Th_Store("date", db_text(0, "SELECT datetime('now')"));
Th_CreateCommand(g.interp, "append_field", appendRemarkCmd, 0, 0);
Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd, (void*)&zName,0);
if( Th_Render(zScript)==TH_RETURN && zName ){
cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zName));
return;
}
@ </form>
style_footer();
}
/*
** Check the ticket configuration in zConfig to see if it appears to
** be well-formed. If everything is OK, return NULL. If something is
** amiss, then return a pointer to a string (obtained from malloc) that
** describes the problem.
*/
char *ticket_config_check(const char *zConfig){
char *zErr = 0;
const char *z;
int n;
int i;
int rc;
sqlite3 *db;
static const char *azRequired[] = {
"tktnew_template",
"tktview_template",
"tktedit_template",
};
Th_FossilInit();
rc = Th_Eval(g.interp, 0, (const uchar*)zConfig, strlen(zConfig));
if( rc!=TH_OK ){
zErr = (char*)Th_TakeResult(g.interp, 0);
return zErr;
}
for(i=0; i<sizeof(azRequired)/sizeof(azRequired[0]); i++){
z = Th_Fetch(azRequired[i], &n);
if( z==0 ){
zErr = mprintf("missing definition: %s", azRequired[i]);
return zErr;
}
}
z = Th_Fetch("ticket_sql", &n);
if( z==0 ){
zErr = mprintf("missing definition: ticket_sql");
return zErr;
}
rc = sqlite3_open(":memory:", &db);
if( rc==SQLITE_OK ){
char *zSql = mprintf("%.*s", n, z);
rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
if( rc!=SQLITE_OK ){
sqlite3_close(db);
return zErr;
}
/* TODO: verify that the TICKET table exists and has required fields */
sqlite3_close(db);
}
return 0;
}
|
<
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
>
>
>
>
>
>
|
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
}
ticket_init();
getAllTicketFields();
initializeVariablesFromCGI();
initializeVariablesFromDb();
@ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
@ <input type="hidden" name="name" value="%s(zName)">
zScript = ticket_editpage_code();
Th_Store("login", g.zLogin);
Th_Store("date", db_text(0, "SELECT datetime('now')"));
Th_CreateCommand(g.interp, "append_field", appendRemarkCmd, 0, 0);
Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd, (void*)&zName,0);
if( Th_Render(zScript)==TH_RETURN && zName ){
cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zName));
return;
}
@ </form>
style_footer();
}
/*
** Check the ticket table schema in zSchema to see if it appears to
** be well-formed. If everything is OK, return NULL. If something is
** amiss, then return a pointer to a string (obtained from malloc) that
** describes the problem.
*/
char *ticket_schema_check(const char *zSchema){
char *zErr = 0;
int rc;
sqlite3 *db;
rc = sqlite3_open(":memory:", &db);
if( rc==SQLITE_OK ){
rc = sqlite3_exec(db, zSchema, 0, 0, &zErr);
if( rc!=SQLITE_OK ){
sqlite3_close(db);
return zErr;
}
rc = sqlite3_exec(db, "SELECT tkt_id, tkt_uuid, tkt_mtime FROM ticket",
0, 0, 0);
sqlite3_close(db);
if( rc!=SQLITE_OK ){
zErr = mprintf("schema fails to define a valid ticket table "
"containing all required fields");
return zErr;
}
}
return 0;
}
|