Detect SuiteCRM only with global variable ['sugarcrm']
This commit is contained in:
parent
052824e4b7
commit
3249260653
6 changed files with 153 additions and 147 deletions
|
@ -356,7 +356,7 @@ function storm_user($op, &$edit, &$account, $category = NULL) {
|
|||
* $_SESSION['SuiteCRM_Session_ID'] = Session ID for user in SuiteCRM
|
||||
*/
|
||||
function storm_init() {
|
||||
global $user, $base_url, $conf;
|
||||
global $user, $base_url;
|
||||
|
||||
// It is intended to move these calls to pages which specifically need them rather than on hook_init.
|
||||
drupal_add_js(drupal_get_path('module', 'storm') .'/storm.js', 'module', 'header', FALSE);
|
||||
|
@ -397,7 +397,7 @@ function storm_init() {
|
|||
$_SESSION['deskmenu'] = $deskmenu;
|
||||
|
||||
// Verify SuiteCRM access. Get the SuiteCRM User ID:
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugaruid = $user->uid == 1 ? 1 : db_result(db_query("SELECT field_stormperson_sugaruid_value FROM {stormperson} JOIN {content_type_stormperson} USING (vid) WHERE user_uid = %d", $user->uid));
|
||||
if (!empty($sugaruid)) {
|
||||
$password = md5(substr(md5(microtime()), rand(0, 26), 16));
|
||||
|
@ -3360,6 +3360,15 @@ function storm_cron_is_running() {
|
|||
return preg_match('/\/cron.php$/', $_SERVER['SCRIPT_NAME']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TRUE if database connection with SuiteCRM is defined.
|
||||
*/
|
||||
function storm_suitecrm_is_defined() {
|
||||
global $db_url;
|
||||
|
||||
return !empty($db_url['sugarcrm']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch from original user to mail submission user and back. Notes:
|
||||
*
|
||||
|
|
|
@ -393,9 +393,7 @@ function stormorganization_form(&$node) {
|
|||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function stormorganization_form_stormorganization_node_form_alter(&$form, &$form_state) {
|
||||
global $conf;
|
||||
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$form['group3']['#access'] = FALSE;
|
||||
$form['group4']['#access'] = FALSE;
|
||||
$form['group5']['taxid']['#access'] = FALSE;
|
||||
|
@ -448,7 +446,7 @@ function stormorganization_update($node) {
|
|||
}
|
||||
|
||||
function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
||||
global $base_url, $conf;
|
||||
global $base_url;
|
||||
|
||||
if ($node->type != 'stormorganization') {
|
||||
return;
|
||||
|
@ -474,7 +472,7 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
case 'validate':
|
||||
$nid = $node->nid;
|
||||
$organization_name = $node->title;
|
||||
if (!$conf['storm_suitecrm'] || empty($organization_name)) {
|
||||
if (!storm_suitecrm_is_defined() || empty($organization_name)) {
|
||||
return;
|
||||
}
|
||||
// Checking if exists the organization in SuiteCRM:
|
||||
|
@ -501,12 +499,12 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
array('!organization' => l(t('organization'), drupal_get_path_alias('node/' . $organization_nid)))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'presave':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormorganization_sugarid[0]['value'];
|
||||
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -528,7 +526,7 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
|
||||
case 'insert':
|
||||
case 'update':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormorganization_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -539,7 +537,7 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormorganization_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -555,7 +553,7 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
break;
|
||||
|
||||
case 'view':
|
||||
if ($conf['storm_suitecrm'] && !storm_cron_is_running()) {
|
||||
if (storm_suitecrm_is_defined() && !storm_cron_is_running()) {
|
||||
$sugarid = $node->field_stormorganization_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -591,7 +589,7 @@ function stormorganization_nodeapi(&$node, $op, $teaser, $page) {
|
|||
function _stormorganization_validate_predelete($node) {
|
||||
$nid = $node->nid;
|
||||
$items = array();
|
||||
|
||||
|
||||
if (_storm_validate_predelete('stormperson', "s.organization_nid = $nid")) {
|
||||
$items[] = '<a href="/people">' . t('people') . '</a>';
|
||||
}
|
||||
|
|
|
@ -389,9 +389,7 @@ function stormperson_form(&$node) {
|
|||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function stormperson_form_stormperson_node_form_alter(&$form, &$form_state) {
|
||||
global $conf;
|
||||
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$form['group1']['#access'] = FALSE;
|
||||
$form['group3']['#access'] = FALSE;
|
||||
$form['group4']['#access'] = FALSE;
|
||||
|
@ -501,7 +499,7 @@ function _stormperson_aftersave(&$node) {
|
|||
}
|
||||
|
||||
function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
||||
global $base_url, $conf;
|
||||
global $base_url;
|
||||
|
||||
if ($node->type != 'stormperson') {
|
||||
return;
|
||||
|
@ -512,7 +510,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
$name = $node->field_stormperson_name[0]['value'];
|
||||
$lastname = $node->field_stormperson_lastname[0]['value'];
|
||||
$fullname = empty($lastname) ? $name : $lastname . ', ' . $name;
|
||||
if (!$conf['storm_suitecrm'] || empty($fullname)) {
|
||||
if (!storm_suitecrm_is_defined() || empty($fullname)) {
|
||||
return;
|
||||
}
|
||||
// Checking if exists the contact in SuiteCRM:
|
||||
|
@ -544,7 +542,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
break;
|
||||
|
||||
case 'presave':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormperson_sugarid[0]['value'];
|
||||
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -566,7 +564,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
|
||||
case 'insert':
|
||||
case 'update':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormperson_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -577,7 +575,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($conf['storm_suitecrm']) {
|
||||
if (storm_suitecrm_is_defined()) {
|
||||
$sugarid = $node->field_stormperson_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -593,7 +591,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
break;
|
||||
|
||||
case 'view':
|
||||
if ($conf['storm_suitecrm'] && !storm_cron_is_running()) {
|
||||
if (storm_suitecrm_is_defined() && !storm_cron_is_running()) {
|
||||
$sugarid = $node->field_stormperson_sugarid[0]['value'];
|
||||
if (!empty($sugarid)) {
|
||||
db_set_active('sugarcrm');
|
||||
|
@ -606,7 +604,7 @@ function stormperson_nodeapi(&$node, $op, $teaser, $page) {
|
|||
if ($node->field_stormperson_sugarmod[0]['value'] != $suitecrm_contact['date_modified']) {
|
||||
$node_update = node_load($node->nid);
|
||||
// Prepare node for a submit.
|
||||
$node_update = node_submit($node_update);
|
||||
$node_update = node_submit($node_update);
|
||||
node_save($node_update);
|
||||
drupal_set_message(t('SuiteCRM contact has been updated, refresh to view changes.'));
|
||||
}
|
||||
|
|
Reference in a new issue