From 12ccb846e82815c4a40b400fc5a86ee1fb033aee Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Mon, 31 Mar 2025 09:58:34 +0100 Subject: [PATCH] Add Scheduled Job --- api/v3/Job/Contactcatsync.mgd.php | 21 ++++++++ api/v3/Job/Contactcatsync.php | 36 +++++++++++++ .../phpunit/api/v3/Job/ContactcatsyncTest.php | 54 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 api/v3/Job/Contactcatsync.mgd.php create mode 100644 api/v3/Job/Contactcatsync.php create mode 100644 tests/phpunit/api/v3/Job/ContactcatsyncTest.php diff --git a/api/v3/Job/Contactcatsync.mgd.php b/api/v3/Job/Contactcatsync.mgd.php new file mode 100644 index 0000000..3134dc2 --- /dev/null +++ b/api/v3/Job/Contactcatsync.mgd.php @@ -0,0 +1,21 @@ + 'Cron:Job.Contactcatsync', + 'entity' => 'Job', + 'params' => [ + 'version' => 3, + 'name' => 'Contact Category sync', + 'description' => 'Keeps contacts’s categories updated daily, recording change activities to track over time. Should be run hourly but will only actually work around 3am.', + 'run_frequency' => 'Hourly', + 'api_entity' => 'Job', + 'api_action' => 'Contactcatsync', + 'parameters' => '', + ], + ], +]; diff --git a/api/v3/Job/Contactcatsync.php b/api/v3/Job/Contactcatsync.php new file mode 100644 index 0000000..e8f71c2 --- /dev/null +++ b/api/v3/Job/Contactcatsync.php @@ -0,0 +1,36 @@ +execute()->getArrayCopy(); + + return civicrm_api3_create_success($returnValues, $params, 'Job', 'Contactcatsync'); +} diff --git a/tests/phpunit/api/v3/Job/ContactcatsyncTest.php b/tests/phpunit/api/v3/Job/ContactcatsyncTest.php new file mode 100644 index 0000000..2432e9a --- /dev/null +++ b/tests/phpunit/api/v3/Job/ContactcatsyncTest.php @@ -0,0 +1,54 @@ +installMe(__DIR__) + ->apply(); + } + + /** + * The setup() method is executed before the test is executed (optional). + */ + public function setUp(): void { + parent::setUp(); + } + + /** + * The tearDown() method is executed after the test was executed (optional) + * This can be used for cleanup. + */ + public function tearDown(): void { + parent::tearDown(); + } + + /** + * Simple example test case. + * + * Note how the function name begins with the word "test". + */ + public function testApiExample() { + $result = civicrm_api3('Job', 'contactcatsync', array('magicword' => 'sesame')); + $this->assertEquals('Twelve', $result['values'][12]['name']); + } + +}