{"action":"created","issue":{"url":"https://api.github.com/repos/civicrm/civicrm-core/issues/11517","repository_url":"https://api.github.com/repos/civicrm/civicrm-core","labels_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/11517/labels{/name}","comments_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/11517/comments","events_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/11517/events","html_url":"https://github.com/civicrm/civicrm-core/pull/11517","id":288438415,"number":11517,"title":"Call hook_civicrm_export when exporting custom searches.","user":{"login":"johanv","id":586145,"avatar_url":"https://avatars2.githubusercontent.com/u/586145?v=4","gravatar_id":"","url":"https://api.github.com/users/johanv","html_url":"https://github.com/johanv","followers_url":"https://api.github.com/users/johanv/followers","following_url":"https://api.github.com/users/johanv/following{/other_user}","gists_url":"https://api.github.com/users/johanv/gists{/gist_id}","starred_url":"https://api.github.com/users/johanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanv/subscriptions","organizations_url":"https://api.github.com/users/johanv/orgs","repos_url":"https://api.github.com/users/johanv/repos","events_url":"https://api.github.com/users/johanv/events{/privacy}","received_events_url":"https://api.github.com/users/johanv/received_events","type":"User","site_admin":false},"labels":[{"id":246037889,"url":"https://api.github.com/repos/civicrm/civicrm-core/labels/master","name":"master","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-01-14T20:48:51Z","updated_at":"2018-02-02T12:58:38Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/civicrm/civicrm-core/pulls/11517","html_url":"https://github.com/civicrm/civicrm-core/pull/11517","diff_url":"https://github.com/civicrm/civicrm-core/pull/11517.diff","patch_url":"https://github.com/civicrm/civicrm-core/pull/11517.patch"},"body":"Overview\r\n----------------------------------------\r\nCRM-21657: hook_civicrm_export is not called when exporting custom search results. Since CRM-8140 was fixed, the problem only shows if you export the custom search fields, not if you make a field selection yourself. \r\n\r\nBefore\r\n----------------------------------------\r\nE.g.:\r\n* Click 'search', 'custom searches'\r\n* Click 'basic search' (or any other custom search)\r\n* Click 'search'\r\n* Click 'Select records: All 203 records'\r\n* Click 'Actions', 'Export contacts'\r\n* (Click 'Export custom search fields', and 'Continue' if you are using CiviCRM 4.7.20 or later; this option is not available in earlier versions of CiviCRM.)\r\n* An export is created without calling hook_civicrm_export. \r\n\r\nAfter\r\n----------------------------------------\r\nE.g.:\r\n* Click 'search', 'custom searches'\r\n* Click 'basic search' (or any other custom search)\r\n* Click 'search'\r\n* Click 'Select records: All 203 records'\r\n* Click 'Actions', 'Export contacts'\r\n* (Click 'Export custom search fields', and 'Continue' if you are using CiviCRM 4.7.20 or later; this option is not available in earlier versions of CiviCRM.)\r\n* An export is created after calling hook_civicrm_export. \r\n\r\nTechnical Details\r\n----------------------------------------\r\nExports of 'ordinary' searches create a temporary table, and pass that table to hook_civicrm_export. Exports of custom searches create a CSV file based on in-memory data.\r\nSo I changed the latter so that it also creates a temporary table, and passes it to the hook implementations.\r\n\r\nComments\r\n----------------------------------------\r\nThe column definitions that are passed to the hook, are not correct. I say that all columns are varchar(255), which is obviously not true. This might cause troubles if specific hook implementations rely on this.\r\nBut I guess you look at the source code to see what I've exactly changed ;-)\n\n---\n\n * [CRM-21657: hook_civicrm_export is not called when exporting a custom search](https://issues.civicrm.org/jira/browse/CRM-21657)\n * [CRM-8140: Not possible to select fields for export when using Custom Searches](https://issues.civicrm.org/jira/browse/CRM-8140)"},"comment":{"url":"https://api.github.com/repos/civicrm/civicrm-core/issues/comments/362579536","html_url":"https://github.com/civicrm/civicrm-core/pull/11517#issuecomment-362579536","issue_url":"https://api.github.com/repos/civicrm/civicrm-core/issues/11517","id":362579536,"user":{"login":"johanv","id":586145,"avatar_url":"https://avatars2.githubusercontent.com/u/586145?v=4","gravatar_id":"","url":"https://api.github.com/users/johanv","html_url":"https://github.com/johanv","followers_url":"https://api.github.com/users/johanv/followers","following_url":"https://api.github.com/users/johanv/following{/other_user}","gists_url":"https://api.github.com/users/johanv/gists{/gist_id}","starred_url":"https://api.github.com/users/johanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanv/subscriptions","organizations_url":"https://api.github.com/users/johanv/orgs","repos_url":"https://api.github.com/users/johanv/repos","events_url":"https://api.github.com/users/johanv/events{/privacy}","received_events_url":"https://api.github.com/users/johanv/received_events","type":"User","site_admin":false},"created_at":"2018-02-02T12:58:38Z","updated_at":"2018-02-02T12:58:38Z","author_association":"CONTRIBUTOR","body":"I tried to add a test, but it fails. Because of 2 issues:\r\n\r\nI call [`CRM_Export_BAO_Export::exportCustom()`]([https://github.com/civicrm/civicrm-core/pull/11517/files#diff-2e1de3666cf0b15e640b507b1ab5941fL1200) from [my test](https://github.com/civicrm/civicrm-core/pull/11517/files#diff-4686601201fee8a8402a894c1b7df226R182). But `CRM_Export_BAO_Export::exportCustom()` ends up calling [`CRM_Core_ReportExcel::writeCSVFile()`](https://github.com/civicrm/civicrm-core/pull/11517/files#diff-2e1de3666cf0b15e640b507b1ab5941fR1918), which causes these error messages when running phpunit:\r\n```\r\n1) CRM_Export_BAO_ExportTest::testExportCustomShouldCallHook\r\nCannot modify header information - headers already sent by (output started at phar:///opt/buildkit/bin/ph\r\npunit4/phpunit/Util/Printer.php:134)                                                              \r\n                          \r\n/var/www/html/sites/all/modules/civicrm/CRM/Utils/System/Base.php:926                             \r\n/var/www/html/sites/all/modules/civicrm/CRM/Utils/System.php:74\r\n/var/www/html/sites/all/modules/civicrm/CRM/Utils/System.php:820\r\n/var/www/html/sites/all/modules/civicrm/CRM/Core/Report/Excel.php:215\r\n/var/www/html/sites/all/modules/civicrm/CRM/Export/BAO/Export.php:1923                                   \r\n/var/www/html/sites/all/modules/civicrm/CRM/Export/BAO/Export.php:1249\r\n/var/www/html/sites/all/modules/civicrm/tests/phpunit/CRM/Export/BAO/ExportTest.php:182\r\n/var/www/html/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php:184           \r\n/opt/buildkit/bin/phpunit4:545\r\n```\r\nEven if this problem could be fixed, there is still a call to [`CRM_Utils_System::civiExit()`](https://github.com/civicrm/civicrm-core/pull/11517/files#diff-2e1de3666cf0b15e640b507b1ab5941fR1288), which would cause phpunit to stop running tests.\r\n\r\nAny suggestions about how I can create a decent test for this issue?"}}
{"actor":{"display_login":"johanv"}}