mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
Added investigation means: DB dump from the ITopConsultant page, this feature should not rely on mySQL statements that are not allowed in the OVH hosting setup. The feature is 100% new and does not interfere with any existing code. Therefore I would advise to upgrade the official build as quickly as possible.
SVN:code[190]
This commit is contained in:
@@ -410,6 +410,24 @@ class CMDBSource
|
|||||||
return self::$m_aTablesInfo[strtolower($sTable)];
|
return self::$m_aTablesInfo[strtolower($sTable)];
|
||||||
//return null;
|
//return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function DumpTable($sTable)
|
||||||
|
{
|
||||||
|
$sSql = "SELECT * FROM `$sTable`";
|
||||||
|
$result = mysql_query($sSql, self::$m_resDBLink);
|
||||||
|
if (!$result)
|
||||||
|
{
|
||||||
|
throw new MySQLException('Failed to issue SQL query', array('query' => $sSql));
|
||||||
|
}
|
||||||
|
|
||||||
|
$aRows = array();
|
||||||
|
while ($aRow = mysql_fetch_array($result, MYSQL_ASSOC))
|
||||||
|
{
|
||||||
|
$aRows[] = $aRow;
|
||||||
|
}
|
||||||
|
mysql_free_result($result);
|
||||||
|
return $aRows;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -294,6 +294,28 @@ abstract class MetaModel
|
|||||||
// This attribute has been inherited (compound objects)
|
// This attribute has been inherited (compound objects)
|
||||||
return self::DBGetTable(self::$m_aAttribOrigins[$sClass][$sAttCode]);
|
return self::DBGetTable(self::$m_aAttribOrigins[$sClass][$sAttCode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final static protected function DBEnumTables()
|
||||||
|
{
|
||||||
|
// This API do not rely on our capability to query the DB and retrieve
|
||||||
|
// the list of existing tables
|
||||||
|
// Rather, it uses the list of expected tables, corresponding to the data model
|
||||||
|
$aTables = array();
|
||||||
|
foreach (self::GetClasses() as $sClass)
|
||||||
|
{
|
||||||
|
if (self::IsAbstract($sClass)) continue;
|
||||||
|
$sTable = self::DBGetTable($sClass);
|
||||||
|
|
||||||
|
// Could be completed later with all the classes that are using a given table
|
||||||
|
if (!array_key_exists($sTable, $aTables))
|
||||||
|
{
|
||||||
|
$aTables[$sTable] = array();
|
||||||
|
}
|
||||||
|
$aTables[$sTable][] = $sClass;
|
||||||
|
}
|
||||||
|
return $aTables;
|
||||||
|
}
|
||||||
|
|
||||||
final static public function DBGetKey($sClass)
|
final static public function DBGetKey($sClass)
|
||||||
{
|
{
|
||||||
self::_check_subclass($sClass);
|
self::_check_subclass($sClass);
|
||||||
@@ -1998,6 +2020,17 @@ abstract class MetaModel
|
|||||||
// $sDoCreateAll = implode(" ; ", $aSQL);
|
// $sDoCreateAll = implode(" ; ", $aSQL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function DBDump()
|
||||||
|
{
|
||||||
|
$aDataDump = array();
|
||||||
|
foreach (self::DBEnumTables() as $sTable => $aClasses)
|
||||||
|
{
|
||||||
|
$aRows = CMDBSource::DumpTable($sTable);
|
||||||
|
$aDataDump[$sTable] = $aRows;
|
||||||
|
}
|
||||||
|
return $aDataDump;
|
||||||
|
}
|
||||||
|
|
||||||
public static function DBCheckFormat()
|
public static function DBCheckFormat()
|
||||||
{
|
{
|
||||||
$aErrors = array();
|
$aErrors = array();
|
||||||
|
|||||||
@@ -207,6 +207,46 @@ function DebugQuery($sConfigFile)
|
|||||||
$oSet = new CMDBObjectSet($oFlt);
|
$oSet = new CMDBObjectSet($oFlt);
|
||||||
echo $oSet; // __toString()
|
echo $oSet; // __toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DumpDatabase()
|
||||||
|
{
|
||||||
|
$aData = MetaModel::DBDump();
|
||||||
|
foreach ($aData as $sTable => $aRows)
|
||||||
|
{
|
||||||
|
echo "<h1>".htmlentities($sTable)."</h1>\n";
|
||||||
|
|
||||||
|
if (count($aRows) == 0)
|
||||||
|
{
|
||||||
|
echo "<p>no data</p>\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "<p>".count($aRows)." row(s)</p>\n";
|
||||||
|
// Table header
|
||||||
|
echo "<table border=\"1\">\n";
|
||||||
|
echo "<tr>\n";
|
||||||
|
foreach (reset($aRows) as $key => $value)
|
||||||
|
{
|
||||||
|
echo "<th>".htmlentities($key)."</th>";
|
||||||
|
}
|
||||||
|
echo "</tr>\n";
|
||||||
|
|
||||||
|
// Table body
|
||||||
|
foreach ($aRows as $aRow)
|
||||||
|
{
|
||||||
|
echo "<tr>\n";
|
||||||
|
foreach ($aRow as $key => $value)
|
||||||
|
{
|
||||||
|
echo "<td>".htmlentities($value)."</td>";
|
||||||
|
}
|
||||||
|
echo "</tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Helper functions
|
// Helper functions
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -234,6 +274,7 @@ function printMenu($sConfigFile)
|
|||||||
echo " <li><a href=\"$sUrl&todo=checkall\">Check business model, DB format and data integrity</a></li>";
|
echo " <li><a href=\"$sUrl&todo=checkall\">Check business model, DB format and data integrity</a></li>";
|
||||||
echo " <li><a href=\"$sUrl&todo=showtables\">Show Tables</a></li>";
|
echo " <li><a href=\"$sUrl&todo=showtables\">Show Tables</a></li>";
|
||||||
echo " <li><a href=\"$sUrl&todo=debugquery\">Test an OQL query (debug)</a></li>";
|
echo " <li><a href=\"$sUrl&todo=debugquery\">Test an OQL query (debug)</a></li>";
|
||||||
|
echo " <li><a href=\"$sUrl&todo=dumpdb\">Dump database</a></li>";
|
||||||
// echo " <li>".htmlentities($sUrl)."&<b>todo=execsql</b>&<b>sql=xxx</b>, to execute a specific sql request</li>";
|
// echo " <li>".htmlentities($sUrl)."&<b>todo=execsql</b>&<b>sql=xxx</b>, to execute a specific sql request</li>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -443,6 +484,11 @@ else
|
|||||||
MetaModel::DBCheckIntegrity($sBaseUrl, "sql");
|
MetaModel::DBCheckIntegrity($sBaseUrl, "sql");
|
||||||
echo "done...</br>\n";
|
echo "done...</br>\n";
|
||||||
break;
|
break;
|
||||||
|
case "dumpdb":
|
||||||
|
echo "Dump DB data...</br>\n";
|
||||||
|
DumpDatabase();
|
||||||
|
echo "done...</br>\n";
|
||||||
|
break;
|
||||||
case "userrightssetup":
|
case "userrightssetup":
|
||||||
echo "Setup user rights module (init DB)...</br>\n";
|
echo "Setup user rights module (init DB)...</br>\n";
|
||||||
UserRights::Setup();
|
UserRights::Setup();
|
||||||
|
|||||||
Reference in New Issue
Block a user