Skip to content

Commit

Permalink
Merge pull request #89 from ixiam/dev#ExportAllConfigs
Browse files Browse the repository at this point in the history
New Feature: Export all configs in zip file
  • Loading branch information
bjendres committed Jun 11, 2021
2 parents 5b2ef43 + 26c3f41 commit e97ade2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
36 changes: 36 additions & 0 deletions CRM/Sqltasks/Page/Manager.php
Expand Up @@ -25,6 +25,7 @@ public function run() {
CRM_Utils_System::setTitle(E::ts('SQL Task Manager'));

// first: process commands (if any)
$this->processExportAllCommand();
$this->processExportCommand();
$this->processDeleteCommand();
$this->processEnableDisableCommand();
Expand Down Expand Up @@ -124,6 +125,41 @@ protected function renderRuntime($value) {
}
}

/**
* export all tasks in zip file
*/
protected function processExportAllCommand() {
$exportall = CRM_Utils_Request::retrieve('exportall', 'Integer');
if ($exportall) {
$tasks = CRM_Sqltasks_Task::getAllTasks();
if (!empty($tasks)) {
$zip = new ZipArchive();
$fileURL = CRM_Core_Config::singleton()->uploadDir . "sqltasks_" . time() . ".zip";
if ($zip->open($fileURL, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE) {
foreach ($tasks as $task) {
$taskFileName = preg_replace('/[^A-Za-z0-9_\- ]/', '', $task->getAttribute('name')) . '.sqltask';
$zip->addFromString($taskFileName, $task->exportConfiguration());
}
$zip->close();
CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($fileURL)));
CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($fileURL));
ob_clean();
flush();
readfile($fileURL);
unlink($fileURL);
CRM_Utils_System::civiExit();
}
else {
CRM_Core_Session::setStatus(E::ts('Cannot create ZIP file'), E::ts('Error'), 'error');
}
}
else {
CRM_Core_Session::setStatus(E::ts('There are no Tasks to be exported'), E::ts('Error'), 'error');
}
}
}

/**
* export a file
*/
Expand Down
6 changes: 4 additions & 2 deletions templates/CRM/Sqltasks/Page/Manager.tpl
Expand Up @@ -59,7 +59,9 @@
{capture assign=add_url}{crmURL p="civicrm/sqltasks/configure" q="reset=1&tid=0"}{/capture}
{capture assign=repo_url}https://github.com/systopia/de.systopia.sqltasks/blob/master/tasks/readme.md{/capture}
{capture assign=import_url}{crmURL p="civicrm/sqltasks/import" q="reset=1&tid=0"}{/capture}
{ts 1=$add_url 2=$repo_url 3=$import_url}You might want to <a href="%1">ADD A NEW ONE</a>. You can also <a href="%3">IMPORT</a> an existing one from our <a href="%2" target="_blank">REPOSITORY</a> for examples to get you started.{/ts}</a>
{capture assign=export_all_url}{crmURL p="civicrm/sqltasks/manage" q="exportall=1&reset=1"}{/capture}
{ts 1=$add_url 2=$repo_url 3=$import_url}You might want to <a href="%1">ADD A NEW ONE</a>. You can also <a href="%3">IMPORT</a> an existing one from our <a href="%2" target="_blank">REPOSITORY</a> for examples to get you started.{/ts}</a><br/>
{ts 1=$export_all_url}You can <a href="%1">EXPORT ALL</a> tasks configurations files for backup.{/ts}
</div>
<br/>
Expand Down Expand Up @@ -167,4 +169,4 @@ CRM.$('.sqltasks-job-run').click(function(e) {
});
});
{/literal}
</script>
</script>

0 comments on commit e97ade2

Please sign in to comment.