public static function remove($typeName, $values, $updateTables = false)
    {
        $values = (array) $values;

        $db = static::getDb();
        $transaction = $db->beginTransaction();
        try {
            $allValues = static::values($typeName);
            $removedValues = [];

            $isAssociative = ArrayHelper::isAssociative($values, false);
            if ($isAssociative) {
                $caseQuery = '';
                $placeholders = [];
                $phIndex = 0;
                foreach ($values as $k => $v) {
                    $ph1 = 'case' . $phIndex++;
                    $ph2 = 'case' . $phIndex++;
                    if (is_int($k)) {
                        $removedValues[] = $v;
                    } else {
                        $removedValues[] = $k;
                        $placeholders[$ph1] = $k;
                        $placeholders[$ph2] = $v;
                        if (!in_array($v, $allValues)) {
                            static::add($typeName, $v);
                            $allValues[] = $v;
                        }
                        $caseQuery .= ' WHEN :' . $ph1 . ' THEN :' . $ph2;
                    }
                }

                $caseQuery .= ' ELSE NULL END::' . $db->quoteColumnName($typeName);
            } else {
                $removedValues = $values;
            }

            if ($updateTables) {
                $columns = static::columns($typeName);
                foreach ($columns as $column) {
                    $columnName = $column['column_name'];
                    $value = $isAssociative
                        ? new Expression('CASE ' . $db->quoteColumnName($columnName) . $caseQuery, $placeholders)
                        : null;
                    $db->createCommand()
                        ->update($column['table_name'], [$columnName => $value], [$columnName => $removedValues])
                        ->execute();
                }
            }

            static::recreate($typeName, array_diff($allValues, $removedValues));

            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();
            throw $e;
        }
    }
public static function remove($typeName, $values, $updateTables = false)
    {
        $values = (array) $values;

        $db = static::getDb();
        $transaction = $db->beginTransaction();
        try {
            $allValues = static::values($typeName);
            $removedValues = [];

            $isAssociative = ArrayHelper::isAssociative($values, false);
            if ($isAssociative) {
                $caseQuery = '';
                $placeholders = [];
                $phIndex = 0;
                foreach ($values as $k => $v) {
                    $ph1 = 'case' . $phIndex++;
                    $ph2 = 'case' . $phIndex++;
                    if (is_int($k)) {
                        $removedValues[] = $v;
                    } else {
                        $removedValues[] = $k;
                        $placeholders[$ph1] = $k;
                        $placeholders[$ph2] = $v;
                        if (!in_array($v, $allValues)) {
                            static::add($typeName, $v);
                            $allValues[] = $v;
                        }
                        $caseQuery .= ' WHEN :' . $ph1 . ' THEN :' . $ph2;
                    }
                }

                $caseQuery .= ' ELSE NULL END::' . $db->quoteColumnName($typeName);
            } else {
                $removedValues = $values;
            }

            if ($updateTables) {
                $columns = static::columns($typeName);
                foreach ($columns as $column) {
                    $columnName = $column['column_name'];
                    $value = $isAssociative
                        ? new Expression('CASE ' . $db->quoteColumnName($columnName) . $caseQuery, $placeholders)
                        : null;
                    $db->createCommand()
                        ->update($column['table_name'], [$columnName => $value], [$columnName => $removedValues])
                        ->execute();
                }
            }

            static::recreate($typeName, array_diff($allValues, $removedValues));

            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();
            throw $e;
        }
    }
public static function remove ( $ typeName , $ values , $ updateTables = false ) { $ values = ( array ) $ values ; $ db = static :: getDb ( ) ; $ transaction = $ db -> beginTransaction ( ) ; try { $ allValues = static :: values ( $ typeName ) ; $ removedValues = [ ] ; $ isAssociative = ArrayHelper :: isAssociative ( $ values , false ) ; if ( $ isAssociative ) { $ caseQuery = '' ; $ placeholders = [ ] ; $ phIndex = 0 ; foreach ( $ values as $ k => $ v ) { $ ph1 = 'case' . $ phIndex ++ ; $ ph2 = 'case' . $ phIndex ++ ; if ( is_int ( $ k ) ) { $ removedValues [ ] = $ v ; } else { $ removedValues [ ] = $ k ; $ placeholders [ $ ph1 ] = $ k ; $ placeholders [ $ ph2 ] = $ v ; if ( ! in_array ( $ v , $ allValues ) ) { static :: add ( $ typeName , $ v ) ; $ allValues [ ] = $ v ; } $ caseQuery .= ' WHEN :' . $ ph1 . ' THEN :' . $ ph2 ; } } $ caseQuery .= ' ELSE NULL END::' . $ db -> quoteColumnName ( $ typeName ) ; } else { $ removedValues = $ values ; } if ( $ updateTables ) { $ columns = static :: columns ( $ typeName ) ; foreach ( $ columns as $ column ) { $ columnName = $ column [ 'column_name' ] ; $ value = $ isAssociative ? new Expression ( 'CASE ' . $ db -> quoteColumnName ( $ columnName ) . $ caseQuery , $ placeholders ) : null ; $ db -> createCommand ( ) -> update ( $ column [ 'table_name' ] , [ $ columnName => $ value ] , [ $ columnName => $ removedValues ] ) -> execute ( ) ; } } static :: recreate ( $ typeName , array_diff ( $ allValues , $ removedValues ) ) ; $ transaction -> commit ( ) ; } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } }
Remove values from an enum type

@param string $typeName name of the enum type
@param string|array $values values for removing
It is a value (e.g. 'value1') or list of values (e.g. ['value1', 'value2']) to be removed,
the removed values will be replaced with null values.
Or a list of key => value pairs if you need to replace the removing values with new values
where keys are the removing values and values are the new values
e.g. ['removing value 1' => 'new value 1', 'removing value 2' => 'new value 2']
In this case the removing values will be changed to the new values.
@param bool $updateTables indicates if required to replace the enum values in all tables with the enum type
before removing.
@throws \Exception
Remove values from an enum type