29if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
30 define(
'CSRFCHECK_WITH_TOKEN',
'1');
34require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
51$table =
GETPOST(
'table',
'aZ09');
52$action =
GETPOST(
'action',
'aZ09');
62if ($action ==
'convert') {
63 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ENGINE=INNODB";
64 $logsql .= $sql.
'<br>';
65 $resultsql = $db->query($sql);
67if ($action ==
'convertutf8') {
68 $collation =
'utf8_unicode_ci';
69 $defaultcollation = $db->getDefaultCollationDatabase();
70 if (preg_match(
'/general/', $defaultcollation)) {
71 $collation =
'utf8_general_ci';
73 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
74 $logsql .= $sql.
'<br>';
75 $resql1 = $db->query($sql);
80 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
81 $logsql .= $sql.
'<br>';
82 $resql2 = $db->query($sql);
89if ($action ==
'convertutf8mb4') {
90 $collation =
'utf8mb4_unicode_ci';
91 $defaultcollation = $db->getDefaultCollationDatabase();
92 if (preg_match(
'/general/', $defaultcollation)) {
93 $collation =
'utf8mb4_general_ci';
95 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
96 $logsql .= $sql.
'<br>';
97 $resql1 = $db->query($sql);
100 $resultsql = $resql1;
102 $sql =
"ALTER TABLE ".$db->sanitize($table).
" CONVERT TO CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
103 $logsql .= $sql.
'<br>';
104 $resql2 = $db->query($sql);
107 $resultsql = $resql2;
111if ($action ==
'convertdynamic') {
112 $sql =
"ALTER TABLE ".$db->sanitize($table).
" ROW_FORMAT=DYNAMIC;";
113 $logsql .= $sql.
'<br>';
114 $resultsql = $db->query($sql);
122llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-database_tables');
124$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/system/database.php?restore_lastsearch_values=1">'.
img_picto($langs->trans(
"GoBack"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"GoBack").
'</span></a>';
126print
load_fiche_titre($langs->trans(
"Tables").
" ".ucfirst($conf->db->type), $linkback,
'title_setup');
129 print
info_admin($logsql.
' '.(empty($resultsql) ?
' => KO '.$db->lasterror() :
' => OK'));
134if (preg_match(
'/mysql/i', $conf->db->type)) {
135 $sql =
"SHOW TABLE STATUS";
137} elseif ($conf->db->type ==
'pgsql') {
138 $sql =
"SELECT conname, contype FROM pg_constraint;";
140} elseif ($conf->db->type ==
'mssql') {
143} elseif ($conf->db->type ==
'sqlite' || $conf->db->type ==
'sqlite3') {
150 print $langs->trans(
"FeatureNotAvailableWithThisDatabaseDriver");
154 print
'<div class="div-table-responsive-no-min">';
155 print
'<table class="noborder">';
156 print
'<tr class="liste_titre">';
158 print
'<td>'.$langs->trans(
"TableName").
'</td>';
159 print
'<td colspan="2">'.$langs->trans(
"Type").
'</td>';
160 print
'<td>'.$langs->trans(
"Format").
'</td>';
161 print
'<td class="right">'.$langs->trans(
"NbOfRecord").
'</td>';
162 print
'<td class="right">Avg_row_length</td>';
163 print
'<td class="right">Data_length</td>';
164 print
'<td class="right">Max_Data_length</td>';
165 print
'<td class="right">Index_length</td>';
166 print
'<td class="right">Increment</td>';
167 print
'<td class="right">Last check</td>';
168 print
'<td class="right">Collation</td>';
171 $arrayoffilesrich =
dol_dir_list(DOL_DOCUMENT_ROOT.
'/install/mysql/tables/',
'files', 0,
'\.sql$');
172 $arrayoffiles = array();
173 $arrayoftablesautocreated = array();
174 foreach ($arrayoffilesrich as $value) {
176 $shortsqlfilename = preg_replace(
'/\-[a-z]+\./',
'.', $value[
'name']);
177 $arrayoffiles[$value[
'name']] = $shortsqlfilename;
178 if ($value[
'name'] == $shortsqlfilename && ! preg_match(
'/\.key\.sql$/', $value[
'name'])) {
180 $arrayoftablesautocreated[$value[
'name']] = $shortsqlfilename;
185 $sql =
"SHOW TABLE STATUS";
187 $resql = $db->query($sql);
189 $num = $db->num_rows($resql);
192 $obj = $db->fetch_object($resql);
194 print
'<tr class="oddeven">';
196 print
'<td>'.($i + 1).
'</td>';
197 print
'<td class="tdoverflowmax300" title="'.dol_escape_htmltag($obj->Name).
'"><a href="dbtable.php?table='.urlencode($obj->Name).
'">'.$obj->Name.
'</a>';
198 $tablename = preg_replace(
'/^'.MAIN_DB_PREFIX.
'/',
'llx_', $obj->Name);
200 if (in_array($tablename.
'.sql', $arrayoffiles)) {
201 if (in_array($tablename.
'.sql', $arrayoftablesautocreated)) {
205 print
img_picto($langs->trans(
"NotAvailableByDefaultEnabledOnModuleActivation"), $img,
'class="small opacitymedium"');
209 print
img_picto($langs->trans(
"ExternalModule"), $img,
'class="small"');
212 print
'<td>'.$obj->Engine.
'</td>';
213 if (isset($obj->Engine) && $obj->Engine ==
"MyISAM") {
214 print
'<td><a class="reposition" href="database-tables.php?action=convert&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' InnoDb</a></td>';
216 print
'<td> </td>';
219 print $obj->Row_format;
220 if (isset($obj->Row_format) && (in_array($obj->Row_format, array(
"Compact")))) {
221 print
'<br><a class="reposition" href="database-tables.php?action=convertdynamic&table='.urlencode($obj->Name).
'&token='.
newToken().
'">'.$langs->trans(
"Convert").
' Dynamic</a>';
224 print
'<td class="right">'.$obj->Rows.
'</td>';
225 print
'<td class="right">'.$obj->Avg_row_length.
'</td>';
226 print
'<td class="right">'.$obj->Data_length.
'</td>';
227 print
'<td class="right">'.$obj->Max_data_length.
'</td>';
228 print
'<td class="right">'.$obj->Index_length.
'</td>';
229 print
'<td class="right">'.$obj->Auto_increment.
'</td>';
230 print
'<td class="right">'.$obj->Check_time.
'</td>';
231 print
'<td class="right nowraponall">'.$obj->Collation;
233 if (isset($obj->Collation)) {
234 print
'<br><span class="opacitymedium small">'.$langs->trans(
"ConvertInto");
235 if (!in_array($obj->Collation, array(
"utf8_unicode_ci"))) {
236 print
' <a class="reposition" href="database-tables.php?action=convertutf8&table='.urlencode($obj->Name).
'&token='.
newToken().
'" title="Charset utf8 + Collation utf8_unicode_ci">utf8</a>';
238 if (!in_array($obj->Collation, array(
"utf8mb4_unicode_ci"))) {
239 print
' <a class="reposition" href="database-tables.php?action=convertutf8mb4&table='.urlencode($obj->Name).
'&token='.
newToken().
'" title="Charset utf8mb4 + Collation utf8mb4_unicode_ci">utf8mb4</a>';
253 print
'<div class="div-table-responsive-no-min">';
254 print
'<table class="noborder">';
255 print
'<tr class="liste_titre">';
258 print
'<td>'.$langs->trans(
"TableName").
'</td>';
259 print
'<td>Nb of tuples</td>';
260 print
'<td>Nb index fetcher.</td>';
261 print
'<td>Nb tuples insert</td>';
262 print
'<td>Nb tuples modify</td>';
263 print
'<td>Nb tuples delete</td>';
266 $sql =
"SELECT relname, seq_tup_read, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del";
267 $sql .=
" FROM pg_stat_user_tables ORDER BY relname";
269 $resql = $db->query($sql);
271 $num = $db->num_rows($resql);
274 $row = $db->fetch_row($resql);
275 print
'<tr class="oddeven">';
276 print
'<td>'.($i + 1).
'</td>';
277 print
'<td>'.$row[0].
'</td>';
278 print
'<td class="right">'.$row[1].
'</td>';
279 print
'<td class="right">'.$row[2].
'</td>';
280 print
'<td class="right">'.$row[3].
'</td>';
281 print
'<td class="right">'.$row[4].
'</td>';
282 print
'<td class="right">'.$row[5].
'</td>';
293 print
'<div class="div-table-responsive-no-min">';
294 print
'<table class="noborder">';
295 print
'<tr class="liste_titre">';
297 print
'<td>'.$langs->trans(
"TableName").
'</td>';
298 print
'<td>'.$langs->trans(
"NbOfRecord").
'</td>';
301 $sql =
"SELECT name, type FROM sqlite_master where type='table' and name not like 'sqlite%' ORDER BY name";
302 $resql = $db->query($sql);
305 while ($row = $db->fetch_row($resql)) {
306 $rescount = $db->query(
"SELECT COUNT(*) FROM ".$row[0]);
308 $row_count = $db->fetch_row($rescount);
309 $count = $row_count[0];
314 print
'<tr class="oddeven">';
315 print
'<td>'.($i + 1).
'</td>';
316 print
'<td>'.$row[0].
'</td>';
317 print
'<td>'.$count.
'</td>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.