16ac161a7e0835ba943b8c33c21858b0d1938219
braney
  Thu Oct 6 15:02:49 2011 -0700
change the relationship between the trackHub structure and the hubConnectStatus structure to be hierarchical. This fixes #4920.  We now *always* fetch the URL contents instead of trusting what's in the hubStatus table *unless* there's an error message in the hubStatus table.
diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index 0a7e78f..9180bce 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -64,96 +64,102 @@
 	"<th colspan=\"5\" id=\"addHubBar\"><label>URL:</label> "
 	"<input name=\"hubText\" id=\"hubUrl\" class=\"hubField\""
 	    "type=\"text\" size=\"65\"> "
 	"<input name=\"hubAddButton\""
 	    "onClick=\"document.addHubForm.elements['hubUrl'].value=hubText.value;"
 		"document.addHubForm.submit();return true;\" "
 		"class=\"hubField\" type=\"button\" value=\"Add Hub\">"
 	"</th> "
     "</tr> ");
 
 // count up the number of unlisted hubs we currently have
 int count = 0;
 struct hubConnectStatus *hub, *hubList =  hubConnectStatusListFromCartAll(cart);
 for(hub = hubList; hub; hub = hub->next)
     {
-    if (isHubUnlisted(hub) && hubHasDatabase(hub, database) )
+    if (isHubUnlisted(hub) && ((hub->trackHub == NULL) || trackHubHasDatabase(hub->trackHub, database) ))
 	count++;
     }
 
 if (count == 0)
     {
     // nothing to see here
     printf(
 	"<tr><td>No Track Hubs for this genome assembly</td></tr>"
 	"</td></table>");
     printf("</thead></div>");
     return;
     }
 
 // time to output the big table.  First the header
 printf(
     "<tr> "
 	"<th>Display</th> "
 	"<th>Hub Name</th> "
 	"<th>Description</th> "
 	"<th>URL</th> "
 	"<th>Disconnect</th> "
     "</tr></thead>\n");
 
 // start first row
 printf("<tbody><tr>");
 
 count = 0;
 for(hub = hubList; hub; hub = hub->next)
     {
     /* if the hub is public, then don't list it here */
-    if (!(isHubUnlisted(hub) && hubHasDatabase(hub, database) ))
+    if (!(isHubUnlisted(hub) && ((hub->trackHub == NULL) || trackHubHasDatabase(hub->trackHub, database) )))
 	continue;
 
     if (count)
 	webPrintLinkTableNewRow();  // ends last row and starts a new one
     count++;
 
     // if there's an error message, we don't let people select it
     if (isEmpty(hub->errorMessage))
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id);
 	cartMakeCheckBox(cart, hubName, FALSE);
 	ourCellEnd();
 	}
     else
 	{
 	// give people a chance to clear the error 
 	ourCellStart();
 	printf(
 	"<input name=\"hubClearButton\""
 	    "onClick=\"document.resetHubForm.elements['hubUrl'].value='%s';"
 		"document.resetHubForm.submit();return true;\" "
 		"class=\"hubField\" type=\"button\" value=\"clear error\">"
 		, hub->hubUrl);
 	ourCellEnd();
 	}
-    ourPrintCell(hub->shortLabel);
-    if (isEmpty(hub->errorMessage))
-	ourPrintCell(hub->longLabel);
+    if (hub->trackHub != NULL)
+	ourPrintCell(hub->trackHub->shortLabel);
     else
+	ourPrintCell("");
+
+    if (!isEmpty(hub->errorMessage))
 	printf("<TD><span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>", 
 	    hub->errorMessage);
+    else if (hub->trackHub != NULL)
+	ourPrintCell(hub->trackHub->longLabel);
+    else
+	ourPrintCell("");
 
     ourPrintCell(hub->hubUrl);
 
     ourCellStart();
     printf(
     "<input name=\"hubDisconnectButton\""
 	"onClick=\"document.disconnectHubForm.elements['hubId'].value='%d';"
 	    "document.disconnectHubForm.submit();return true;\" "
 	    "class=\"hubField\" type=\"button\" value=\"X\">"
 	    , hub->id);
     ourCellEnd();
     }
 
 printf("</TR></tbody></TABLE>\n");
 printf("</div>");
@@ -252,42 +258,43 @@
 else
     {
     printf("<div id=\"publicHubs\" class=\"hubList\"> \n");
     printf("No Public Track Hubs for this genome assembly<BR>");
     }
 
 printf("</div>");
 
 hDisconnectCentral(&conn);
 }
 
 static void tryHubOpen(unsigned id)
 /* try to open hub, leaks trackHub structure */
 {
 /* try opening this again to reset error */
+struct sqlConnection *conn = hConnectCentral();
 struct errCatch *errCatch = errCatchNew();
-struct trackHub *tHub;
+struct hubConnectStatus *hub;
 if (errCatchStart(errCatch))
-    tHub = trackHubFromId(id);
+    hub = hubConnectStatusForId(conn, id);
 errCatchEnd(errCatch);
 if (errCatch->gotError)
-    hubSetErrorMessage( errCatch->message->string, id);
+    hubUpdateStatus( errCatch->message->string, NULL);
 else
-    hubSetErrorMessage(NULL, id);
+    hubUpdateStatus(NULL, hub);
 errCatchFree(&errCatch);
 
-tHub = NULL;
+hDisconnectCentral(&conn);
 }
 
 
 static void doResetHub(struct cart *theCart)
 {
 char *url = cartOptionalString(cart, hgHubDataText);
 
 if (url != NULL)
     {
     unsigned id = hubResetError(url);
     tryHubOpen(id);
     }
 else
     errAbort("must specify url in %s\n", hgHubDataText);
 }
@@ -363,34 +370,31 @@
    "the box in the list below. "
    "After import the hub will show up as a group of tracks with its own blue "
    "bar and label underneath the main browser graphic, and in the "
    "configure page. For more information, see the "
    "<A HREF=\"../goldenPath/help/hgTrackHubHelp.html\" TARGET=_blank>"
    "User's Guide</A>.</P>\n"
    "<P><B>NOTE: Because Track Hubs are created and maintained by external sources,"
    " UCSC cannot be held responsible for their content.</B></P>"
    );
 printf("</div>\n");
 
 // figure out and print out genome name
 makeGenomePrint();
 
 // check to see if we have any new hubs
-unsigned newId = hubCheckForNew(database, cart);
-
-if (newId)
-    tryHubOpen(newId);
+hubCheckForNew(database, cart);
 
 // here's a little form for the add new hub button
 printf("<FORM ACTION=\"%s\" NAME=\"addHubForm\">\n",  "../cgi-bin/hgHubConnect");
 cgiMakeHiddenVar("hubUrl", "");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // this the form for the disconnect hub button
 printf("<FORM ACTION=\"%s\" NAME=\"disconnectHubForm\">\n",  "../cgi-bin/hgHubConnect");
 cgiMakeHiddenVar("hubId", "");
 cgiMakeHiddenVar(hgHubDoDisconnect, "on");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // this the form for the reset hub button