我一直在努力彌合Joomla和CiviCRM配置文件更新過程中的變量不是「復位」。最初,所有我想要做的就是更新CiviCRM匹配的配置時的Joomla個人資料電子郵件的變化(注:最新版本CIVI將更新時CIVI電子郵件的變化......使側被覆蓋的Joomla個人資料電子郵件) 。用那個,我有代碼可以工作。也就是說,當我手動從認證會話中激發代碼時,它會正確更新civi電子郵件。現在我試圖將這些代碼嵌入到Joomla user_profile插件中,這樣當用戶更改電子郵件時,它將更新civi電子郵件。PHP - 同一個會話
注:我不知道砍了核心代碼。最終,我將使用自定義代碼創建一個新的配置文件插件,但爲了簡化開發,我使用了核心user_profile插件。任何人閱讀此文,請勿在生產中使用以下代碼!它不完整,核心不應該被黑客攻擊。
這是有效的,但是我發現如果用戶沒有註銷會話,然後再次在同一個會話中更改電子郵件,則最新的電子郵件無法識別(舊電子郵件),但如果用戶註銷然後登錄,更改電子郵件,它將起作用。我希望這是有道理的。
問題必須有事情做與變量或東西的效果「實例」,但我是新新PHP編碼和不太清楚我在做什麼錯。我已將自定義代碼放入user_profile插件的profile.php腳本中的onUserAfterSave函數中。
任何PHP程序員知道我怎麼能解決這個問題,使我的自定義代碼下面將火每次電子郵件中的Joomla改變了它是否在同一會話期間是不?
我的代碼:
function onUserAfterSave($data, $isNew, $result, $error)
{
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
// *** Truncating function code to de-clutter
// .
// .
// .
/*****************************************************
* Begin my custom code to save data to civi.
*****************************************************/
require_once '/var/www/joomla/administrator/components/com_civicrm/civicrm.settings.php';
require_once '/var/www/joomla/administrator/components/com_civicrm/civicrm/CRM/Core/Config.php';
require_once '/var/www/joomla/administrator/components/com_civicrm/civicrm/api/v3/UFMatch.php';
require_once '/var/www/joomla/administrator/components/com_civicrm/civicrm.settings.php';
require_once('/var/www/joomla/administrator/components/com_civicrm/civicrm/CRM/Core/DAO.php');
$t911_config = CRM_Core_Config::singleton();
$t911_user = JFactory::getUser();
$t911_ufID = $t911_user->id;
$t911_ufUSER = $t911_user->username;
$t911_ufEMAIL = $t911_user->email; //this variable only sets on each login session
$t911_ufTYPE = $t911_user->usertype;
$t911_ufGUEST = $t911_user->guest;
$t911_contactID = CRM_Core_BAO_UFMatch::getContactId($t911_ufID);
$t911_query = "select email from civicrm_email where contact_id = $t911_contactID";
$daoResult =& CRM_Core_DAO::executeQuery($t911_query, $t911_params);
$daoResult->fetch();
if ($daoResult->email <> $t911_ufEMAIL)
{
CRM_Core_BAO_UFMatch::updateContactEmail($t911_contactID,$t911_ufEMAIL);
}
/*****************************************************
* End my custom code to save data to civi.
****************************************************/
// .
// .
// .
// *** The remainder of the function code
return true;
}