From 35c4f1e26f0cc38386eebb5f6844493f985691ee Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 2 Oct 2011 00:41:55 +0200 Subject: [PATCH] MDL-29611 xmldb editor - comments and whitespace cleanup --- .../tool/xmldb/actions/XMLDBAction.class.php | 34 +-- .../xmldb/actions/XMLDBCheckAction.class.php | 58 ++-- .../check_bigints/check_bigints.class.php | 34 +-- .../check_defaults/check_defaults.class.php | 24 +- .../check_foreign_keys.class.php | 20 +- .../check_indexes/check_indexes.class.php | 32 +-- .../create_xml_file/create_xml_file.class.php | 24 +- .../delete_field/delete_field.class.php | 30 +- .../delete_index/delete_index.class.php | 30 +- .../actions/delete_key/delete_key.class.php | 30 +- .../delete_table/delete_table.class.php | 22 +- .../delete_xml_file/delete_xml_file.class.php | 20 +- .../actions/edit_field/edit_field.class.php | 68 +++-- .../xmldb/actions/edit_field/edit_field.js | 89 +++--- .../edit_field_save/edit_field_save.class.php | 62 ++--- .../actions/edit_index/edit_index.class.php | 46 ++-- .../edit_index_save/edit_index_save.class.php | 64 ++--- .../xmldb/actions/edit_key/edit_key.class.php | 58 ++-- admin/tool/xmldb/actions/edit_key/edit_key.js | 80 +++--- .../edit_key_save/edit_key_save.class.php | 82 +++--- .../actions/edit_table/edit_table.class.php | 115 ++++---- .../edit_table_save/edit_table_save.class.php | 48 ++-- .../edit_xml_file/edit_xml_file.class.php | 75 +++-- .../edit_xml_file_save.class.php | 26 +- .../generate_all_documentation.class.php | 14 +- .../generate_documentation.class.php | 18 +- .../get_db_directories.class.php | 24 +- .../load_xml_file/load_xml_file.class.php | 30 +- .../load_xml_files/load_xml_files.class.php | 24 +- .../actions/main_view/main_view.class.php | 78 +++--- .../move_updown_field.class.php | 40 +-- .../move_updown_index.class.php | 40 +-- .../move_updown_key/move_updown_key.class.php | 40 +-- .../move_updown_table.class.php | 40 +-- .../actions/new_field/new_field.class.php | 31 +-- .../actions/new_index/new_index.class.php | 31 +-- .../xmldb/actions/new_key/new_key.class.php | 31 +-- .../actions/new_table/new_table.class.php | 29 +- .../new_table_from_mysql.class.php | 68 ++--- .../revert_changes/revert_changes.class.php | 22 +- .../save_xml_file/save_xml_file.class.php | 30 +- .../xmldb/actions/template/template.class.php | 24 +- .../unload_xml_file/unload_xml_file.class.php | 23 +- .../view_field_xml/view_field_xml.class.php | 36 +-- .../view_index_xml/view_index_xml.class.php | 36 +-- .../view_key_xml/view_key_xml.class.php | 36 +-- .../view_reserved_words.class.php | 26 +- .../view_structure_php.class.php | 91 +++---- .../view_structure_sql.class.php | 23 +- .../view_structure_xml.class.php | 28 +- .../view_table_php/view_table_php.class.php | 257 +++++++++--------- .../actions/view_table_php/view_table_php.js | 54 ++-- .../view_table_sql/view_table_sql.class.php | 25 +- .../view_table_xml/view_table_xml.class.php | 32 +-- .../xmldb/actions/view_xml/view_xml.class.php | 26 +- admin/tool/xmldb/index.php | 30 +- 56 files changed, 1236 insertions(+), 1272 deletions(-) diff --git a/admin/tool/xmldb/actions/XMLDBAction.class.php b/admin/tool/xmldb/actions/XMLDBAction.class.php index 9d1aa343bb0..b853a7e631d 100644 --- a/admin/tool/xmldb/actions/XMLDBAction.class.php +++ b/admin/tool/xmldb/actions/XMLDBAction.class.php @@ -126,14 +126,14 @@ class XMLDBAction { * array parameter */ function loadStrings($strings) { - /// Load some commonly used strings + // Load some commonly used strings if (get_string_manager()->string_exists($this->title, 'tool_xmldb')) { $this->str['title'] = get_string($this->title, 'tool_xmldb'); } else { $this->str['title'] = $this->title; } - /// Now process the $strings array loading it in the $str atribute + // Now process the $strings array loading it in the $str atribute if ($strings) { foreach ($strings as $key => $module) { $this->str[$key] = get_string($key, $module); @@ -149,19 +149,19 @@ class XMLDBAction { global $SESSION; - /// Sesskey protection + // Sesskey protection if ($this->sesskey_protected) { require_sesskey(); } - /// If we are used any dir, save it in the lastused session object - /// Some actions can use it to perform positioning + // If we are used any dir, save it in the lastused session object + // Some actions can use it to perform positioning if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) { $SESSION->lastused = $lastused; } $this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT); - /// Avoid being recursive + // Avoid being recursive if ($this->title == $this->postaction) { $this->postaction = NULL; } @@ -174,12 +174,12 @@ class XMLDBAction { global $CFG; - /// Get the action path and invoke it + // Get the action path and invoke it $actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions"; $actionclass = $action . '.class.php'; $actionpath = "$actionsroot/$action/$actionclass"; - /// Load and invoke the proper action + // Load and invoke the proper action $result = false; if (file_exists($actionpath) && is_readable($actionpath)) { require_once($actionpath); @@ -218,16 +218,16 @@ class XMLDBAction { $path = $structure->getPath(); - /// Trim "db" from path + // Trim "db" from path $path = dirname($path); - /// Get pluginname, plugindir and plugintype + // Get pluginname, plugindir and plugintype $pluginname = basename($path); - if ($path == 'lib') { /// exception for lib (not proper plugin) + if ($path == 'lib') { // exception for lib (not proper plugin) $plugindir = 'lib'; $plugintype = 'lib'; - } else { /// rest of plugins - //TODO: this is not nice and may fail, plugintype should be passed around somehow instead + } else { // rest of plugins + // TODO: this is not nice and may fail, plugintype should be passed around somehow instead $plugintypes = get_plugin_types(false); $plugindir = dirname($path); $plugindir = str_replace('\\', '/', $plugindir); @@ -237,22 +237,22 @@ class XMLDBAction { $result = ''; switch ($plugintype ) { - case 'lib': /// has own savepoint function + case 'lib': // has own savepoint function $result = XMLDB_LINEFEED . ' // Main savepoint reached' . XMLDB_LINEFEED . ' upgrade_main_savepoint(true, XXXXXXXXXX);' . XMLDB_LINEFEED; break; - case 'mod': /// has own savepoint function + case 'mod': // has own savepoint function $result = XMLDB_LINEFEED . ' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . ' upgrade_mod_savepoint(true, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; break; - case 'block': /// has own savepoint function + case 'block': // has own savepoint function $result = XMLDB_LINEFEED . ' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . ' upgrade_block_savepoint(true, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; break; - default: /// rest of plugins + default: // rest of plugins $result = XMLDB_LINEFEED . ' // ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . ' upgrade_plugin_savepoint(true, XXXXXXXXXX, ' . "'$plugintype'" . ', ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; diff --git a/admin/tool/xmldb/actions/XMLDBCheckAction.class.php b/admin/tool/xmldb/actions/XMLDBCheckAction.class.php index 0212c5d1253..547f00e9877 100644 --- a/admin/tool/xmldb/actions/XMLDBCheckAction.class.php +++ b/admin/tool/xmldb/actions/XMLDBCheckAction.class.php @@ -43,11 +43,11 @@ abstract class XMLDBCheckAction extends XMLDBAction { function init() { parent::init(); - /// Set own core attributes + // Set own core attributes - /// Set own custom attributes + // Set own custom attributes - /// Get needed strings + // Get needed strings $this->loadStrings(array( $this->introstr => 'tool_xmldb', 'ok' => '', @@ -73,24 +73,24 @@ abstract class XMLDBCheckAction extends XMLDBAction { $result = true; - /// Set own core attributes + // Set own core attributes $this->does_generate = ACTION_GENERATE_HTML; - /// These are always here + // These are always here global $CFG, $XMLDB, $DB, $OUTPUT; - /// And we nedd some ddl suff + // And we nedd some ddl suff $dbman = $DB->get_manager(); - /// Here we'll acummulate all the wrong fields found + // Here we'll acummulate all the wrong fields found $problemsfound = array(); - /// Do the job, setting $result as needed + // Do the job, setting $result as needed - /// Get the confirmed to decide what to do + // Get the confirmed to decide what to do $confirmed = optional_param('confirmed', false, PARAM_BOOL); - /// If not confirmed, show confirmation box + // If not confirmed, show confirmation box if (!$confirmed) { $o = ''; $o.= ' '; $r.= ' '; $r.= ' '; $r.= '
'; @@ -110,59 +110,59 @@ abstract class XMLDBCheckAction extends XMLDBAction { $this->output = $o; } else { - /// The back to edit table button + // The back to edit table button $b = '

'; $b .= '[' . $this->str['back'] . ']'; $b .= '

'; - /// Iterate over $XMLDB->dbdirs, loading their XML data to memory + // Iterate over $XMLDB->dbdirs, loading their XML data to memory if ($XMLDB->dbdirs) { $dbdirs =& $XMLDB->dbdirs; $o='
    '; foreach ($dbdirs as $dbdir) { - /// Only if the directory exists + // Only if the directory exists if (!$dbdir->path_exists) { continue; } - /// Load the XML file + // Load the XML file $xmldb_file = new xmldb_file($dbdir->path . '/install.xml'); - /// Only if the file exists + // Only if the file exists if (!$xmldb_file->fileExists()) { continue; } - /// Load the XML contents to structure + // Load the XML contents to structure $loaded = $xmldb_file->loadXMLStructure(); if (!$loaded || !$xmldb_file->isLoaded()) { echo $OUTPUT->notification('Errors found in XMLDB file: '. $dbdir->path . '/install.xml'); continue; } - /// Arriving here, everything is ok, get the XMLDB structure + // Arriving here, everything is ok, get the XMLDB structure $structure = $xmldb_file->getStructure(); $o.='
  • ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml'); - /// Getting tables + // Getting tables if ($xmldb_tables = $structure->getTables()) { $o.='
      '; - /// Foreach table, process its fields + // Foreach table, process its fields foreach ($xmldb_tables as $xmldb_table) { - /// Skip table if not exists + // Skip table if not exists if (!$dbman->table_exists($xmldb_table)) { continue; } - /// Fetch metadata from physical DB. All the columns info. + // Fetch metadata from physical DB. All the columns info. if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) { - //// Skip table if no metacolumns is available for it + // / Skip table if no metacolumns is available for it continue; } - /// Table processing starts here + // Table processing starts here $o.='
    • ' . $xmldb_table->getName(); - /// Do the specific check. + // Do the specific check. list($output, $newproblems) = $this->check_table($xmldb_table, $metacolumns); $o.=$output; $problemsfound = array_merge($problemsfound, $newproblems); $o.='
    • '; - /// Give the script some more time (resetting to current if exists) + // Give the script some more time (resetting to current if exists) if ($currenttl = @ini_get('max_execution_time')) { @ini_set('max_execution_time',$currenttl); } @@ -174,19 +174,19 @@ abstract class XMLDBCheckAction extends XMLDBAction { $o.='
    '; } - /// Create a report of the problems found. + // Create a report of the problems found. $r = $this->display_results($problemsfound); - /// Combine the various bits of output. + // Combine the various bits of output. $this->output = $b . $r . $o; } - /// Launch postaction if exists (leave this here!) + // Launch postaction if exists (leave this here!) if ($this->getPostAction() && $result) { return $this->launch($this->getPostAction()); } - /// Return ok if arrived here + // Return ok if arrived here return $result; } diff --git a/admin/tool/xmldb/actions/check_bigints/check_bigints.class.php b/admin/tool/xmldb/actions/check_bigints/check_bigints.class.php index 94f5c77b6db..f2def4aad10 100644 --- a/admin/tool/xmldb/actions/check_bigints/check_bigints.class.php +++ b/admin/tool/xmldb/actions/check_bigints/check_bigints.class.php @@ -44,11 +44,11 @@ class check_bigints extends XMLDBCheckAction { $this->introstr = 'confirmcheckbigints'; parent::init(); - /// Set own core attributes + // Set own core attributes - /// Set own custom attributes + // Set own custom attributes - /// Get needed strings + // Get needed strings $this->loadStrings(array( 'wrongints' => 'tool_xmldb', 'nowrongintsfound' => 'tool_xmldb', @@ -56,7 +56,7 @@ class check_bigints extends XMLDBCheckAction { 'mysqlextracheckbigints' => 'tool_xmldb', )); - /// Correct fields must be type bigint for MySQL and int8 for PostgreSQL + // Correct fields must be type bigint for MySQL and int8 for PostgreSQL $this->dbfamily = $DB->get_dbfamily(); switch ($this->dbfamily) { case 'mysql': @@ -74,26 +74,26 @@ class check_bigints extends XMLDBCheckAction { $o = ''; $wrong_fields = array(); - /// Get and process XMLDB fields + // Get and process XMLDB fields if ($xmldb_fields = $xmldb_table->getFields()) { $o.='
      '; foreach ($xmldb_fields as $xmldb_field) { - /// If the field isn't integer(10), skip + // If the field isn't integer(10), skip if ($xmldb_field->getType() != XMLDB_TYPE_INTEGER || $xmldb_field->getLength() != 10) { continue; } - /// If the metadata for that column doesn't exist, skip + // If the metadata for that column doesn't exist, skip if (!isset($metacolumns[$xmldb_field->getName()])) { continue; } - /// To variable for better handling + // To variable for better handling $metacolumn = $metacolumns[$xmldb_field->getName()]; - /// Going to check this field in DB + // Going to check this field in DB $o.='
    • ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; - /// Detect if the physical field is wrong and, under mysql, check for incorrect signed fields too + // Detect if the physical field is wrong and, under mysql, check for incorrect signed fields too if ($metacolumn->type != $this->correct_type || ($this->dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) { $o.='' . $this->str['wrong'] . ''; - /// Add the wrong field to the list + // Add the wrong field to the list $obj = new stdClass(); $obj->table = $xmldb_table; $obj->field = $xmldb_field; @@ -121,41 +121,41 @@ class check_bigints extends XMLDBCheckAction { $r.= '
'; - /// If we have found wrong integers inform about them + // If we have found wrong integers inform about them if (count($wrong_fields)) { $r.= '

' . $this->str['yeswrongintsfound'] . '

'; $r.= '
    '; foreach ($wrong_fields as $obj) { $xmldb_table = $obj->table; $xmldb_field = $obj->field; - /// MySQL directly supports this + // MySQL directly supports this // TODO: move this hack to generators!! if ($this->dbfamily == 'mysql') { $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field); - /// PostgreSQL (XMLDB implementation) is a bit, er... imperfect. + // PostgreSQL (XMLDB implementation) is a bit, er... imperfect. } else if ($this->dbfamily == 'postgres') { $sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() . ' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;'); } $r.= '
  • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['field'] . ': ' . $xmldb_field->getName() . '
  • '; - /// Add to output if we have sentences + // Add to output if we have sentences if ($sqlarr) { $sqlarr = $dbman->generator->getEndedStatements($sqlarr); $s.= '' . str_replace("\n", '
    ', implode('
    ', $sqlarr)). '

    '; } } $r.= '
'; - /// Add the SQL statements (all together) + // Add the SQL statements (all together) $r.= '
' . $s; } else { $r.= '

' . $this->str['nowrongintsfound'] . '

'; } $r.= '
'; - /// Add the complete log message + // Add the complete log message $r.= '

' . $this->str['completelogbelow'] . '

'; $r.= '
'; diff --git a/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php b/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php index 9e01ce3b104..7365326a163 100644 --- a/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php +++ b/admin/tool/xmldb/actions/check_defaults/check_defaults.class.php @@ -40,11 +40,11 @@ class check_defaults extends XMLDBCheckAction { $this->introstr = 'confirmcheckdefaults'; parent::init(); - /// Set own core attributes + // Set own core attributes - /// Set own custom attributes + // Set own custom attributes - /// Get needed strings + // Get needed strings $this->loadStrings(array( 'wrongdefaults' => 'tool_xmldb', 'nowrongdefaultsfound' => 'tool_xmldb', @@ -58,7 +58,7 @@ class check_defaults extends XMLDBCheckAction { $o = ''; $wrong_fields = array(); - /// Get and process XMLDB fields + // Get and process XMLDB fields if ($xmldb_fields = $xmldb_table->getFields()) { $o.='