/** * This test was needed because of the wierd type casting issues with 0 and 1 and '1' and '0' as keys in an array. * '0' and '1' turn into integers which they shouldn't and this messes up the oneOf sql query builder. Additionally * on some versions of MySQL, 0,1 in a NOT IN, will evaluate true to 'abc' which it shouldn't. As a result * the 0/1 boolean values have been removed from the BooleanSanitizerUtil::getAcceptableValues(). */ public function testBooleanAcceptableValuesMappingAndSqlOneOfString() { $string = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', BooleanSanitizerUtil::getAcceptableValues()); $compareString = "IN('false','true','y','n','yes','no','0','1','')"; // Not Coding Standard $this->assertEquals($compareString, $string); }
/** * @see DataAnalyzerInterface::runAndMakeMessages() */ public function runAndMakeMessages(AnalyzerSupportedDataProvider $dataProvider, $columnName) { $acceptableValues = BooleanSanitizerUtil::getAcceptableValues(); $inPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', $acceptableValues); $where = DatabaseCompatibilityUtil::lower($columnName) . ' NOT ' . $inPart; $count = $dataProvider->getCountByWhere($where); if ($count > 0) { $label = '{count} value(s) have invalid check box values. '; $label .= 'These values will be set to false upon import.'; $this->addMessage(Zurmo::t('ImportModule', $label, array('{count}' => $count))); } }
public static function userAddedToRole(User $user) { assert('$user->role->id > 0'); foreach (self::getMungableModelClassNames() as $modelClassName) { $mungeTableName = self::getMungeTableName($modelClassName); $userId = $user->id; $sql = "select securableitem_id\n from ownedsecurableitem\n where owner__user_id = {$userId}"; $securableItemIds = R::getCol($sql); //Increment the parent roles for securableItems that the user is the owner on. self::bulkIncrementParentRolesCounts($mungeTableName, $securableItemIds, $user->role); //Get all downstream groups the user is in including any groups that are in those groups recursively. //Then for each group found, add weight for the user's upstream roles. $groupMungeIds = array(); foreach ($user->groups as $group) { $groupMungeIds[] = 'G' . $group->id; self::getAllUpstreamGroupsRecursively($group, $groupMungeIds); } if (count($groupMungeIds) > 0) { $inSqlPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', $groupMungeIds, true); $sql = "select distinct {$mungeTableName}.securableitem_id\n from {$mungeTableName}\n where {$mungeTableName}.munge_id {$inSqlPart}"; $securableItemIds = R::getCol($sql); self::bulkIncrementParentRolesCounts($mungeTableName, $securableItemIds, $user->role); } } }
public function testResolveOperatorAndValueForOneOfWithEscapedContent() { $queryPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', array('a', "b'd", 'c')); $compareQueryPart = "IN('a','b\\'d','c')"; // Not Coding Standard $this->assertEquals($compareQueryPart, $queryPart); }
/** * Given an operator type and value, SQL is constructed. Example * return would be '>= 5'. * @return string */ public static function getOperatorAndValueWherePart($operatorType, $value) { assert('is_string($operatorType)'); if (!SQLOperatorUtil::isValidOperatorTypeByValue($operatorType, $value)) { throw new NotSupportedException('value: ' . $value . ' operator type: ' . $operatorType); } if (is_string($value)) { return self::resolveToLowerForStringComparison($operatorType, self::escape($value)); } elseif (is_array($value) && count($value) > 0) { return SQLOperatorUtil::resolveOperatorAndValueForOneOf($operatorType, $value); } elseif ($value !== null) { return SQLOperatorUtil::getOperatorByType($operatorType) . " " . self::escape($value); } elseif ($value === null) { return SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty($operatorType); } }