本文整理汇总了PHP中CRM_Core_Transaction::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Transaction::commit方法的具体用法?PHP CRM_Core_Transaction::commit怎么用?PHP CRM_Core_Transaction::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Transaction
的用法示例。
在下文中一共展示了CRM_Core_Transaction::commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function add_participant_to_cart()
{
require 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$cart_id = $_GET['cart_id'];
$event_id = $_GET['event_id'];
$cart = CRM_Event_Cart_BAO_Cart::find_by_id($_GET['cart_id']);
$params_array = array('cart_id' => $cart->id, 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), 'event_id' => $event_id);
//XXX security?
$participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
$participant->save();
$form = new CRM_Core_Form();
$pform = new CRM_Event_Cart_Form_MerParticipant($participant);
$pform->appendQuickForm($form);
$renderer = $form->getRenderer();
$config = CRM_Core_Config::singleton();
$templateDir = $config->templateDir;
if (is_array($templateDir)) {
$templateDir = array_pop($templateDir);
}
$requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
$renderer->setRequiredTemplate($requiredTemplate);
$form->accept($renderer);
$template = CRM_Core_Smarty::singleton();
$template->assign('form', $renderer->toArray());
$template->assign('participant', $participant);
$output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
$transaction->commit();
echo $output;
CRM_Utils_System::civiExit();
}
示例2:
/**
* Add or update a link between contribution and membership
*
* @param array $params (reference ) input parameters
*
* @return array (reference ) membership_payment_id of created or updated record
* @static void
* @access public
*/
function &civicrm_membershipcontributionlink_create(&$params)
{
_civicrm_initialize();
if (empty($params)) {
return civicrm_create_error(ts('No input parameters present'));
}
if (!is_array($params)) {
return civicrm_create_error(ts('Input parameters is not an array'));
}
if (!isset($params['contribution_id']) || !isset($params['membership_id'])) {
return civicrm_create_error(ts('Required parameters missing'));
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
require_once 'CRM/Member/DAO/MembershipPayment.php';
$mpDAO =& new CRM_Member_DAO_MembershipPayment();
$mpDAO->copyValues($params);
$result = $mpDAO->save();
if (is_a($result, 'CRM_Core_Error')) {
$transaction->rollback();
return civicrm_create_error($result->_errors[0]['message']);
}
$transaction->commit();
_civicrm_object_to_array($mpDAO, $mpArray);
return $mpArray;
}
示例3: postProcess
function postProcess()
{
$values = $this->exportValues();
$title = str_replace("'", "''", $values['title']);
$params = array(1 => array($title, 'String'), 2 => array($values['widget'], 'Integer'));
if (isset($this->_id)) {
$params += array(3 => array($this->_id, 'Integer'));
$sql = "UPDATE civicrm_wci_embed_code SET name = %1, widget_id = %2 where id = %3";
} else {
$sql = "INSERT INTO civicrm_wci_embed_code (name, widget_id)VALUES (%1, %2)";
}
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
$transaction = new CRM_Core_Transaction();
CRM_Core_DAO::executeQuery($sql, $params);
$transaction->commit();
CRM_Core_Session::setStatus(ts('Embed code created successfully'), '', 'success');
if (isset($_REQUEST['_qf_NewEmbedCode_next'])) {
isset($this->_id) ? $embed_id = $this->_id : ($embed_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
CRM_Utils_System::redirect('?action=update&reset=1&id=' . $embed_id);
} else {
CRM_Utils_System::redirect('embed-code?reset=1');
}
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to create embed code'), '', 'error');
$transaction->rollback();
}
parent::postProcess();
}
示例4: civicrm_api3_multisite_domain_create
/**
* Create a new domain - with a domain group.
*
* This is not fully developed & need to work on creating admin menus etc
*
* @param array $params
*
* @return array
* @example DomainCreate.php
* {@getfields domain_create}
*/
function civicrm_api3_multisite_domain_create($params)
{
$transaction = new CRM_Core_Transaction();
if (empty($params['contact_id'])) {
$params['contact_id'] = _civicrm_api3_multisite_domain_create_if_not_exists('Contact', array('organization_name' => $params['name'], 'contact_type' => 'organization'));
}
$domain = civicrm_api('domain', 'getsingle', array('version' => 3, 'current_domain' => TRUE));
$fullParams = array_merge($domain, $params);
$fullParams['domain_version'] = $domain['version'];
$fullParams['version'] = 3;
unset($fullParams['id']);
if (empty($params['group_id'])) {
$groupParams = array('title' => !empty($params['group_name']) ? $params['group_name'] : $params['name']);
$group = civicrm_api3('Group', 'get', array_merge($groupParams, array('options' => array('limit' => 1))));
if (empty($group['id'])) {
// Ideally would fix the api to be more consistent & not assume default but...
$groupParams['group_type'] = array(1 => 1);
$group = civicrm_api3('Group', 'create', $groupParams);
}
$domainGroupID = $group['id'];
} else {
$domainGroupID = $params['group_id'];
}
_civicrm_api3_multisite_domain_create_if_not_exists('GroupOrganization', array('group_id' => $domainGroupID, 'organization_id' => $params['contact_id']));
$domainID = _civicrm_api3_multisite_domain_create_if_not_exists('domain', $fullParams);
if (!$domainID || $domainID != civicrm_api3('Domain', 'getvalue', array('name' => $params['name'], 'return' => 'id'))) {
throw new CiviCRM_API3_Exception('Failed to create domain', 'unknown');
}
$transaction->commit();
if (!civicrm_api3('Navigation', 'getcount', array('domain_id' => $domainID))) {
_civicrm_load_navigation($params['name'], $domainID);
}
civicrm_api3('Setting', 'create', array('is_enabled' => TRUE, 'domain_group_id' => $domainGroupID, 'domain_id' => $domainID));
return civicrm_api3_create_success(array($domainID => array('id' => $domainID)));
}
示例5: civicrm_api3_workflow_save
/**
* PriceSet.FetchSection API
*
* @param array $params
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
*/
function civicrm_api3_workflow_save($params)
{
if (!array_key_exists("data", $params) || !$params['data']) {
throw new API_Exception('Missing parameter: data', 170);
}
if (!array_key_exists("wid", $params) || !$params['wid']) {
throw new API_Exception('Missing parameter: wid', 170);
}
$wid = $params['wid'];
$d = urldecode($params['data']);
$data = parse_str($d);
//I don't know why this is important, but it made things work.
$try2 = parse_str($params['data']);
//Hook in case someone wants to alter the data
CRM_Workflow_hook::beforeSave($wid, $data);
$transaction = new CRM_Core_Transaction();
$dsql = "DELETE FROM civicrm_workflow_detail WHERE workflow_id = {$wid}";
$dao =& CRM_Core_DAO::executeQuery($dsql);
if (!empty($data)) {
$sql = "INSERT INTO civicrm_workflow_detail ( workflow_id, entity_table, entity_id, `order`, breadcrumb, `next`, title) VALUES ";
$i = 1;
$vals = array();
foreach ($data as $key => $d) {
//$did = (strpos($id, ":")) ? 0 : $id;
$eid = $d['entity_id'];
$e_type = $d['entity_table'];
$order = $d['order'];
$breadcrumb = $d['breadcrumb'];
$next = $d['next'];
$title = $d['title'];
$sql = $sql . "( %" . ($i + 0) . ", %" . ($i + 1) . ", %" . ($i + 2) . ", %" . ($i + 3) . ", %" . ($i + 4) . ", %" . ($i + 5) . ", %" . ($i + 6) . "),";
//$vals[$i++] = array($did, 'Integer');
$vals[$i++] = array($wid, 'Integer');
$vals[$i++] = array($e_type, 'String');
$vals[$i++] = array($eid, 'String');
$vals[$i++] = array($order, 'Integer');
$vals[$i++] = array($breadcrumb, 'String');
$vals[$i++] = array($next, 'String');
$vals[$i++] = array($title, 'String');
}
$sql = substr($sql, 0, -1);
try {
$dao =& CRM_Core_DAO::executeQuery($sql, $vals);
} catch (Exception $e) {
$transaction->rollback();
return civicrm_api3_create_error($e . message);
}
//TODO: Better error checking?
if ($dao->_lastError) {
$transaction->rollback();
} else {
$transaction->commit();
CRM_Workflow_hook::afterSave($wid, $data);
}
}
$returnValues = array();
return civicrm_api3_create_success($returnValues, $params, 'PriceSet', 'FetchSection');
}
示例6: run
function run()
{
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
if ($action & CRM_Core_Action::UPDATE) {
$controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar', 'Edit Progressbar', CRM_Core_Action::UPDATE);
$controller->set('id', $id);
$controller->process();
return $controller->run();
} elseif ($action & CRM_Core_Action::COPY) {
try {
$sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount)\n SELECT concat(name, '-', (SELECT MAX(id) FROM civicrm_wci_progress_bar)),\n starting_amount, goal_amount FROM civicrm_wci_progress_bar\n WHERE id=%1";
CRM_Core_DAO::executeQuery($sql, array(1 => array($id, 'Integer')));
$new_pb_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
$sql = "INSERT INTO civicrm_wci_progress_bar_formula\n (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n SELECT contribution_page_id, financial_type_id, %1, start_date,\n end_date, percentage FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=%2";
CRM_Core_DAO::executeQuery($sql, array(1 => array($new_pb_id, 'Integer'), 2 => array($id, 'Integer')));
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . $e->getMessage(), '', 'error');
$transaction->rollback();
}
} elseif ($action & CRM_Core_Action::DELETE) {
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
$transaction = new CRM_Core_Transaction();
$sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = %1";
$params = array(1 => array($id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $params);
$sql = "DELETE FROM civicrm_wci_progress_bar where id = %1";
$params = array(1 => array($id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $params);
$transaction->commit();
} catch (Exception $e) {
$errmgs = $e->getMessage() . ts('. Check whether progressbar is used by any widget or not');
CRM_Core_Session::setStatus($errmgs, '', 'error');
$transaction->rollback();
}
}
// Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
CRM_Utils_System::setTitle(ts('Progress Bar List'));
$query = "SELECT * FROM civicrm_wci_progress_bar";
$params = array();
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
while ($dao->fetch()) {
$con_page[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
$action = array_sum(array_keys($this->actionLinks()));
//build the normal action links.
$con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
}
if (isset($con_page)) {
$this->assign('rows', $con_page);
}
return parent::run();
}
示例7: run
function run()
{
$transaction = new CRM_Core_Transaction();
$cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
$cart->load_associations();
$this->assign_by_ref('events_in_carts', $cart->get_main_events_in_carts());
$this->assign('events_count', count($cart->get_main_events_in_carts()));
$transaction->commit();
return parent::run();
}
示例8: create
/**
* @param array $params
*
* @return $this
* @throws Exception
*/
public static function create($params)
{
$transaction = new CRM_Core_Transaction();
$cart = self::add($params);
if (is_a($cart, 'CRM_Core_Error')) {
$transaction->rollback();
CRM_Core_Error::fatal(ts('There was an error creating an event cart'));
}
$transaction->commit();
return $cart;
}
示例9: create
/**
* Construct a new mailingab object.
*
* @params array $params
* Form values.
*
* @param array $params
* @param array $ids
*
* @return object
* $mailingab The new mailingab object
*/
public static function create(&$params, $ids = array())
{
$transaction = new CRM_Core_Transaction();
$mailingab = self::add($params, $ids);
if (is_a($mailingab, 'CRM_Core_Error')) {
$transaction->rollback();
return $mailingab;
}
$transaction->commit();
return $mailingab;
}
示例10: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
*
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
// before we proceed lets just check if this contact is already 'Added'
// if so, we should ignore this request and hence avoid sending multiple
// emails - CRM-11157
$details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
if ($details && $details->status == 'Added') {
// This contact is already subscribed
// lets return the group title
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
}
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(TRUE);
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
$mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
// send - ignore errors because the desired status change has already been successful
$unused_result = CRM_Utils_Mail::send($mailParams);
return $group->title;
}
示例11:
static function &create(&$params)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$statusType = self::add($params);
if (is_a($statusType, 'CRM_Core_Error')) {
$transaction->rollback();
return $statusType;
}
$transaction->commit();
return $statusType;
}
示例12: run
function run()
{
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
if ($action & CRM_Core_Action::UPDATE) {
$controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_CreateWidget', 'Edit Widget', CRM_Core_Action::UPDATE);
$controller->set('id', $id);
$controller->process();
return $controller->run();
} elseif ($action & CRM_Core_Action::COPY) {
try {
$sql = "INSERT INTO civicrm_wci_widget (title, logo_image, image,\n button_title, button_link_to, progress_bar_id, description,\n email_signup_group_id, size_variant, color_title, color_title_bg,\n color_progress_bar, color_progress_bar_bg, color_widget_bg, color_description, color_border,\n color_button, color_button_bg, hide_title, hide_border, hide_pbcap,\n color_btn_newsletter, color_btn_newsletter_bg, newsletter_text,\n color_newsletter_text, style_rules, override, custom_template, show_pb_perc)\n SELECT concat(title, '-', (SELECT MAX(id) FROM civicrm_wci_widget)), logo_image, image,\n button_title, button_link_to, progress_bar_id, description,\n email_signup_group_id, size_variant, color_title, color_title_bg,\n color_progress_bar, color_progress_bar_bg, color_widget_bg, color_description, color_border,\n color_button, color_button_bg, hide_title, hide_border, hide_pbcap,\n color_btn_newsletter, color_btn_newsletter_bg, newsletter_text,\n color_newsletter_text, style_rules, override, custom_template, show_pb_perc FROM civicrm_wci_widget WHERE id=%1";
CRM_Core_DAO::executeQuery("SET foreign_key_checks = 0;");
CRM_Core_DAO::executeQuery($sql, array(1 => array($id, 'Integer')));
CRM_Core_DAO::executeQuery("SET foreign_key_checks = 1;");
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to create widget. ') . $e->getMessage(), '', 'error');
$transaction->rollback();
}
} elseif ($action & CRM_Core_Action::DELETE) {
try {
$transaction = new CRM_Core_Transaction();
$sql = "DELETE FROM civicrm_wci_widget where id = %1";
$params = array(1 => array($id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $params);
$transaction->commit();
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to delete widget. ') . $e->getMessage(), '', 'error');
$transaction->rollback();
}
}
CRM_Utils_System::setTitle(ts('Widget List'));
$query = "SELECT * FROM civicrm_wci_widget";
$params = array();
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
while ($dao->fetch()) {
$wid_page[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $wid_page[$dao->id]);
$wid_page[$dao->id]['title'] = $wid_page[$dao->id]['title'];
$description = $wid_page[$dao->id]['description'];
$wid_page[$dao->id]['description'] = strip_tags($description);
$action = array_sum(array_keys($this->actionLinks()));
//build the normal action links.
$wid_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
}
if (isset($wid_page)) {
$this->assign('rows', $wid_page);
}
parent::run();
}
示例13: foreach
function stub_out_and_inherit()
{
$transaction = new CRM_Core_Transaction();
foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
if (empty($event_in_cart->participants)) {
$participant = CRM_Event_Cart_BAO_MerParticipant::create(array('cart_id' => $this->cart->id, 'event_id' => $event_in_cart->event_id, 'contact_id' => self::find_or_create_contact($this->getContactID())));
$participant->save();
$event_in_cart->add_participant($participant);
}
$event_in_cart->save();
}
$transaction->commit();
}
示例14: run
/**
* This function takes care of all the things common to all pages.
*
* This typically involves assigning the appropriate smarty variables :)
*/
public function run()
{
$transaction = new CRM_Core_Transaction();
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
$cart->load_associations();
$event_in_cart = $cart->get_event_in_cart_by_event_id($this->_id);
$removed_event = $cart->remove_event_in_cart($event_in_cart->id);
$removed_event_title = $removed_event->event->title;
CRM_Core_Session::setStatus(ts("<b>%1</b> has been removed from your cart.", array(1 => $removed_event_title)), '', 'success');
$transaction->commit();
return CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
}
示例15: create
/**
* @param array $params
*
* @return object $this|CRM_Event_Cart_BAO_EventInCart
* @throws Exception
*/
public static function create(&$params)
{
$transaction = new CRM_Core_Transaction();
$event_in_cart = new CRM_Event_Cart_BAO_EventInCart();
$event_in_cart->copyValues($params);
$event_in_cart = $event_in_cart->save();
if (is_a($event_in_cart, 'CRM_Core_Error')) {
$transaction->rollback();
CRM_Core_Error::fatal(ts('There was an error creating an event_in_cart'));
}
$transaction->commit();
return $event_in_cart;
}