Merge pull request #4817 from christianbeeznest/ofaj-20846-4
Migrations: Check files of migrations and improve interface - refs BT#20846pull/4818/head
commit
0b50c22c8d
@ -0,0 +1,37 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
ini_set('memory_limit', '1024M'); |
||||
|
||||
require_once __DIR__.'/../../../vendor/autoload.php'; |
||||
require_once api_get_path(SYS_CODE_PATH).'install/install.lib.php'; |
||||
|
||||
$result = checkMigrationStatus(); |
||||
|
||||
$logFile = api_get_path(SYS_PATH) . '/../var/log/migration-to-2.0.log'; |
||||
|
||||
if (!file_exists($logFile)) { |
||||
error_log('Initiating migration at '.date('d/m/Y H:i') . PHP_EOL, 3, $logFile); |
||||
chmod($logFile, 0644); |
||||
} |
||||
|
||||
if (!empty($result['current_migration'])) { |
||||
$migrationPath = "Current Migration path: " . $result['current_migration']; |
||||
error_log($migrationPath . PHP_EOL, 3, $logFile); |
||||
} |
||||
|
||||
$logContent = ''; |
||||
if (file_exists($logFile)) { |
||||
// The migration log file was found |
||||
chmod($logFile, 0644); |
||||
$logContent = file_get_contents($logFile); |
||||
} |
||||
|
||||
// Prepare the response array |
||||
$response = [ |
||||
'log_terminal' => '<pre class="terminal">' . $logContent . '</pre>', |
||||
'progress_percentage' => $result['progress_percentage'], |
||||
]; |
||||
|
||||
// Send the response as JSON |
||||
header('Content-Type: application/json'); |
||||
echo json_encode($response); |
@ -0,0 +1,220 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
|
||||
final class Version20201211114900 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Migrate access_url, users'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
error_log('MIGRATIONS :: FILE -- Version20201211114900 ...'); |
||||
|
||||
if ($schema->hasTable('gradebook_category')) { |
||||
$table = $schema->getTable('gradebook_category'); |
||||
if (!$table->hasColumn('allow_skills_by_subcategory')) { |
||||
$this->addSql( |
||||
'ALTER TABLE gradebook_category ADD allow_skills_by_subcategory INT DEFAULT 1' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_survey_answer')) { |
||||
$table = $schema->getTable('c_survey_answer'); |
||||
if (!$table->hasColumn('session_id')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_survey_answer ADD session_id INT NOT NULL' |
||||
); |
||||
} |
||||
if (!$table->hasColumn('c_lp_item_id')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_survey_answer ADD c_lp_item_id INT NOT NULL' |
||||
); |
||||
} |
||||
|
||||
} |
||||
|
||||
if ($schema->hasTable('c_survey_invitation')) { |
||||
$table = $schema->getTable('c_survey_invitation'); |
||||
if (!$table->hasColumn('c_lp_item_id')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_survey_invitation ADD c_lp_item_id INT NOT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_quiz')) { |
||||
$table = $schema->getTable('c_quiz'); |
||||
if (!$table->hasColumn('hide_attempts_table')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_quiz ADD hide_attempts_table TINYINT(1) NOT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_attendance_calendar')) { |
||||
$table = $schema->getTable('c_attendance_calendar'); |
||||
if (!$table->hasColumn('blocked')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_attendance_calendar ADD blocked TINYINT(1) DEFAULT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_attendance_sheet')) { |
||||
$table = $schema->getTable('c_attendance_sheet'); |
||||
if (!$table->hasColumn('signature')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_attendance_sheet ADD signature VARCHAR(255) DEFAULT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_lp')) { |
||||
$table = $schema->getTable('c_lp'); |
||||
if (!$table->hasColumn('published_on')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp CHANGE publicated_on published_on datetime NULL;' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_lp')) { |
||||
$table = $schema->getTable('c_lp'); |
||||
if (!$table->hasColumn('next_lp_id')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp ADD next_lp_id INT DEFAULT 0 NOT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if ($schema->hasTable('c_lp_item')) { |
||||
$table = $schema->getTable('c_lp_item'); |
||||
if (!$table->hasColumn('item_root')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp_item CHANGE c_id item_root INT DEFAULT NULL' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp_item ADD CONSTRAINT FK_CCC9C1EDDEC4BDA0 FOREIGN KEY (item_root) REFERENCES c_lp_item (iid) ON DELETE CASCADE' |
||||
); |
||||
$this->addSql( |
||||
'CREATE INDEX IDX_CCC9C1EDDEC4BDA0 ON c_lp_item (item_root)' |
||||
); |
||||
} |
||||
} |
||||
|
||||
if (!$schema->hasTable('c_wiki_category')) { |
||||
$this->addSql( |
||||
'CREATE TABLE c_wiki_category (id INT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, session_id INT DEFAULT NULL, tree_root INT DEFAULT NULL, parent_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, lft INT NOT NULL, lvl INT NOT NULL, rgt INT NOT NULL, INDEX IDX_17F1099A91D79BD3 (c_id), INDEX IDX_17F1099A613FECDF (session_id), INDEX IDX_17F1099AA977936C (tree_root), INDEX IDX_17F1099A727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099AA977936C FOREIGN KEY (tree_root) REFERENCES c_wiki_category (id) ON DELETE CASCADE' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_category ADD CONSTRAINT FK_17F1099A727ACA70 FOREIGN KEY (parent_id) REFERENCES c_wiki_category (id) ON DELETE CASCADE' |
||||
); |
||||
} |
||||
|
||||
if (!$schema->hasTable('c_wiki_rel_category')) { |
||||
$this->addSql( |
||||
'CREATE TABLE c_wiki_rel_category (wiki_id INT NOT NULL, category_id INT NOT NULL, INDEX IDX_AC88945BAA948DBE (wiki_id), INDEX IDX_AC88945B12469DE2 (category_id), PRIMARY KEY(wiki_id, category_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_rel_category ADD CONSTRAINT FK_AC88945BAA948DBE FOREIGN KEY (wiki_id) REFERENCES c_wiki (iid) ON DELETE CASCADE' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE c_wiki_rel_category ADD CONSTRAINT FK_AC88945B12469DE2 FOREIGN KEY (category_id) REFERENCES c_wiki_category (id) ON DELETE CASCADE' |
||||
); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
if ($schema->hasTable('c_wiki_category')) { |
||||
$this->addSql( |
||||
'DROP TABLE c_wiki_category' |
||||
); |
||||
} |
||||
|
||||
if ($schema->hasTable('c_wiki_rel_category')) { |
||||
$this->addSql( |
||||
'DROP TABLE c_wiki_rel_category' |
||||
); |
||||
} |
||||
|
||||
if ($schema->hasTable('c_lp_item')) { |
||||
$table = $schema->getTable('c_lp_item'); |
||||
if ($table->hasColumn('item_root')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp_item CHANGE item_root c_id INT DEFAULT NULL' |
||||
); |
||||
} |
||||
} |
||||
|
||||
$table = $schema->getTable('c_lp'); |
||||
if ($table->hasColumn('next_lp_id')) { |
||||
$this->addSql('ALTER TABLE c_lp DROP next_lp_id'); |
||||
} |
||||
|
||||
if ($schema->hasTable('c_lp')) { |
||||
$table = $schema->getTable('c_lp'); |
||||
if ($table->hasColumn('published_on')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp CHANGE published_on publicated_on datetime NULL;' |
||||
); |
||||
} |
||||
} |
||||
$table = $schema->getTable('c_attendance_sheet'); |
||||
if ($table->hasColumn('signature')) { |
||||
$this->addSql('ALTER TABLE c_attendance_sheet DROP signature'); |
||||
} |
||||
|
||||
$table = $schema->getTable('c_attendance_calendar'); |
||||
if ($table->hasColumn('blocked')) { |
||||
$this->addSql('ALTER TABLE c_attendance_calendar DROP blocked'); |
||||
} |
||||
|
||||
$table = $schema->getTable('c_quiz'); |
||||
if ($table->hasColumn('hide_attempts_table')) { |
||||
$this->addSql('ALTER TABLE c_quiz DROP hide_attempts_table'); |
||||
} |
||||
|
||||
$table = $schema->getTable('c_survey_answer'); |
||||
if ($table->hasColumn('session_id')) { |
||||
$this->addSql('ALTER TABLE c_survey_answer DROP session_id'); |
||||
} |
||||
|
||||
if ($table->hasColumn('c_lp_item_id')) { |
||||
$this->addSql('ALTER TABLE c_survey_answer DROP c_lp_item_id'); |
||||
} |
||||
|
||||
$table = $schema->getTable('c_survey_invitation'); |
||||
if ($table->hasColumn('c_lp_item_id')) { |
||||
$this->addSql('ALTER TABLE c_survey_invitation DROP c_lp_item_id'); |
||||
} |
||||
|
||||
$table = $schema->getTable('gradebook_category'); |
||||
if ($table->hasColumn('allow_skills_by_subcategory')) { |
||||
$this->addSql('ALTER TABLE gradebook_category DROP allow_skills_by_subcategory'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
final class Version20201211114910 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Create table resource_format'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
if (!$schema->hasTable('resource_format')) { |
||||
$this->addSql( |
||||
"CREATE TABLE resource_format (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;" |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE resource_node ADD resource_format_id INT DEFAULT NULL;' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE resource_node ADD CONSTRAINT FK_8A5F48FF7EE0A59A FOREIGN KEY (resource_format_id) REFERENCES resource_format (id) ON DELETE SET NULL;' |
||||
); |
||||
$this->addSql( |
||||
'CREATE INDEX IDX_8A5F48FF7EE0A59A ON resource_node (resource_format_id);' |
||||
); |
||||
} |
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
if ($schema->hasTable('resource_format')) { |
||||
$this->addSql( |
||||
'ALTER TABLE resource_node DROP FOREIGN KEY FK_8A5F48FF7EE0A59A;' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE resource_node DROP INDEX IDX_8A5F48FF7EE0A59A;' |
||||
); |
||||
$this->addSql( |
||||
'ALTER TABLE resource_node DROP resource_format_id;' |
||||
); |
||||
$this->addSql( |
||||
'DROP TABLE resource_format;' |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
final class Version20201211124910 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Insert default values to table resource_format'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
$connection = $this->getEntityManager()->getConnection(); |
||||
if ($schema->hasTable('resource_format')) { |
||||
$result = $connection->executeQuery(" SELECT * FROM resource_format WHERE name = 'html'"); |
||||
$exists = $result->fetchAllAssociative(); |
||||
if (empty($exists)) { |
||||
$this->addSql("INSERT INTO resource_format SET name = 'html', created_at = NOW(), updated_at = NOW();"); |
||||
} |
||||
$result = $connection->executeQuery(" SELECT * FROM resource_format WHERE name = 'txt'"); |
||||
$exists = $result->fetchAllAssociative(); |
||||
if (empty($exists)) { |
||||
$this->addSql("INSERT INTO resource_format SET name = 'txt', created_at = NOW(), updated_at = NOW();"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
$connection = $this->getEntityManager()->getConnection(); |
||||
if ($schema->hasTable('resource_format')) { |
||||
$result = $connection->executeQuery(" SELECT * FROM resource_format WHERE name = 'txt'"); |
||||
$exists = $result->fetchAllAssociative(); |
||||
if (!empty($exists)) { |
||||
$this->addSql("DELETE FROM resource_format WHERE name = 'txt';"); |
||||
} |
||||
$result = $connection->executeQuery(" SELECT * FROM resource_format WHERE name = 'html'"); |
||||
$exists = $result->fetchAllAssociative(); |
||||
if (!empty($exists)) { |
||||
$this->addSql("DELETE FROM resource_format WHERE name = 'html';"); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
class Version20201212195110 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Session changes'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
$table = $schema->getTable('session'); |
||||
if (false === $table->hasColumn('image_id')) { |
||||
$this->addSql("ALTER TABLE session ADD image_id BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid)'"); |
||||
$this->addSql("ALTER TABLE session ADD CONSTRAINT FK_D044D5D43DA5256D FOREIGN KEY (image_id) REFERENCES asset (id) ON DELETE SET NULL"); |
||||
$this->addSql("CREATE INDEX IDX_D044D5D43DA5256D ON session (image_id)"); |
||||
} |
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
} |
||||
} |
@ -1,34 +0,0 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
final class Version20230124123419 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Rename c_lp.publicated_on to c_lp.published_on'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
if ($schema->hasTable('c_lp')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp CHANGE publicated_on published_on datetime NULL;' |
||||
); |
||||
} |
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
if ($schema->hasTable('c_lp')) { |
||||
$this->addSql( |
||||
'ALTER TABLE c_lp CHANGE published_on publicated_on datetime NULL;' |
||||
); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue