The branch, master has been updated via 855dc6e6456be8503061ef7f473fa4d95b4a25d6 (commit) via 6b0fb6c20678e490b72f768ec66ded5028187ec1 (commit) via d5489c4432e09f5eb026223c4878db6e7261e0ff (commit) from 5e860f187467162b2995c48feaff6689ba1accd2 (commit)
- Log ----------------------------------------------------------------- commit 855dc6e6456be8503061ef7f473fa4d95b4a25d6 Merge: 6b0fb6c 5e860f1 Author: Madhura Jayaratne madhura.cj@gmail.com Date: Fri Aug 19 23:30:32 2011 +0530
Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin/phpmyadmin
commit 6b0fb6c20678e490b72f768ec66ded5028187ec1 Author: Madhura Jayaratne madhura.cj@gmail.com Date: Fri Aug 19 21:51:32 2011 +0530
Code style improvements
commit d5489c4432e09f5eb026223c4878db6e7261e0ff Author: Madhura Jayaratne madhura.cj@gmail.com Date: Fri Aug 19 21:43:07 2011 +0530
Fix doc blocks and multi line if statements
-----------------------------------------------------------------------
Summary of changes: libraries/Tracker.class.php | 184 ++++++++++++++++++------------------- libraries/transformations.lib.php | 47 ++++++---- 2 files changed, 119 insertions(+), 112 deletions(-)
diff --git a/libraries/Tracker.class.php b/libraries/Tracker.class.php index de216ab..e71b7d6 100644 --- a/libraries/Tracker.class.php +++ b/libraries/Tracker.class.php @@ -71,6 +71,7 @@ class PMA_Tracker * * @static * + * @return nothing */ static public function init() { @@ -86,15 +87,15 @@ class PMA_Tracker self::$default_tracking_set = $GLOBALS['cfg']['Server']['tracking_default_statements'];
self::$version_auto_create = $GLOBALS['cfg']['Server']['tracking_version_auto_create']; - }
/** - * Actually enables tracking. This needs to be done after all + * Actually enables tracking. This needs to be done after all * underlaying code is initialized. * * @static * + * @return nothing */ static public function enable() { @@ -133,9 +134,9 @@ class PMA_Tracker /** * Parses the name of a table from a SQL statement substring. * - * @static + * @param string $string part of SQL statement * - * @param string $string part of SQL statement + * @static * * @return string the name of table */ @@ -144,8 +145,7 @@ class PMA_Tracker if (strstr($string, '.')) { $temp = explode('.', $string); $tablename = $temp[1]; - } - else { + } else { $tablename = $string; }
@@ -163,10 +163,10 @@ class PMA_Tracker /** * Gets the tracking status of a table, is it active or deactive ? * - * @static + * @param string $dbname name of database + * @param string $tablename name of table * - * @param string $dbname name of database - * @param string $tablename name of table + * @static * * @return boolean true or false */ @@ -184,8 +184,7 @@ class PMA_Tracker return false; }
- $sql_query = - " SELECT tracking_active FROM " . self::$pma_table . + $sql_query = " SELECT tracking_active FROM " . self::$pma_table . " WHERE db_name = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND table_name = '" . PMA_sqlAddSlashes($tablename) . "' " . " ORDER BY version DESC"; @@ -215,14 +214,14 @@ class PMA_Tracker * Creates tracking version of a table / view * (in other words: create a job to track future changes on the table). * - * @static - * * @param string $dbname name of database * @param string $tablename name of table * @param string $version version * @param string $tracking_set set of tracking statements * @param bool $is_view if table is a view * + * @static + * * @return int result of version insertion */ static public function createVersion($dbname, $tablename, $version, $tracking_set = '', $is_view = false) @@ -233,7 +232,7 @@ class PMA_Tracker $tracking_set = self::$default_tracking_set; }
- require_once './libraries/export/sql.php'; + include_once './libraries/export/sql.php';
$sql_backquotes = true;
@@ -256,7 +255,7 @@ class PMA_Tracker
$indexes = array();
- while($row = PMA_DBI_fetch_assoc($sql_result)) { + while ($row = PMA_DBI_fetch_assoc($sql_result)) { $indexes[] = $row; }
@@ -284,8 +283,7 @@ class PMA_Tracker
// Save version
- $sql_query = - "/*NOTRACK*/\n" . + $sql_query = "/*NOTRACK*/\n" . "INSERT INTO" . self::$pma_table . " (" . "db_name, " . "table_name, " . @@ -320,19 +318,18 @@ class PMA_Tracker
/** - * Removes all tracking data for a table + * Removes all tracking data for a table * - * @static + * @param string $dbname name of database + * @param string $tablename name of table * - * @param string $dbname name of database - * @param string $tablename name of table + * @static * * @return int result of version insertion */ static public function deleteTracking($dbname, $tablename) { - $sql_query = - "/*NOTRACK*/\n" . + $sql_query = "/*NOTRACK*/\n" . "DELETE FROM " . self::$pma_table . " WHERE `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' AND `table_name` = '" . PMA_sqlAddSlashes($tablename) . "'"; $result = PMA_query_as_controluser($sql_query);
@@ -343,13 +340,13 @@ class PMA_Tracker * Creates tracking version of a database * (in other words: create a job to track future changes on the database). * - * @static - * * @param string $dbname name of database * @param string $version version * @param string $query query * @param string $tracking_set set of tracking statements * + * @static + * * @return int result of version insertion */ static public function createDatabaseVersion($dbname, $version, $query, $tracking_set = 'CREATE DATABASE,ALTER DATABASE,DROP DATABASE') @@ -360,7 +357,7 @@ class PMA_Tracker $tracking_set = self::$default_tracking_set; }
- require_once './libraries/export/sql.php'; + include_once './libraries/export/sql.php';
$create_sql = "";
@@ -372,8 +369,7 @@ class PMA_Tracker $create_sql .= self::getLogComment() . $query;
// Save version - $sql_query = - "/*NOTRACK*/\n" . + $sql_query = "/*NOTRACK*/\n" . "INSERT INTO" . self::$pma_table . " (" . "db_name, " . "table_name, " . @@ -406,19 +402,18 @@ class PMA_Tracker /** * Changes tracking of a table. * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $version version + * @param integer $new_state the new state of tracking * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $version version - * @param integer $new_state the new state of tracking + * @static * * @return int result of SQL query */ - static private function changeTracking($dbname, $tablename, $version, $new_state) + static private function _changeTracking($dbname, $tablename, $version, $new_state) { - $sql_query = - " UPDATE " . self::$pma_table . + $sql_query = " UPDATE " . self::$pma_table . " SET `tracking_active` = '" . $new_state . "' " . " WHERE `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND `table_name` = '" . PMA_sqlAddSlashes($tablename) . "' " . @@ -432,38 +427,38 @@ class PMA_Tracker /** * Changes tracking data of a table. * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $version version + * @param string $type type of data(DDL || DML) + * @param string|array $new_data the new tracking data * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $version version - * @param string $type type of data(DDL || DML) - * @param string|array $new_data the new tracking data + * @static * * @return bool result of change */ static public function changeTrackingData($dbname, $tablename, $version, $type, $new_data) { - if ($type == 'DDL') + if ($type == 'DDL') { $save_to = 'schema_sql'; - elseif ($type == 'DML') + } elseif ($type == 'DML') { $save_to = 'data_sql'; - else + } else { return false; - + } $date = date('Y-m-d H:i:s');
$new_data_processed = ''; if (is_array($new_data)) { foreach ($new_data as $data) { - $new_data_processed .= '# log ' . $date . ' ' . $data['username'] . PMA_sqlAddSlashes($data['statement']) . "\n"; + $new_data_processed .= '# log ' . $date . ' ' . $data['username'] + . PMA_sqlAddSlashes($data['statement']) . "\n"; } } else { $new_data_processed = $new_data; }
- $sql_query = - " UPDATE " . self::$pma_table . + $sql_query = " UPDATE " . self::$pma_table . " SET `" . $save_to . "` = '" . $new_data_processed . "' " . " WHERE `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND `table_name` = '" . PMA_sqlAddSlashes($tablename) . "' " . @@ -477,34 +472,34 @@ class PMA_Tracker /** * Activates tracking of a table. * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $version version * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $version version + * @static * * @return int result of SQL query */ static public function activateTracking($dbname, $tablename, $version) { - return self::changeTracking($dbname, $tablename, $version, 1); + return self::_changeTracking($dbname, $tablename, $version, 1); }
/** * Deactivates tracking of a table. * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $version version * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $version version + * @static * * @return int result of SQL query */ static public function deactivateTracking($dbname, $tablename, $version) { - return self::changeTracking($dbname, $tablename, $version, 0); + return self::_changeTracking($dbname, $tablename, $version, 0); }
@@ -512,18 +507,17 @@ class PMA_Tracker * Gets the newest version of a tracking job * (in other words: gets the HEAD version). * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $statement tracked statement * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $statement tracked statement + * @static * * @return int (-1 if no version exists | > 0 if a version exists) */ static public function getVersion($dbname, $tablename, $statement = null) { - $sql_query = - " SELECT MAX(version) FROM " . self::$pma_table . + $sql_query = " SELECT MAX(version) FROM " . self::$pma_table . " WHERE `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND `table_name` = '" . PMA_sqlAddSlashes($tablename) . "' ";
@@ -540,11 +534,11 @@ class PMA_Tracker /** * Gets the record of a tracking job. * - * @static + * @param string $dbname name of database + * @param string $tablename name of table + * @param string $version version number * - * @param string $dbname name of database - * @param string $tablename name of table - * @param string $version version number + * @static * * @return mixed record DDM log, DDL log, structure snapshot, tracked statements. */ @@ -644,12 +638,12 @@ class PMA_Tracker * - type of statement, is it part of DDL or DML ? * - tablename * + * @param string $query query + * * @static * @todo: using PMA SQL Parser when possible * @todo: support multi-table/view drops * - * @param string $query - * * @return mixed Array containing identifier, type and tablename. * */ @@ -684,9 +678,10 @@ class PMA_Tracker $result['type'] = 'DDL';
// Parse CREATE VIEW statement - if (in_array('CREATE', $tokens) == true && - in_array('VIEW', $tokens) == true && - in_array('AS', $tokens) == true) { + if (in_array('CREATE', $tokens) == true + && in_array('VIEW', $tokens) == true + && in_array('AS', $tokens) == true + ) { $result['identifier'] = 'CREATE VIEW';
$index = array_search('VIEW', $tokens); @@ -695,10 +690,11 @@ class PMA_Tracker }
// Parse ALTER VIEW statement - if (in_array('ALTER', $tokens) == true && - in_array('VIEW', $tokens) == true && - in_array('AS', $tokens) == true && - ! isset($result['identifier'])) { + if (in_array('ALTER', $tokens) == true + && in_array('VIEW', $tokens) == true + && in_array('AS', $tokens) == true + && ! isset($result['identifier']) + ) { $result['identifier'] = 'ALTER VIEW';
$index = array_search('VIEW', $tokens); @@ -778,11 +774,10 @@ class PMA_Tracker }
// Parse CREATE INDEX statement - if (! isset($result['identifier']) && - ( substr($query, 0, 12) == 'CREATE INDEX' || - substr($query, 0, 19) == 'CREATE UNIQUE INDEX' || - substr($query, 0, 20) == 'CREATE SPATIAL INDEX' - ) + if (! isset($result['identifier']) + && (substr($query, 0, 12) == 'CREATE INDEX' + || substr($query, 0, 19) == 'CREATE UNIQUE INDEX' + || substr($query, 0, 20) == 'CREATE SPATIAL INDEX') ) { $result['identifier'] = 'CREATE INDEX'; $prefix = explode('ON ', $query); @@ -822,7 +817,7 @@ class PMA_Tracker }
// Parse INSERT INTO statement - if (! isset($result['identifier']) && substr($query, 0, 11 ) == 'INSERT INTO') { + if (! isset($result['identifier']) && substr($query, 0, 11) == 'INSERT INTO') { $result['identifier'] = 'INSERT'; $prefix = explode('INSERT INTO', $query); $suffix = explode('(', $prefix[1]); @@ -830,7 +825,7 @@ class PMA_Tracker }
// Parse DELETE statement - if (! isset($result['identifier']) && substr($query, 0, 6 ) == 'DELETE') { + if (! isset($result['identifier']) && substr($query, 0, 6) == 'DELETE') { $result['identifier'] = 'DELETE'; $prefix = explode('FROM ', $query); $suffix = explode(' ', $prefix[1]); @@ -838,7 +833,7 @@ class PMA_Tracker }
// Parse TRUNCATE statement - if (! isset($result['identifier']) && substr($query, 0, 8 ) == 'TRUNCATE') { + if (! isset($result['identifier']) && substr($query, 0, 8) == 'TRUNCATE') { $result['identifier'] = 'TRUNCATE'; $prefix = explode('TRUNCATE', $query); $result['tablename'] = self::getTableName($prefix[1]); @@ -851,8 +846,11 @@ class PMA_Tracker /** * Analyzes a given SQL statement and saves tracking data. * - * @static * @param string $query a SQL query + * + * @static + * + * @return nothing */ static public function handleQuery($query) { @@ -881,8 +879,9 @@ class PMA_Tracker
// If version not exists and auto-creation is enabled if (self::$version_auto_create == true - && self::isTracked($dbname, $result['tablename']) == false - && $version == -1) { + && self::isTracked($dbname, $result['tablename']) == false + && $version == -1 + ) { // Create the version
switch ($result['identifier']) { @@ -916,11 +915,10 @@ class PMA_Tracker $query = self::getLogComment() . $query ;
// Mark it as untouchable - $sql_query = - " /*NOTRACK*/\n" . + $sql_query = " /*NOTRACK*/\n" . " UPDATE " . self::$pma_table . - " SET " . PMA_backquote($save_to) ." = CONCAT( " . PMA_backquote($save_to) . ",'\n" . PMA_sqlAddSlashes($query) . "') ," . - " `date_updated` = '" . $date . "' "; + " SET " . PMA_backquote($save_to) ." = CONCAT( " . PMA_backquote($save_to) . ",'\n" + . PMA_sqlAddSlashes($query) . "') ," . " `date_updated` = '" . $date . "' ";
// If table was renamed we have to change the tablename attribute in pma_tracking too if ($result['identifier'] == 'RENAME TABLE') { diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index a5460ab..51da6ce 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -19,23 +19,26 @@ * // } * </code> * - * @param string $option_string comma separated options - * @return array options + * @param string $option_string comma separated options + * + * @return array options */ function PMA_transformation_getOptions($option_string) { $result = array();
if (! strlen($option_string) - || ! $transform_options = preg_split('/,/', $option_string)) { + || ! $transform_options = preg_split('/,/', $option_string) + ) { return $result; }
while (($option = array_shift($transform_options)) !== null) { $trimmed = trim($option); if (strlen($trimmed) > 1 - && $trimmed[0] == "'" - && $trimmed[strlen($trimmed) - 1] == "'") { + && $trimmed[0] == "'" + && $trimmed[strlen($trimmed) - 1] == "'" + ) { // '...' $option = substr($trimmed, 1, -1); } elseif (isset($trimmed[0]) && $trimmed[0] == "'") { @@ -117,11 +120,13 @@ function PMA_getAvailableMIMEtypes() /** * Gets the mimetypes for all columns of a table * + * @param string $db the name of the db to check for + * @param string $table the name of the table to check for + * @param string $strict whether to include only results having a mimetype set + * * @access public - * @param string $db the name of the db to check for - * @param string $table the name of the table to check for - * @param string $strict whether to include only results having a mimetype set - * @return array [field_name][field_key] = field_value + * + * @return array [field_name][field_key] = field_value */ function PMA_getMIME($db, $table, $strict = false) { @@ -136,7 +141,7 @@ function PMA_getMIME($db, $table, $strict = false) `mimetype`, `transformation`, `transformation_options` - FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' + FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE `db_name` = '' . PMA_sqlAddSlashes($db) . '' AND `table_name` = '' . PMA_sqlAddSlashes($table) . '' AND ( `mimetype` != ''' . (!$strict ? ' @@ -148,14 +153,17 @@ function PMA_getMIME($db, $table, $strict = false) /** * Set a single mimetype to a certain value. * + * @param string $db the name of the db + * @param string $table the name of the table + * @param string $key the name of the column + * @param string $mimetype the mimetype of the column + * @param string $transformation the transformation of the column + * @param string $transformation_options the transformation options of the column + * @param string $forcedelete force delete, will erase any existing + * comments for this column + * * @access public - * @param string $db the name of the db - * @param string $table the name of the table - * @param string $key the name of the column - * @param string $mimetype the mimetype of the column - * @param string $transformation the transformation of the column - * @param string $transformation_options the transformation options of the column - * @param string $forcedelete force delete, will erase any existing comments for this column + * * @return boolean true, if comment-query was made. */ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, @@ -181,8 +189,9 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, PMA_DBI_free_result($test_rs);
if (! $forcedelete - && (strlen($mimetype) || strlen($transformation) - || strlen($transformation_options) || strlen($row['comment']))) { + && (strlen($mimetype) || strlen($transformation) + || strlen($transformation_options) || strlen($row['comment'])) + ) { $upd_query = ' UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' SET `mimetype` = '' . PMA_sqlAddSlashes($mimetype) . '',
hooks/post-receive