Roxen.git / server / config_interface / dbs / db_maintenance.pike

version» Context lines:

Roxen.git/server/config_interface/dbs/db_maintenance.pike:5:      // Note: The difference between this and the normal db_list/browse   // interfaces is that it also includes databases in the local mysql   // that aren't registered with DBManager. You need -DMORE_DB_OPTS to   // add a tab for this.      #include <config_interface.h>   #include <config.h>   #include <roxen.h>   //<locale-token project="roxen_config">_</locale-token> - #define _(X,Y) _STR_LOCALE("roxen_config",X,Y) + #define _(X,Y) _STR_LOCALE("roxen_config",X,Y)      #define CU_AUTH id->misc->config_user->auth      mixed query( mixed ... args ) {    return connect_to_my_mysql( 0, "roxen" )->query( @args );   }      string|mapping parse( RequestID id )   {    // Permissions check    if ( !(CU_AUTH( "Edit Global Variables" )) ) return "Access denied";    -  array colors = ({ ({"&usr.matrix11;","&usr.matrix21;",}), ({"&usr.matrix12;","&usr.matrix22;",}) }); +  // Database table +  string res = #" +  <table class='nice db-list'> +  <thead> +  <tr> +  <th>Target</th> +  <th class='text-right'>Tables</th> +  <th class='text-right'>Rows</th> +  <th>Actions</th> +  </tr> +  </thead> +  <tbody>";    -  // CSS stylesheet -  string res = "<style type='text/css'>"; -  res += ".table_column { font-size: 8pt; font-weight: bold; background-color: &usr.matrix12;; color: black; padding: 2px; border-top: 1px solid &usr.matrix11;; border-left: 1px solid &usr.matrix11;; border-right: 1px solid &usr.matrix21;; border-bottom: 1px solid &usr.matrix21;; }\n"; -  res += ".table_row { font-size: 8pt; padding: 1px; border-bottom: 1px solid &usr.matrix22;; }\n"; -  res += ".df_text { font-size: 8pt; }"; -  res += "</style>"; +  string get_link(string action, string db, string name) { +  array(string) args = ({ });    -  // Database table -  res += "<table cellspacing='0' cellpadding='1'>"; -  res += "<tr>"; -  res += "<td class='table_column'>Target</td>"; -  res += "<td class='table_column'>Tables</td>"; -  res += "<td class='table_column'>Rows</td>"; -  res += "<td class='table_column'>Actions</td>"; -  res += "<tr>"; +  switch (action) { +  case "repair": +  args += ({ "repair=" + db }); +  break;    -  +  case "optimize": +  args += ({ "optimize=" + db }); +  break; +  +  case "both": +  args += ({ "optimize=" + db, "repair=" + db }); +  break; +  } +  +  args += ({ "&usr.set-wiz-id;" }); +  +  return sprintf("<a href='&page.path;?%s#op'>%s</a>", +  args*"&amp;", name); +  }; +     // List databases -  mixed m = query( "SHOW DATABASES" ); -  if( sizeof( m ) ) { -  foreach( m, m ) { +  mixed m = query("SHOW DATABASES"); +  +  if (sizeof(m)) { +  foreach (m, m) {    int table_count = 0;    int table_rows = 0;    -  mixed q = query( "SHOW TABLE STATUS IN " + m->Database ); -  if( sizeof( q ) ) { -  foreach( q, q ) { -  table_count += 1; -  table_rows += (int)q->Rows; +  mixed q = query("SHOW TABLE STATUS IN " + m->Database); +  +  if (sizeof(q)) { +  table_count = sizeof(q); +  table_rows = Array.sum((array(int)) q->Rows);    } -  } +     -  res += "<tr>" + -  "<td class='table_row'><a href='browser.pike?db=" + m->Database + "&amp;&usr.set-wiz-id;'>" + m->Database + "</a></td>" + -  "<td class='table_row'>" + table_count + "</td>" + -  "<td class='table_row'>" + table_rows + "</td>" + -  "<td class='table_row'><a href='&page.path;?repair=" + m->Database + "&amp;&usr.set-wiz-id;'>[Repair]</a> <a href='&page.path;?optimize=" + m->Database + "&amp;&usr.set-wiz-id;'>[Optimize]</a> <a href='&page.path;?repair=" + m->Database + "&optimize=" + m->Database + "&amp;&usr.set-wiz-id;'>[Both]</a></td>" + -  "</tr>\n"; +  res += sprintf(#" +  <tr> +  <td> +  <a href='browser.pike?db=%s&amp;&usr.set-wiz-id;'>%[0]s</a> +  </td> +  <td class='num'>%d</td> +  <td class='num'>%d</td> +  <td>%s | %s | %s</td> +  </tr>", +  m->Database, +  table_count, +  table_rows, +  get_link("repair", m->Database, "Repair"), +  get_link("optimize", m->Database, "Optimize"), +  get_link("both", m->Database, "Both"));    }    } -  res += "</table><br/>"; -  res += "<a href='db_repairall.html'><gbutton>Repair all</gbutton></a> <a href='db_optimizeall.html'><gbutton>Optimize all</gbutton></a>"; -  res += "<br/><br/>"; +     -  +  res += "</tbody></table><br/>"; +  res += "<link-gbutton href='db_repairall.html'>Repair all</link-gbutton> "; +  res += "<link-gbutton href='db_optimizeall.html'>Optimize all</link-gbutton>"; +     // Draw result table    if (id->variables->repair || id->variables->optimize) { -  res += "<table cellspacing='0' cellpadding='1'>"; -  res += "<tr>"; -  res += "<td class='table_column'>Target</td>"; -  res += "<td class='table_column'>Operation</td>"; -  res += "<td class='table_column'>Result</td>"; -  res += "<td class='table_column'>Time</td>"; -  res += "<tr>"; +  res += #" +  <hr class='margin-top margin-bottom'> +  <table class='nice db-list' id='op'> +  <thead> +  <tr> +  <th>Target</th> +  <th>Operation</th> +  <th>Result</th> +  <th>Time</th> +  </tr> +  </thead> +  <tbody>";    }       // Repair and optimize    float t3 = 0; -  if (id->variables->repair) { -  mixed m = query( "SHOW TABLE STATUS IN " + id->variables->repair ); -  if( sizeof( m ) ) { -  foreach( m, m ) { +  mixed st; +  void do_operation(string op) { +  string db_name = id->variables->repair || id->variables->optimize; +  +  if (!st) { +  st = query("SHOW TABLE STATUS IN " + db_name); +  } +  +  if (sizeof(st)) { +  foreach (st, mapping tbl) {    int t = time();    float t1 = time(t); -  mixed q = query( "REPAIR TABLE `" + id->variables->repair + "`.`" + m->Name + "`" ); +  mixed q = query(upper_case(op) + " TABLE `" + +  db_name + "`.`" + tbl->Name + "`");    float t2 = (time(t)-t1);    t3 += t2;       string result = ""; -  if (q->Msg_text = "OK") -  result = "<font color='green'>OK</font>"; -  else -  result = "<font color='red'>Error</font>"; +     -  res += "<tr>" + -  "<td class='table_row'><a href='browser.pike?db=" + id->variables->repair + "&amp;&usr.set-wiz-id;'>" + id->variables->repair + "</a>.<a href='browser.pike?db=" + id->variables->repair + "&table=" + m->Name + "&amp;&usr.set-wiz-id;'>" + m->Name + "</a></td>" + -  "<td class='table_row'>Repair</td><td class='table_row'><b>" + result + "</b></td>" + -  "<td class='table_row'>" + t2 + " sec</td>" + -  "</tr>"; +  if (q->Msg_text = "OK") { +  result = "<span class='notify ok inline'>Ok</span>";    } -  +  else { +  result = "<span class='notify error inline'>Error</span>";    } -  +  +  res += sprintf(#" +  <tr> +  <td> +  <a href='browser.pike?db=%s&amp;%s'>%[0]s</a>.<a +  href='browser.pike?db=%[0]s&amp;table=%s&amp;%[1]s'>%[2]s</a> +  </td> +  <td>%s</td> +  <td>%s</td> +  <td>%.5f</td> +  </tr>", +  db_name, +  "&usr.set-wiz-id;", +  tbl->Name, +  op, +  result, +  t2);    } -  if (id->variables->optimize) { -  mixed m = query( "SHOW TABLE STATUS IN " + id->variables->optimize ); -  if( sizeof( m ) ) { -  foreach( m, m ) { -  int t = time(); -  float t1 = time(t); -  mixed q = query( "OPTIMIZE TABLE `" + id->variables->optimize + "`.`" + m->Name + "`" ); -  float t2 = (time(t)-t1); -  t3 += t2; +  } +  };    -  string result = ""; -  if (q->Msg_text = "OK") -  result = "<font color='green'>OK</font>"; -  else -  result = "<font color='red'>Error</font>"; +  if (id->variables->repair) { +  do_operation("Repair"); +  }    -  res += "<tr>" + -  "<td class='table_row'><a href='browser.pike?db=" + id->variables->optimize + "&amp;&usr.set-wiz-id;'>" + id->variables->optimize + "</a>.<a href='browser.pike?db=" + id->variables->optimize + "&amp;table=" + m->Name + "&amp;&usr.set-wiz-id;'>" + m->Name + "</a></td>" + -  "<td class='table_row'>Optimize</td><td class='table_row'><b>" + result + "</b></td>" + -  "<td class='table_row'>" + t2 + " sec</td>" + -  "</tr>"; +  if (id->variables->optimize) { +  do_operation("Optimize");    } -  +  +  if (id->variables->repair || id->variables->optimize) { +  res += sprintf(#" +  </tbody> +  <tfoot> +  <tr> +  <td colspan='3'>Total:</td> +  <td>%.5f</td> +  </tr> +  </tfoot> +  </table>", +  t3);    } -  } -  if (id->variables->repair || id->variables->optimize) res += "<tr><td colspan='3'>Total:</td><td>" + t3 + " sec</td></tr></table><br/>"; +        // Done    return Roxen.http_string_answer(res);   }