Merge pull request #15572 from civicrm/5.19
[civicrm-core.git] / api / v3 / examples / Job / Create.ex.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Job.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function job_create_example() {
cf8f0fff 9 $params = [
50fb255d 10 'sequential' => 1,
11 'name' => 'API_Test_Job',
12 'description' => 'A long description written by hand in cursive',
13 'run_frequency' => 'Daily',
14 'api_entity' => 'ApiTestEntity',
15 'api_action' => 'apitestaction',
16 'parameters' => 'Semi-formal explanation of runtime job parameters',
17 'is_active' => 1,
cf8f0fff 18 ];
6a488035 19
50fb255d 20 try{
a828d7b8 21 $result = civicrm_api3('Job', 'create', $params);
50fb255d 22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
cf8f0fff 28 return [
5be22f39 29 'is_error' => 1,
30 'error_message' => $errorMessage,
50fb255d 31 'error_code' => $errorCode,
32 'error_data' => $errorData,
cf8f0fff 33 ];
50fb255d 34 }
35
36 return $result;
6a488035
TO
37}
38
fb32de45 39/**
50fb255d 40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
6a488035 44 */
50fb255d 45function job_create_expectedresult() {
6a488035 46
cf8f0fff 47 $expectedResult = [
50fb255d 48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
1d8ee3d6 51 'id' => 30,
cf8f0fff
CW
52 'values' => [
53 '0' => [
1d8ee3d6 54 'id' => '30',
50fb255d 55 'domain_id' => '1',
56 'run_frequency' => 'Daily',
57 'last_run' => '',
1d8ee3d6 58 'scheduled_run_date' => '',
50fb255d 59 'name' => 'API_Test_Job',
60 'description' => 'A long description written by hand in cursive',
61 'api_entity' => 'ApiTestEntity',
62 'api_action' => 'apitestaction',
63 'parameters' => 'Semi-formal explanation of runtime job parameters',
64 'is_active' => '1',
cf8f0fff
CW
65 ],
66 ],
67 ];
6a488035 68
fb32de45 69 return $expectedResult;
6a488035
TO
70}
71
a828d7b8 72/*
50fb255d 73* This example has been generated from the API test suite.
a828d7b8
CW
74* The test that created it is called "testCreate"
75* and can be found at:
69d79249 76* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/JobTest.php
6a488035
TO
77*
78* You can see the outcome of the API tests at
8390b11b 79* https://test.civicrm.org/job/CiviCRM-Core-Matrix/
6a488035
TO
80*
81* To Learn about the API read
8390b11b 82* https://docs.civicrm.org/dev/en/latest/api/
6a488035 83*
8390b11b
SL
84* Browse the API on your own site with the API Explorer. It is in the main
85* CiviCRM menu, under: Support > Development > API Explorer.
6a488035
TO
86*
87* Read more about testing here
8390b11b 88* https://docs.civicrm.org/dev/en/latest/testing/
6a488035
TO
89*
90* API Standards documentation:
8390b11b 91* https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
49f8272d 92*/