upgrade.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../../../main/inc/global.inc.php';
  5. $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo'));
  6. // Security
  7. api_protect_admin_script();
  8. Virtual::checkSettings();
  9. $plugin = VChamiloPlugin::create();
  10. $id = isset($_REQUEST['vid']) ? (int) $_REQUEST['vid'] : 0;
  11. $instance = Virtual::getInstance($id);
  12. $canBeUpgraded = Virtual::canBeUpgraded($instance);
  13. $form = new FormValidator('upgrade', 'post', api_get_self().'?vid='.$id);
  14. // Database host.
  15. $form->addHeader(get_lang('Upgrade'));
  16. $form->addText('root_web', $plugin->get_lang('rootweb'));
  17. $form->addText('db_host', $plugin->get_lang('dbhost'));
  18. $form->addText('db_user', $plugin->get_lang('dbuser'));
  19. $form->addText('main_database', [$plugin->get_lang('maindatabase')]);
  20. $form->setDefaults((array) $instance);
  21. if ($canBeUpgraded) {
  22. $form->addLabel(get_lang('From'), $canBeUpgraded);
  23. $form->addLabel(get_lang('To'), api_get_setting('chamilo_database_version'));
  24. $form->addButtonSave(get_lang('Upgrade'));
  25. } else {
  26. Display::addFlash(Display::return_message(get_lang('NothingToUpgrade')));
  27. }
  28. $form->freeze();
  29. $content = $form->returnForm();
  30. if ($form->validate() && $canBeUpgraded) {
  31. $values = $form->getSubmitValues();
  32. require_once api_get_path(SYS_CODE_PATH).'install/install.lib.php';
  33. $manager = Virtual::getConnectionFromInstance($instance, true);
  34. if ($manager) {
  35. ob_start();
  36. $result = migrateSwitch($canBeUpgraded, $manager, false);
  37. $data = ob_get_clean();
  38. if ($result) {
  39. Display::addFlash(Display::return_message(get_lang('Upgraded')));
  40. } else {
  41. Display::addFlash(Display::return_message(get_lang('Error')));
  42. }
  43. $content = $data;
  44. } else {
  45. Display::addFlash(Display::return_message(get_lang('Error')));
  46. }
  47. }
  48. $tpl = new Template(get_lang('Upgrade'), true, true, false, true, false);
  49. $tpl->assign('content', $content);
  50. $tpl->display_one_col_template();