我可以在模块构建中检查什么以确保drupal中没有崩溃

时间:2010-09-30 21:34:58

标签: drupal drupal-6 module drupal-modules

我有一个简单的问题,我目前正在运行Drupal的测试网站。我有一个模块,编写并支持最高6.16版本的测试站点,当我启用模块时,我目前想在崩溃时使用该模块。

我想知道可以查看哪些基本元素以确保代码兼容和/或是否需要更改。

该模块提供了将CRM集成到Drupal for SSO中。

我想是否有其他人遇到过创建模块来弥合他们可能指向正确方向的系统之间的差距。

这是我启用模块时收到的错误:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /homepages/22/d223624283/htdocs/drupal6/sites/all/modules/convio/convio.module on line 104

这是名为convio.module的文件中的代码,它给我一个问题:

<?php

/**
 * Classes. (The order is important.)
 */
module_load_include("inc", "convio", "ConvioConstants");
module_load_include("inc", "convio", "ConvioUtils");
module_load_include("inc", "convio", "ConvioConfiguration");
module_load_include("inc", "convio", "ConvioAPIClient");
module_load_include("inc", "convio", "ConvioUser");
module_load_include("inc", "convio", "ConvioLoginHandler");
module_load_include("inc", "convio", "ConvioTokenHandler");


/**
* Implementation of hook_help.
*/
function convio_help() {
if ($path == 'admin/help#convio') {
$txt = 'The Convio module uses the !convio_url API to .';
$link = l('Convio Open', 'http://open.convio.com');
$replace = array('!convio_url' => $link);
return '<p>' . t($txt, $replace) . '</p>';
  }
 }

/**
* Implementation of hook_menu.
*/
function convio_menu() {

// Test
$items['convio/test'] = array(
'title' => 'Convio Test',
'description' => 'Testing.',
'page callback' => 'convio_test',
'file' => 'ui/test.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

// Admin configuration page.
$items['admin/convio/configure'] = array(
'title' => 'Convio Integration',
'description' => 'Settings for the Convio Open API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('convio_configuration_form'),
'file' => 'ui/admin/configure.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);

// SSO Authentication callback.
$items['convio/session/status'] = array(
'title' => 'Convio Session Status',
'description' => 'Validates the Convio user session and updates the Drupal user session.',
'page callback' => 'convio_session_status',
'file' => 'ui/session/status.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

 // SSO Authentication callback.
 $items['convio/session/validate'] = array(
'title' => 'Convio Session Validation',
'description' => 'Validates the Convio user session and updates the Drupal user session.',
'page callback' => 'convio_session_validate',
'file' => 'ui/session/validate.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

// SSO Authentication callback.
$items['convio/session/clear'] = array(
'title' => 'Convio Session Reset',
'description' => 'Clears the Drupal user session.',
'page callback' => 'convio_session_clear',
'file' => 'ui/session/clear.inc',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
 );

 return $items;
}

// Only enable the following hooks if the Open APIs have been configured.
if (ConvioConfiguration::getInstance()->isEnabled()) {

/**
* Implementation of hook_menu_alter()
*
* Alter the user/registration menu item to point to the external
* user account registration page
*/
function convio_menu_alter($items) {

// Always allow access to the user/login.
$items['user/login']['access callback'] = TRUE;

/**
 * Overrides user/register from user.module.
 *
 * $items['user/register'] = array(
 *   'title' => 'Create new account',
 *   'page callback' => 'drupal_get_form',
 *   'page arguments' => array('user_register'),
 *   'access callback' => 'user_register_access',
 *   'type' => MENU_LOCAL_TASK,
 *   'file' => 'user.pages.inc',
 * );
 */
unset($items['user/register']);
$items['user/register'] = array(
                                'title' => 'Sign up',
                                'page callback' => 'convio_user_signup',
                                'access callback' => 'user_register_access',
                                'type' => MENU_CALLBACK,
                                'file path' => drupal_get_path('module','convio'),
                                'file' => 'ui/register.inc',
                                );

// Disable Forgot/Reset Password pages from user.module.
unset($items['user/password']);
unset($items['user/reset/%/%/%']);

// Disable Manage User Profile pages from user.module.
unset($items['user/autocomplete']);
unset($items['user/%user/delete']);

//TODO: alter profile edit form
//unset($items['user/%user_category/edit']);
unset($items['user/%user_category/edit/account']);
unset($items['admin/user/user/create']);

return $items;
}


/**
* Implementation of hook_form_alter.
*
* Replaces the standard login form with a Convio login form.
*/
function convio_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login_block' || $form_id == 'user_login') {
  ConvioLoginHandler::getInstance()->getLoginForm($form, $form_state, $form_id);
}

return $form;
}


/**
* Implementation of hook_user.
*
* Maps cons_id to the Drupal user account.
*/
function convio_user($op, &$edit, &$account, $category = NULL) {

if ($op == "load") {
  // Make cons_id available from the user.

  $result = db_query("SELECT user_id, cons_id FROM {convio_users} where cons_id = %d", $cons_id);
  $convio_user = db_fetch_object($result);
  if ($convio_user) {
    $account->convio_cons_id = $convio_user->cons_id;
  }

  } else if ($op == "insert") {
  // The user account was created. Map it to the cons_id.

  db_query("INSERT INTO {convio_users} (user_id, cons_id) VALUES (%d, %d)",
           $account->uid,
           $edit["convio_cons_id"]);

  } else if ($op == "after_update") {
  // The user account was updated. 

  $result = db_query("SELECT user_id, cons_id FROM {convio_users} where cons_id = %d", $edit["convio_cons_id"]);
  $convio_user = db_fetch_object($result);
  if (! $convio_user) {
    db_query("INSERT INTO {convio_users} (user_id, cons_id) VALUES (%d, %d)",
             $account->uid,
             $edit["convio_cons_id"]);
  }

  } else if ($op == "delete") {
  // The user account was deleted. Delete any associated Convio mappings.
  // It would be better to have MySQL FK support with cascading deletes.

  db_query("DELETE FROM {convio_users} WHERE user_id = %d", $account->uid);

  } else if ($op == "logout") {

  ConvioLoginHandler::getInstance()->logout();
  }
  }


 /**
 * Implements hook_token_values();
 */
 function convio_token_values($type, $object = NULL) {
  if ($type == 'convio') {
  return ConvioTokenHandler::getInstance()->getValues();
  }
  }

 /**
 * Implements hook_token_list();
 */
 function convio_token_list($type = 'all') {
if ($type == 'convio' || $type == 'all') {
  return ConvioTokenHandler::getInstance()->getList();
  }
 }

/**
* Adds standard includes to every page.
*
* 1) Open API JS lib and init script -> <head>
* 2) Session tracking beacon -> header region
* 3) Keep-alive beacon -> footer region
*/
function _convio_add_includes() {
static $included = FALSE;
if (!$included) {

  $api_config = ConvioConfiguration::getInstance();

  // Establish a new C360 session if one doesn't exist already.
  if (ConvioLoginHandler::getInstance()->newUserSession()) {
    return;
  }

  $api_uri = $api_config->getURI();
  $api_key = $api_config->getPublicKey();

  // TODO: allow the regions to be overriden in the module configuration.
  $region_header = "header";
  $region_footer = "footer";

  // Add Convio Open API JS library and init script.
  drupal_set_html_head('<script type="text/javascript" src="' . $api_uri . '/../api/ConvioApi.js"></script>');

  $script = '<script type="text/javascript">';
  $script .= '  var CONVIO = {};';
  $script .= '  CONVIO.OPEN = new ConvioApiClient("' . $api_key . '","/api_client.html","json");';
  $script .= '</script>';
  drupal_set_html_head($script);

  // Add the session tracking beacon to the body of every page.
  $trackerUrl = url('convio/session/status', array('query' => drupal_get_destination()));
  $tracker = '<script type="text/javascript" src="' . $trackerUrl . '"></script>';
  drupal_set_content($region_header, $tracker);

  // Add a keepalive beacon to the bottom of every page.
  $img = '<img src="' . $api_uri . '/PixelServer" />';
  drupal_set_content($region_footer, $img);
}
    $included = TRUE;
  }

  // Include Convio module JS libraries on every page.
  _convio_add_includes();

} // end: if (ConvioConfiguration::getInstance()->isEnabled())

1 个答案:

答案 0 :(得分:2)

新评论后更新:

你还在使用PHP 4吗?这将解释错误 - 方法链接(意味着直接在应该返回对象的函数上使用' - &gt;'运算符),仅支持PHP 5,IIRC。

如果是这种情况,正确的解决方案是切换到PHP 5!

作为临时解决方案,您可以搜索“ - &gt;”所有位置operator直接用于函数/方法结果(functionCall()->...)并通过另一个变量插入分隔。 请注意,我不建议这样做 - 不推荐使用PHP 4,并且不再接收安全更新。在它上面运行一个生产环境是不可能的!


原始回答:

该代码中唯一的T_OBJECT_OPERATOR(' - &gt;')似乎在:

if (ConvioConfiguration::getInstance()->isEnabled()) { ...

因此您可能希望将该行更改为以下内容:

$convioConfiguration = ConvioConfiguration::getInstance();
if (is_object($convioConfiguration) && $convioConfiguration->isEnabled()) { ...