$reverter->revert();
return civicrm_api3_create_success(1);
}
+
+/**
+ * Get a log change.
+ *
+ * @param array $params
+ *
+ * @return array
+ * API Success Array
+ * @throws \API_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+function civicrm_api3_logging_get($params) {
+ $schema = new CRM_Logging_Schema();
+ $interval = (empty($params['log_date'])) ? NULL : $params['interval'];
+ $differ = new CRM_Logging_Differ($params['log_conn_id'], CRM_Utils_Array::value('log_date', $params), $interval);
+ return civicrm_api3_create_success($differ->getAllChangesForConnection($schema->getLogTablesForContact()));
+}
+
+/**
+ * Get a log change.
+ *
+ * @param array $params
+ *
+ * @throws \API_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+function _civicrm_api3_logging_get_spec(&$params) {
+ $params['log_conn_id'] = array(
+ 'title' => 'Logging Connection ID',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'api.required' => TRUE,
+ );
+ $params['log_date'] = array(
+ 'title' => 'Logging Timestamp',
+ 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
+ );
+ $params['interval'] = array(
+ 'title' => ts('Interval (required if date is included)'),
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'api.default' => '10 SECOND',
+ 'description' => ts('Used when log_date is passed in'),
+ );
+}
--- /dev/null
+<?php
+/**
+ * Test Generated example demonstrating the Logging.get API.
+ *
+ * @return array
+ * API result array
+ */
+function logging_get_example() {
+ $params = array(
+ 'log_conn_id' => 'wooty woot',
+ 'log_date' => '2016-04-06 00:08:23',
+ );
+
+ try{
+ $result = civicrm_api3('Logging', 'get', $params);
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ // Handle error here.
+ $errorMessage = $e->getMessage();
+ $errorCode = $e->getErrorCode();
+ $errorData = $e->getExtraParams();
+ return array(
+ 'error' => $errorMessage,
+ 'error_code' => $errorCode,
+ 'error_data' => $errorData,
+ );
+ }
+
+ return $result;
+}
+
+/**
+ * Function returns array of result expected from previous function.
+ *
+ * @return array
+ * API result array
+ */
+function logging_get_expectedresult() {
+
+ $expectedResult = array(
+ 'is_error' => 0,
+ 'version' => 3,
+ 'count' => 17,
+ 'values' => array(
+ '0' => array(
+ 'action' => 'Update',
+ 'id' => '3',
+ 'field' => 'sort_name',
+ 'from' => 'Anderson, Anthony',
+ 'to' => 'Dwarf, Dopey',
+ 'table' => 'civicrm_contact',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '1' => array(
+ 'action' => 'Update',
+ 'id' => '3',
+ 'field' => 'display_name',
+ 'from' => 'Mr. Anthony Anderson II',
+ 'to' => 'Mr. Dopey Dwarf II',
+ 'table' => 'civicrm_contact',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '2' => array(
+ 'action' => 'Update',
+ 'id' => '3',
+ 'field' => 'first_name',
+ 'from' => 'Anthony',
+ 'to' => 'Dopey',
+ 'table' => 'civicrm_contact',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '3' => array(
+ 'action' => 'Update',
+ 'id' => '3',
+ 'field' => 'last_name',
+ 'from' => 'Anderson',
+ 'to' => 'Dwarf',
+ 'table' => 'civicrm_contact',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '4' => array(
+ 'action' => 'Update',
+ 'id' => '3',
+ 'field' => 'modified_date',
+ 'from' => '2016-04-06 00:08:06',
+ 'to' => '2016-04-06 00:08:23',
+ 'table' => 'civicrm_contact',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '5' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'id',
+ 'from' => '',
+ 'to' => '4',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '6' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'contact_id',
+ 'from' => '',
+ 'to' => '3',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '7' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'location_type_id',
+ 'from' => '',
+ 'to' => '',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '8' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'email',
+ 'from' => '',
+ 'to' => 'dopey@mail.com',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '9' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'is_primary',
+ 'from' => '',
+ 'to' => 0,
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '10' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'is_billing',
+ 'from' => '',
+ 'to' => 0,
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '11' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'on_hold',
+ 'from' => '',
+ 'to' => 0,
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '12' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'is_bulkmail',
+ 'from' => '',
+ 'to' => 0,
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '13' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'hold_date',
+ 'from' => '',
+ 'to' => '',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '14' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'reset_date',
+ 'from' => '',
+ 'to' => '',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '15' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'signature_text',
+ 'from' => '',
+ 'to' => '',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ '16' => array(
+ 'action' => 'Insert',
+ 'id' => '4',
+ 'field' => 'signature_html',
+ 'from' => '',
+ 'to' => '',
+ 'table' => 'civicrm_email',
+ 'log_date' => '2016-04-06 00:08:23',
+ 'log_conn_id' => 'wooty woot',
+ ),
+ ),
+ );
+
+ return $expectedResult;
+}
+
+/*
+* This example has been generated from the API test suite.
+* The test that created it is called "testGet"
+* and can be found at:
+* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LoggingTest.php
+*
+* You can see the outcome of the API tests at
+* https://test.civicrm.org/job/CiviCRM-master-git/
+*
+* To Learn about the API read
+* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
+*
+* Browse the api on your own site with the api explorer
+* http://MYSITE.ORG/path/to/civicrm/api
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
* Clean up log tables.
*/
protected function tearDown() {
+ $this->quickCleanup(array('civicrm_email'));
parent::tearDown();
$this->callAPISuccess('Setting', 'create', array('logging' => FALSE));
$schema = new CRM_Logging_Schema();
$this->callAPISuccessGetCount('Email', array('id' => $email['id']), 0);
}
+ /**
+ * Test changes can be retrieved.
+ */
+ public function testGet() {
+ $contactId = $this->individualCreate();
+ $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ CRM_Core_DAO::executeQuery("SET @uniqueID = 'wooty woot'");
+ $timeStamp = date('Y-m-d H:i:s');
+ $this->callAPISuccess('Contact', 'create', array(
+ 'id' => $contactId,
+ 'first_name' => 'Dopey',
+ 'last_name' => 'Dwarf',
+ 'api.email.create' => array('email' => 'dopey@mail.com'))
+ );
+ $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com'));
+ $diffs = $this->callAPIAndDocument('Logging', 'get', array('log_conn_id' => 'wooty woot', 'log_date' => $timeStamp), __FUNCTION__, __FILE__);
+ $this->assertLoggingIncludes($diffs['values'], array('to' => 'Dwarf, Dopey'));
+ $this->assertLoggingIncludes($diffs['values'], array('to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name'));
+ $this->assertLoggingIncludes($diffs['values'], array('to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email'));
+ }
+
+ /**
+ * Assert the values in the $expect array in included in the logging diff.
+ *
+ * @param array $diffs
+ * @param array $expect
+ *
+ * @return bool
+ * @throws \CRM_Core_Exception
+ */
+ public function assertLoggingIncludes($diffs, $expect) {
+ foreach ($diffs as $diff) {
+ foreach ($expect as $expectKey => $expectValue) {
+ if ($diff[$expectKey] != $expectValue) {
+ continue;
+ }
+ return TRUE;
+ }
+ }
+ throw new CRM_Core_Exception("No match found for key : $expectKey with value : $expectValue");
+ }
+
}