Changeset 11998 for trunk/gsdl/src/recpt/collectoraction.cpp
- Timestamp:
- 2006-07-04T15:23:58+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/collectoraction.cpp
r11166 r11998 56 56 #endif 57 57 58 collectoraction::collectoraction () { 59 60 recpt = NULL; 61 disabled = true; 58 collectoraction::collectoraction () 59 : wizardaction() 60 { 61 macro_prefix = "bc1"; 62 62 63 do_mkcol = false; 63 64 badsources = false; 64 65 failedsources.erase(failedsources.begin(), failedsources.end()); 65 gsdlosc = NULL;66 gsdlhomec = NULL;67 pathc = NULL;68 66 69 67 cgiarginfo arg_ainfo; … … 245 243 246 244 collectoraction::~collectoraction () { 247 if (gsdlosc != NULL) delete []gsdlosc;248 if (gsdlhomec != NULL) delete []gsdlhomec;249 if (pathc != NULL) delete []pathc;250 245 } 251 246 252 247 253 void collectoraction::configure (const text_t &key, const text_tarray &cfgline) {254 if ((key == "collector") && (cfgline.size() == 1) &&255 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {256 disabled = false;257 } else {258 // call the parent class to deal with the things which259 // are not dealt with here260 action::configure (key, cfgline);261 }262 }263 264 265 bool collectoraction::init (ostream & /*logout*/) {266 267 // set up GSDLOS, GSDLHOME and PATH environment variables268 text_t gsdlos, path;269 unsigned int path_separator = ':';270 #if defined (__WIN32__)271 gsdlos = "windows";272 path_separator = ';';273 274 path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;");275 276 #else277 struct utsname *buf = new struct utsname();278 int i = uname (buf);279 if (i == -1) gsdlos = "linux"; // uname failed280 else gsdlos.setcstr (buf->sysname);281 delete buf;282 lc (gsdlos);283 #endif284 285 pathc = getenv ("PATH");286 path += filename_cat (gsdlhome, "bin", gsdlos);287 path.push_back (path_separator);288 path += filename_cat (gsdlhome, "bin", "script");289 if (pathc != NULL) {290 path.push_back (path_separator);291 path += pathc;292 }293 path = "PATH=" + path;294 295 gsdlos = "GSDLOS=" + gsdlos;296 text_t setgsdlhome = "GSDLHOME=" + gsdlhome;297 298 // these will be cleaned up in the destructor299 gsdlosc = gsdlos.getcstr();300 gsdlhomec = setgsdlhome.getcstr();301 pathc = path.getcstr();302 303 putenv (gsdlosc);304 putenv (gsdlhomec);305 putenv (pathc);306 307 return true;308 }309 248 310 249 bool collectoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, … … 335 274 // clean up any old builds left laying about in the tmp directory 336 275 // (note that it's possible this could take some time if there's a huge 337 // partially built collect ion laying about so we'll make it an asynchronous276 // partially built collecton laying about so we'll make it an asynchronous 338 277 // system call) 339 278 gsdl_system ("perl -S cleantmp.pl", false, logout); … … 710 649 } 711 650 712 void collectoraction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,713 response_t &response,text_t &response_data,714 ostream &/*logout*/) {715 response = content;716 response_data = "text/html";717 }718 651 719 652 // return html for buttons used in collector bar … … 728 661 // will be hyperlinked 729 662 730 text_t collectoraction::get_button(const text_t &thispage, const text_t &color, 731 const text_t &type, bool enabled) { 732 733 if ((color != "green" && color != "grey" && color != "yellow") || 734 (type != "info" && type != "srce" && type != "conf" && type != "bild" && type != "view")) 735 return g_EmptyText; 736 737 text_t href = "_http"+type+"_"; 738 text_t target = ""; 739 if (thispage == "info" || thispage == "srce" || thispage == "conf" || 740 thispage == "bildcancel" || thispage == "bildfail") { 741 // call the check submit macro instead of linking directly to the page 742 href="\"javascript:check_submit('"+type+"');\""; 743 } else if (type == "view") { 744 // view button is special case as it needs a target=_top 745 target = " target=_top"; 746 } 747 748 text_t tdclass = "collectorbar"+color; 749 if (enabled) { 750 // link to the appropriate page 751 return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>"; 752 } 753 else { 754 // just display the text 755 return "<td class="+tdclass+">_text"+type+"_</td>"; 756 } 757 } 758 663 // Wendy left a comment suggesting this be move, but where to 664 // was not specified. Into wizardaction.cpp? 759 665 760 666 // set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if … … 771 677 772 678 text_t ¤t_page = args["p"]; 773 text_t currentname = args[ "bc1dirname"];774 if (current_page == "srce") currentname = args[ "bc1clonecol"];679 text_t currentname = args[macro_prefix+"dirname"]; 680 if (current_page == "srce") currentname = args[macro_prefix + "clonecol"]; 775 681 776 682 text_tarray dirnames; … … 825 731 826 732 bool first = true; 733 827 734 text_t warnindex; 828 text_t fullnamemenu = "<select name=\"bc1dirname\">\n"; 735 text_t fullnamemenu = "<select name=\""+macro_prefix+"dirname\" onChange=\"menuchange();\">\n"; 736 829 737 if (current_page == "srce") { 830 fullnamemenu = "<select name=\" bc1clonecol\" onChange=\"menuchange();\">\n";738 fullnamemenu = "<select name=\""+macro_prefix+"clonecol\" onChange=\"menuchange();\">\n"; 831 739 fullnamemenu += "<option value=defaultstructure"; 832 740 if (!is_selected) fullnamemenu += " selected>"; … … 834 742 fullnamemenu += "_collector:textdefaultstructure_\n"; 835 743 } 744 745 fullnamemenu += "<option value=\"\"></option>\n"; 746 836 747 for (int i = 0; i < index; ++i) { 837 748 // don't want write protected collections in list on "change existing … … 863 774 } 864 775 fullnamemenu += "</select>\n"; 865 866 disp.setmacro ("fullnamemenu", "collector", fullnamemenu);776 text_t action_name = get_action_name(); 777 disp.setmacro ("fullnamemenu", action_name, fullnamemenu); 867 778 if (current_page == "srce") { 868 disp.setmacro ("warnindex", "collector", warnindex);869 disp.setmacro ("selectedindex", "collector", text_t(selected_index));779 disp.setmacro ("warnindex",action_name , warnindex); 780 disp.setmacro ("selectedindex", action_name, text_t(selected_index)); 870 781 } 871 782 } 783 872 784 873 785 // set _sourcelist_ and _badsources_ macros … … 1005 917 } 1006 918 1007 // set the _statusline_ macro1008 void collectoraction::set_statusline (displayclass &disp, cgiargsclass &args, ostream & /*logout*/) {1009 1010 // the build command creates .bld.download, .bld.import, and .bld.build files (in that1011 // order) and deletes them (also in that order) when each stage is complete. the .bld1012 // file is the concatenation of all these files.1013 text_t bld_file = filename_cat (gsdlhome, "tmp", args["bc1tmp"], args["bc1dirname"] + ".bld");1014 text_t statusline;1015 1016 if (file_exists (bld_file + ".download")) {1017 statusline = "_collector:textdownloadingfiles_<br>\n";1018 statusline += dm_safe(file_tail(bld_file + ".download", 1, 0));1019 } else if (file_exists (bld_file + ".import")) {1020 statusline = "_collector:textimportingcollection_<br>\n";1021 statusline += dm_safe(file_tail(bld_file + ".import", 1, 0));1022 } else if (file_exists (bld_file + ".build")) {1023 statusline = "_collector:textbuildingcollection_<br>\n";1024 statusline += dm_safe(file_tail(bld_file + ".build", 1, 0));1025 } else {1026 statusline += "_collector:textcreatingcollection_<br>\n";1027 statusline += dm_safe(file_tail(bld_file, 1, 0));1028 }1029 1030 disp.setmacro ("statusline", "collector", statusline);1031 1032 }1033 919 1034 920 void collectoraction::define_internal_macros (displayclass &disp, cgiargsclass &args, … … 1065 951 1066 952 // set the collectorbar macro 1067 text_t collectorbar = "<table class= collectorbar border=0 cellspacing=4 cellpadding=0><tr>\n";953 text_t collectorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n"; 1068 954 1069 955 if (collector_page == "new") { 1070 956 collectorbar += "<td>_icongreyarrow_</td>\n"; 1071 collectorbar += get_button ( collector_page, "green", "info", true);1072 collectorbar += "<td>_icongreyarrow_</td>\n"; 1073 collectorbar += get_button ( collector_page, "grey", "srce", false);1074 collectorbar += "<td>_icongreyarrow_</td>\n"; 1075 collectorbar += get_button ( collector_page, "grey", "conf", false);1076 collectorbar += "<td>_icongreyarrow_</td>\n"; 1077 collectorbar += get_button ( collector_page, "grey", "bild", false);1078 collectorbar += "<td>_icongreyarrow_</td>\n"; 1079 collectorbar += get_button ( collector_page, "grey", "view", false);957 collectorbar += get_button (args,collector_page, "green", "info", true); 958 collectorbar += "<td>_icongreyarrow_</td>\n"; 959 collectorbar += get_button (args,collector_page, "grey", "srce", false); 960 collectorbar += "<td>_icongreyarrow_</td>\n"; 961 collectorbar += get_button (args,collector_page, "grey", "conf", false); 962 collectorbar += "<td>_icongreyarrow_</td>\n"; 963 collectorbar += get_button (args,collector_page, "grey", "bild", false); 964 collectorbar += "<td>_icongreyarrow_</td>\n"; 965 collectorbar += get_button (args,collector_page, "grey", "view", false); 1080 966 1081 967 } else if (collector_page == "info") { 1082 968 collectorbar += "<td>_icongreyarrow_</td>\n"; 1083 collectorbar += get_button ( collector_page, "yellow", "info", false);1084 collectorbar += "<td>_icongreyarrow_</td>\n"; 1085 collectorbar += get_button ( collector_page, "green", "srce", true);1086 collectorbar += "<td>_icongreyarrow_</td>\n"; 1087 collectorbar += get_button ( collector_page, "grey", "conf", false);1088 collectorbar += "<td>_icongreyarrow_</td>\n"; 1089 collectorbar += get_button ( collector_page, "grey", "bild", false);1090 collectorbar += "<td>_icongreyarrow_</td>\n"; 1091 collectorbar += get_button ( collector_page, "grey", "view", false);969 collectorbar += get_button (args,collector_page, "yellow", "info", false); 970 collectorbar += "<td>_icongreyarrow_</td>\n"; 971 collectorbar += get_button (args,collector_page, "green", "srce", true); 972 collectorbar += "<td>_icongreyarrow_</td>\n"; 973 collectorbar += get_button (args,collector_page, "grey", "conf", false); 974 collectorbar += "<td>_icongreyarrow_</td>\n"; 975 collectorbar += get_button (args,collector_page, "grey", "bild", false); 976 collectorbar += "<td>_icongreyarrow_</td>\n"; 977 collectorbar += get_button (args,collector_page, "grey", "view", false); 1092 978 collectorbar += "</tr><tr><td></td><td align=center>_icongreyuparrow_</td><td colspan=8></td>\n"; 1093 979 … … 1097 983 // if we came from the "change an existing collection" page previous button(s) 1098 984 // are disabled 1099 collectorbar += get_button ( collector_page, "grey", "info", false);985 collectorbar += get_button (args,collector_page, "grey", "info", false); 1100 986 } else { 1101 collectorbar += get_button ( collector_page, "yellow", "info", true);1102 } 1103 collectorbar += "<td>_icongreyarrow_</td>\n"; 1104 collectorbar += get_button ( collector_page, "yellow", "srce", false);1105 collectorbar += "<td>_icongreyarrow_</td>\n"; 1106 collectorbar += get_button ( collector_page, "green", "conf", true);1107 collectorbar += "<td>_icongreyarrow_</td>\n"; 1108 collectorbar += get_button ( collector_page, "green", "bild", true);1109 collectorbar += "<td>_icongreyarrow_</td>\n"; 1110 collectorbar += get_button ( collector_page, "grey", "view", false);987 collectorbar += get_button (args,collector_page, "yellow", "info", true); 988 } 989 collectorbar += "<td>_icongreyarrow_</td>\n"; 990 collectorbar += get_button (args,collector_page, "yellow", "srce", false); 991 collectorbar += "<td>_icongreyarrow_</td>\n"; 992 collectorbar += get_button (args,collector_page, "green", "conf", true); 993 collectorbar += "<td>_icongreyarrow_</td>\n"; 994 collectorbar += get_button (args,collector_page, "green", "bild", true); 995 collectorbar += "<td>_icongreyarrow_</td>\n"; 996 collectorbar += get_button (args,collector_page, "grey", "view", false); 1111 997 collectorbar += "</tr><tr><td colspan=3></td><td align=center>_icongreyuparrow_</td><td colspan=6></td>\n"; 1112 998 … … 1116 1002 // page 1117 1003 if (esrce == 1 || econf == 1) { 1118 collectorbar += get_button ( collector_page, "grey", "info", false);1004 collectorbar += get_button (args,collector_page, "grey", "info", false); 1119 1005 } else { 1120 collectorbar += get_button ( collector_page, "yellow", "info", true);1006 collectorbar += get_button (args,collector_page, "yellow", "info", true); 1121 1007 } 1122 1008 collectorbar += "<td>_icongreyarrow_</td>\n"; 1123 1009 if (econf == 1) { 1124 collectorbar += get_button ( collector_page, "grey", "srce", false);1010 collectorbar += get_button (args,collector_page, "grey", "srce", false); 1125 1011 } else { 1126 collectorbar += get_button ( collector_page, "yellow", "srce", true);1127 } 1128 collectorbar += "<td>_icongreyarrow_</td>\n"; 1129 collectorbar += get_button ( collector_page, "yellow", "conf", false);1130 collectorbar += "<td>_icongreyarrow_</td>\n"; 1131 collectorbar += get_button ( collector_page, "green", "bild", true);1132 collectorbar += "<td>_icongreyarrow_</td>\n"; 1133 collectorbar += get_button ( collector_page, "grey", "view", false);1012 collectorbar += get_button (args,collector_page, "yellow", "srce", true); 1013 } 1014 collectorbar += "<td>_icongreyarrow_</td>\n"; 1015 collectorbar += get_button (args,collector_page, "yellow", "conf", false); 1016 collectorbar += "<td>_icongreyarrow_</td>\n"; 1017 collectorbar += get_button (args,collector_page, "green", "bild", true); 1018 collectorbar += "<td>_icongreyarrow_</td>\n"; 1019 collectorbar += get_button (args,collector_page, "grey", "view", false); 1134 1020 collectorbar += "</tr><tr><td colspan=5></td><td align=center>_icongreyuparrow_</td><td colspan=4></td>\n"; 1135 1021 … … 1137 1023 collectorbar += "<td>_icongreyarrow_</td>\n"; 1138 1024 // all previous buttons grey after build was completed 1139 collectorbar += get_button ( collector_page, "grey", "info", false);1140 collectorbar += "<td>_icongreyarrow_</td>\n"; 1141 collectorbar += get_button ( collector_page, "grey", "srce", false);1142 collectorbar += "<td>_icongreyarrow_</td>\n"; 1143 collectorbar += get_button ( collector_page, "grey", "conf", false);1144 collectorbar += "<td>_icongreyarrow_</td>\n"; 1145 collectorbar += get_button ( collector_page, "yellow", "bild", false);1146 collectorbar += "<td>_icongreyarrow_</td>\n"; 1147 collectorbar += get_button ( collector_page, "green", "view", true);1025 collectorbar += get_button (args,collector_page, "grey", "info", false); 1026 collectorbar += "<td>_icongreyarrow_</td>\n"; 1027 collectorbar += get_button (args,collector_page, "grey", "srce", false); 1028 collectorbar += "<td>_icongreyarrow_</td>\n"; 1029 collectorbar += get_button (args,collector_page, "grey", "conf", false); 1030 collectorbar += "<td>_icongreyarrow_</td>\n"; 1031 collectorbar += get_button (args,collector_page, "yellow", "bild", false); 1032 collectorbar += "<td>_icongreyarrow_</td>\n"; 1033 collectorbar += get_button (args,collector_page, "green", "view", true); 1148 1034 collectorbar += "</tr><tr><td colspan=7></td><td align=center>_icongreyuparrow_</td><td colspan=2></td>\n"; 1149 1035 … … 1153 1039 // page 1154 1040 if (esrce == 1 || econf == 1) { 1155 collectorbar += get_button ( collector_page, "grey", "info", false);1041 collectorbar += get_button (args,collector_page, "grey", "info", false); 1156 1042 } else { 1157 collectorbar += get_button ( collector_page, "yellow", "info", true);1043 collectorbar += get_button (args,collector_page, "yellow", "info", true); 1158 1044 } 1159 1045 collectorbar += "<td>_icongreyarrow_</td>\n"; 1160 1046 if (econf == 1) { 1161 collectorbar += get_button ( collector_page, "grey", "srce", false);1047 collectorbar += get_button (args,collector_page, "grey", "srce", false); 1162 1048 } else { 1163 collectorbar += get_button ( collector_page, "yellow", "srce", true);1164 } 1165 collectorbar += "<td>_icongreyarrow_</td>\n"; 1166 collectorbar += get_button ( collector_page, "yellow", "conf", true);1167 collectorbar += "<td>_icongreyarrow_</td>\n"; 1168 collectorbar += get_button ( collector_page, "yellow", "bild", true);1169 collectorbar += "<td>_icongreyarrow_</td>\n"; 1170 collectorbar += get_button ( collector_page, "grey", "view", false);1049 collectorbar += get_button (args,collector_page, "yellow", "srce", true); 1050 } 1051 collectorbar += "<td>_icongreyarrow_</td>\n"; 1052 collectorbar += get_button (args,collector_page, "yellow", "conf", true); 1053 collectorbar += "<td>_icongreyarrow_</td>\n"; 1054 collectorbar += get_button (args,collector_page, "yellow", "bild", true); 1055 collectorbar += "<td>_icongreyarrow_</td>\n"; 1056 collectorbar += get_button (args,collector_page, "grey", "view", false); 1171 1057 } 1172 1058 … … 1207 1093 disp.setmacro ("gsdlhome", "collector", dm_safe(gsdlhome)); 1208 1094 } 1095 1209 1096 1210 1097 bool collectoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, … … 1439 1326 } 1440 1327 1441 // if sw = 0 replace all carriage returns in intext with the string "\n"1442 // else replace all occurances of "\n" with a carriage return1443 text_t collectoraction::carriage_replace (const text_t &intext, int sw) {1444 1445 text_t outtext;1446 text_t::const_iterator here = intext.begin();1447 text_t::const_iterator end = intext.end();1448 while (here != end) {1449 if (sw == 0) {1450 if (*here == '\n') {1451 if ((here+1) != end && *(here+1) == '\r') ++here;1452 outtext += "\\n";1453 } else if (*here == '\r') {1454 if ((here+1) != end && *(here+1) == '\n') ++here;1455 outtext += "\\n";1456 } else {1457 outtext.push_back (*here);1458 }1459 } else if (*here == '\\' && (here+1) != end && *(here+1) == 'n') {1460 outtext.push_back ('\n');1461 ++here;1462 } else {1463 outtext.push_back (*here);1464 }1465 ++here;1466 }1467 return outtext;1468 }1469 1470 // create a short directory name from fullname1471 text_t collectoraction::get_directory_name (const text_t &fullname) {1472 1473 text_t shortname;1474 if (fullname.empty()) {1475 shortname = "coll";1476 1477 } else {1478 1479 // first make all lowercase and remove any dodgy characters1480 // (i.e. anything not [a-z]1481 text_t::const_iterator here = fullname.begin();1482 text_t::const_iterator end = fullname.end();1483 while (here != end) {1484 if ((*here >= 'A' && *here <= 'Z') || (*here >= 'a' && *here <= 'z') ||1485 (*here == ' ')) {1486 if (*here >= 'A' && *here <= 'Z') shortname.push_back (*here+32);1487 else if (*here == ' ') {1488 while ((*(here+1)) == ' ') ++here;1489 shortname.push_back (*here);1490 } else shortname.push_back (*here);1491 }1492 ++here;1493 }1494 1495 text_tarray words;1496 splitchar (shortname.begin(), shortname.end(), ' ', words);1497 int num_words = words.size();1498 1499 if (num_words == 0) {1500 shortname = "coll";1501 1502 } else {1503 1504 shortname.clear();1505 int use_words = (num_words <= 6) ? num_words : 6;1506 unsigned int substr_len = 6 / use_words;1507 1508 for (int i = 0; i < use_words; ++i) {1509 if (words[i].size() < substr_len) shortname += words[i];1510 else shortname += substr (words[i].begin(), words[i].begin()+substr_len);1511 }1512 }1513 }1514 1515 // check to see if shortname is unique1516 text_t fulldirname = filename_cat (gsdlhome, "collect", shortname);1517 if (directory_exists (fulldirname)) {1518 int version = 0;1519 text_t newname;1520 do {1521 ++version;1522 newname = shortname;1523 newname.push_back ('v');1524 newname.appendint (version);1525 fulldirname = filename_cat (gsdlhome, "collect", newname);1526 } while (directory_exists (fulldirname));1527 1528 shortname = newname;1529 }1530 1531 return shortname;1532 }1533 1534 // tests if collection is write protected (currently just checks if1535 // collect.cfg file is writable1536 bool collectoraction::collection_protected (const text_t &collection) {1537 text_t cfgfile = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg");1538 if (file_writable(cfgfile)) return false;1539 return true;1540 }1541 1542 // assigns a temporary directory name for this collector session1543 // and creates temporary directory1544 // returns false if it couldn't create the directory1545 bool collectoraction::assign_tmpname (cgiargsclass &args, ostream &logout) {1546 1547 int i = 0;1548 text_t tmpname = "tbuild";1549 while (directory_exists (filename_cat (gsdlhome, "tmp", tmpname + text_t(i)))) {1550 ++i;1551 }1552 tmpname.appendint (i);1553 1554 text_t fulltmpdir = filename_cat (gsdlhome, "tmp", tmpname);1555 if (!mk_dir (fulltmpdir)) {1556 outconvertclass text_t2ascii;1557 logout << text_t2ascii << "collectoraction::assign_tmpname unable to create directory ("1558 << fulltmpdir << ")\n";1559 return false;1560 }1561 1562 args["bc1tmp"] = tmpname;1563 return true;1564 }1565 1566 1328 void collectoraction::gsdl_mkcol (cgiargsclass &args, ostream &logout) { 1567 1329 … … 1569 1331 if (!directory_exists (tmpdir)) { 1570 1332 message = "tmpfail"; 1333 cerr << "WE CANNOT CREATE THE DIRECTORY!!! " << endl; 1571 1334 return; 1572 1335 } … … 1605 1368 text_t mkcol_cmd = "perl -S mkcol.pl -optionfile \"" + optionfile; 1606 1369 mkcol_cmd += "\" " + collection; 1370 1371 1607 1372 gsdl_system (mkcol_cmd, true, logout); 1608 1373 … … 1627 1392 } 1628 1393 1629 void collectoraction::gsdl_build (cgiargsclass &args, ostream &logout) {1630 1631 outconvertclass text_t2ascii;1632 1633 text_t tmpdir = filename_cat (gsdlhome, "tmp", args["bc1tmp"]);1634 if (!directory_exists (tmpdir)) {1635 message = "tmpfail";1636 return;1637 }1638 1639 text_t &collection = args["bc1dirname"];1640 if (collection.empty()) {1641 message = "nocollection";1642 return;1643 }1644 1645 // check for a .build file - if it exists then we've already built1646 // the collection (or are in the process of building it)1647 text_t buildfile = filename_cat (tmpdir, ".build");1648 if (file_exists (buildfile)) {1649 return;1650 } else {1651 // create the .build file (this file is just a place holder to let any future1652 // pages know that we've already been here)1653 char *buildfilec = buildfile.getcstr();1654 ofstream bfile_out (buildfilec);1655 delete []buildfilec;1656 if (bfile_out) {1657 bfile_out << "collection building\n";1658 bfile_out.close();1659 } else {1660 message = "tmpfail";1661 return;1662 }1663 }1664 1665 const recptconf &rcinfo = recpt->get_configinfo ();1666 1667 // create the event header file if LogEvents, EmailEvents or1668 // EmailUserEvents options are turned on.1669 bool logevents =1670 (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents ||1671 rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents ||1672 rcinfo.EmailUserEvents);1673 text_t ehead_file = filename_cat (tmpdir, "ehead.txt");1674 if (logevents) {1675 if (!create_event_header_file (ehead_file, args, logout)) {1676 logevents = false;1677 }1678 }1679 1680 text_t collectdir = get_collectdir (args);1681 1682 // set up build options1683 text_t options = "-make_writable -remove_import -out \"";1684 options += filename_cat (tmpdir, collection + ".bld");1685 options += "\" -collectdir \"" + collectdir + "\" -statsfile \"";1686 options += filename_cat(collectdir, collection, "etc", "import.log") + "\"";1687 1688 if (args["bc1esrce"] == 1) {1689 // we're adding data to an existing collection1690 options += " -save_archives -append";1691 }1692 1693 text_tarray inputvalues, inputtypes;1694 splitchar (args["bc1input"].begin(), args["bc1input"].end(), ',', inputvalues);1695 splitchar (args["bc1inputtype"].begin(), args["bc1inputtype"].end(), ',', inputtypes);1696 int numvalues = inputvalues.size();1697 int numtypes = inputtypes.size();1698 for (int i = 0; i < numvalues; ++i) {1699 if (!inputvalues[i].empty()) {1700 text_t type = "file://"; // default1701 if (i < numtypes) type = inputtypes[i];1702 options += " -download \"" +1703 remove_trailing_slashes(type + format_url(decode_commas(inputvalues[i]))) + "\"";1704 }1705 }1706 1707 if (logevents) {1708 if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents)1709 options += " -log_events";1710 if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) {1711 options += " -mail_server " + rcinfo.MailServer;1712 options += " -email_events " + rcinfo.maintainer;1713 if (rcinfo.EmailUserEvents) options += "," + args["bc1contactemail"];1714 } else if (rcinfo.EmailUserEvents) {1715 options += " -mail_server " + rcinfo.MailServer;1716 options += " -email_events " + args["bc1contactemail"];1717 }1718 options += " -event_header " + ehead_file;1719 }1720 1721 text_t optionfile = filename_cat (tmpdir, "build.opt");1722 char *optionfilec = optionfile.getcstr();1723 ofstream ofile_out (optionfilec);1724 delete []optionfilec;1725 if (!ofile_out) {1726 message = "tmpfail";1727 return;1728 }1729 ofile_out << text_t2ascii << options << "\n";1730 ofile_out.close();1731 1732 // if we're altering an existing collection we need to kill off1733 // the existing collection server - we do this for the local library1734 // (and any other persistent version of the library) as the existing1735 // gdbm file can't be deleted while the collection server holds it open1736 if ((args["bc1econf"] == 1) || (args["bc1esrce"] == 1)) {1737 remove_colservr (collection, logout);1738 }1739 1740 // set up the build command - build.bat has some issues with quoting1741 // on win2k when gsdlhome contains spaces so we'll avoid using1742 // "perl -S" here in favor of calling the "build" perl script explicitly1743 text_t build_cmd = "perl \"" + filename_cat (gsdlhome, "bin", "script", "build");1744 build_cmd += "\" -optionfile \"" + optionfile + "\" " + collection;1745 // run build command in background (i.e. asynchronously)1746 gsdl_system (build_cmd, false, logout);1747 }1748 1749 void collectoraction::gsdl_cancel_build (cgiargsclass &args, ostream &logout) {1750 // I really wanted to do what this perl script does from within the library1751 // c++ code. I ran into some problems though (like how do you write a portable1752 // "rm -r" in c++?). One day I'll spend some time sorting it out ... maybe.1753 text_t cancel_cmd = "perl -S cancel_build.pl -collectdir \"";1754 cancel_cmd += filename_cat (gsdlhome, "tmp", args["bc1tmp"]) + "\" ";1755 cancel_cmd += args["bc1dirname"];1756 // To be on the safe side we'll make this a synchronous call1757 // so that all tidying up is done before the user has a chance1758 // to do anything else (like start rebuilding their collection).1759 // This means that for a big collection where there's lots of1760 // stuff to delete etc. it might take a while before the "build1761 // cancelled" page appears.1762 gsdl_system (cancel_cmd, true, logout);1763 }1764 1765 text_t collectoraction::get_collectdir (cgiargsclass &args)1766 {1767 if ((args["bc1econf"] == 1) || (args["bc1esrce"] == 1)) {1768 // we're adding to a collection in place1769 return filename_cat(gsdlhome, "collect");1770 }1771 else {1772 return filename_cat (gsdlhome, "tmp", args["bc1tmp"]);1773 }1774 }1775 1776 // checks to see if any of the plugins in pluginset occur in1777 // collections configuration file1778 bool collectoraction::uses_weird_plugin (const text_t &collection) {1779 1780 text_tset pluginset;1781 pluginset.insert ("HBPlug");1782 1783 text_t cfgfile_content;1784 text_t cfgfile_name = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");1785 text_t pluginstr, pluginname;1786 1787 if (read_file (cfgfile_name, cfgfile_content)) {1788 text_t::const_iterator here = cfgfile_content.begin();1789 text_t::const_iterator end = cfgfile_content.end();1790 while (here != end) {1791 here = findchar (here, end, 'p');1792 if (here == end) break;1793 if ((here+6 < end) && (substr (here, here+6) == "plugin")) {1794 getdelimitstr (here+6, end, '\n', pluginstr);1795 text_t::const_iterator hp = pluginstr.begin();1796 text_t::const_iterator ep = pluginstr.end();1797 bool found = false;1798 // remove any leading whitespace, trailing options etc.1799 while (hp != ep) {1800 if (*hp == '\t' || *hp == ' ' || *hp == '\n') {1801 if (found) break;1802 } else {1803 pluginname.push_back (*hp);1804 found = true;1805 }1806 ++hp;1807 }1808 text_tset::const_iterator it = pluginset.find (pluginname);1809 if (it != pluginset.end()) return true; // found matching plugin1810 pluginname.clear();1811 }1812 ++here;1813 }1814 }1815 return false;1816 }1817 1818 // create and initialize a new collection server and1819 // add it to the null protocol.1820 void collectoraction::create_colserver (const text_t &collection, ostream &logout) {1821 1822 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();1823 recptprotolistclass::iterator rprotolist_here = protos->begin();1824 recptprotolistclass::iterator rprotolist_end = protos->end();1825 while (rprotolist_here != rprotolist_end) {1826 comerror_t err = noError;1827 if ((*rprotolist_here).p != NULL) {1828 if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {1829 // create collection server and add it to nullproto1830 (*rprotolist_here).p->add_collection (collection, recpt, gsdlhome, gsdlhome);1831 // make sure gsdlhome is configured1832 text_tarray tmp;1833 tmp.push_back (gsdlhome);1834 (*rprotolist_here).p->configure ("gsdlhome", tmp, err);1835 // re-initialize the null protocol1836 if (!(*rprotolist_here).p->init (err, logout)) {1837 logout << "collectoraction::create_colserver: nullproto init failed\n";1838 }1839 return;1840 }1841 }1842 ++rprotolist_here;1843 }1844 1845 logout << "collectoraction::create_colserver: no valid nullproto found\n";1846 }1847 1848 // delete a collection server from the null protocol1849 void collectoraction::remove_colservr (const text_t &collection, ostream &logout) {1850 1851 recpt->uncache_collection (collection);1852 1853 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();1854 recptprotolistclass::iterator rprotolist_here = protos->begin();1855 recptprotolistclass::iterator rprotolist_end = protos->end();1856 while (rprotolist_here != rprotolist_end) {1857 comerror_t err = noError;1858 if ((*rprotolist_here).p != NULL) {1859 if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {1860 (*rprotolist_here).p->remove_collection (collection, logout);1861 return;1862 }1863 }1864 ++rprotolist_here;1865 }1866 1867 logout << "collectoraction::create_colserver: no valid nullproto found\n";1868 }1869 1870 bool collectoraction::create_event_header_file (const text_t &filename, cgiargsclass &args,1871 ostream &logout) {1872 1873 outconvertclass text_t2ascii;1874 char *filenamec = filename.getcstr();1875 ofstream eheadfile (filenamec);1876 delete []filenamec;1877 1878 if (eheadfile) {1879 eheadfile << text_t2ascii << get_event_header (args);1880 eheadfile.close();1881 return true;1882 }1883 1884 logout << text_t2ascii << "collectoraction::create_event_header ERROR: Couldn't create "1885 << "Event Header file " << filename << ". Event logging disabled\n";1886 return false;1887 }1888 1889 text_t collectoraction::get_event_header (cgiargsclass &args) {1890 text_t header = "Greenstone Username: " + args["un"] + "\n";1891 header += "Collection: " + args["bc1dirname"] + "\n";1892 header += "Collection Creator: " + args["bc1contactemail"] + "\n";1893 header += "GSDLHOME: " + gsdlhome + "\n";1894 header += "Build Location: " + get_collectdir(args) + "\n";1895 1896 return header;1897 }1898 1394 1899 1395 bool collectoraction::check_sources (cgiargsclass &args, ostream &logout) { … … 1946 1442 } 1947 1443 1948 // format_url simply strips "http://", "ftp://", or "file://" off the 1949 // beginning of url if they're there 1950 text_t collectoraction::format_url (const text_t &url) { 1951 text_t::const_iterator begin = url.begin(); 1952 text_t::const_iterator end = url.end(); 1953 1954 if (url.size() >= 7) { 1955 text_t prefix = substr(begin, begin+7); 1956 if (prefix == "http://" || prefix == "file://") { 1957 return substr(begin+7, end); 1958 } 1959 } 1960 if (url.size() >= 6) { 1961 if (substr(begin, begin+6) == "ftp://") { 1962 return substr(begin+6, end); 1963 } 1964 } 1965 return url; 1444 text_t collectoraction::get_button(cgiargsclass &args, const text_t &thispage, 1445 const text_t &color, 1446 const text_t &type, bool enabled) 1447 { 1448 1449 if ((color != "green" && color != "grey" && color != "yellow") || 1450 (type != "info" && type != "srce" && type != "conf" && type != "bild" && type != "view")) 1451 return g_EmptyText; 1452 1453 text_t href = "_http"+type+"_"; 1454 text_t target = ""; 1455 1456 if (thispage == "info" || thispage == "srce" || thispage == "conf" || 1457 thispage == "bildcancel" || thispage == "bildfail") { 1458 // call the check submit macro instead of linking directly to the page 1459 href="\"javascript:check_submit('"+type+"');\""; 1460 } else if (type == "view") { 1461 // view button is special case as it needs a target=_top 1462 target = " target=_top"; 1463 } 1464 1465 text_t tdclass = "wizardbar"+color; 1466 if (enabled) { 1467 // link to the appropriate page 1468 return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>"; 1469 } 1470 else { 1471 // just display the text 1472 return "<td class="+tdclass+">_text"+type+"_</td>"; 1473 } 1966 1474 } 1967 1475 1968 text_t collectoraction::remove_trailing_slashes (text_t str) {1969 1970 while (*(str.end()-1) == '\\') {1971 str.pop_back();1972 }1973 return str;1974 }1975 1976 1476 #endif //GSDL_USE_COLLECTOR_ACTION
Note:
See TracChangeset
for help on using the changeset viewer.