From 379b5b59821bb16d6767caad693460f0f07f0f1b Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Sat, 13 Jan 2024 15:27:57 -0500 Subject: [PATCH] Migration: Change default disk quota to MB and migration --- .../Schema/V200/Version20240112103400.php | 20 +++++++++++++++++-- .../Settings/DocumentSettingsSchema.php | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240112103400.php b/src/CoreBundle/Migrations/Schema/V200/Version20240112103400.php index fb4554fb31..8daec51b09 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240112103400.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240112103400.php @@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; +use Chamilo\CoreBundle\Repository\SettingsCurrentRepository; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Schema; @@ -28,18 +29,33 @@ final class Version20240112103400 extends AbstractMigrationChamilo $kernel = $container->get('kernel'); $rootPath = $kernel->getProjectDir(); + $settingRepo = $container->get(SettingsCurrentRepository::class); + $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); /** @var Course $course */ foreach ($q->toIterable() as $course) { $diskQuotaInBytes = $course->getDiskQuota(); - if (null !== $diskQuotaInBytes) { + if ($diskQuotaInBytes !== null) { $diskQuotaInMegabytes = $diskQuotaInBytes / (1024 * 1024); $course->setDiskQuota($diskQuotaInMegabytes); $em->persist($course); } + } + $em->flush(); - $em->flush(); + $setting = $settingRepo->findOneBy(['variable' => 'default_document_quotum']); + if ($setting) { + $selectedValueInBytes = (int) $setting->getSelectedValue() / (1024 * 1024); + $setting->setSelectedValue((string) $selectedValueInBytes); } + + $setting = $settingRepo->findOneBy(['variable' => 'default_group_quotum']); + if ($setting) { + $selectedValueInBytes = (int) $setting->getSelectedValue() / (1024 * 1024); + $setting->setSelectedValue((string) $selectedValueInBytes); + } + $em->flush(); + } } diff --git a/src/CoreBundle/Settings/DocumentSettingsSchema.php b/src/CoreBundle/Settings/DocumentSettingsSchema.php index cb781f0688..616f6cb568 100644 --- a/src/CoreBundle/Settings/DocumentSettingsSchema.php +++ b/src/CoreBundle/Settings/DocumentSettingsSchema.php @@ -20,8 +20,8 @@ class DocumentSettingsSchema extends AbstractSettingsSchema $builder ->setDefaults( [ - 'default_document_quotum' => '1048576000', - 'default_group_quotum' => '262144000', + 'default_document_quotum' => '1000', + 'default_group_quotum' => '250', 'permanently_remove_deleted_files' => 'false', 'upload_extensions_list_type' => 'blacklist', 'upload_extensions_blacklist' => '',