Exemplo n.º 1
0
 public function action_index()
 {
     $model = new $this->model();
     $this->setMaxId($model);
     $spreadsheet = \Spreadsheet::factory(array('filename' => 'Excel/base.xlsx'), FALSE)->load();
     $spreadsheet->set_active_worksheet($this->sheetnumber);
     $return = $spreadsheet->read();
     // Переносим таблицу порциями
     $count = count($return);
     $connection = $model->getDbConnection();
     $transaction = $connection->beginTransaction();
     try {
         for ($offset = $this->ignored; $offset < $count; $offset = $offset + $this->per_limit) {
             if ($offset >= $this->limit) {
                 break;
             }
             // Порция
             $spreed = array_slice($return, $offset, $this->per_limit);
             // Заносим во все таблицы
             foreach ($this->table_to as $handler => $table) {
                 // Show SQL Logger
                 if ($table == $this->show_table) {
                     var_dump($this->source_tables[$table]);
                     echo "<hr><strong>Table::</strong> " . $table . "<hr>";
                 }
                 // Получаем SQL запрос
                 $insert = $this->{$handler}($table, $spreed);
                 // Выполнение запроса
                 if (!$this->testMode) {
                     $this->commandSQL($insert, $connection);
                 }
             }
             // Next Max Element
             $this->setMaxId($model);
             //$this->maxId += $this->per_limit;
         }
         $transaction->commit();
     } catch (Exception $e) {
         echo "Transaction Error!<br>";
         $transaction->rollback();
     }
     return;
 }