/** * Save a list of models, each model may be inserted or updated depend on its existence. * This method could be used to achieve better performance during insertion/update of the large * amount of data to the database table. * @param \yii\db\ActiveRecord[] $models list of models to be saved. * If a key is not a valid column name, the corresponding value will be ignored. * @param array $attributeNames name list of attributes that need to be update. Defaults to empty, * meaning all fields of corresponding active record will be saved. * This parameter is ignored in the case of insertion * @param int $mode the save mode flag. * If this flag value is set to 0, any model that have a PK value is NULL will be inserted, otherwise it will be update. * If this flag value is set to 1, all models will be inserted regardless to PK values. * If this flag value is set to 2, all models will be updated regardless to PK values * @return \stdClass An instance of stdClass that may have one of the following fields: * - The 'lastId' field is the last model ID (auto-incremental primary key) inserted. * - The 'insertCount' is the number of rows inserted. * - The 'updateCount' is the number of rows updated. */ public static function batchSave($models, $attributeNames = [], $mode = DbHelper::SAVE_MODE_AUTO) { $returnModels = []; $a = DbHelper::batchSave($models, $attributeNames, $mode, $returnModels); if (isset($a)) { $insertModels = isset($returnModels['inserted']) ? $returnModels['inserted'] : null; $updateModels = isset($returnModels['updated']) ? $returnModels['updated'] : null; static::afterBatchSave($attributeNames, $mode, $insertModels, $updateModels); } return $a; }