setView (new View_Admin ('migration34/introduction')); $this->getForm () ->addSubmitButton ('Proceed', 'install'); if ($this->getForm ()->validate ()) { $this->moveToStep ('stepOldDatabase'); } } function stepOldDatabase () { $this->setView (new View_Admin ('migration34/old_database')); $current_connection = Kohana::config('database.default.connection'); $form = $this->getForm (); $form ->add ('text', 'host') ->set ('host','value', $current_connection ['host']) ->add ('text', 'port') ->set ('port','value', $current_connection ['port']) ->add ('text', 'database', $current_connection ['database']) ->add ('text', 'table prefix') ->add_rule ('table_prefix', 'common_name', 'Only letters and underscore are allowed starting with a letter.') ->add ('text', 'user', $current_connection ['user']) ->add ('text', 'password', $current_connection ['pass']) ->noRequiredFields ('table_prefix') ->addSubmitButton ('Connect to Database', 'install') ->addBackwardButton ('stepIntroduction') ; $connection = $this->getPersistent ('connection'); if (isset ($connection)) { $form->host->value = $connection->getHost (); $form->port->value = $connection->getPort (); $form->database->value = $connection->getDatabase (); $form->table_prefix->value = $connection->getTablePrefix (); $form->user->value = $connection->getUser (); $form->password->value = $connection->getPassword (); } if ($this->getForm ()->validate ()) { $connection = new MySQLConnection (); $connection->setHost ($form->host->value); $connection->setPort ($form->port->value); $connection->setDatabase ($form->database->value); $connection->setTablePrefix ($form->table_prefix->value); $connection->setUser ($form->user->value); $connection->setPassword ($form->password->value); try { try { $result = $connection->test (); if ($result !== true) { throw new Exception ($result); } $conntection_as_array = $connection->getConnectionSettings (); $conntection_as_array ['character_set'] = 'utf8'; $conntection_as_array ['persistent'] = true; $conntection_as_array ['benchmark'] = true; $db = new Database ($conntection_as_array); $db->connect (); $migrator = new Migration34 ($db); $migrator->checkPrerequisites (); } catch (Exception $e) { throw new Migration34_Exception ($e->getMessage ()); } $this->setPersistent ('connection', $connection); $this->moveToStep ('stepMigrate'); } catch (Migration34_Exception $e) { $error = $e->getMessage (); if (! $error) { $error = 'Invalid database settings.'; } $this->getForm ()->error ('host', $error); } } } function stepMigrate () { $this->setView (new View_Admin ('migration34/migrate')); $this->getForm () ->addSubmitButton ('Start', 'install') ->addBackwardButton ('stepOldDatabase') ; if ($this->getForm ()->validate ()) { $this->logger (new Zend_Log ()); $this->setupLogger (); $this->logger ()->notice ("Migration 3.xx-4.xx tool started."); $connection = $this->getPersistent ('connection'); $conntection_as_array = $connection->getConnectionSettings (); $conntection_as_array ['character_set'] = 'utf8'; $conntection_as_array ['persistent'] = 0; $conntection_as_array ['benchmark'] = true; $migrator = new Migration34 ($conntection_as_array); $migrator->logger ($this->logger()); $migrator->run (); $this->logger ()->notice ("Migration is now finished."); $this->moveToStep ('stepFinished'); } } function stepFinished () { $this->setView (new View_Admin ('migration34/finished')); } private function getTableStructure (Database $db, $tablename) { $result = array(); $records = $db->query ('EXPLAIN ' . $tablename); foreach ($records as $row) { settype ($row, 'array'); $result [$row ['Field']] = $row; } return $result; } private function checkSettingsTable (array $settings) { if (!isset ($settings ['id'])) { return false; } $id = $settings ['id']; if (!preg_match ('/^int/', $id ['Type'])) { return false; } return true; } private function setupLogger () { $log_filename = strtolower (preg_replace ('/.*_/', '', get_class ($this))); $log_filename .= ' '; $log_filename = LOGDIR . "/$log_filename" . date ('Y-m-d_H-i-s') . '.log'; $file = new Zend_Log_Writer_Stream ($log_filename); $this->logger ()->addWriter ($file); } function logger (Zend_Log $logger = null) { if (isset ($logger)) { $this->logger = $logger; } else { return $this->logger; } } }