本文整理汇总了PHP中CRM_Core_TemporaryErrorScope::useException方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_TemporaryErrorScope::useException方法的具体用法?PHP CRM_Core_TemporaryErrorScope::useException怎么用?PHP CRM_Core_TemporaryErrorScope::useException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_TemporaryErrorScope
的用法示例。
在下文中一共展示了CRM_Core_TemporaryErrorScope::useException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
}
示例2: 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();
}
示例3: 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);
}
}
示例4: 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();
}
示例5: 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();
}
示例6: 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());
}
}
示例7: 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;
}
}
示例8: 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);
}
示例9: setUp
/**
* Common setup functions for all unit tests.
*/
protected function setUp()
{
$session = CRM_Core_Session::singleton();
$session->set('userID', NULL);
$this->errorScope = CRM_Core_TemporaryErrorScope::useException();
// REVERT
// Use a temporary file for STDIN
$GLOBALS['stdin'] = tmpfile();
if ($GLOBALS['stdin'] === FALSE) {
echo "Couldn't open temporary file\n";
exit(1);
}
// Get and save a connection to the database
$this->_dbconn = $this->getConnection();
// reload database before each test
// $this->_populateDB();
// "initialize" CiviCRM to avoid problems when running single tests
// FIXME: look at it closer in second stage
$GLOBALS['civicrm_setting']['domain']['fatalErrorHandler'] = 'CiviUnitTestCase_fatalErrorHandler';
$GLOBALS['civicrm_setting']['domain']['backtrace'] = 1;
// disable any left-over test extensions
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_extension WHERE full_name LIKE "test.%"');
// reset all the caches
CRM_Utils_System::flushCache();
// initialize the object once db is loaded
\Civi::reset();
$config = CRM_Core_Config::singleton(TRUE, TRUE);
// ugh, performance
// when running unit tests, use mockup user framework
$this->hookClass = CRM_Utils_Hook::singleton();
// Make sure the DB connection is setup properly
$config->userSystem->setMySQLTimeZone();
$env = new CRM_Utils_Check_Component_Env();
CRM_Utils_Check::singleton()->assertValid($env->checkMysqlTime());
// clear permissions stub to not check permissions
$config->userPermissionClass->permissions = NULL;
//flush component settings
CRM_Core_Component::getEnabledComponents(TRUE);
error_reporting(E_ALL);
$this->_sethtmlGlobals();
}
示例10: civicrm_tag_delete
/**
* Deletes an existing Tag
*
* @param array $params
*
* @return boolean | error true if successfull, error otherwise
* @access public
*/
function civicrm_tag_delete(&$params)
{
_civicrm_initialize();
$errorScope = CRM_Core_TemporaryErrorScope::useException();
try {
civicrm_verify_mandatory($params, NULL, array('tag_id'));
$tagID = CRM_Utils_Array::value('tag_id', $params);
require_once 'CRM/Core/BAO/Tag.php';
return CRM_Core_BAO_Tag::del($tagID) ? civicrm_create_success() : civicrm_create_error(ts('Could not delete tag'));
} catch (Exception $e) {
if (CRM_Core_Error::$modeException) {
throw $e;
}
return civicrm_create_error($e->getMessage());
}
}
示例11: smarty_function_crmSQL
function smarty_function_crmSQL($params, &$smarty) {
$is_error = 0;
$error = "";
$values = "";
$sql="";
if (!array_key_exists('sql', $params) && !array_key_exists('file', $params) && !array_key_exists('json', $params)) {
$smarty->trigger_error("assign: missing 'sql', 'json' OR 'file' parameter");
$error = "crmAPI: missing 'sql', 'json' or 'file' parameter";
$is_error = 1;
}
$parameters = array();
if(array_key_exists('json', $params)){
$json=json_decode(file_get_contents('queries/'.$params["json"].".json", true));//file_get_contents('queries/'.$params["json"].".json", true)
$sql=$json->{"query"};
foreach ($json->{"params"} as $key => $value) {
$var=intval($key);
$name=$value->{"name"};
$type=$value->{"type"};
if(array_key_exists($name, $params)){
$parameters[$var] = array($params[$name],$type);
}
}
}
else if(array_key_exists('sql', $params)){
$sql = $params["sql"];
}
else if(array_key_exists('file', $params)){
$sql = file_get_contents('queries/'.$params["file"].".sql", true);
}
$forbidden=array("delete ", "drop ","update ","grant ");
foreach ($forbidden as $check) {
if(strpos(strtolower($sql), $check)!==false){
$smarty->trigger_error($check."command not allowed");
$error = "crmAPI: you can not ".$check."using crmSQL";
$is_error = 1;
break;
}
}
if (array_key_exists('debug', $params)) {
$smarty->trigger_error("sql:". $params["sql"]);
}
try{
if($is_error==0){
$errorScope = CRM_Core_TemporaryErrorScope::useException();
$dao = CRM_Core_DAO::executeQuery($sql,$parameters);
$values = array();
while ($dao->fetch()) {
$values[] = $dao->toArray();
}
}
}
catch(Exception $e){
$is_error=1;
$error = "crmAPI: ".$e->getMessage();
$values="";
}
if(array_key_exists('set', $params)){
if($values!=""){
//echo "console.log('string')";
$smarty->assign($params['set'], $values);
}
}
return json_encode(array("is_error"=>$is_error, "error"=>$error, "values" => $values), JSON_NUMERIC_CHECK);
}
示例12: testDupesByParams
public function testDupesByParams()
{
// make dupe checks based on based on following contact sets:
// FIRST - LAST - EMAIL
// ---------------------------------
// robin - hood - robin@example.com
// robin - hood - hood@example.com
// robin - dale - robin@example.com
// little - dale - dale@example.com
// will - dale - dale@example.com
// will - dale - will@example.com
// will - dale - will@example.com
// contact data set
// FIXME: move create params to separate function
$params = array(array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'robin@example.com', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'dale', 'email' => 'robin@example.com', 'contact_type' => 'Individual'), array('first_name' => 'little', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'dale@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => 'will@example.com', 'contact_type' => 'Individual'));
$count = 1;
// TODO: This is not an API test!!
foreach ($params as $param) {
$param['version'] = 3;
$contact = civicrm_api('contact', 'create', $param);
$params = array('contact_id' => $contact['id'], 'street_address' => 'Ambachtstraat 23', 'location_type_id' => 1, 'version' => 3);
$result = civicrm_api('address', 'create', $params);
$contactIds[$count++] = $contact['id'];
}
// verify that all contacts have been created separately
$this->assertEquals(count($contactIds), 7, 'Check for number of contacts.');
$dao = new CRM_Dedupe_DAO_RuleGroup();
$dao->contact_type = 'Individual';
$dao->used = 'General';
$dao->is_default = 1;
$dao->find(TRUE);
$fields = array('first_name' => 'robin', 'last_name' => 'hood', 'email' => 'hood@example.com', 'street_address' => 'Ambachtstraat 23');
$errorScope = CRM_Core_TemporaryErrorScope::useException();
$dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
$ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'General');
// Check with default Individual-General rule
$this->assertEquals(count($ids), 2, 'Check Individual-General rule for dupesByParams().');
// delete all created contacts
foreach ($contactIds as $contactId) {
Contact::delete($contactId);
}
}
示例13: postProcess
function postProcess()
{
$errorScope = CRM_Core_TemporaryErrorScope::useException();
if (isset($this->_id)) {
try {
$transaction = new CRM_Core_Transaction();
$sql = "UPDATE civicrm_wci_progress_bar SET name = %1,\n starting_amount = %2, goal_amount = %3 where id = %4";
CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST['progressbar_name'], 'String'), 2 => array($_REQUEST['starting_amount'], 'Float'), 3 => array($_REQUEST['goal_amount'], 'Float'), 4 => array($this->_id, 'Integer')));
/** Delete existiing formula fields and add fields fresh*/
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_wci_progress_bar_formula
WHERE progress_bar_id=%1', array(1 => array($this->_id, 'Integer')));
$elem_added = 0;
for ($i = 1; $elem_added < (int) $_REQUEST['contrib_count']; $i++) {
if (!isset($_REQUEST['contribution_page_' . (string) $i])) {
continue;
}
$page = 'contribution_page_' . (string) $i;
$type = 'financial_type_' . (string) $i;
$perc = 'percentage_' . (string) $i;
$sdate = 'contribution_start_date_' . (string) $i;
$edate = 'contribution_end_date_' . (string) $i;
$sql = "INSERT INTO civicrm_wci_progress_bar_formula\n (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n VALUES (%1, %2, %3, %4, %5, %6)";
$start = NULL;
$end = NULL;
if (!empty($_REQUEST[$sdate])) {
$start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd");
}
if (!empty($_REQUEST[$edate])) {
$end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd");
}
CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST[$page], 'Integer'), 2 => array($_REQUEST[$type], 'Integer'), 3 => array($this->_id, 'Integer'), 4 => array($start, 'Date'), 5 => array($end, 'Date'), 6 => array($_REQUEST[$perc], 'Float')));
$elem_added++;
}
$transaction->commit();
CRM_Wci_BAO_WidgetCache::deleteWidgetCacheByProgressbar($this->_id);
CRM_Core_Session::setStatus(ts('Progress bar created successfully'), '', 'success');
CRM_Utils_System::redirect('progress-bar?reset=1');
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to create progress bar'), '', 'error');
$transaction->rollback();
}
} else {
$sql = "INSERT INTO civicrm_wci_progress_bar\n (name, starting_amount, goal_amount) VALUES (%1, %2, %3)";
try {
$transaction = new CRM_Core_Transaction();
CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST['progressbar_name'], 'String'), 2 => array($_REQUEST['starting_amount'], 'Float'), 3 => array($_REQUEST['goal_amount'], 'Float')));
$progressbar_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
for ($i = 1; $i <= (int) $_REQUEST['contrib_count']; $i++) {
$page = 'contribution_page_' . (string) $i;
$type = 'financial_type_' . (string) $i;
$perc = 'percentage_' . (string) $i;
$sdate = 'contribution_start_date_' . (string) $i;
$edate = 'contribution_end_date_' . (string) $i;
$sql = "INSERT INTO civicrm_wci_progress_bar_formula\n (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n VALUES (%1, %2, %3, %4, %5, %6)";
$start = NULL;
$end = NULL;
if (!empty($_REQUEST[$sdate])) {
$start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd");
}
if (!empty($_REQUEST[$edate])) {
$end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd");
}
CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST[$page], 'Integer'), 2 => array($_REQUEST[$type], 'Integer'), 3 => array($progressbar_id, 'Integer'), 4 => array($start, 'Date'), 5 => array($end, 'Date'), 6 => array($_REQUEST[$perc], 'Float')));
}
$transaction->commit();
CRM_Utils_System::redirect('civicrm/wci/progress-bar?reset=1');
} catch (Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . $e->getMessage(), '', 'error');
$transaction->rollback();
}
$elem = $this->getElement('contrib_count');
$elem->setValue('1');
}
parent::postProcess();
}
示例14: runAll
/**
* Immediately run all tasks in a queue (until either reaching the end
* of the queue or encountering an error)
*
* If the runner has an onEndUrl, then this function will not return
*
* @return mixed
* TRUE if all tasks complete normally; otherwise, an array describing the
* failed task
*/
public function runAll()
{
$taskResult = $this->formatTaskResult(TRUE);
while ($taskResult['is_continue']) {
// setRaiseException should't be necessary here, but there's a bug
// somewhere which causes this setting to be lost. Observed while
// upgrading 4.0=>4.2. This preference really shouldn't be a global
// setting -- it should be more of a contextual/stack-based setting.
// This should be appropriate because queue-runners are not used with
// basic web pages -- they're used with CLI/REST/AJAX.
$errorScope = CRM_Core_TemporaryErrorScope::useException();
$taskResult = $this->runNext();
$errorScope = NULL;
}
if ($taskResult['numberOfItems'] == 0) {
$result = $this->handleEnd();
if (!empty($result['redirect_url'])) {
CRM_Utils_System::redirect($result['redirect_url']);
}
return TRUE;
} else {
return $taskResult;
}
}
示例15: civicrm_api
function civicrm_api($entity, $action, $params, $extra = NULL)
{
$apiWrappers = array(CRM_Core_HTMLInputCoder::singleton());
try {
require_once 'api/v3/utils.php';
require_once 'api/Exception.php';
if (!is_array($params)) {
throw new API_Exception('Input variable `params` is not an array', 2000);
}
_civicrm_api3_initialize();
$errorScope = CRM_Core_TemporaryErrorScope::useException();
require_once 'CRM/Utils/String.php';
require_once 'CRM/Utils/Array.php';
$apiRequest = array();
$apiRequest['entity'] = CRM_Utils_String::munge($entity);
$apiRequest['action'] = CRM_Utils_String::munge($action);
$apiRequest['version'] = civicrm_get_api_version($params);
$apiRequest['params'] = $params;
$apiRequest['extra'] = $extra;
// look up function, file, is_generic
$apiRequest += _civicrm_api_resolve($apiRequest);
if (strtolower($action) == 'create' || strtolower($action) == 'delete') {
$apiRequest['is_transactional'] = 1;
$tx = new CRM_Core_Transaction();
}
$errorFnName = $apiRequest['version'] == 2 ? 'civicrm_create_error' : 'civicrm_api3_create_error';
if ($apiRequest['version'] > 2) {
_civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
}
// we do this before we
_civicrm_api3_swap_out_aliases($apiRequest);
if (strtolower($action) != 'getfields') {
if (!CRM_Utils_Array::value('id', $params)) {
$apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest), $apiRequest['params']);
}
//if 'id' is set then only 'version' will be checked but should still be checked for consistency
civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest));
}
foreach ($apiWrappers as $apiWrapper) {
$apiRequest = $apiWrapper->fromApiInput($apiRequest);
}
$function = $apiRequest['function'];
if ($apiRequest['function'] && $apiRequest['is_generic']) {
// Unlike normal API implementations, generic implementations require explicit
// knowledge of the entity and action (as well as $params). Bundle up these bits
// into a convenient data structure.
$result = $function($apiRequest);
} elseif ($apiRequest['function'] && !$apiRequest['is_generic']) {
_civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
$result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']);
} else {
return $errorFnName("API (" . $apiRequest['entity'] . "," . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
}
foreach ($apiWrappers as $apiWrapper) {
$result = $apiWrapper->toApiOutput($apiRequest, $result);
}
if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
if ($result['is_error'] === 0) {
return 1;
} else {
return 0;
}
}
if (CRM_Utils_Array::value('format.only_id', $apiRequest['params']) && isset($result['id'])) {
return $result['id'];
}
if (CRM_Utils_Array::value('is_error', $result, 0) == 0) {
_civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']);
}
if (CRM_Utils_Array::value('format.smarty', $apiRequest['params']) || CRM_Utils_Array::value('format_smarty', $apiRequest['params'])) {
// return _civicrm_api_parse_result_through_smarty($result,$apiRequest['params']);
}
if (function_exists('xdebug_time_index') && CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) {
$result['xdebug']['peakMemory'] = xdebug_peak_memory_usage();
$result['xdebug']['memory'] = xdebug_memory_usage();
$result['xdebug']['timeIndex'] = xdebug_time_index();
}
return $result;
} catch (PEAR_Exception $e) {
if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
return 0;
}
$data = array();
$err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest);
if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
$err['trace'] = $e->getTraceSafe();
} else {
$err['tip'] = "add debug=1 to your API call to have more info about the error";
}
if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
$tx->rollback();
}
return $err;
} catch (API_Exception $e) {
if (!isset($apiRequest)) {
$apiRequest = array();
}
if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params', $apiRequest)) == 1) {
return 0;
}
//.........这里部分代码省略.........