Example #1
0
 /**
  * @inheritdoc
  */
 protected function safeRun()
 {
     parent::safeRun();
     $this->fillModels($this->_phpExcel->getActiveSheet()->getRowIterator());
     foreach ($this->_models as $model) {
         $model->load();
         $model->validate();
     }
     Yii::$app->db->transaction(function () {
         foreach ($this->_models as $model) {
             $model->save(false);
         }
     });
     $this->trigger(self::EVENT_RUN);
 }
Example #2
0
 /**
  * @inheritdoc
  */
 protected function safeRun()
 {
     parent::safeRun();
     $sheetNames = $this->sheetNames === '*' ? $this->_phpExcel->getSheetNames() : (array) $this->sheetNames;
     foreach ($sheetNames as $sheetName) {
         $sheet = $this->_phpExcel->getSheetByName($sheetName);
         $this->fillModels($sheet->getRowIterator());
     }
     Yii::$app->db->transaction(function () {
         foreach ($this->_models as $model) {
             $model->load();
             $model->save();
         }
     });
     $this->trigger(self::EVENT_RUN);
 }