Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / StorageEngine.class.php
blob2dfe7f7ef15597ec21eee961e4ce3f86513b66cb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * defines
15 define('PMA_ENGINE_SUPPORT_NO', 0);
16 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
17 define('PMA_ENGINE_SUPPORT_YES', 2);
18 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
20 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
21 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
22 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
23 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
25 /**
26 * Base Storage Engine Class
28 * @package PhpMyAdmin
30 class PMA_StorageEngine
32 /**
33 * @var string engine name
35 var $engine = 'dummy';
37 /**
38 * @var string engine title/description
40 var $title = 'PMA Dummy Engine Class';
42 /**
43 * @var string engine lang description
45 var $comment
46 = 'If you read this text inside phpMyAdmin, something went wrong...';
48 /**
49 * @var integer engine supported by current server
51 var $support = PMA_ENGINE_SUPPORT_NO;
53 /**
54 * returns array of storage engines
56 * @static
57 * @staticvar array $storage_engines storage engines
58 * @access public
59 * @return array of storage engines
61 static public function getStorageEngines()
63 static $storage_engines = null;
65 if (null == $storage_engines) {
66 if (PMA_DRIZZLE) {
67 $sql = "SELECT
68 p.plugin_name AS Engine,
69 (CASE
70 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
71 WHEN p.is_active THEN 'YES'
72 ELSE 'DISABLED' END) AS Support,
73 m.module_description AS Comment
74 FROM data_dictionary.plugins p
75 JOIN data_dictionary.modules m USING (module_name)
76 WHERE p.plugin_type = 'StorageEngine'
77 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
78 $storage_engines = PMA_DBI_fetch_result($sql, 'Engine');
79 } else {
80 $storage_engines
81 = PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
85 return $storage_engines;
88 /**
89 * returns HTML code for storage engine select box
91 * @param string $name The name of the select form element
92 * @param string $id The ID of the form field
93 * @param string $selected The selected engine
94 * @param boolean $offerUnavailableEngines Should unavailable storage
95 * engines be offered?
97 * @static
98 * @return string html selectbox
100 static public function getHtmlSelect(
101 $name = 'engine', $id = null,
102 $selected = null, $offerUnavailableEngines = false
104 $selected = strtolower($selected);
105 $output = '<select name="' . $name . '"'
106 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
108 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
109 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
110 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
111 if (! $offerUnavailableEngines
112 && ($details['Support'] == 'NO'
113 || $details['Support'] == 'DISABLED'
114 || $details['Engine'] == 'PERFORMANCE_SCHEMA')
115 || (PMA_DRIZZLE && $details['Engine'] == 'MyISAM')
117 continue;
120 $output .= ' <option value="' . htmlspecialchars($key). '"'
121 . (empty($details['Comment'])
122 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
123 . (strtolower($key) == $selected
124 || (empty($selected) && $details['Support'] == 'DEFAULT')
125 ? ' selected="selected"' : '')
126 . '>' . "\n"
127 . ' ' . htmlspecialchars($details['Engine']) . "\n"
128 . ' </option>' . "\n";
130 $output .= '</select>' . "\n";
131 return $output;
135 * public static final PMA_StorageEngine getEngine()
137 * Loads the corresponding engine plugin, if available.
139 * @param string $engine The engine ID
141 * @return object The engine plugin
143 static public function getEngine($engine)
145 $engine = str_replace('/', '', str_replace('.', '', $engine));
146 $filename = './libraries/engines/' . strtolower($engine) . '.lib.php';
147 if (file_exists($filename) && include_once $filename) {
148 $class_name = 'PMA_StorageEngine_' . $engine;
149 $engine_object = new $class_name($engine);
150 } else {
151 $engine_object = new PMA_StorageEngine($engine);
153 return $engine_object;
157 * return true if given engine name is supported/valid, otherwise false
159 * @param string $engine name of engine
161 * @static
162 * @return boolean whether $engine is valid or not
164 static public function isValid($engine)
166 if ($engine == "PBMS") {
167 return true;
169 $storage_engines = PMA_StorageEngine::getStorageEngines();
170 return isset($storage_engines[$engine]);
174 * returns as HTML table of the engine's server variables
176 * @return string The table that was generated based on the retrieved
177 * information
179 function getHtmlVariables()
181 $odd_row = false;
182 $ret = '';
184 foreach ($this->getVariablesStatus() as $details) {
185 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
186 . ' <td>' . "\n";
187 if (! empty($details['desc'])) {
188 $ret .= ' '
189 . PMA_Util::showHint($details['desc'])
190 . "\n";
192 $ret .= ' </td>' . "\n"
193 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
194 . "\n"
195 . ' <td class="value">';
196 switch ($details['type']) {
197 case PMA_ENGINE_DETAILS_TYPE_SIZE:
198 $parsed_size = $this->resolveTypeSize($details['value']);
199 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
200 unset($parsed_size);
201 break;
202 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
203 $ret .= PMA_Util::formatNumber($details['value']) . ' ';
204 break;
205 default:
206 $ret .= htmlspecialchars($details['value']) . ' ';
208 $ret .= '</td>' . "\n"
209 . '</tr>' . "\n";
210 $odd_row = ! $odd_row;
213 if (! $ret) {
214 $ret = '<p>' . "\n"
215 . ' '
216 . __('There is no detailed status information available for this storage engine.')
217 . "\n"
218 . '</p>' . "\n";
219 } else {
220 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
223 return $ret;
227 * Returns the engine specific handling for
228 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
230 * This function should be overridden when
231 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
232 * handled differently for a particular engine.
234 * @param integer $value Value to format
236 * @return string the formatted value and its unit
238 function resolveTypeSize($value)
240 return PMA_Util::formatByteDown($value);
244 * returns array with detailed info about engine specific server variables
246 * @return array with detailed info about specific engine server variables
248 function getVariablesStatus()
250 $variables = $this->getVariables();
251 $like = $this->getVariablesLikePattern();
253 if ($like) {
254 $like = " LIKE '" . $like . "' ";
255 } else {
256 $like = '';
259 $mysql_vars = array();
261 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
262 $res = PMA_DBI_query($sql_query);
263 while ($row = PMA_DBI_fetch_assoc($res)) {
264 if (isset($variables[$row['Variable_name']])) {
265 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
266 } elseif (! $like
267 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0
269 continue;
271 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
273 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
274 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
277 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
278 $mysql_vars[$row['Variable_name']]['type']
279 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
282 PMA_DBI_free_result($res);
284 return $mysql_vars;
288 * Constructor
290 * @param string $engine The engine ID
292 function __construct($engine)
294 $storage_engines = PMA_StorageEngine::getStorageEngines();
295 if (! empty($storage_engines[$engine])) {
296 $this->engine = $engine;
297 $this->title = $storage_engines[$engine]['Engine'];
298 $this->comment
299 = (isset($storage_engines[$engine]['Comment'])
300 ? $storage_engines[$engine]['Comment']
301 : '');
302 switch ($storage_engines[$engine]['Support']) {
303 case 'DEFAULT':
304 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
305 break;
306 case 'YES':
307 $this->support = PMA_ENGINE_SUPPORT_YES;
308 break;
309 case 'DISABLED':
310 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
311 break;
312 case 'NO':
313 default:
314 $this->support = PMA_ENGINE_SUPPORT_NO;
320 * public String getTitle()
322 * Reveals the engine's title
324 * @return string The title
326 function getTitle()
328 return $this->title;
332 * public String getComment()
334 * Fetches the server's comment about this engine
336 * @return string The comment
338 function getComment()
340 return $this->comment;
344 * public String getSupportInformationMessage()
346 * @return string The localized message.
348 function getSupportInformationMessage()
350 switch ($this->support) {
351 case PMA_ENGINE_SUPPORT_DEFAULT:
352 $message = __('%s is the default storage engine on this MySQL server.');
353 break;
354 case PMA_ENGINE_SUPPORT_YES:
355 $message = __('%s is available on this MySQL server.');
356 break;
357 case PMA_ENGINE_SUPPORT_DISABLED:
358 $message = __('%s has been disabled for this MySQL server.');
359 break;
360 case PMA_ENGINE_SUPPORT_NO:
361 default:
362 $message = __('This MySQL server does not support the %s storage engine.');
364 return sprintf($message, htmlspecialchars($this->title));
368 * public string[][] getVariables()
370 * Generates a list of MySQL variables that provide information about this
371 * engine. This function should be overridden when extending this class
372 * for a particular engine.
374 * @abstract
375 * @return Array The list of variables.
377 function getVariables()
379 return array();
383 * returns string with filename for the MySQL helppage
384 * about this storage engine
386 * @return string mysql helppage filename
388 function getMysqlHelpPage()
390 return $this->engine . '-storage-engine';
394 * public string getVariablesLikePattern()
396 * @abstract
397 * @return string SQL query LIKE pattern
399 function getVariablesLikePattern()
401 return false;
405 * public String[] getInfoPages()
407 * Returns a list of available information pages with labels
409 * @abstract
410 * @return array The list
412 function getInfoPages()
414 return array();
418 * public String getPage()
420 * Generates the requested information page
422 * @param string $id The page ID
424 * @abstract
425 * @return string The page
426 * boolean or false on error.
428 function getPage($id)
430 return false;