I ran the coder upgrade module which I suppose did lot's of good stuff, but it did also some really bad stuff, by removing entire working form code functions!

The module was:
http://drupal.org/project/vchess

Notice in particular that the new "upgraded" function only has the vchess_main_page() code.

Simplified view of old code, with lots of functions, including lots of functions for form handling:

<?php
// $Id: vchess.module,v 1.2 2009/03/18 23:31:51 hrocho Exp $
/**
 * @file
 * Drupal chess module
 * VChess is based on OCC chess by Michael Speck
 * @author: Andrej Prochazka
 */

require_once drupal_get_path('module', 'vchess') .'/io.inc';
require_once drupal_get_path('module', 'vchess') .'/render.inc';
require_once drupal_get_path('module', 'vchess') .'/chess.inc';
require_once drupal_get_path('module', 'vchess') .'/rating.inc';

/**
 * Display help and module information
 */
function vchess_help($path,$arg) {
  if($path == 'admin/help#vchess'){
    $txt = t('Drupal chess module.Chess games between site users');
    return $txt;
  }
}

/**
 * VChess permissions
 */
function vchess_perm() {
  return array('access VChess', );
}

/**
 * hook_menu() impementation
 */
function vchess_menu(){
  $items = array();

  $items['vchess/main'] = array(
  'page callback' => 'vchess_main_page',
  //      'access arguments' => array('access content'),
  'title' => t('VChess chess'),
  'access' => TRUE,
  'access callback' => TRUE,
  'type' => MENU_NORMAL_ITEM,
  );

  $items['vchess/newgame_form'] = array(
  'page callback' => 'drupal_get_form',
  'access arguments' => array('access content'),
  'page arguments' => array('vchess_new_game_form'),
  'title' => t('Create VChess chess game'),
  'type' => MENU_CALLBACK,
  );

  $items['vchess/board/%'] = array(
  'page callback' => 'vchess_board',
  'page arguments' => array(2),
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
  );

  return $items;
}


/**
 * menu callback vchess_main_page to display main vchess window
 */
function vchess_main_page()
{
  ...

  return $out;
}


/**
 * menu callback vchess_new_game_page to display new game form
 */
function vchess_new_game_form()
{
  ...

  return $form;
}

function vchess_new_game_form_submit($form,&$form_state)
{
 ...

}

function vchess_new_game_form_validate($form,&$form_state)
{

 ...

}

function vchess_board($gid)
{
 ...

  return $out;
}

Simplified new code:

<?php
// $Id: vchess.module,v 1.2 2009/03/18 23:31:51 hrocho Exp $
/**
 * @file
 * Drupal chess module
 * VChess is based on OCC chess by Michael Speck
 * @author: Andrej Prochazka
 */

require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'vchess') . '/io.inc';
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'vchess') . '/render.inc';
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'vchess') . '/chess.inc';
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'vchess') . '/rating.inc';

/**
 * Display help and module information
 */
function vchess_help($path, $arg) {
  if ($path == 'admin/help#vchess') {
    $txt = t('Drupal chess module.Chess games between site users');
    return $txt;
  }
}

/**
 * VChess permissions
 */
function vchess_permission() {
  return array(
    'access VChess' => array(
      'title' => t('access VChess'),
      'description' => t('TODO Add a description for \'access VChess\''),
    ),
  );
}

/**
 * hook_menu() impementation
 */
function vchess_menu() {
  $items = array();

  $items['vchess/main'] = array(
    'page callback' => 'vchess_main_page',
    //      'access arguments' => array('access content'),
    'title' => t('VChess chess'),
    'access' => TRUE,
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  $items['vchess/newgame_form'] = array(
    'page callback' => 'drupal_get_form',
    'access arguments' => array('access content'),
    'page arguments' => array('vchess_new_game_form'),
    'title' => t('Create VChess chess game'),
    'type' => MENU_CALLBACK,
  );

  $items['vchess/board/%'] = array(
    'page callback' => 'vchess_board',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}


/**
 * menu callback vchess_main_page to display main vchess window
 */
function vchess_main_page() {
...
  return $out;
}

The "new" code when I pasted back the deleted functions gives a nice form as I wanted and had in D6.

Comments

solotandem’s picture

Category: bug » support
Priority: Major » Normal
Status: Active » Fixed

In the module file, on line 121 there is a double "{" and on line 130 there is the closing brace for this duplicate brace. If you remove those duplicate braces, then the parser handles the file and you do not lose the functions past vchess_main_page(). While PHP allows the syntax, the grammar parser considers (and I believe most developers would also) it a syntax error and does not parse further.

It is useful to run the file through the syntax-only routine before running the upgrade routines, so you can distinguish the two.

solotandem’s picture

Project: Coder » Grammar Parser
Component: Coder Upgrade » Code
Category: support » feature
Status: Fixed » Active

Consider supporting nested braces that begin a "statement" or are inside an existing block.

solotandem’s picture

Title: Coder upgrade completely removed entire working form code functions » Consider supporting nested braces
solotandem’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Simplified code to make clearer the differences