function write(phpMorphy_Dict_Source_Interface $source) { $source = phpMorphy_Dict_Source_Normalized_Ancodes::wrap($source); $context = $this->createContext(); $tables = $this->getTablesToProcess(); $old_time_limit = ini_get('max_execution_time'); set_time_limit(0); $b = microtime(true); $restore_keys_stmt = new phpMorphy_Dict_Writer_Sql_StatementsBundle($this->engine); $e = null; try { $old_state = $this->engine->initState(); try { // drop keys foreach ($tables as $table_name) { $restore_keys_stmt->prepend($this->engine->dropKeys($table_name)); } $this->engine->begin(); // protect transaction try { $context->setDictId($this->createNewDict($source)); foreach ($tables as $table) { $this->loadSection($table, $source, $context); } $this->engine->commit(); } catch (Exception $e) { $this->engine->rollback(); throw $e; } } catch (Exception $e) { } // restore keys if (!$restore_keys_stmt->safeExecute()) { $message = "An error occured while restore keys: " . implode(', ', $restore_keys_stmt->getLastErrors()); if (isset($e)) { $message .= ' (prev. error = ' . $e->getMessage(); } throw new phpMorphy_Dict_Writer_Sql_Exception($message); } $this->engine->restoreState($old_state); if (isset($e)) { throw $e; } } catch (Exception $e) { } set_time_limit($old_time_limit); $this->log(sprintf("Total time taken = %0.2f", microtime(true) - $b)); if (isset($e)) { throw $e; } return $context->getDictId(); }
function dropKeys($tableName) { $schema = $this->getSchema($tableName); $stmt = new phpMorphy_Dict_Writer_Sql_StatementsBundle($this); $stmt->prepend($schema->dropForeignKeys()); $stmt->prepend($schema->dropConstraints()); $stmt->prepend($schema->dropIndex()); return $stmt; }