Adding upgrade controller in order to upgrade chamilo to the latest version (work in progress)

skala
Julio Montoya 11 years ago
parent 9875562ffa
commit 8be4e3e169
  1. 1
      main/inc/routes.php
  2. 15
      main/inc/services.php
  3. 21
      main/install/index.php
  4. 9
      main/template/default/admin/administrator/upgrade/index.tpl
  5. 6
      main/template/default/admin/administrator/upgrade/upgrade.tpl
  6. 36
      src/ChamiloLMS/Component/Console/Output/BufferedOutput.php
  7. 167
      src/ChamiloLMS/Controller/Admin/Administrator/UpgradeController.php
  8. 31
      vendor/chamilo/chash/src/Chash/Command/Chash/SetupCommand.php
  9. 20
      vendor/chamilo/chash/src/Chash/Command/Installation/CommonCommand.php
  10. 51
      vendor/chamilo/chash/src/Chash/Command/Installation/UpgradeCommand.php
  11. 4
      vendor/chamilo/chash/src/Chash/Migrations/migrations.yml
  12. 1
      vendor/chamilo/chash/src/Chash/Resources/Database/1.11.0/post.sql
  13. 1
      vendor/chamilo/chash/src/Chash/Resources/Database/1.11.0/pre.sql
  14. 1
      vendor/chamilo/chash/src/Chash/Resources/Database/1.11.0/update.php

@ -651,6 +651,7 @@ $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
->bind('model_ajax');
if ($alreadyInstalled) {
$app->mount('/admin/administrator/upgrade', new ChamiloLMS\Provider\ReflectionControllerProvider('upgrade.controller'));
$app->mount('/admin/administrator/roles', new ChamiloLMS\Provider\ReflectionControllerProvider('role.controller'));
$app->mount('/admin/administrator/question_scores', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score.controller'));
$app->mount('/admin/administrator/question_score_names', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score_name.controller'));

@ -25,6 +25,14 @@ $app->register(new Flint\Provider\RoutingServiceProvider(), array(
),
));
use Knp\Provider\ConsoleServiceProvider;
$app->register(new ConsoleServiceProvider(), array(
'console.name' => 'Chamilo',
'console.version' => '1.0.0',
'console.project_directory' => __DIR__.'/..'
));
// Monolog.
if (is_writable($app['sys_temp_path'])) {
@ -672,3 +680,10 @@ $app['curriculum_user.controller'] = $app->share(
return new ChamiloLMS\Controller\Tool\Curriculum\CurriculumUserController($app);
}
);
$app['upgrade.controller'] = $app->share(
function () use ($app) {
return new ChamiloLMS\Controller\Admin\Administrator\UpgradeController($app);
}
);

@ -19,26 +19,7 @@ error_reporting(-1);
use Symfony\Component\Console\Output\Output;
use Symfony\Component\HttpFoundation\Request;
class BufferedOutput extends Output
{
public $messages = array();
public $lastMessage = null;
public $buffer = null;
public function doWrite($message, $newline)
{
//$this->buffer .= $message. ($newline ? PHP_EOL: '');
$this->buffer .= $message. '<br />';
$this->messages[] = $message;
$this->lastMessage = $message;
}
public function getBuffer()
{
return $this->buffer;
}
}
use ChamiloLMS\Component\Console\Output\BufferedOutput;
$app = new Silex\Application();

@ -0,0 +1,9 @@
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
{% block content %}
<h2>{{ 'Upgrade' }}</h2>
<h3>{{ 'ClickToUpgradeToVersion' }} {{ version }}</h3>
<form action="{{ url('upgrade.controller:upgradeAction', { 'version': version }) }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
</form>
{% endblock %}

@ -0,0 +1,6 @@
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
{% block content %}
{{ output }}
{% endblock %}

@ -0,0 +1,36 @@
<?php
namespace ChamiloLMS\Component\Console\Output;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\HttpFoundation\Request;
/**
* Class BufferedOutput
* @package ChamiloLMS\Component\Console\Output
*/
class BufferedOutput extends Output
{
public $messages = array();
public $lastMessage = null;
public $buffer = null;
/**
* @param string $message
* @param bool $newline
*/
public function doWrite($message, $newline)
{
$this->buffer .= $message. '<br />';
$this->messages[] = $message;
$this->lastMessage = $message;
}
/**
* @return null
*/
public function getBuffer()
{
return $this->buffer;
}
}

@ -0,0 +1,167 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Controller\Admin\Administrator;
use ChamiloLMS\Controller\CommonController;
use Silex\Application;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
use ChamiloLMS\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Entity;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
//use Guzzle\Http\Client;
/**
* Class RoleController
* @todo @route and @method function don't work yet
* @package ChamiloLMS\Controller
* @author Julio Montoya <gugli100@gmail.com>
*/
class UpgradeController extends CommonController
{
/**
* @Route("/")
* @Method({"GET"})
*/
public function indexAction()
{
//$version = api_http_request('version.chamilo.org', 80, '/version.php');
$version = '1.11.0';
$request = $this->getRequest();
$builder = $this->createFormBuilder();
$builder
->add('submit', 'submit');
$form = $builder->getForm();
if ($request->getMethod() == 'POST') {
if ($form->isValid()) {
$this->get('session')->getFlashBag()->add('success', "Added");
$url = $this->generateUrl('upgrade.controller:upgradeAction');
return $this->redirect($url);
}
}
$template = $this->get('template');
$template->assign('form', $form->createView());
$template->assign('version', $version);
$response = $template->render_template($this->getTemplatePath().'index.tpl');
return new Response($response, 200, array());
}
/**
* @Route("{version}/update")
* @Method({"GET"})
*/
public function upgradeAction($version)
{
/** @var \Knp\Console\Application $console */
$console = $this->get('console');
$console->addCommands(
array(
// DBAL Commands.
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
// Migrations Commands.
new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(),
new \Chash\Command\Chash\SetupCommand(),
new \Chash\Command\Database\RunSQLCommand(),
new \Chash\Command\Database\DumpCommand(),
new \Chash\Command\Database\RestoreCommand(),
new \Chash\Command\Database\SQLCountCommand(),
new \Chash\Command\Database\FullBackupCommand(),
new \Chash\Command\Database\DropDatabaseCommand(),
new \Chash\Command\Database\ShowConnInfoCommand(),
new \Chash\Command\Files\CleanDataFilesCommand(),
new \Chash\Command\Files\CleanTempFolderCommand(),
new \Chash\Command\Files\CleanConfigFilesCommand(),
new \Chash\Command\Files\MailConfCommand(),
new \Chash\Command\Files\SetPermissionsAfterInstallCommand(),
new \Chash\Command\Files\GenerateTempFileStructureCommand(),
new \Chash\Command\Installation\InstallCommand(),
new \Chash\Command\Installation\WipeCommand(),
new \Chash\Command\Installation\StatusCommand(),
new \Chash\Command\Installation\UpgradeCommand()
)
);
$helpers = array(
'configuration' => new \Chash\Helpers\ConfigurationHelper()
);
$helperSet = $console->getHelperSet();
foreach ($helpers as $name => $helper) {
$helperSet->set($helper, $name);
}
$command = $console->get('chamilo:upgrade');
$version = '1.11.0';
$def = $command->getDefinition();
$input = new \Symfony\Component\Console\Input\ArrayInput(
array(
'name',
'--path' => $this->get('sys_root'),
'version' => $version,
'--migration-yml-path' => api_remove_trailing_slash($this->get('sys_temp_path')),
'--migration-class-path' => $this->get('sys_root').'vendor/chamilo/chash/src/Chash/Migrations',
'--download-package' => 'false',
'--silent' => 'true'
),
$def
);
$output = new BufferedOutput();
$result = $command->run($input, $output);
if ($result) {
}
$output = $output->getBuffer();
$template = $this->get('template');
$template->assign('output', $output);
$response = $template->render_template($this->getTemplatePath().'upgrade.tpl');
return new Response($response, 200, array());
}
protected function getControllerAlias()
{
return 'upgrade.controller';
}
/**
* {@inheritdoc}
*/
protected function getTemplatePath()
{
return 'admin/administrator/upgrade/';
}
/**
* @return \Entity\Repository\BranchSyncRepository
*/
protected function getRepository()
{
}
}

@ -13,11 +13,15 @@ use Symfony\Component\Yaml\Dumper;
*/
class SetupCommand extends AbstractCommand
{
public $migrationFile = null;
protected function configure()
{
$this
->setName('chash:setup')
->setDescription('Setups the migration.yml');
->setDescription('Setups the migration.yml')
->addOption('migration-yml-path', null, InputOption::VALUE_OPTIONAL, 'The path to the migration.yml file')
->addOption('migration-class-path', null, InputOption::VALUE_OPTIONAL, 'The path to the migration classes');
}
@ -31,14 +35,26 @@ class SetupCommand extends AbstractCommand
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$srcPath = realpath(__DIR__.'/../../../');
$path = $input->getOption('migration-yml-path');
if (empty($path)) {
$srcPath = realpath(__DIR__.'/../../../').'/Chash/Migrations/';
} else {
$srcPath = $path;
}
$migrationClassPath = $input->getOption('migration-class-path');
if (empty($migrationClassPath)) {
$migrationClassPath = $srcPath;
}
//$migrationDist = $srcPath."/Chash/Migrations/migrations_dist.yml";
$migrations = array(
'name' => 'Chamilo Migrations',
'migrations_namespace' => 'Chash\Migrations',
'table_name' => 'chamilo_migration_versions',
'migrations_directory' => $srcPath.'/Chash/Migrations/'
'migrations_directory' => $migrationClassPath
);
// does not work because it need a callable function yml_emit
@ -47,10 +63,17 @@ class SetupCommand extends AbstractCommand
$writer->toFile($srcPath.'/Chash/Migrations/migrations.ypl', $config);*/
$dumper = new Dumper();
$yaml = $dumper->dump($migrations, 1);
$file = $srcPath.'/Chash/Migrations/migrations.yml';
$file = $srcPath.'/migrations.yml';
file_put_contents($file, $yaml);
// migrations_directory
$output->writeln("<comment>Chash migrations.yml saved: $file</comment>");
$this->migrationFile = $file;
}
public function getMigrationFile()
{
return $this->migrationFile;
}
}

@ -19,6 +19,7 @@ class CommonCommand extends AbstractCommand
public $configurationPath = null;
public $configuration = array();
public $extraDatabaseSettings;
private $migrationConfigurationFile;
/**
* @param array $configuration
@ -477,6 +478,14 @@ class CommonCommand extends AbstractCommand
'update_files' => null,
'hook_to_doctrine_version' => '10'
),
'1.11.0' => array(
'require_update' => true,
'pre' => 'pre.sql',
'post' => 'post.sql',
'update_db' => 'update.php',
'update_files' => null,
'hook_to_doctrine_version' => '11'
),
'master' => array(
'require_update' => true,
'pre' => 'migrate-db-1.9.0-1.10.0-pre.sql',
@ -496,7 +505,12 @@ class CommonCommand extends AbstractCommand
*/
public function getMigrationConfigurationFile()
{
return realpath(__DIR__.'/../../Migrations/migrations.yml');
return $this->migrationConfigurationFile;
}
public function setMigrationConfigurationFile($file)
{
$this->migrationConfigurationFile = $file;
}
/**
@ -1058,6 +1072,10 @@ class CommonCommand extends AbstractCommand
$destinationPath = $this->getRootSys();
}
if (empty($chamiloLocationPath)) {
$output->writeln("<error>The chamiloLocationPath variable is empty<error>");
}
$output->writeln("<comment>Copying files from </comment><info>$chamiloLocationPath</info><comment> to </comment><info>".$destinationPath."</info>");
if (empty($destinationPath)) {

@ -20,6 +20,7 @@ class UpgradeCommand extends CommonCommand
{
public $queryList;
public $databaseList;
public $commandLine = true;
/**
* Get connection
@ -40,6 +41,9 @@ class UpgradeCommand extends CommonCommand
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Execute the migration as a dry run.')
->addOption('update-installation', null, InputOption::VALUE_OPTIONAL, 'Updates the portal with the current zip file. http:// or /var/www/file.zip')
->addOption('temp-folder', null, InputOption::VALUE_OPTIONAL, 'The temp folder.', '/tmp')
->addOption('migration-yml-path', null, InputOption::VALUE_OPTIONAL, 'The temp folder.', '/tmp')
->addOption('migration-class-path', null, InputOption::VALUE_OPTIONAL, 'The temp folder.', '/tmp')
->addOption('download-package', null, InputOption::VALUE_OPTIONAL, 'Downloads the chamilo package', 'true')
->addOption('silent', null, InputOption::VALUE_NONE, 'Execute the migration with out asking questions.');
//->addOption('force', null, InputOption::VALUE_NONE, 'Force the update. Only for tests');
}
@ -54,20 +58,39 @@ class UpgradeCommand extends CommonCommand
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if (PHP_SAPI != 'cli') {
$this->commandLine = false;
}
// Setting up Chash:
$command = $this->getApplication()->find('chash:setup');
$migrationPath = $input->getOption('migration-yml-path');
$migrationDir = $input->getOption('migration-class-path');
$arguments = array(
'command' => 'chash:setup'
);
if (!empty($migrationPath)) {
$arguments['--migration-yml-path'] = $migrationPath;
}
if (!empty($migrationDir)) {
$arguments['--migration-class-path'] = $migrationDir;
}
$inputSetup = new ArrayInput($arguments);
$command->run($inputSetup, $output);
$this->setMigrationConfigurationFile($command->getMigrationFile());
// Arguments and options
$version = $originalVersion = $input->getArgument('version');
$path = $input->getOption('path');
$dryRun = $input->getOption('dry-run');
$silent = $input->getOption('silent') == true;
$tempFolder = $input->getOption('temp-folder');
$downloadPackage = $input->getOption('download-package') == 'true' ? true : false;
$updateInstallation = $input->getOption('update-installation');
// Setting the configuration path and configuration array
@ -173,18 +196,23 @@ class UpgradeCommand extends CommonCommand
}
if ($dryRun == false) {
$chamiloLocationPath = $this->getPackage($output, $originalVersion, $updateInstallation, $tempFolder);
if (empty($chamiloLocationPath)) {
return;
if ($downloadPackage) {
$output->writeln("<comment>Downloading package ...</comment>");
$chamiloLocationPath = $this->getPackage($output, $originalVersion, $updateInstallation, $tempFolder);
if (empty($chamiloLocationPath)) {
return;
}
}
}
$this->writeCommandHeader($output, 'Welcome to the Chamilo upgrade process!');
if ($dryRun == false) {
$output->writeln("<comment>When the installation process finished the files located here:<comment>");
$output->writeln("<info>$chamiloLocationPath</info>");
$output->writeln("<comment>will be copied in your portal here: </comment><info>".$this->getRootSys()."</info>");
if ($downloadPackage) {
$output->writeln("<comment>When the installation process finished the files located here:<comment>");
$output->writeln("<info>$chamiloLocationPath</info>");
$output->writeln("<comment>will be copied in your portal here: </comment><info>".$this->getRootSys()."</info>");
}
} else {
$output->writeln("<comment>When the installation process finished PHP files are not going to be updated (--dry-run is on).</comment>");
}
@ -346,7 +374,9 @@ class UpgradeCommand extends CommonCommand
$output->writeln("<comment>Executing update db: <info>'$sqlToInstall'</info>");
}
require $sqlToInstall;
$update($_configuration, $conn, $courseList, $dryRun, $output);
if (!empty($update)) {
$update($_configuration, $conn, $courseList, $dryRun, $output);
}
}
}
@ -359,7 +389,9 @@ class UpgradeCommand extends CommonCommand
} else {
$output->writeln("<comment>Executing update files: <info>'$sqlToInstall'</info>");
require $sqlToInstall;
$updateFiles($_configuration, $conn, $courseList, $dryRun, $output);
if (!empty($updateFiles)) {
$updateFiles($_configuration, $conn, $courseList, $dryRun, $output);
}
}
}
}
@ -388,6 +420,9 @@ class UpgradeCommand extends CommonCommand
$output->writeln("<comment>Executing migrations:migrate ".$versionInfo['hook_to_doctrine_version']." --configuration=".$this->getMigrationConfigurationFile()."<comment>");
$input = new ArrayInput($arguments);
if ($this->commandLine == false) {
$input->setInteractive(false);
}
$command->run($input, $output);
$output->writeln("<comment>Migration ended successfully</comment>");

@ -1,4 +0,0 @@
name: 'Chamilo Migrations'
migrations_namespace: Chash\Migrations
table_name: chamilo_migration_versions
migrations_directory: /var/www/chash/src/Chash/Migrations/

@ -0,0 +1 @@
UPDATE settings_current SET selected_value = '1.11.post' WHERE variable = 'chamilo_database_version';

@ -0,0 +1 @@
UPDATE settings_current SET selected_value = '1.11.pre' WHERE variable = 'chamilo_database_version';
Loading…
Cancel
Save