forked from systopia/de.systopia.sqltasks
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev_14' of https://github.com/systopia/de.systopia.sqlt…
…asks into merge-calltask * 'dev_14' of https://github.com/systopia/de.systopia.sqltasks: implementing #14 (WIP) implementing #14 (WIP)
- Loading branch information
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
/*-------------------------------------------------------+ | ||
| SYSTOPIA SQL TASKS EXTENSION | | ||
| Copyright (C) 2018 SYSTOPIA | | ||
| Author: B. Endres (endres@systopia.de) | | ||
+--------------------------------------------------------+ | ||
| This program is released as free software under the | | ||
| Affero GPL license. You can redistribute it and/or | | ||
| modify it under the terms of this license which you | | ||
| can read by viewing the included agpl.txt or online | | ||
| at www.gnu.org/licenses/agpl.html. Removal of this | | ||
| copyright header is strictly prohibited without | | ||
| written permission from the original author(s). | | ||
+--------------------------------------------------------*/ | ||
|
||
use CRM_Sqltasks_ExtensionUtil as E; | ||
|
||
/** | ||
* This action will "simply" call another task | ||
* | ||
*/ | ||
class CRM_Sqltasks_Action_CallTask extends CRM_Sqltasks_Action { | ||
|
||
/** | ||
* Get identifier string | ||
*/ | ||
public function getID() { | ||
return 'task'; | ||
} | ||
|
||
/** | ||
* Get a human readable name | ||
*/ | ||
public function getName() { | ||
return E::ts('Run SQL Task(s)'); | ||
} | ||
|
||
/** | ||
* Build the configuration UI | ||
*/ | ||
public function buildForm(&$form) { | ||
parent::buildForm($form); | ||
|
||
$form->add( | ||
'select', | ||
$this->getID() . '_tasks', | ||
E::ts('SQL Tasks'), | ||
$this->getTaskList(), | ||
FALSE, | ||
array('class' => 'crm-select2 huge', 'multiple' => 'multiple') | ||
); | ||
|
||
$form->add( | ||
'select', | ||
$this->getID() . '_categories', | ||
E::ts('SQL Task Categories'), | ||
$this->getTaskCategoryList(), | ||
FALSE, | ||
array('class' => 'crm-select2 huge', 'multiple' => 'multiple') | ||
); | ||
} | ||
|
||
|
||
/** | ||
* RUN this action | ||
*/ | ||
public function execute() { | ||
$this->resetHasExecuted(); | ||
|
||
$tasks = $this->getConfigValue('tasks'); | ||
$categories = $this->getConfigValue('categories'); | ||
if (empty($tasks) && empty($categories)) { | ||
return; | ||
} | ||
|
||
// generate query for task selection | ||
$query = "SELECT * FROM `civicrm_sqltasks` WHERE enabled=1 AND "; | ||
$or_clauses = array(); | ||
if (!empty($tasks)) { | ||
$or_clauses[] = '`id` IN (' . implode(',', $tasks) . ')'; | ||
} | ||
if (!empty($categories)) { | ||
$escaped_categories = array(); | ||
foreach ($categories as $category) { | ||
$escaped_categories[] = "'" . mysql_escape_string($category) . "'"; | ||
} | ||
$or_clauses[] = '`category` IN (' . implode(',', $escaped_categories) . ')'; | ||
} | ||
$query .= '((' . implode(') OR (', $or_clauses). '))'; | ||
$query .= ' ORDER BY weight ASC'; | ||
$tasks2run = CRM_Sqltasks_Task::getTasks($query); | ||
|
||
foreach ($tasks2run as $task) { | ||
if ($task->getID() == $this->task->getID()) { | ||
continue; | ||
} | ||
// all good: execute! | ||
$task->execute(); | ||
$this->log("Executed task '" . $task->getAttribute('name') . "' [" . $task->getID() . ']'); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Get a list of all SQL Tasks | ||
*/ | ||
protected function getTaskList() { | ||
$task_options = array(); | ||
$task_list = CRM_Sqltasks_Task::getExecutionTaskList(); | ||
|
||
// make sure this one is not in it | ||
foreach ($task_list as $task) { | ||
$task_id = $task->getID(); | ||
if ($task_id != $this->task->getID()) { | ||
$task_options[$task_id] = "[{$task_id}] " . $task->getAttribute('name'); | ||
} | ||
} | ||
|
||
return $task_options; | ||
} | ||
|
||
/** | ||
* Get a list of all SQL Task categories | ||
*/ | ||
protected function getTaskCategoryList() { | ||
$category_options = array(); | ||
$category_query = CRM_Core_DAO::executeQuery("SELECT DISTINCT(category) AS category FROM `civicrm_sqltasks`;"); | ||
while ($category_query->fetch()) { | ||
$category_options[$category_query->category] = $category_query->category; | ||
} | ||
return $category_options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{*-------------------------------------------------------+ | ||
| SYSTOPIA SQL TASKS EXTENSION | | ||
| Copyright (C) 2018 SYSTOPIA | | ||
| Author: B. Endres (endres@systopia.de) | | ||
+--------------------------------------------------------+ | ||
| This program is released as free software under the | | ||
| Affero GPL license. You can redistribute it and/or | | ||
| modify it under the terms of this license which you | | ||
| can read by viewing the included agpl.txt or online | | ||
| at www.gnu.org/licenses/agpl.html. Removal of this | | ||
| copyright header is strictly prohibited without | | ||
| written permission from the original author(s). | | ||
+-------------------------------------------------------*} | ||
|
||
{htxt id='id-task-tasks'} | ||
<p>{ts domain="de.systopia.sqltasks"}You can select any tasks (except this one) to be run as an action of this task.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}Only enabled tasks will be run, in the order defined by the task manager, <i>not</i> this list.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}The tasks selected here will be run <i>together</i> with the ones selected by category below.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}<strong>Be <id>very</id> careful with this! You can easily create circular execution patterns that <i>will</i> break the system.</strong>{/ts}</p> | ||
{/htxt} | ||
|
||
{htxt id='id-task-categories'} | ||
<p>{ts domain="de.systopia.sqltasks"}You can select any number of task categories to be run as an action of this task.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}Only enabled tasks of the selected categories will be run, in the order defined by the task manager, <i>not</i> this list.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}The tasks selected here will be run <i>together</i> with the ones selected individually above.{/ts}</p> | ||
<p>{ts domain="de.systopia.sqltasks"}<strong>Be <id>very</id> careful with this! You can easily create circular execution patterns that <i>will</i> break the system.</strong>{/ts}</p> | ||
{/htxt} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{*-------------------------------------------------------+ | ||
| SYSTOPIA SQL TASKS EXTENSION | | ||
| Copyright (C) 2018 SYSTOPIA | | ||
| Author: B. Endres (endres@systopia.de) | | ||
+--------------------------------------------------------+ | ||
| This program is released as free software under the | | ||
| Affero GPL license. You can redistribute it and/or | | ||
| modify it under the terms of this license which you | | ||
| can read by viewing the included agpl.txt or online | | ||
| at www.gnu.org/licenses/agpl.html. Removal of this | | ||
| copyright header is strictly prohibited without | | ||
| written permission from the original author(s). | | ||
+-------------------------------------------------------*} | ||
|
||
<div class="sql-tasks"> | ||
<div class="crm-section"> | ||
<div class="label">{$form.task_tasks.label} <a onclick='CRM.help("{ts domain="de.systopia.sqltasks"}Tasks{/ts}", {literal}{"id":"id-task-tasks","file":"CRM\/Sqltasks\/Action\/CallTask"}{/literal}); return false;' href="#" title="{ts domain="de.systopia.sqltasks"}Help{/ts}" class="helpicon"> </a></div> | ||
<div class="content">{$form.task_tasks.html}</div> | ||
<div class="clear"></div> | ||
</div> | ||
<div class="crm-section"> | ||
<div class="label">{$form.task_categories.label} <a onclick='CRM.help("{ts domain="de.systopia.sqltasks"}Categories{/ts}", {literal}{"id":"id-task-categories","file":"CRM\/Sqltasks\/Action\/CallTask"}{/literal}); return false;' href="#" title="{ts domain="de.systopia.sqltasks"}Help{/ts}" class="helpicon"> </a></div> | ||
<div class="content">{$form.task_categories.html}</div> | ||
<div class="clear"></div> | ||
</div> | ||
</div> |