src/commands/TagController.php
public function actionFixTableNames()
    {
        $batch = TagRelation::find()->batch();
        $i = 0;
        $fixed = 0;
        $errors = 0;
        foreach ($batch as $rows) {
            foreach ($rows as $relation) {
                $i++;
                $tableName = TaggableTrait::cleanBaseTableName($relation->table_name);
                if ($relation->table_name !== $tableName) {

                    // if the new name exists already as combination, we can just delete the old one.
                    /*
                    // maybe use configuration option to delete entries by default.
                    if (TagRelation::find()->where(['table_name' => $tableName, 'pk_id' => $relation->pk_id, 'tag_id' => $relation->tag_id])->exists()) {
                        $relation->delete();
                        $fixed++;
                        continue;
                    }
                    */

                    $relation->table_name = $tableName;
                    if ($relation->save()) {
                        $fixed++;
                    } else {
                        $errors++;
                    }
                }

                unset($tableName, $relation);
            }
        }

        return $this->outputSuccess("{$i} items checked and {$fixed} items fixed with {$errors} errors.");
    }
public function actionFixTableNames()
    {
        $batch = TagRelation::find()->batch();
        $i = 0;
        $fixed = 0;
        $errors = 0;
        foreach ($batch as $rows) {
            foreach ($rows as $relation) {
                $i++;
                $tableName = TaggableTrait::cleanBaseTableName($relation->table_name);
                if ($relation->table_name !== $tableName) {

                    // if the new name exists already as combination, we can just delete the old one.
                    /*
                    // maybe use configuration option to delete entries by default.
                    if (TagRelation::find()->where(['table_name' => $tableName, 'pk_id' => $relation->pk_id, 'tag_id' => $relation->tag_id])->exists()) {
                        $relation->delete();
                        $fixed++;
                        continue;
                    }
                    */

                    $relation->table_name = $tableName;
                    if ($relation->save()) {
                        $fixed++;
                    } else {
                        $errors++;
                    }
                }

                unset($tableName, $relation);
            }
        }

        return $this->outputSuccess("{$i} items checked and {$fixed} items fixed with {$errors} errors.");
    }
public function actionFixTableNames ( ) { $ batch = TagRelation :: find ( ) -> batch ( ) ; $ i = 0 ; $ fixed = 0 ; $ errors = 0 ; foreach ( $ batch as $ rows ) { foreach ( $ rows as $ relation ) { $ i ++ ; $ tableName = TaggableTrait :: cleanBaseTableName ( $ relation -> table_name ) ; if ( $ relation -> table_name !== $ tableName ) { // if the new name exists already as combination, we can just delete the old one. /*
                    // maybe use configuration option to delete entries by default.
                    if (TagRelation::find()->where(['table_name' => $tableName, 'pk_id' => $relation->pk_id, 'tag_id' => $relation->tag_id])->exists()) {
                        $relation->delete();
                        $fixed++;
                        continue;
                    }
                    */ $ relation -> table_name = $ tableName ; if ( $ relation -> save ( ) ) { $ fixed ++ ; } else { $ errors ++ ; } } unset ( $ tableName , $ relation ) ; } } return $ this -> outputSuccess ( "{$i} items checked and {$fixed} items fixed with {$errors} errors." ) ; }
Handle wrong declared table names and try to cleanup not existing relations.

@return integer
Handle wrong declared table names and try to cleanup not existing relations .