本文整理汇总了PHP中CRM_Core_TemporaryErrorScope类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_TemporaryErrorScope类的具体用法?PHP CRM_Core_TemporaryErrorScope怎么用?PHP CRM_Core_TemporaryErrorScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_TemporaryErrorScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: smarty_function_crmAPI
/**
* @param $params
* @param $smarty
* @return string|void
*/
function smarty_function_crmAPI($params, &$smarty)
{
if (!array_key_exists('entity', $params)) {
$smarty->trigger_error("assign: missing 'entity' parameter");
return "crmAPI: missing 'entity' parameter";
}
$errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Utils_REST', 'fatal'));
$entity = $params['entity'];
$action = CRM_Utils_Array::value('action', $params, 'get');
$params['sequential'] = CRM_Utils_Array::value('sequential', $params, 1);
$var = CRM_Utils_Array::value('var', $params);
CRM_Utils_Array::remove($params, 'entity', 'action', 'var');
$params['version'] = 3;
require_once 'api/api.php';
$result = civicrm_api($entity, $action, $params);
unset($errorScope);
if ($result === FALSE) {
$smarty->trigger_error("Unknown error");
return;
}
if (!empty($result['is_error'])) {
$smarty->trigger_error("{crmAPI} " . $result["error_message"]);
}
if (!$var) {
return json_encode($result);
}
if (!empty($params['json'])) {
$smarty->assign($var, json_encode($result));
} else {
$smarty->assign($var, $result);
}
}
示例3: civicrm_event_create
/**
* Create a Event
*
* This API is used for creating a Event
*
* @param array $params (reference ) input parameters
* Allowed @params array keys are:
* {@schema Event/Event.xml}
*
* @return array of newly created event property values.
* @access public
*/
function civicrm_event_create(&$params)
{
_civicrm_initialize();
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
civicrm_verify_mandatory($params, 'CRM_Event_DAO_Event', array('start_date', 'event_type_id', 'title'));
// Do we really want $params[id], even if we have
// $params[event_id]? if yes then please uncomment the below line
//$ids['event' ] = $params['id'];
$ids['eventTypeId'] = (int) $params['event_type_id'];
$ids['startDate'] = $params['start_date'];
$ids['event_id'] = CRM_Utils_Array::value('event_id', $params);
require_once 'CRM/Event/BAO/Event.php';
$eventBAO = CRM_Event_BAO_Event::create($params, $ids);
if (is_a($eventBAO, 'CRM_Core_Error')) {
return civicrm_create_error("Event is not created");
} else {
$event = array();
_civicrm_object_to_array($eventBAO, $event);
$values = array();
$values['event_id'] = $event['id'];
$values['is_error'] = 0;
}
return $values;
} catch (Exception $e) {
return civicrm_create_error($e->getMessage());
}
}
示例4: run
/**
* @param string $entity
* type of entities to deal with
* @param string $action
* create, get, delete or some special action name.
* @param array $params
* array to be passed to function
* @param null $extra
*
* @return array|int
*/
public function run($entity, $action, $params, $extra = NULL)
{
/**
* @var $apiProvider \Civi\API\Provider\ProviderInterface|NULL
*/
$apiProvider = NULL;
// TODO Define alternative calling convention makes it easier to construct $apiRequest
// without the ambiguity of "data" vs "options"
$apiRequest = Request::create($entity, $action, $params, $extra);
try {
if (!is_array($params)) {
throw new \API_Exception('Input variable `params` is not an array', 2000);
}
$this->boot();
$errorScope = \CRM_Core_TemporaryErrorScope::useException();
list($apiProvider, $apiRequest) = $this->resolve($apiRequest);
$this->authorize($apiProvider, $apiRequest);
$apiRequest = $this->prepare($apiProvider, $apiRequest);
$result = $apiProvider->invoke($apiRequest);
$apiResponse = $this->respond($apiProvider, $apiRequest, $result);
return $this->formatResult($apiRequest, $apiResponse);
} catch (\Exception $e) {
$this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, $apiProvider, $apiRequest));
if ($e instanceof \PEAR_Exception) {
$err = $this->formatPearException($e, $apiRequest);
} elseif ($e instanceof \API_Exception) {
$err = $this->formatApiException($e, $apiRequest);
} else {
$err = $this->formatException($e, $apiRequest);
}
return $this->formatResult($apiRequest, $err);
}
}
示例5: 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();
}
示例6: activate
function activate()
{
$this->active = TRUE;
$this->backup = array();
foreach (array('display_errors', 'html_errors', 'xmlrpc_errors') as $key) {
$this->backup[$key] = ini_get($key);
ini_set($key, 0);
}
set_error_handler(array($this, 'onError'), $this->level);
// FIXME make this temporary/reversible
$this->errorScope = CRM_Core_TemporaryErrorScope::useException();
}
示例7: civicrm_contact_create
/**
* @todo Write sth
*
* @param array $params (reference ) input parameters
*
* Allowed @params array keys are:
* {@schema Contact/Contact.xml}
* {@schema Core/Address.xml}}
*
* @return array (reference ) contact_id of created or updated contact
*
* @static void
* @access public
*/
function civicrm_contact_create(&$params)
{
// call update and tell it to create a new contact
_civicrm_initialize();
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
$create_new = TRUE;
return civicrm_contact_update($params, $create_new);
} catch (Exception $e) {
return civicrm_create_error($e->getMessage());
}
}
示例8: preProcess
/**
* Set variables up before form is built.
*/
public function preProcess()
{
//Test database user privilege to create table(Temporary) CRM-4725
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$daoTestPrivilege = new CRM_Core_DAO();
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_one(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_two(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("DROP TEMPORARY TABLE IF EXISTS import_job_permission_one, import_job_permission_two");
unset($errorScope);
if ($daoTestPrivilege->_lastError) {
CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.'));
}
$results = array();
$config = CRM_Core_Config::singleton();
$handler = opendir($config->uploadDir);
$errorFiles = array('sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch');
// check for post max size avoid when called twice
$snippet = CRM_Utils_Array::value('snippet', $_GET, 0);
if (empty($snippet)) {
CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
}
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..' && in_array($file, $errorFiles) && !is_writable($config->uploadDir . $file)) {
$results[] = $file;
}
}
closedir($handler);
if (!empty($results)) {
CRM_Core_Error::fatal(ts('<b>%1</b> file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', array(1 => implode(', ', $results), 2 => $config->uploadDir)));
}
$this->_dataSourceIsValid = FALSE;
$this->_dataSource = CRM_Utils_Request::retrieve('dataSource', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
$this->_params = $this->controller->exportValues($this->_name);
if (!$this->_dataSource) {
//considering dataSource as base criteria instead of hidden_dataSource.
$this->_dataSource = CRM_Utils_Array::value('dataSource', $_POST, CRM_Utils_Array::value('dataSource', $this->_params));
$this->assign('showOnlyDataSourceFormPane', FALSE);
} else {
$this->assign('showOnlyDataSourceFormPane', TRUE);
}
$dataSources = $this->_getDataSources();
if ($this->_dataSource && isset($dataSources[$this->_dataSource])) {
$this->_dataSourceIsValid = TRUE;
$this->assign('showDataSourceFormPane', TRUE);
$dataSourcePath = explode('_', $this->_dataSource);
$templateFile = "CRM/Contact/Import/Form/" . $dataSourcePath[3] . ".tpl";
$this->assign('dataSourceFormTemplateFile', $templateFile);
} elseif ($this->_dataSource) {
throw new \CRM_Core_Exception("Invalid data source");
}
}
示例9: startTest
public function startTest(\PHPUnit_Framework_Test $test)
{
if ($this->isCiviTest($test)) {
error_reporting(E_ALL);
$this->errorScope = \CRM_Core_TemporaryErrorScope::useException();
}
if ($test instanceof HeadlessInterface) {
$this->bootHeadless($test);
}
if ($test instanceof HookInterface) {
// Note: bootHeadless() indirectly resets any hooks, which means that hook_civicrm_config
// is unsubscribable. However, after bootHeadless(), we're free to subscribe to hooks again.
$this->registerHooks($test);
}
if ($test instanceof TransactionalInterface) {
$this->tx = new \CRM_Core_Transaction(TRUE);
$this->tx->rollback();
} else {
$this->tx = NULL;
}
}
示例10: smarty_function_crmSetting
/**
* Retrieve CiviCRM settings from the api for use in templates.
*
* @param $params
* @param $smarty
*
* @return int|string|null
*/
function smarty_function_crmSetting($params, &$smarty)
{
$errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Utils_REST', 'fatal'));
unset($params['method']);
unset($params['assign']);
$params['version'] = 3;
require_once 'api/api.php';
$result = civicrm_api('setting', 'getvalue', $params);
unset($errorScope);
if ($result === FALSE) {
$smarty->trigger_error("Unknown error");
return NULL;
}
if (empty($params['var'])) {
return is_numeric($result) ? $result : json_encode($result);
}
if (!empty($params['json'])) {
$smarty->assign($params["var"], json_encode($result));
} else {
$smarty->assign($params["var"], $result);
}
}
示例11: unset
/**
* Singleton function used to manage this object.
*
* @param bool $loadFromDB
* whether to load from the database.
* @param bool $force
* whether to force a reconstruction.
*
* @return CRM_Core_Config
*/
public static function &singleton($loadFromDB = TRUE, $force = FALSE)
{
if (self::$_singleton === NULL || $force) {
$GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle'));
$errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler'));
if (defined('E_DEPRECATED')) {
error_reporting(error_reporting() & ~E_DEPRECATED);
}
self::$_singleton = new CRM_Core_Config();
\Civi\Core\Container::boot($loadFromDB);
if ($loadFromDB && self::$_singleton->dsn) {
$domain = \CRM_Core_BAO_Domain::getDomain();
\CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
unset($errorScope);
CRM_Utils_Hook::config(self::$_singleton);
self::$_singleton->authenticate();
// Extreme backward compat: $config binds to active domain at moment of setup.
self::$_singleton->getSettings();
Civi::service('settings_manager')->useDefaults();
}
}
return self::$_singleton;
}
示例12: send_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email
* The email address.
*
* @return void
*/
public function send_confirm_request($email)
{
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
$group = new CRM_Contact_BAO_Group();
$group->id = $this->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Subscribe';
$component->find(TRUE);
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$emailDomain}");
$url = CRM_Utils_System::url('civicrm/mailing/confirm', "reset=1&cid={$this->contact_id}&sid={$this->id}&h={$this->hash}", TRUE);
$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::replaceSubscribeTokens($html, $group->title, $url, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, FALSE);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message = new Mail_mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 's', $this->contact_id, $this->id, $this->hash);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($email, $h, $b);
unset($errorScope);
}
}
示例13: testMoveField
/**
* Move a custom field from $groupA to $groupB. Make sure that data records are
* correctly matched and created.
*/
public function testMoveField()
{
$countriesByName = array_flip(CRM_Core_PseudoConstant::country(FALSE, FALSE));
$this->assertTrue($countriesByName['ANDORRA'] > 0);
$groups = array('A' => Custom::createGroup(array('title' => 'Test_Group A', 'name' => 'test_group_a', 'extends' => array('Individual'), 'style' => 'Inline', 'is_multiple' => 0, 'is_active' => 1, 'version' => 3)), 'B' => Custom::createGroup(array('title' => 'Test_Group B', 'name' => 'test_group_b', 'extends' => array('Individual'), 'style' => 'Inline', 'is_multiple' => 0, 'is_active' => 1, 'version' => 3)));
$fields = array('countryA' => Custom::createField(array(), array('groupId' => $groups['A']->id, 'label' => 'Country A', 'dataType' => 'Country', 'htmlType' => 'Select Country')), 'countryB' => Custom::createField(array(), array('groupId' => $groups['A']->id, 'label' => 'Country B', 'dataType' => 'Country', 'htmlType' => 'Select Country')), 'countryC' => Custom::createField(array(), array('groupId' => $groups['B']->id, 'label' => 'Country C', 'dataType' => 'Country', 'htmlType' => 'Select Country')));
$contacts = array('alice' => Contact::createIndividual(array('first_name' => 'Alice', 'last_name' => 'Albertson', 'custom_' . $fields['countryA']->id => $countriesByName['ANDORRA'], 'custom_' . $fields['countryB']->id => $countriesByName['BARBADOS'])), 'bob' => Contact::createIndividual(array('first_name' => 'Bob', 'last_name' => 'Roberts', 'custom_' . $fields['countryA']->id => $countriesByName['AUSTRIA'], 'custom_' . $fields['countryB']->id => $countriesByName['BERMUDA'], 'custom_' . $fields['countryC']->id => $countriesByName['CHAD'])), 'carol' => Contact::createIndividual(array('first_name' => 'Carol', 'last_name' => 'Carolson', 'custom_' . $fields['countryC']->id => $countriesByName['CAMBODIA'])));
// Move!
CRM_Core_BAO_CustomField::moveField($fields['countryB']->id, $groups['B']->id);
// Group[A] no longer has fields[countryB]
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
$this->assertDBQuery(1, "SELECT {$fields['countryB']->column_name} FROM {$groups['A']->table_name}");
$this->fail('Expected exception when querying column on wrong table');
} catch (PEAR_Exception $e) {
}
$errorScope = NULL;
// Alice: Group[B] has fields[countryB], but fields[countryC] did not exist before
$this->assertDBQuery(1, "SELECT count(*) FROM {$groups['B']->table_name}\n WHERE entity_id = %1\n AND {$fields['countryB']->column_name} = %3\n AND {$fields['countryC']->column_name} is null", array(1 => array($contacts['alice'], 'Integer'), 3 => array($countriesByName['BARBADOS'], 'Integer')));
// Bob: Group[B] has merged fields[countryB] and fields[countryC] on the same record
$this->assertDBQuery(1, "SELECT count(*) FROM {$groups['B']->table_name}\n WHERE entity_id = %1\n AND {$fields['countryB']->column_name} = %3\n AND {$fields['countryC']->column_name} = %4", array(1 => array($contacts['bob'], 'Integer'), 3 => array($countriesByName['BERMUDA'], 'Integer'), 4 => array($countriesByName['CHAD'], 'Integer')));
// Carol: Group[B] still has fields[countryC] but did not get fields[countryB]
$this->assertDBQuery(1, "SELECT count(*) FROM {$groups['B']->table_name}\n WHERE entity_id = %1\n AND {$fields['countryB']->column_name} is null\n AND {$fields['countryC']->column_name} = %4", array(1 => array($contacts['carol'], 'Integer'), 4 => array($countriesByName['CAMBODIA'], 'Integer')));
Custom::deleteGroup($groups['A']);
Custom::deleteGroup($groups['B']);
}
示例14: testSetGetValuesYesNoRadio
/**
* Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio
*/
public function testSetGetValuesYesNoRadio()
{
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate(array('is_multiple' => 1));
//create Custom Field of type YesNo(Boolean) Radio
$fields = array('custom_group_id' => $customGroup['id'], 'data_type' => 'Boolean', 'html_type' => 'Radio', 'default_value' => '');
$customField = $this->customFieldCreate($fields);
// Retrieve the field ID for sample custom field 'test_Boolean'
$params = array('label' => 'test_Boolean');
$field = array();
//get field Id
CRM_Core_BAO_CustomField::retrieve($params, $field);
$fieldID = $customField['id'];
// valid boolean value '1' for Boolean Radio
$yesNo = '1';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo);
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the YesNo radio value is stored
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the boolean value is stored for contact ' . $contactID);
// Now set YesNo radio to an invalid boolean value and try to reset
$badYesNo = '20';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo);
CRM_Core_TemporaryErrorScope::useException();
$message = NULL;
try {
CRM_Core_BAO_CustomValueTable::setValues($params);
} catch (Exception $e) {
$message = $e->getMessage();
}
$errorScope = NULL;
// Check that an exception has been thrown
$this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed');
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID);
// Cleanup
$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
示例15: checkTriggerViewPermission
/**
* @param bool $view
* @param bool $trigger
*
* @return bool
*/
public static function checkTriggerViewPermission($view = TRUE, $trigger = TRUE)
{
// test for create view and trigger permissions and if allowed, add the option to go multilingual
// and logging
// I'm not sure why we use the getStaticProperty for an error, rather than checking for DB_Error
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$dao = new CRM_Core_DAO();
if ($view) {
$dao->query('CREATE OR REPLACE VIEW civicrm_domain_view AS SELECT * FROM civicrm_domain');
if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) {
return FALSE;
}
}
if ($trigger) {
$result = $dao->query('CREATE TRIGGER civicrm_domain_trigger BEFORE INSERT ON civicrm_domain FOR EACH ROW BEGIN END');
if (PEAR::getStaticProperty('DB_DataObject', 'lastError') || is_a($result, 'DB_Error')) {
if ($view) {
$dao->query('DROP VIEW IF EXISTS civicrm_domain_view');
}
return FALSE;
}
$dao->query('DROP TRIGGER IF EXISTS civicrm_domain_trigger');
if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) {
if ($view) {
$dao->query('DROP VIEW IF EXISTS civicrm_domain_view');
}
return FALSE;
}
}
if ($view) {
$dao->query('DROP VIEW IF EXISTS civicrm_domain_view');
if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) {
return FALSE;
}
}
return TRUE;
}