Merge pull request #4817 from christianbeeznest/ofaj-20846-4

Migrations: Check files of migrations and improve interface - refs BT#20846
pull/4818/head
Angel Fernando Quiroz Campos 1 year ago committed by GitHub
commit 0b50c22c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      assets/css/app.scss
  2. 29
      assets/vue/components/installer/Step1.vue
  3. 53
      assets/vue/components/installer/Step6.vue
  4. 2
      public/main/inc/lib/course.lib.php
  5. 37
      public/main/install/get_migration_status.php
  6. 36
      public/main/install/index.php
  7. 117
      public/main/install/install.lib.php
  8. 3
      src/CoreBundle/Entity/Listener/ResourceListener.php
  9. 2
      src/CoreBundle/Entity/ResourceNode.php
  10. 8
      src/CoreBundle/Migrations/Schema/V200/Version20.php
  11. 2
      src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php
  12. 3
      src/CoreBundle/Migrations/Schema/V200/Version20180904175500.php
  13. 2
      src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php
  14. 1
      src/CoreBundle/Migrations/Schema/V200/Version20191101132000.php
  15. 4
      src/CoreBundle/Migrations/Schema/V200/Version20191206150000.php
  16. 1
      src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php
  17. 220
      src/CoreBundle/Migrations/Schema/V200/Version20201211114900.php
  18. 52
      src/CoreBundle/Migrations/Schema/V200/Version20201211114910.php
  19. 50
      src/CoreBundle/Migrations/Schema/V200/Version20201211124910.php
  20. 2
      src/CoreBundle/Migrations/Schema/V200/Version20201212195011.php
  21. 31
      src/CoreBundle/Migrations/Schema/V200/Version20201212195110.php
  22. 23
      src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php
  23. 1
      src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php
  24. 3
      src/CoreBundle/Migrations/Schema/V200/Version20201215141131.php
  25. 4
      src/CoreBundle/Migrations/Schema/V200/Version20201215153517.php
  26. 2
      src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php
  27. 3
      src/CoreBundle/Migrations/Schema/V200/Version20201217124011.php
  28. 2
      src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php
  29. 1
      src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php
  30. 1
      src/CoreBundle/Migrations/Schema/V200/Version20210813150011.php
  31. 2
      src/CoreBundle/Migrations/Schema/V200/Version20210923090920.php
  32. 1
      src/CoreBundle/Migrations/Schema/V200/Version20211005154000.php
  33. 34
      src/CoreBundle/Migrations/Schema/V200/Version20230124123419.php
  34. 8
      src/CoreBundle/Migrations/Schema/V200/Version20230204150030.php
  35. 11
      src/CoreBundle/Migrations/Schema/V200/Version20230215072918.php
  36. 147
      src/CoreBundle/Migrations/Schema/V200/Version20230216122950.php
  37. 0
      var/upload/.gitkeep

@ -132,7 +132,17 @@
.progress {
@apply rounded-sm ring-1 text-center min-h-full ml-12 mr-4;
}
.progress .progress-bar {
.log-container {
height: 300px;
overflow-y: scroll;
background-color: #000;
padding: 10px;
}
.terminal {
color: #00ff00; /* Green */
font-family: monospace;
}
// Pager

@ -42,20 +42,39 @@
<hr>
<div class="formgroup-inline">
<div class="formgroup">
<Message
v-if="installerData.isUpdateAvailable"
id="pleasewait"
:closable="false"
severity="warn"
>
<p class="update-message-text">
{{ t('An update is available. Click the button below to proceed with the update.') }}
</p>
<p>{{ installerData.checkMigrationStatus.message }}</p>
<p v-if="installerData.checkMigrationStatus.current_migration">
Current Migration: {{ installerData.checkMigrationStatus.current_migration }}
</p>
<p v-if="installerData.checkMigrationStatus.progress_percentage">
Progress: {{ installerData.checkMigrationStatus.progress_percentage }}%
</p>
<hr>
</Message>
<Button
:label="t('Next')"
class="p-button-secondary"
:class="[installerData.isUpdateAvailable ? 'p-button-secondary' : 'p-button-success']"
icon="mdi mdi-page-next"
name="step1"
:name="installerData.isUpdateAvailable ? 'step5' : 'step1'"
type="submit"
/>
<input
id="is_executable"
name="is_executable"
type="hidden"
value="step1"
>
:value="!installerData.isUpdateAvailable ? 'step1' : '-'"
/>
</div>
</div>
</template>

@ -238,29 +238,21 @@
<div class="formgroup-inline">
<div class="field">
<Button
v-if="!installerData.isUpdateAvailable"
:label="t('Previous')"
class="p-button-secondary"
icon="mdi mdi-page-previous"
name="step4"
type="submit"
/>
<input
id="is_executable"
v-model="isExecutable"
name="is_executable"
type="hidden"
>
<input
type="hidden"
name="step6"
value="1"
>
<input id="is_executable" v-model="isExecutable" name="is_executable" type="hidden" />
<input type="hidden" name="step6" value="1" />
</div>
<Button
id="button_step6"
:label="t('Install Chamilo')"
:label="installerData.isUpdateAvailable ? t('Update Chamilo') : t('Install Chamilo')"
:loading="loading"
:disabled="isButtonDisabled"
class="p-button-success"
icon="mdi mdi-progress-download"
name="button_step6"
@ -303,6 +295,10 @@
/>
<ProgressBar mode="indeterminate" />
</Message>
<ProgressBar :value="progressPercentage" style="height: 22px"> {{ progressPercentage }}/100 </ProgressBar>
<div class="log-container">
<div v-html="logTerminalContent"></div>
</div>
</div>
</template>
@ -319,14 +315,39 @@ const { t } = useI18n();
const installerData = inject('installerData');
const loading = ref(false);
const isButtonDisabled = ref(installerData.value.isUpdateAvailable);
const isExecutable = ref('');
const logTerminalContent = ref('');
const progressPercentage = ref(0);
function updateLog() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
logTerminalContent.value = response.log_terminal;
progressPercentage.value = response.progress_percentage;
scrollToBottom();
isButtonDisabled.value = false;
}
};
xhr.open('GET', installerData.value.logUrl, true);
xhr.send();
}
function btnStep6OnClick() {
loading.value = true;
isExecutable.value = 'step6';
document.getElementById('install_form').submit();
}
function scrollToBottom() {
const logContainer = document.querySelector('.log-container');
logContainer.scrollTop = logContainer.scrollHeight;
}
setInterval(updateLog, 2000);
</script>

@ -3445,7 +3445,7 @@ class CourseManager
);
if (!empty($result)) {
if (1 == $result['value']) {
if (1 == $result['field_value']) {
return true;
}
}

@ -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);

@ -134,6 +134,7 @@ $upgradeFromVersion = [
'1.11.11',
'1.11.12',
'1.11.14',
'1.11.16',
];
$my_old_version = '';
@ -165,6 +166,8 @@ if (!empty($_POST['updatePath'])) {
$proposedUpdatePath = $_POST['updatePath'];
}
$checkMigrationStatus = checkMigrationStatus();
$isUpdateAvailable = isUpdateAvailable(api_get_path(SYS_PATH));
if (isset($_POST['step2_install']) || isset($_POST['step2_update_8']) || isset($_POST['step2_update_6'])) {
if (isset($_POST['step2_install'])) {
$installType = 'new';
@ -188,7 +191,7 @@ if (isset($_POST['step2_install']) || isset($_POST['step2_update_8']) || isset($
}
} elseif (isset($_POST['step1'])) {
$_POST['updatePath'] = '';
$installType = '';
$installType = $_GET['installType'] ?? '';
$updateFromConfigFile = '';
unset($_GET['running']);
} else {
@ -428,11 +431,24 @@ if (isset($_POST['step2'])) {
$stepData['institutionUrlForm'] = $institutionUrlForm;
$stepData['encryptPassForm'] = $encryptPassForm;
$isPendingMigration = ($isUpdateAvailable && false === $checkMigrationStatus['status']);
if ($isPendingMigration) {
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv = new Dotenv();
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv->loadEnv($envFile);
$stepData['dbHostForm'] = $_ENV['DATABASE_HOST'];
$stepData['dbPortForm'] = $_ENV['DATABASE_PORT'];
$stepData['dbUsernameForm'] = $_ENV['DATABASE_USER'];
$stepData['dbPassForm'] = str_repeat('*', api_strlen($_ENV['DATABASE_PASSWORD']));
$stepData['dbNameForm'] = $_ENV['DATABASE_NAME'];
} else {
$stepData['dbHostForm'] = $dbHostForm;
$stepData['dbPortForm'] = $dbPortForm;
$stepData['dbUsernameForm'] = $dbUsernameForm;
$stepData['dbPassForm'] = str_repeat('*', api_strlen($dbPassForm));
$stepData['dbNameForm'] = $dbNameForm;
}
} elseif (isset($_POST['step6'])) {
//STEP 6 : INSTALLATION PROCESS
$current_step = 7;
@ -452,10 +468,11 @@ if (isset($_POST['step2'])) {
$perm = octdec('0777');
$perm_file = octdec('0777');
if (!$isUpdateAvailable) {
$installType = 'update';
// Create .env.local file
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$distFile = api_get_path(SYMFONY_SYS_PATH) . '.env';
$params = [
'{{DATABASE_HOST}}' => $dbHostForm,
'{{DATABASE_PORT}}' => $dbPortForm,
@ -466,11 +483,16 @@ if (isset($_POST['step2'])) {
'{{APP_ENCRYPT_METHOD}}' => $encryptPassForm,
'{{APP_SECRET}}' => generateRandomToken(),
];
error_log('Update env file');
updateEnvFile($distFile, $envFile, $params);
(new Dotenv())->load($envFile);
} else {
$dotenv = new Dotenv();
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv->loadEnv($envFile);
}
// Load Symfony Kernel
$kernel = new Kernel('dev', true);
$application = new Application($kernel);
@ -629,6 +651,9 @@ if (isset($_POST['step2'])) {
$stepData['installationProfile'] = $installationProfile;
}
if ($isUpdateAvailable) {
$installType = 'update';
}
$installerData = [
'poweredBy' => 'Powered by <a href="https://chamilo.org" target="_blank">Chamilo</a> &copy; '.date('Y'),
@ -678,9 +703,10 @@ $installerData = [
'old_version' => api_htmlentities($my_old_version, ENT_QUOTES),
'new_version' => api_htmlentities($new_version, ENT_QUOTES),
'installationProfile' => api_htmlentities($installationProfile, ENT_QUOTES),
'currentStep' => $current_step,
'isUpdateAvailable' => $isUpdateAvailable,
'checkMigrationStatus' => $checkMigrationStatus,
'logUrl' => '/main/install/get_migration_status.php',
'stepData' => $stepData,
];
?>

@ -15,6 +15,7 @@ use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Query\Query;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
use Symfony\Component\Dotenv\Dotenv;
/*
* Chamilo LMS
@ -1347,21 +1348,21 @@ function migrate(EntityManager $manager)
$versionCounter = 1;
foreach ($versions as $version => $queries) {
$total = count($queries);
echo '----------------------------------------------<br />';
//echo '----------------------------------------------<br />';
$message = "VERSION: $version";
echo "$message<br/>";
//echo "$message<br/>";
error_log('-------------------------------------');
error_log($message);
$counter = 1;
foreach ($queries as $query) {
$sql = $query->getStatement();
echo "<code>$sql</code><br>";
//echo "<code>$sql</code><br>";
error_log("$counter/$total : $sql");
$counter++;
}
$versionCounter++;
}
echo '<br/>DONE!<br />';
//echo '<br/>DONE!<br />';
error_log('DONE!');
}
@ -1661,6 +1662,7 @@ function migrateSwitch($fromVersion, $manager, $processFiles = true)
case '1.11.10':
case '1.11.12':
case '1.11.14':
case '1.11.16':
$start = time();
// Migrate using the migration files located in:
// /srv/http/chamilo2/src/CoreBundle/Migrations/Schema/V200
@ -1724,3 +1726,110 @@ function checkCanCreateFile(string $file): bool
return false;
}
/**
* Checks if the update option is available.
*
* Checks the existence of the "app" folder and the "configuration.php" file
* to determine if an update is available from version 1.11.x.
*
* @param string $baseDir The base directory.
* @return bool True if the update is available, false otherwise.
*/
function isUpdateAvailable(string $baseDir): bool
{
// Path to the "app" folder
$appFolder = $baseDir.'/../app';
// Path to the "configuration.php" file
$configFile = $baseDir.'/../app/config/configuration.php';
// Check the existence of the "app" folder and the "configuration.php" file
return is_dir($appFolder) && file_exists($configFile);
}
function checkMigrationStatus(): array
{
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv = new Dotenv();
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv->loadEnv($envFile);
$database = connectToDatabase(
$_ENV['DATABASE_HOST'],
$_ENV['DATABASE_USER'],
$_ENV['DATABASE_PASSWORD'],
$_ENV['DATABASE_NAME'],
$_ENV['DATABASE_PORT']
);
$manager = $database->getManager();
$connection = $manager->getConnection();
// Loading migration configuration.
$config = new PhpFile('./migrations.php');
$dependency = DependencyFactory::fromConnection($config, new ExistingConnection($connection));
// Check if old "version" table exists from 1.11.x, use new version.
$schema = $manager->getConnection()->getSchemaManager();
$hasOldVersionTable = false;
$anyVersionYet = !$schema->tablesExist('version');
$isVersionEmpty = false;
$executedMigrations = 0;
$currentMigration = '';
if ($schema->tablesExist('version')) {
$columns = $schema->listTableColumns('version');
if (in_array('id', array_keys($columns), true)) {
$hasOldVersionTable = true;
}
$query = $connection->createQueryBuilder()
->select('*')
->from('version');
$result = $query->execute();
$executedMigrations = $result->rowCount();
$isVersionEmpty = ($executedMigrations == 0);
if (!$isVersionEmpty) {
$query = $connection->createQueryBuilder()
->select('*')
->from('version')
->orderBy('executed_at', 'DESC')
->setMaxResults(1);
$result = $query->execute()->fetch();
$currentMigration = $result['version'];
}
}
if (!$hasOldVersionTable) {
// Loading migrations.
$migratorConfigurationFactory = $dependency->getConsoleInputMigratorConfigurationFactory();
$result = '';
$input = new Symfony\Component\Console\Input\StringInput($result);
$planCalculator = $dependency->getMigrationPlanCalculator();
$migrations = $planCalculator->getMigrations();
$totalMigrations = $migrations->count();
$lastVersion = $migrations->getLast();
if ($anyVersionYet || $isVersionEmpty) {
$currentMigration = '';
$executedMigrations = 0;
}
// Calculate progress percentage
$progressPercentage = ceil(($executedMigrations / $totalMigrations) * 100);
$resultStatus = [
'status' => ($progressPercentage >= 100),
'message' => ($progressPercentage >= 100) ? 'All migrations have been executed.' : 'Migrations are pending.',
'current_migration' => ($progressPercentage >= 100) ? null : $currentMigration,
'progress_percentage' => $progressPercentage
];
} else {
$resultStatus = [
'status' => false,
'message' => 'Error executing migrations status command.',
'current_migration' => null,
'progress_percentage' => 0
];
}
return $resultStatus;
}

@ -183,6 +183,9 @@ class ResourceListener
}
if ($resource instanceof PersonalFile) {
if (null === $currentUser) {
$currentUser = $parentNode->getCreator();
}
$valid = $parentNode->getCreator()->getUsername() === $currentUser->getUsername() ||
$parentNode->getId() === $currentUser->getResourceNode()->getId();

@ -121,7 +121,7 @@ class ResourceNode implements Stringable
#[Assert\NotNull]
#[Groups(['resource_node:read', 'resource_node:write', 'document:write'])]
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'resourceNodes')]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\User::class, cascade: ["persist"], inversedBy: 'resourceNodes')]
#[ORM\JoinColumn(name: 'creator_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
protected User $creator;

@ -378,9 +378,17 @@ class Version20 extends AbstractMigrationChamilo
$this->addSql('CREATE TABLE IF NOT EXISTS ext_translations (id INT AUTO_INCREMENT NOT NULL, locale VARCHAR(8) NOT NULL, object_class VARCHAR(191) NOT NULL, field VARCHAR(32) NOT NULL, foreign_key VARCHAR(64) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX translations_lookup_idx (locale, object_class, foreign_key), UNIQUE INDEX lookup_unique_idx (locale, object_class, field, foreign_key), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;');
// Rename extra_field field_type and extra_field_type to item_type and value_type, also, the term "value" in exta_field_values.value renamed to field_value
$table = $schema->getTable('extra_field');
if (false === $table->hasColumn('extra_field_type')) {
$this->addSql('ALTER TABLE extra_field CHANGE extra_field_type item_type INT NOT NULL');
}
if (false === $table->hasColumn('field_type')) {
$this->addSql('ALTER TABLE extra_field CHANGE field_type value_type INT NOT NULL');
}
$table = $schema->getTable('extra_field_values');
if (false === $table->hasColumn('value')) {
$this->addSql('ALTER TABLE extra_field_values CHANGE `value` field_value LONGTEXT DEFAULT NULL');
}
// Drop unused columns
$dropColumnsAndIndex = [

@ -107,7 +107,7 @@ class Version20180319145700 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_survey_invitation CHANGE reminder_date reminder_date DATETIME DEFAULT NULL');
$this->addSql(
'UPDATE c_survey_invitation SET reminder_date = NULL WHERE CAST(reminder_date AS CHAR(20)) = "0000-00-00 00:00:00"'
'UPDATE c_survey_invitation SET reminder_date = NULL WHERE reminder_date = "0000-00-00 00:00:00"'
);
// c_survey_invitation.user_id

@ -24,10 +24,11 @@ class Version20180904175500 extends AbstractMigrationChamilo
$this->addSql('DELETE FROM track_e_exercises WHERE exe_user_id = 0 OR exe_user_id IS NULL');
$this->addSql('ALTER TABLE track_e_exercises CHANGE exe_user_id exe_user_id INT NOT NULL');
$this->addSql('ALTER TABLE track_e_exercises CHANGE session_id session_id INT DEFAULT NULL');
$this->addSql('UPDATE track_e_exercises SET session_id = NULL WHERE session_id = 0');
$this->addSql('DELETE FROM track_e_exercises WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)');
$this->addSql('ALTER TABLE track_e_exercises CHANGE session_id session_id INT NOT NULL');
if (!$schema->hasTable('attempt_file')) {
$this->addSql("CREATE TABLE attempt_file (id BINARY(16) NOT NULL COMMENT '(DC2Type:uuid)', attempt_id INT DEFAULT NULL, asset_id BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid)', comment LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetime)', INDEX IDX_4F22BDF0B191BE6B (attempt_id), INDEX IDX_4F22BDF05DA1941 (asset_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;");

@ -291,7 +291,7 @@ class Version20181025064351 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE gradebook_certificate ADD downloaded_at DATETIME DEFAULT NULL;');
$this->addSql(
'UPDATE gradebook_certificate gc SET downloaded_at = (
SELECT value from extra_field e
SELECT field_value from extra_field e
INNER JOIN extra_field_values v on v.field_id = e.id
WHERE variable = "downloaded_at" and item_type = 11 and item_id = gc.id
)'

@ -152,6 +152,7 @@ class Version20191101132000 extends AbstractMigrationChamilo
}
$filePath = $rootPath.'/app/upload/course_category/'.$category['image'];
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$fileName = basename($filePath);
$mimeType = mime_content_type($filePath);

@ -22,7 +22,7 @@ class Version20191206150000 extends AbstractMigrationChamilo
if (false === $table->hasColumn('helper_text')) {
$this->addSql('ALTER TABLE extra_field ADD helper_text text DEFAULT NULL AFTER display_text');
}
$this->addSql('ALTER TABLE extra_field_values CHANGE value value LONGTEXT DEFAULT NULL;');
$this->addSql('ALTER TABLE extra_field_values CHANGE field_value field_value LONGTEXT DEFAULT NULL;');
if (false === $table->hasColumn('description')) {
$this->addSql('ALTER TABLE extra_field ADD description LONGTEXT DEFAULT NULL');
}
@ -31,7 +31,7 @@ class Version20191206150000 extends AbstractMigrationChamilo
$this->addSql("UPDATE extra_field_values SET created_at = NOW() WHERE CAST(created_at AS CHAR(20)) = '0000-00-00 00:00:00'");
$this->addSql("UPDATE extra_field_values SET updated_at = NOW() WHERE CAST(updated_at AS CHAR(20)) = '0000-00-00 00:00:00'");
$this->addSql('ALTER TABLE extra_field_values MODIFY COLUMN value LONGTEXT NULL');
$this->addSql('ALTER TABLE extra_field_values MODIFY COLUMN field_value LONGTEXT NULL');
if (!$table->hasIndex('idx_efv_item')) {
$this->addSql('CREATE INDEX idx_efv_item ON extra_field_values (item_id)');

@ -43,6 +43,7 @@ class Version20191206150030 extends AbstractMigrationChamilo
continue;
}
$filePath = $rootPath.'/app/upload/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$fileName = basename($path);
$mimeType = mime_content_type($filePath);

@ -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';");
}
}
}
}

@ -88,7 +88,7 @@ final class Version20201212195011 extends AbstractMigrationChamilo
$extraFieldId = (int) $extraFieldId;
$sql = "SELECT DISTINCT(item_id)
FROM extra_field_values
WHERE field_id = $extraFieldId AND value = 1 ";
WHERE field_id = $extraFieldId AND field_value= 1 ";
$result = $connection->executeQuery($sql);
$specialCourses = $result->fetchAllAssociative();
if (!empty($specialCourses)) {

@ -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
{
}
}

@ -18,6 +18,7 @@ use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\EntityManager;
use DocumentManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -32,10 +33,12 @@ final class Version20201212203625 extends AbstractMigrationChamilo
{
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
/** @var EntityManager $em */
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
/* @var CDocumentRepository $documentRepo */
$documentRepo = $container->get(CDocumentRepository::class);
$courseRepo = $container->get(CourseRepository::class);
$attemptRepo = $em->getRepository(TrackEAttempt::class);
@ -68,7 +71,7 @@ final class Version20201212203625 extends AbstractMigrationChamilo
$path = str_replace('/../exercises/teacher_audio/', '', $path);
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/exercises/teacher_audio/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
preg_match('#/(.*)/#', '/'.$path, $matches);
if (isset($matches[1]) && !empty($matches[1])) {
@ -138,6 +141,7 @@ final class Version20201212203625 extends AbstractMigrationChamilo
$path = str_replace('/../exercises/', '', $path);
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/exercises/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$fileName = basename($filePath);
preg_match('#/(.*)/(.*)/(.*)/(.*)/#', '/'.$path, $matches);
@ -217,12 +221,14 @@ final class Version20201212203625 extends AbstractMigrationChamilo
$parent = null;
if ('.' !== \dirname($documentPath)) {
$parentId = (int) DocumentManager::get_document_id(
[
'real_id' => $courseId,
],
\dirname($documentPath)
);
$currentPath = \dirname($documentPath);
$sql = "SELECT iid FROM c_document
WHERE
c_id = {$courseId} AND
path LIKE '$currentPath'";
$result = $connection->executeQuery($sql);
$parentId = $result->fetchOne();
if (!empty($parentId)) {
$parent = $documentRepo->find($parentId);
}
@ -237,8 +243,9 @@ final class Version20201212203625 extends AbstractMigrationChamilo
if (false === $result) {
continue;
}
$documentPath = ltrim($documentPath, '/');
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/document/'.$documentPath;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $documentRepo, $document, $documentId);
$em->persist($document);

@ -127,6 +127,7 @@ final class Version20201215072918 extends AbstractMigrationChamilo
}
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/calendar/'.$attachmentPath;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $eventAttachmentRepo, $attachment, $id, $fileName);
$em->persist($attachment);
$em->flush();

@ -37,9 +37,6 @@ final class Version20201215141131 extends AbstractMigrationChamilo
$linkRepo = $container->get(CLinkRepository::class);
$linkCategoryRepo = $container->get(CLinkCategoryRepository::class);
$courseRepo = $container->get(CourseRepository::class);
$sessionRepo = $container->get(SessionRepository::class);
$groupRepo = $container->get(CGroupRepository::class);
$userRepo = $container->get(UserRepository::class);
$admin = $this->getAdmin();

@ -112,13 +112,11 @@ final class Version20201215153517 extends AbstractMigrationChamilo
$em->flush();
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/announcements/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $announcementAttachmentRepo, $resource, $id, $fileName);
$em->persist($resource);
$em->flush();
}
$em->flush();
$em->clear();
}
}
}

@ -139,6 +139,7 @@ final class Version20201215160445 extends AbstractMigrationChamilo
$forumImage = $itemData['forum_image'];
if (!empty($forumImage)) {
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/forum/images/'.$forumImage;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$this->addLegacyFileToResource($filePath, $forumRepo, $resource, $id, $forumImage);
}
@ -284,6 +285,7 @@ final class Version20201215160445 extends AbstractMigrationChamilo
if (!empty($fileName) && !empty($path)) {
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/forum/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$this->addLegacyFileToResource($filePath, $forumPostRepo, $post, $id, $fileName);
$em->persist($post);

@ -127,6 +127,7 @@ final class Version20201217124011 extends AbstractMigrationChamilo
}
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $studentPublicationRepo, $resource, $id, $title);
$em->persist($resource);
$em->flush();
@ -165,6 +166,7 @@ final class Version20201217124011 extends AbstractMigrationChamilo
$em->persist($correction);
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $studentPublicationCorrectionRepo, $correction, null, $title);
$em->persist($correction);
$em->flush();
@ -202,6 +204,7 @@ final class Version20201217124011 extends AbstractMigrationChamilo
$resource->addCourseLink($course, $session, $group, ResourceLink::VISIBILITY_PUBLISHED);
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/'.$file;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $studentPublicationRepo, $resource, $id, $title);
$em->persist($resource);
$em->flush();

@ -59,6 +59,7 @@ final class Version20210205082253 extends AbstractMigrationChamilo
$path = 'users/'.substr((string) $id, 0, 1).'/'.$id.'/';
}
$picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture;
error_log('MIGRATIONS :: $filePath -- '.$picturePath.' ...');
if ($this->fileExists($picturePath)) {
$mimeType = mime_content_type($picturePath);
$file = new UploadedFile($picturePath, $picture, $mimeType, null, true);
@ -125,6 +126,7 @@ final class Version20210205082253 extends AbstractMigrationChamilo
$path = 'groups/'.substr((string) $id, 0, 1).'/'.$id.'/';
}
$picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture;
error_log('MIGRATIONS :: $filePath -- '.$picturePath.' ...');
if ($this->fileExists($picturePath)) {
$mimeType = mime_content_type($picturePath);
$file = new UploadedFile($picturePath, $picture, $mimeType, null, true);

@ -47,6 +47,7 @@ class Version20210221082033 extends AbstractMigrationChamilo
$lp = $lpRepo->find($id);
if ($lp && !empty($path)) {
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path);
$em->persist($lp);

@ -47,6 +47,7 @@ class Version20210813150011 extends AbstractMigrationChamilo
}
$filePath = $rootPath.'/app/upload/badges/'.$icon;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$mimeType = mime_content_type($filePath);
$fileName = basename($filePath);

@ -43,7 +43,7 @@ final class Version20210923090920 extends AbstractMigrationChamilo
}
$picturePath = $rootPath.'/app/courses/'.$directory.'/course-pic.png';
error_log('MIGRATIONS :: $filePath -- '.$picturePath.' ...');
if ($this->fileExists($picturePath)) {
$admin = $this->getAdmin();
$mimeType = mime_content_type($picturePath);

@ -63,6 +63,7 @@ class Version20211005154000 extends AbstractMigrationChamilo
$attachmentRepo->create($messageAttachment);
$filePath = $rootPath.'/app/upload/ticket_attachment/'.$item['path'];
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
$this->addLegacyFileToResource($filePath, $attachmentRepo, $messageAttachment, $item['id']);
$em->persist($messageAttachment);

@ -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;'
);
}
}
}

@ -7,10 +7,12 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
use ExtraField;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class Version20230204150030 extends AbstractMigrationChamilo
@ -24,6 +26,7 @@ class Version20230204150030 extends AbstractMigrationChamilo
{
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
/* @var EntityManager $em */
$em = $doctrine->getManager();
$kernel = $container->get('kernel');
@ -40,7 +43,7 @@ class Version20230204150030 extends AbstractMigrationChamilo
'itemType' => ExtraField::SESSION_FIELD_TYPE,
]);
$sessionRepo = $container->get(Session::class);
$sessionRepo = $container->get(SessionRepository::class);
/** @var ExtraFieldValues $item */
foreach ($q->toIterable() as $item) {
$path = $item->getFieldValue();
@ -48,6 +51,7 @@ class Version20230204150030 extends AbstractMigrationChamilo
continue;
}
$filePath = $rootPath.'/app/upload/'.$path;
error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...');
if ($this->fileExists($filePath)) {
$fileName = basename($path);
$mimeType = mime_content_type($filePath);

@ -11,9 +11,12 @@ use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpRelUser;
use Chamilo\CourseBundle\Repository\CLpRelUserRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
@ -33,14 +36,14 @@ final class Version20230215072918 extends AbstractMigrationChamilo
/** @var Connection $connection */
$connection = $em->getConnection();
$lpRepo = $container->get(CLp::class);
$lpRepo = $container->get(CLpRepository::class);
/** @var CLpRelUserRepository $cLpRelUserRepo */
$cLpRelUserRepo = $container->get(CLpRelUser::class);
$cLpRelUserRepo = $container->get(CLpRelUserRepository::class);
$courseRepo = $container->get(CourseRepository::class);
$sessionRepo = $container->get(Session::class);
$userRepo = $container->get(User::class);
$sessionRepo = $container->get(SessionRepository::class);
$userRepo = $container->get(UserRepository::class);
/** @var Kernel $kernel */
$kernel = $container->get('kernel');

@ -17,16 +17,27 @@ final class Version20230216122950 extends AbstractMigrationChamilo
public function up(Schema $schema): void
{
if ($schema->hasTable('ticket_ticket')) {
$table = $schema->getTable('ticket_ticket');
if (!$table->hasColumn('exercise_id')) {
$this->addSql(
'ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL'
);
}
if (!$table->hasColumn('lp_id')) {
$this->addSql(
'ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL, ADD lp_id INT DEFAULT NULL'
'ALTER TABLE ticket_ticket ADD lp_id INT DEFAULT NULL'
);
}
}
if ($schema->hasTable('c_quiz_question_rel_category')) {
$table = $schema->getTable('c_quiz_question_rel_category');
if (!$table->hasColumn('mandatory')) {
$this->addSql(
'ALTER TABLE c_quiz_question_rel_category ADD COLUMN mandatory INT DEFAULT 0'
);
}
}
if (!$schema->hasTable('c_plagiarism_compilatio_docs')) {
$this->addSql(
@ -41,10 +52,13 @@ final class Version20230216122950 extends AbstractMigrationChamilo
}
if ($schema->hasTable('system_template')) {
$table = $schema->getTable('system_template');
if (!$table->hasColumn('language')) {
$this->addSql(
'ALTER TABLE system_template ADD language VARCHAR(40) NOT NULL DEFAULT "english"'
);
}
}
if (!$schema->hasTable('agenda_event_invitee')) {
$this->addSql(
@ -73,58 +87,13 @@ final class Version20230216122950 extends AbstractMigrationChamilo
);
}
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'
);
}
if (!$schema->hasTable('notification_event_rel_user')) {
$this->addSql(
'CREATE TABLE notification_event_rel_user (id INT UNSIGNED AUTO_INCREMENT NOT NULL, event_id INT unsigned, user_id INT, INDEX FK_EVENT (event_id), INDEX FK_USER (user_id), PRIMARY KEY (id))'
);
$this->addSql(
'ALTER TABLE notification_event_rel_user ADD CONSTRAINT FK_EVENT FOREIGN KEY (event_id) REFERENCES notification_event (id) ON DELETE CASCADE'
);
$this->addSql(
'ALTER TABLE notification_event_rel_user ADD CONSTRAINT FK_USER FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
}
if ($schema->hasTable('c_survey_answer')) {
$this->addSql(
'ALTER TABLE c_survey_answer ADD session_id INT NOT NULL, ADD c_lp_item_id INT NOT NULL'
);
}
if ($schema->hasTable('c_survey_invitation')) {
$this->addSql(
'ALTER TABLE c_survey_invitation ADD c_lp_item_id INT NOT NULL'
);
$this->addSql('CREATE TABLE notification_event_rel_user (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
event_id INT UNSIGNED,
user_id INT,
PRIMARY KEY (id)
)');
}
if (!$schema->hasTable('message_feedback')) {
@ -175,64 +144,15 @@ final class Version20230216122950 extends AbstractMigrationChamilo
);
}
if ($schema->hasTable('c_attendance_calendar')) {
$this->addSql(
'ALTER TABLE c_attendance_calendar ADD blocked TINYINT(1) DEFAULT NULL'
);
}
if ($schema->hasTable('c_attendance_sheet')) {
$this->addSql(
'ALTER TABLE c_attendance_sheet ADD signature VARCHAR(255) DEFAULT NULL'
);
}
if ($schema->hasTable('gradebook_category')) {
$this->addSql(
'ALTER TABLE gradebook_category ADD allow_skills_by_subcategory INT DEFAULT 1'
);
}
if ($schema->hasTable('c_quiz')) {
$this->addSql(
'ALTER TABLE c_quiz ADD hide_attempts_table TINYINT(1) NOT NULL'
);
}
if ($schema->hasTable('c_lp')) {
$this->addSql(
'ALTER TABLE c_lp ADD next_lp_id INT DEFAULT 0 NOT NULL'
);
}
}
public function down(Schema $schema): void
{
$table = $schema->getTable('c_lp');
if ($table->hasColumn('next_lp_id')) {
$this->addSql('ALTER TABLE c_lp DROP next_lp_id');
}
$table = $schema->getTable('c_quiz');
if ($table->hasColumn('hide_attempts_table')) {
$this->addSql('ALTER TABLE c_quiz DROP hide_attempts_table');
}
$table = $schema->getTable('gradebook_category');
if ($table->hasColumn('allow_skills_by_subcategory')) {
$this->addSql('ALTER TABLE c_attendance_sheet DROP allow_skills_by_subcategory');
}
$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');
}
if ($schema->hasTable('c_attendance_result_comment')) {
$this->addSql(
'DROP TABLE c_attendance_result_comment'
@ -274,37 +194,12 @@ final class Version20230216122950 extends AbstractMigrationChamilo
);
}
$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');
}
if ($schema->hasTable('notification_event_rel_user')) {
$this->addSql(
'DROP TABLE notification_event_rel_user'
);
}
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'
);
}
$table = $schema->getTable('system_template');
if ($table->hasColumn('language')) {
$this->addSql('ALTER TABLE system_template DROP language');

Loading…
Cancel
Save