Commit 40cc6635 authored by jaapjansma's avatar jaapjansma

Merge remote-tracking branch 'origin/dev_31'

parents 299baaad 89c6ab60
......@@ -64,7 +64,7 @@ class CRM_Dataprocessor_BAO_DataProcessor extends CRM_Dataprocessor_DAO_DataProc
$cache = CRM_Dataprocessor_Utils_Cache::singleton();
if (!$force && $dataProcessorClass = $cache->get($cache_key)) {
// Reset the default filter values as they might have been changed.
$dataProcessorClass->setDefaultFilterValues();
$dataProcessorClass->loadedFromCache();
return $dataProcessorClass;
}
$factory = dataprocessor_get_factory();
......
......@@ -8,10 +8,10 @@ namespace Civi\DataProcessor\DataFlow\CombinedDataFlow;
use \Civi\DataProcessor\DataFlow\AbstractDataFlow;
use \Civi\DataProcessor\DataFlow\EndOfFlowException;
use Civi\DataProcessor\DataFlow\InvalidFlowException;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\JoinInterface;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\MultipleSourceDataFlows;
use Civi\DataProcessor\DataFlow\SqlDataFlow;
use \Civi\DataProcessor\DataSpecification\DataSpecification;
......@@ -66,6 +66,21 @@ class CombinedDataFlow extends AbstractDataFlow implements MultipleSourceDataFlo
$this->sourceDataFlowDescriptions[] = $dataFlowDescription;
}
/**
* Removes a source data flow
*
* @param \Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription $dataFlowDescription
* @return void
* @throws \Civi\DataProcessor\DataFlow\InvalidFlowException
*/
public function removeSourceDataFlow(DataFlowDescription $dataFlowDescription) {
foreach($this->sourceDataFlowDescriptions as $idx => $sourceDataFlowDescription) {
if ($sourceDataFlowDescription === $dataFlowDescription) {
unset($this->sourceDataFlowDescriptions[$idx]);
}
}
}
/**
* @param \Civi\DataProcessor\FieldOutputHandler\AbstractFieldOutputHandler $outputFieldHandler[]
*/
......
......@@ -60,6 +60,24 @@ class CombinedSqlDataFlow extends SqlDataFlow implements MultipleSourceDataFlows
$this->sourceDataFlowDescriptions[] = $dataFlowDescription;
}
/**
* Removes a source data flow
*
* @param \Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription $dataFlowDescription
* @return void
* @throws \Civi\DataProcessor\DataFlow\InvalidFlowException
*/
public function removeSourceDataFlow(DataFlowDescription $dataFlowDescription) {
if (!$dataFlowDescription->getDataFlow() instanceof SqlDataFlow) {
throw new InvalidFlowException();
}
foreach($this->sourceDataFlowDescriptions as $idx => $sourceDataFlowDescription) {
if ($sourceDataFlowDescription === $dataFlowDescription) {
unset($this->sourceDataFlowDescriptions[$idx]);
}
}
}
/**
* Returns the Table part in the from statement.
*
......
......@@ -46,6 +46,24 @@ class UnionQueryDataFlow extends SqlDataFlow implements MultipleSourceDataFlows
$this->sourceDataFlowDescriptions[] = $dataFlowDescription;
}
/**
* Removes a source data flow
*
* @param \Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription $dataFlowDescription
* @return void
* @throws \Civi\DataProcessor\DataFlow\InvalidFlowException
*/
public function removeSourceDataFlow(DataFlowDescription $dataFlowDescription) {
if (!$dataFlowDescription->getDataFlow() instanceof SqlDataFlow) {
throw new InvalidFlowException();
}
foreach($this->sourceDataFlowDescriptions as $idx => $sourceDataFlowDescription) {
if ($sourceDataFlowDescription === $dataFlowDescription) {
unset($this->sourceDataFlowDescriptions[$idx]);
}
}
}
public function getName() {
return $this->name;
}
......
......@@ -16,4 +16,12 @@ interface MultipleSourceDataFlows {
*/
public function addSourceDataFlow(DataFlowDescription $dataFlowDescription);
}
\ No newline at end of file
/**
* Removes a source data flow
*
* @param \Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription $dataFlowDescription
* @return void
*/
public function removeSourceDataFlow(DataFlowDescription $dataFlowDescription);
}
......@@ -181,11 +181,17 @@ abstract class AbstractProcessorType {
}
/**
* Sets the default filter values for all filters.
* Sets the default filter values for all filters and calls loadFromCache on a source.
*
* @throws \Exception
*/
public function setDefaultFilterValues() {
public function loadedFromCache() {
if ($this->dataSources && is_array($this->dataSources)) {
foreach ($this->dataSources as $dataSource) {
$dataSource['datasource']->sourceLoadedFromCache();
}
}
if ($this->filterHandlers && is_array($this->filterHandlers)) {
foreach ($this->filterHandlers as $filterHandler) {
$filterHandler->setDefaultFilterValues();
......
......@@ -302,4 +302,12 @@ abstract class AbstractSource implements SourceInterface {
return $configuration;
}
/**
* This function is called after a source is loaded from the cache.
* @return void
*/
public function sourceLoadedFromCache() {
}
}
......@@ -7,6 +7,7 @@
namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\MultipleSourceDataFlows;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\PureSqlStatementJoin;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
......@@ -21,8 +22,10 @@ class ACLContactSource extends ContactSource {
*/
protected $dataFlow;
public function initialize() {
protected $aclJoins = [];
protected $aclWhereClause = null;
public function initialize() {
$tables = array();
$whereTables = array();
$where = \CRM_ACL_API::whereClause(\CRM_ACL_API::VIEW, $tables, $whereTables, NULL, FALSE, TRUE, FALSE);
......@@ -48,12 +51,13 @@ class ACLContactSource extends ContactSource {
$joinCriteria = str_replace('contact_a', $this->primaryDataFlow->getName(), $joinCriteria);
$join = new PureSqlStatementJoin(' JOIN ' . $tableAndAlias . ' ON ' . $joinCriteria);
$this->additionalDataFlowDescriptions[$tableAndAlias] = new DataFlowDescription($aclTable, $join);
$this->aclJoins[] = $tableAndAlias;
}
protected function addAclWhere($where) {
$where = str_replace('contact_a', $this->primaryDataFlow->getName(), $where);
$clause = new PureSqlStatementClause($where);
$this->primaryDataFlow->addWhereClause($clause);
$this->aclWhereClause = new PureSqlStatementClause($where);
$this->primaryDataFlow->addWhereClause($this->aclWhereClause);
}
/**
......@@ -93,4 +97,26 @@ class ACLContactSource extends ContactSource {
}
}
/**
* This function is called after a source is loaded from the cache.
* @return void
*/
public function sourceLoadedFromCache() {
if ($this->primaryDataFlow && $this->aclWhereClause) {
$this->primaryDataFlow->removeWhereClause($this->aclWhereClause);
}
$this->aclWhereClause = null;
if (count($this->aclJoins)) {
foreach($this->aclJoins as $tableAndAlias) {
if (isset($this->additionalDataFlowDescriptions[$tableAndAlias])) {
if ($this->dataFlow && $this->dataFlow instanceof MultipleSourceDataFlows) {
$this->dataFlow->removeSourceDataFlow($this->additionalDataFlowDescriptions[$tableAndAlias]);
}
unset($this->additionalDataFlowDescriptions[$tableAndAlias]);
}
}
$this->aclJoins = [];
}
}
}
......@@ -139,4 +139,10 @@ interface SourceInterface {
*/
public function processConfiguration($submittedValues);
/**
* This function is called after a source is loaded from the cache.
* @return void
*/
public function sourceLoadedFromCache();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment