Skip to content

Commit f80f244

Browse files
committed
Merge branch 'master' of github.com:chamilo/chamilo-lms
2 parents 9375243 + 92d1f3f commit f80f244

File tree

11 files changed

+60
-46
lines changed

11 files changed

+60
-46
lines changed

src/CoreBundle/Command/AzureSyncAbstractCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function getAzureUsers(): Generator
9696
$this->providerParams['script_users_delta'] ? "/v1.0/users/delta?$query" : "/v1.0/users?$query",
9797
$token
9898
);
99-
} catch (GuzzleException|Exception $e) {
99+
} catch (Exception|GuzzleException $e) {
100100
throw new Exception('Exception when requesting users from Azure: '.$e->getMessage());
101101
}
102102

@@ -148,7 +148,7 @@ protected function getAzureGroupMembers(string $groupUid): Generator
148148
"/v1.0/groups/$groupUid/members?$query",
149149
$token
150150
);
151-
} catch (GuzzleException|Exception $e) {
151+
} catch (Exception|GuzzleException $e) {
152152
throw new Exception('Exception when requesting group members from Azure: '.$e->getMessage());
153153
}
154154

src/CoreBundle/Entity/TicketPriority.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getCode()
8181
return $this->code;
8282
}
8383

84-
public function setCode(string|int $code): self
84+
public function setCode(int|string $code): self
8585
{
8686
$this->code = (string) $code;
8787

src/CoreBundle/Entity/TicketStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getCode()
4343
return $this->code;
4444
}
4545

46-
public function setCode(string|int $code): self
46+
public function setCode(int|string $code): self
4747
{
4848
$this->code = (string) $code;
4949

src/CoreBundle/Framework/Container.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
use Chamilo\CoreBundle\Serializer\UserToJsonNormalizer;
5151
use Chamilo\CoreBundle\Settings\SettingsManager;
5252
use Chamilo\CoreBundle\Tool\ToolChain;
53-
use Chamilo\CourseBundle\Entity\CDropboxFile;
5453
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
5554
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
5655
use Chamilo\CourseBundle\Repository\CAttendanceRepository;
@@ -233,7 +232,7 @@ public static function getAuthorizationChecker(): AuthorizationCheckerInterface
233232
return self::getLegacyHelper()->getAuthorizationChecker();
234233
}
235234

236-
public static function getTokenStorage(): TokenStorageInterface|TokenStorage
235+
public static function getTokenStorage(): TokenStorage|TokenStorageInterface
237236
{
238237
return self::getLegacyHelper()->getTokenStorage();
239238
}

src/CoreBundle/Helpers/ChamiloHelper.php

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use DateTime;
1717
use DateTimeZone;
1818
use Display;
19+
use DocumentManager;
1920
use Event;
2021
use Exception;
2122
use ExtraFieldValue;
@@ -24,6 +25,7 @@
2425
use MessageManager;
2526
use Symfony\Component\HttpFoundation\File\UploadedFile;
2627
use Template;
28+
use Throwable;
2729
use UserManager;
2830

2931
use const PHP_ROUND_HALF_UP;
@@ -696,26 +698,29 @@ public static function addLegacyFileToResource(
696698

697699
if (!self::legacyFileUsable($filePath)) {
698700
error_log("LEGACY_FILE: Cannot attach to {$class} – file not found or unreadable: {$basename}");
701+
699702
return false;
700703
}
701704

702705
// If the repository doesn't expose addFile(), use the Asset flow.
703706
if (!method_exists($repo, 'addFile')) {
704-
error_log("LEGACY_FILE: Repository ".get_class($repo)." has no addFile(), falling back to Asset flow");
707+
error_log('LEGACY_FILE: Repository '.$repo::class.' has no addFile(), falling back to Asset flow');
708+
705709
return self::attachLegacyFileToResource($filePath, $resource, $fileName);
706710
}
707711

708712
try {
709713
$mimeType = self::legacyDetectMime($filePath);
710-
$finalName = $fileName !== '' ? $fileName : $basename;
714+
$finalName = '' !== $fileName ? $fileName : $basename;
711715

712716
// UploadedFile in "test mode" (last arg true) avoids PHP upload checks.
713717
$uploaded = new UploadedFile($filePath, $finalName, $mimeType, null, true);
714718
$repo->addFile($resource, $uploaded, $description);
715719

716720
return true;
717-
} catch (\Throwable $e) {
718-
error_log("LEGACY_FILE EXCEPTION (addFile): ".$e->getMessage());
721+
} catch (Throwable $e) {
722+
error_log('LEGACY_FILE EXCEPTION (addFile): '.$e->getMessage());
723+
719724
return false;
720725
}
721726
}
@@ -736,11 +741,13 @@ public static function attachLegacyFileToResource(
736741

737742
if (!self::legacyFileUsable($filePath)) {
738743
error_log("LEGACY_FILE: Cannot attach Asset to {$class} – file not found or unreadable: {$basename}");
744+
739745
return false;
740746
}
741747

742748
if (!method_exists($resource, 'getResourceNode') || null === $resource->getResourceNode()) {
743749
error_log("LEGACY_FILE: Resource has no ResourceNode – cannot attach Asset (class: {$class})");
750+
744751
return false;
745752
}
746753

@@ -751,22 +758,23 @@ public static function attachLegacyFileToResource(
751758
if (method_exists($assetRepo, 'createFromLocalPath')) {
752759
$asset = $assetRepo->createFromLocalPath(
753760
$filePath,
754-
$fileName !== '' ? $fileName : $basename
761+
'' !== $fileName ? $fileName : $basename
755762
);
756763
} else {
757764
// Fallback: simulate an upload-like array for createFromRequest().
758765
$mimeType = self::legacyDetectMime($filePath);
759766
$fakeUpload = [
760767
'tmp_name' => $filePath,
761-
'name' => $fileName !== '' ? $fileName : $basename,
762-
'type' => $mimeType,
763-
'size' => @filesize($filePath) ?: null,
764-
'error' => 0,
768+
'name' => '' !== $fileName ? $fileName : $basename,
769+
'type' => $mimeType,
770+
'size' => @filesize($filePath) ?: null,
771+
'error' => 0,
765772
];
766773

767774
$asset = (new Asset())
768775
->setTitle($fakeUpload['name'])
769-
->setCompressed(false);
776+
->setCompressed(false)
777+
;
770778

771779
// AssetRepository::createFromRequest(Asset $asset, array $uploadLike)
772780
$assetRepo->createFromRequest($asset, $fakeUpload);
@@ -775,20 +783,24 @@ public static function attachLegacyFileToResource(
775783
// Attach to the resource's node.
776784
if (method_exists($assetRepo, 'attachToNode')) {
777785
$assetRepo->attachToNode($asset, $resource->getResourceNode());
786+
778787
return true;
779788
}
780789

781790
// If the resource repository exposes a direct helper:
782791
$repo = self::guessResourceRepository($resource);
783792
if ($repo && method_exists($repo, 'attachAssetToResource')) {
784793
$repo->attachAssetToResource($resource, $asset);
794+
785795
return true;
786796
}
787797

788-
error_log("LEGACY_FILE: No method to attach Asset to node (missing attachToNode/attachAssetToResource)");
798+
error_log('LEGACY_FILE: No method to attach Asset to node (missing attachToNode/attachAssetToResource)');
799+
789800
return false;
790-
} catch (\Throwable $e) {
791-
error_log("LEGACY_FILE EXCEPTION (Asset attach): ".$e->getMessage());
801+
} catch (Throwable $e) {
802+
error_log('LEGACY_FILE EXCEPTION (Asset attach): '.$e->getMessage());
803+
792804
return false;
793805
}
794806
}
@@ -804,6 +816,7 @@ public static function firstExistingPath(array $candidates): ?string
804816
return $p;
805817
}
806818
}
819+
807820
return null;
808821
}
809822

@@ -815,6 +828,7 @@ private static function legacyFileUsable(string $filePath): bool
815828
private static function legacyDetectMime(string $filePath): string
816829
{
817830
$mime = @mime_content_type($filePath);
831+
818832
return $mime ?: 'application/octet-stream';
819833
}
820834

@@ -825,10 +839,11 @@ private static function legacyDetectMime(string $filePath): string
825839
private static function guessResourceRepository(AbstractResource $resource): ?ResourceRepository
826840
{
827841
try {
828-
$em = \Database::getManager();
829-
$repo = $em->getRepository(get_class($resource));
842+
$em = Database::getManager();
843+
$repo = $em->getRepository($resource::class);
844+
830845
return $repo instanceof ResourceRepository ? $repo : null;
831-
} catch (\Throwable $e) {
846+
} catch (Throwable $e) {
832847
return null;
833848
}
834849
}
@@ -842,7 +857,7 @@ public static function attachLegacyFileWithPublicUrl(
842857
AbstractResource $ownerResource,
843858
string $fileName = ''
844859
): array {
845-
$basename = $fileName !== '' ? $fileName : basename($filePath);
860+
$basename = '' !== $fileName ? $fileName : basename($filePath);
846861

847862
if (!self::legacyFileUsable($filePath)) {
848863
return ['ok' => false, 'asset' => null, 'url' => null, 'error' => "File not found or unreadable: $basename"];
@@ -858,25 +873,25 @@ public static function attachLegacyFileWithPublicUrl(
858873
$mimeType = self::legacyDetectMime($filePath);
859874
$fakeUpload = [
860875
'tmp_name' => $filePath,
861-
'name' => $basename,
862-
'type' => $mimeType,
863-
'size' => @filesize($filePath) ?: null,
864-
'error' => 0,
876+
'name' => $basename,
877+
'type' => $mimeType,
878+
'size' => @filesize($filePath) ?: null,
879+
'error' => 0,
865880
];
866881
$asset = (new Asset())->setTitle($basename)->setCompressed(false);
867882
$assetRepo->createFromRequest($asset, $fakeUpload);
868883
}
869884

870885
if (!method_exists($ownerResource, 'getResourceNode') || null === $ownerResource->getResourceNode()) {
871-
return ['ok' => false, 'asset' => null, 'url' => null, 'error' => "Owner resource has no ResourceNode"];
886+
return ['ok' => false, 'asset' => null, 'url' => null, 'error' => 'Owner resource has no ResourceNode'];
872887
}
873888

874889
if (method_exists($assetRepo, 'attachToNode')) {
875890
$assetRepo->attachToNode($asset, $ownerResource->getResourceNode());
876891
} else {
877892
$repo = self::guessResourceRepository($ownerResource);
878893
if (!$repo || !method_exists($repo, 'attachAssetToResource')) {
879-
return ['ok' => false, 'asset' => $asset, 'url' => null, 'error' => "No way to attach asset to node"];
894+
return ['ok' => false, 'asset' => $asset, 'url' => null, 'error' => 'No way to attach asset to node'];
880895
}
881896
$repo->attachAssetToResource($ownerResource, $asset);
882897
}
@@ -890,8 +905,7 @@ public static function attachLegacyFileWithPublicUrl(
890905
}
891906

892907
return ['ok' => true, 'asset' => $asset, 'url' => $url, 'error' => null];
893-
894-
} catch (\Throwable $e) {
908+
} catch (Throwable $e) {
895909
return ['ok' => false, 'asset' => null, 'url' => null, 'error' => $e->getMessage()];
896910
}
897911
}
@@ -906,11 +920,11 @@ public static function rewriteLegacyCourseUrlsToAssets(
906920
string $backupRoot,
907921
array $extraRoots = []
908922
): string {
909-
if ($html === '') {
923+
if ('' === $html) {
910924
return $html;
911925
}
912926

913-
$sources = \DocumentManager::get_resources_from_source_html($html, false, TOOL_DOCUMENT, 1);
927+
$sources = DocumentManager::get_resources_from_source_html($html, false, TOOL_DOCUMENT, 1);
914928
if (empty($sources)) {
915929
return $html;
916930
}
@@ -919,16 +933,16 @@ public static function rewriteLegacyCourseUrlsToAssets(
919933

920934
foreach ($sources as $s) {
921935
[$realUrl, $scope, $kind] = $s;
922-
if ($scope !== 'local') {
936+
if ('local' !== $scope) {
923937
continue;
924938
}
925939

926940
$pos = strpos($realUrl, 'document/');
927-
if ($pos === false) {
941+
if (false === $pos) {
928942
continue;
929943
}
930944

931-
$relAfterDocument = ltrim(substr($realUrl, $pos + strlen('document/')), '/');
945+
$relAfterDocument = ltrim(substr($realUrl, $pos + \strlen('document/')), '/');
932946

933947
$candidates = [];
934948
foreach ($roots as $root) {
@@ -944,7 +958,8 @@ public static function rewriteLegacyCourseUrlsToAssets(
944958

945959
$attached = self::attachLegacyFileWithPublicUrl($filePath, $ownerResource, basename($filePath));
946960
if (!$attached['ok'] || empty($attached['url'])) {
947-
error_log("LEGACY_REWRITE: failed for $realUrl (".$attached['error'].")");
961+
error_log("LEGACY_REWRITE: failed for $realUrl (".$attached['error'].')');
962+
948963
continue;
949964
}
950965

src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class Version20251006172700 extends AbstractMigrationChamilo
1313
{
1414
public function getDescription(): string
1515
{
16-
return "Add survey setting: show_pending_survey_in_menu=false";
16+
return 'Add survey setting: show_pending_survey_in_menu=false';
1717
}
1818

1919
public function up(Schema $schema): void
@@ -27,7 +27,7 @@ public function up(Schema $schema): void
2727
$sqlCheck = "SELECT COUNT(*) AS c FROM settings WHERE variable = '$variable'";
2828
$result = $this->connection->executeQuery($sqlCheck)->fetchAssociative();
2929

30-
if ($result && (int)$result['c'] > 0) {
30+
if ($result && (int) $result['c'] > 0) {
3131
$this->addSql("
3232
UPDATE settings
3333
SET title = '$title',
@@ -57,6 +57,6 @@ public function down(Schema $schema): void
5757
AND subkey IS NULL
5858
AND access_url = 1
5959
");
60-
$this->write("Removed setting: show_pending_survey_in_menu");
60+
$this->write('Removed setting: show_pending_survey_in_menu');
6161
}
6262
}

src/CoreBundle/Repository/ExtraFieldRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getExtraFields(int $type): array
4040
return $qb->getQuery()->getResult();
4141
}
4242

43-
public function getHandlerFieldInfoByFieldVariable(string $variable, int $itemType): bool|array
43+
public function getHandlerFieldInfoByFieldVariable(string $variable, int $itemType): array|bool
4444
{
4545
$extraField = $this->findOneBy([
4646
'variable' => $variable,

src/CoreBundle/Repository/ExtraFieldValuesRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ public function findLegalAcceptByItemId($itemId)
151151
*/
152152
public function findByVariableAndValue(
153153
ExtraField $extraField,
154-
string|int $value,
154+
int|string $value,
155155
bool $last = false,
156156
bool $all = false,
157157
bool $useLike = false,
158-
): ExtraFieldValues|array|null {
158+
): array|ExtraFieldValues|null {
159159
$qb = $this->createQueryBuilder('s');
160160

161161
if ($useLike) {

src/CoreBundle/Repository/LegalRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getLastConditionByLanguage(int $languageId): ?Legal
142142
}
143143

144144
return $result;
145-
} catch (NoResultException|NonUniqueResultException $e) {
145+
} catch (NonUniqueResultException|NoResultException $e) {
146146
return null;
147147
}
148148
}

src/CoreBundle/State/LpCollectionStateProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function supports(Operation $op, array $uriVariables = [], array $ctx = [
3232
return CLp::class === $op->getClass() && 'get_lp_collection_with_progress' === $op->getName();
3333
}
3434

35-
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
35+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
3636
{
3737
$f = $context['filters'] ?? [];
3838
$parentNodeId = (int) ($f['resourceNode.parent'] ?? 0);

0 commit comments

Comments
 (0)