4.3 developer support, apiv3 wrapper, uf level functions to support civimobile/other extensions
function flush() {
// nullop by default
}
+
+ /**
+ * Perform an post login activities required by the UF -
+ * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
+ * @param array $edit: The array of form values submitted by the user.
+ */
+ function userLoginFinalize($edit = array()){
+ }
}
return TRUE;
}
+ /**
+ * Perform an post login activities required by the UF -
+ * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
+ * @param array $edit: The array of form values submitted by the user.
+ */
+ function userLoginFinalize($edit = array()){
+ user_login_finalize(&$edit);
+ }
+
/**
* Set a message in the UF to display to a user
*
return TRUE;
}
+ /**
+ * Perform an post login activities required by the UF -
+ * e.g. for drupal : records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
+ * @param array $edit: The array of form values submitted by the user.
+ */
+ function userLoginFinalize($edit = array()){
+ user_authenticate_finalize(&$edit);
+ }
+
/**
* Set a message in the UF to display to a user
*
);
}
}
+/**
+ * This api exception returns more information than the default one. We are using it rather than
+ * API_Exception from the api wrapper as the namespace is more generic
+ * @param string $message the human friendly error message
+ * @param string $error_code a computer friendly error code. By convention, no space (but underscore allowed)
+ * ex: mandatory_missing, duplicate, invalid_format
+ * @param array $data extra params to return. eg an extra array of ids. It is not mandatory, but can help the computer using the api. Keep in mind the api consumer isn't to be trusted. eg. the database password is NOT a good extra data
+ */
+class CiviCRM_API3_Exception extends Exception
+{
+ private $extraParams = array();
+ public function __construct($message, $error_code, $extraParams = array(),Exception $previous = null) {
+ parent::__construct(ts($message));
+ $this->extraParams = $extraParams + array('error_code' => $error_code);
+ }
+
+ // custom string representation of object
+ public function __toString() {
+ return __CLASS__ . ": [{$this->extraParams['error_code']}: {$this->message}\n";
+ }
+
+ public function getErrorCode() {
+ return $this->extraParams['error_code'];
+ }
+ public function getExtraParams() {
+ return $this->extraParams;
+ }
+}
$cache[$cachekey] = array('function' => FALSE, 'is_generic' => FALSE);
return $cache[$cachekey];
}
+/**
+ * Version 3 wrapper for civicrm_api. Throws exception
+ * @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
+ *
+ * @return array
+ *
+ */
+function civicrm_api3($entity, $action, $params){
+ $params['version'] = 3;
+ $result = civicrm_api($entity, $action, $params);
+ if($result['is_error']){
+ throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result);
+ }
+}
/**
* Load/require all files related to an entity.
$this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual));
}
}
+/**
+ * Test that calling via wrapper works
+ */
+ function testv3Wrapper() {
+ try{
+ $result = civicrm_api3('contact', 'get', array());
+ }
+ catch (CRM_Exception $e){
+ $this->fail("This should have been a success test");
+ }
+ $this->assertAPISuccess($result);
+ }
+
+ /**
+ * test exception is thrown
+ */
+ function testv3WrapperException(){
+ try{
+ $result = civicrm_api3('contact', 'create', array('debug' => 1));
+ }
+ catch (CiviCRM_API3_Exception $e){
+ $this->assertEquals('undefined', $e->getErrorCode());
+ $this->assertEquals('Mandatory key(s) missing from params array: contact_type', $e->getMessage());
+ $extra = $e->getExtraParams();
+ $this->assertArrayHasKey('trace', $extra);
+ return;
+ }
+ $this->fail('Exception was expected');
+ }
+
}