1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8/** 9 * \brief Show list of Tiki tables in DB schema 10 * \author zaufi <zaufi@sendmail.ru> 11 */ 12require_once('lib/debug/debugger-ext.php'); 13 14/** 15 * \brief Show list of Tiki tables in DB schema 16 */ 17class DbgSQLTables extends DebuggerCommand 18{ 19 /// \b Must have function to announce command name in debugger console 20 function name() 21 { 22 return 'tikitables'; 23 } 24 25 /// \b Must have function to provide help to debugger console 26 function description() 27 { 28 return 'Show list of Tiki tables in DB schema'; 29 } 30 31 /// \b Must have function to provide help to debugger console 32 function syntax() 33 { 34 return 'tikitables [partial-name]'; 35 } 36 37 /// \b Must have function to show example of usage of given command 38 function example() 39 { 40 return 'tikitables' . "\n" . 'tikitables user' . "\n" . 'tikitables ions$'; 41 } 42 43 /// Execute command with given set of arguments. 44 function execute($params) 45 { 46 $this->set_result_type(TPL_RESULT); 47 48 $this->set_result_tpl('debug/tiki-debug_tikitables.tpl'); 49 // 50 global $tikilib; 51 // Is regex to match against var name given? 52 $p = explode(" ", trim($params)); 53 $mask = count($p) > 0 ? str_replace('$', '', trim($p[0])) : ''; 54 $len = strlen($mask); 55 // Get list of all tables 56 $qr = $tikilib->query("show tables;"); 57 $tbls = []; 58 59 while ($res = $qr->fetchRow(DB_FETCHMODE_ASSOC)) { 60 /* 61 * Sample output from MySQL. I.e. array(1) have unpredictable key 62 * (bcouse of name user defined table)... 63 * array(163) { 64 * [0]=> 65 * array(1) { 66 * ["Tables_in_tiki-devel"]=> 67 * string(18) "galaxia_activities" 68 * } 69 * [1]=> 70 * array(1) { 71 * ["Tables_in_tiki-devel"]=> 72 * string(22) "galaxia_activity_roles" 73 * } 74 * [2]=> 75 * array(1) { 76 * ["Tables_in_tiki-devel"]=> 77 * string(27) "galaxia_instance_activities" 78 * } 79 * ... 80 */ 81 if (! $len || $len && preg_match('/' . $mask . '/', current($res))) { 82 $tbls[] = current($res); 83 } 84 } 85 86 return $tbls; 87 } 88} 89 90/// Class factory to create instances of defined commands 91function dbg_command_factory_tikitables() 92{ 93 return new DbgSQLTables(); 94} 95