Commit 89c6ab60 authored by jaapjansma's avatar jaapjansma

Fix for issue #31 now tested and it seems to be working

parent 83252648
......@@ -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);
}
......@@ -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);
}
/**
......@@ -98,10 +102,21 @@ class ACLContactSource extends ContactSource {
* @return void
*/
public function sourceLoadedFromCache() {
// reset the source. This completly looks up all the custom fields etc.. of this source
// ideally we only want to reset the aclWherePart.
$this->reset();
$this->initialize();
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 = [];
}
}
}
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