Skip to content

Commit

Permalink
Fix import of legacy tasks ("VERSION 0.9" format)
Browse files Browse the repository at this point in the history
This fixes an issue where tasks using the "##### SQLTASK VERSION 0.9 ###########"
format are only partially imported.

Fixes #108
  • Loading branch information
pfigel committed Mar 23, 2023
1 parent 08df9ac commit 2e71f83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 2 additions & 3 deletions CRM/Sqltasks/Config/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ public static function extractConfigFromLegacyFormat($config) {
$main_sql = substr($config, ($start_main + $len_main), ($start_post - $start_main - $len_main));
$post_sql = substr($config, ($start_post + $len_post));

return [
'config' => json_decode($data, TRUE),
return array_merge(json_decode($data, TRUE), [
'main_sql' => $main_sql,
'post_sql' => $post_sql,
];
]);
}

}
19 changes: 15 additions & 4 deletions tests/phpunit/CRM/Sqltasks/Config/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CRM_Sqltasks_Config_FormatTest extends CRM_Sqltasks_AbstractTaskTest {
"entity_table": "civicrm_contact",
"enabled": "1",
"contact_table": "temp_foo",
"tag_id": "13"
"tag_id": "123"
}
],
"scheduled_hour": "0",
Expand Down Expand Up @@ -138,11 +138,11 @@ public function testV2AppendedToLatest() {
}

/**
* Test that the entity_table field is added in SyncTag actions
* Test that task actions are added
*
* @throws \Exception
*/
public function testEntityTableIsAdded() {
public function testTaskActionsAreAdded() {
$samplesToTest = [
json_decode(self::SAMPLE_V1, TRUE),
self::SAMPLE_V1,
Expand All @@ -153,13 +153,24 @@ public function testEntityTableIsAdded() {
$config = CRM_Sqltasks_Config_Format::toLatest(
$sample
)['config'];
$entity_table = NULL;
$entity_table = $tag_id = $contact_table = $enabled = NULL;
foreach ($config['actions'] as $action) {
if ($action['type'] == 'CRM_Sqltasks_Action_SyncTag') {
$entity_table = $action['entity_table'];
$tag_id = $action['tag_id'];
$contact_table = $action['contact_table'];
$enabled = $action['enabled'];
}
if ($action['type'] == 'CRM_Sqltasks_Action_RunSQL') {
$script = $action['script'];
}
}
$this->assertEquals('civicrm_contact', $entity_table);
$this->assertEquals('123', $tag_id);
$this->assertEquals('temp_foo', $contact_table);
$this->assertEquals('1', $enabled);
$this->assertEquals('sample main script', $script);

}
}

Expand Down

0 comments on commit 2e71f83

Please sign in to comment.