/** * Check if picklist modification caused some issues with workflow triggers and if yes notify users * @return array * @throws NotSupportedException */ public static function getWorkflowsWithInvalidTriggerCustomFieldValue() { $savedWorkflows = SavedWorkflow::getAll(); $workflows = array(); foreach ($savedWorkflows as $savedWorkflow) { $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow); $hasInvalidCustomFieldValue = false; foreach ($workflow->getTriggers() as $trigger) { $modelClassName = $trigger->getModelClassName(); $customFieldAttributeNames = CustomFieldUtil::getCustomFieldAttributeNames($modelClassName); $triggerAttributeName = $trigger->getAttribute(); if (in_array($triggerAttributeName, $customFieldAttributeNames)) { $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $triggerAttributeName); $allCustomFieldValues = unserialize($customFieldData->serializedData); // Check with triggers that allow single value if (in_array($trigger->getOperator(), array(OperatorRules::TYPE_EQUALS, OperatorRules::TYPE_DOES_NOT_EQUAL, OperatorRules::TYPE_BECOMES, OperatorRules::TYPE_WAS))) { if (!in_array($trigger->value, $allCustomFieldValues)) { $hasInvalidCustomFieldValue = true; break; } } elseif (in_array($trigger->getOperator(), array(OperatorRules::TYPE_BECOMES_ONE_OF, OperatorRules::TYPE_WAS_ONE_OF, OperatorRules::TYPE_ONE_OF))) { $triggerSelectedCustomFieldValues = MultiSelectDropDownSanitizerUtil::getCustomFieldValuesFromValueString($trigger->value); foreach ($triggerSelectedCustomFieldValues as $triggerValue) { if (!in_array($triggerValue, $allCustomFieldValues)) { $hasInvalidCustomFieldValue = true; break 2; } } } } } if ($hasInvalidCustomFieldValue) { $workflows[] = $workflow; } } return $workflows; }
public function testGetCustomFieldAttributeNames() { $model = new TestCustomFieldsModel(); $customFieldAttributeNames = CustomFieldUtil::getCustomFieldAttributeNames($model); $this->assertEquals(array('industry'), $customFieldAttributeNames); }
/** * Public for testing only. */ public function getCustomFieldAttributesNotUsedInOtherDependencyAttributes() { $modelClassName = $this->modelClassName; $attributeNames = CustomFieldUtil::getCustomFieldAttributeNames($modelClassName); $dropDownDependencyModels = DropDownDependencyDerivedAttributeMetadata::getAllByModelClassName($this->modelClassName); foreach ($dropDownDependencyModels as $dropDownDependency) { if ($dropDownDependency->name != $this->attributeName) { $usedAttributeNames = $dropDownDependency->getUsedAttributeNames(); foreach ($usedAttributeNames as $usedAttributeName) { if (in_array($usedAttributeName, $attributeNames)) { $key = array_search($usedAttributeName, $attributeNames); unset($attributeNames[$key]); } } } } $attributeNamesAndLabels = array(); foreach ($attributeNames as $attributeName) { $attributeNamesAndLabels[$attributeName] = $modelClassName::getAnAttributeLabel($attributeName); } return $attributeNamesAndLabels; }
public function testGetCustomFieldAttributeNames() { $customFieldAttributeNames = CustomFieldUtil::getCustomFieldAttributeNames('TestCustomFieldsModel'); $this->assertEquals(array('industry', 'market'), $customFieldAttributeNames); }