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

发布于 2024-09-26 02:47:58 字数 8680 浏览 4 评论 0原文

我有一个简单的问题,我目前正在运行 Drupal 的测试站点。我有一个为 6.16 版本之前编写和支持的模块,我目前希望在启用该模块时在崩溃中使用该模块。

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

该模块提供将 CRM 集成到 Drupal 中以实现 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())

I have a quick question I am currently running a test site of Drupal. I have a module that was written and supported for versions up to 6.16 the test site that I would currently like to use this module in crashes when I enable the module.

I would like to know what basic elements can I look at to ensure that the code is compatible and or if changes are needed.

This module provides integration of a CRM into Drupal for SSO.

I figured if anyone else has come across creating a module to bridge the gap between to systems they might point me in the right direction.

This is the error I receive when I enable the module:

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

This is the code in the file named convio.module that is giving me a problem:

<?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())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长伴 2024-10-03 02:47:58

新评论后更新:

您是否仍在使用 PHP 4?这可以解释错误 - 方法链接(意味着直接在应该返回对象的函数上使用“->”运算符),仅从 PHP 5、IIRC 开始受支持。

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

作为临时解决方案,您可以搜索所有包含“->”的位置运算符直接用于函数/方法结果(functionCall()->...)并通过另一个变量插入分隔符。 请注意,我不建议这样做 - PHP 4 已弃用,并且不再接收安全更新。在其上运行生产环境非常重要!


原始答案:

该代码中唯一的 T_OBJECT_OPERATOR ('->') 似乎位于:

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

因此您可能需要将该行更改为如下所示:

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

Update after new comment:

Could it be that you are still using PHP 4? This would explain the errors - method chaining (meaning to use the '->' operator directly on a function that is supposed to return an object), is only supported since PHP 5, IIRC.

If that is the case, the proper solution would be to switch to PHP 5!

As a temporary solution, you could search for all places where the '->' operator is used directly on a function/method result (functionCall()->...) and insert a separation via another variable. Note that I do not recommend this - PHP 4 is deprecated and does not receive security updates anymore. Running a production environment on it is big no no!


Original answer:

The only T_OBJECT_OPERATOR ('->') in that code seems to be in:

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

so you might want to change that line to something like the following:

$convioConfiguration = ConvioConfiguration::getInstance();
if (is_object($convioConfiguration) && $convioConfiguration->isEnabled()) { ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文