Minor: Format code

pull/5106/head
Angel Fernando Quiroz Campos 10 months ago
parent cc2edd8bc2
commit a1993da2ba
  1. 43
      src/CoreBundle/Controller/Api/BaseResourceFileAction.php
  2. 1
      src/CoreBundle/Controller/Api/CreateDocumentFileAction.php
  3. 2
      src/CoreBundle/Migrations/Schema/V200/Version20170524120000.php
  4. 14
      src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php
  5. 2
      src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php
  6. 2
      src/CourseBundle/Entity/CDocument.php
  7. 3
      src/CourseBundle/Repository/CDocumentRepository.php

@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
use ZipArchive;
class BaseResourceFileAction
{
@ -184,7 +185,7 @@ class BaseResourceFileAction
/**
* Function loaded when creating a resource using the api, then the ResourceListener is executed.
*/
protected function handleCreateFileRequest(AbstractResource $resource, ResourceRepository $resourceRepository, Request $request, EntityManager $em, String $fileExistsOption = ''): array
protected function handleCreateFileRequest(AbstractResource $resource, ResourceRepository $resourceRepository, Request $request, EntityManager $em, string $fileExistsOption = ''): array
{
$contentData = $request->getContent();
@ -248,7 +249,7 @@ class BaseResourceFileAction
// Check if a document with the same title and parent resource node already exists
$existingDocument = $resourceRepository->findByTitleAndParentResourceNode($title, $parentResourceNodeId);
if ($existingDocument) {
if ($fileExistsOption == 'overwrite') {
if ('overwrite' == $fileExistsOption) {
// Perform actions when file exists and 'overwrite' option is selected
$resource->setResourceName($title);
$existingDocument->setTitle($title);
@ -264,7 +265,7 @@ class BaseResourceFileAction
];
}
if ($fileExistsOption == 'rename') {
if ('rename' == $fileExistsOption) {
// Perform actions when file exists and 'rename' option is selected
$newTitle = $this->generateUniqueTitle($title); // Generate a unique title
$resource->setResourceName($newTitle);
@ -283,7 +284,7 @@ class BaseResourceFileAction
];
}
if ($fileExistsOption == 'nothing') {
if ('nothing' == $fileExistsOption) {
// Perform actions when file exists and 'nothing' option is selected
// Display a message indicating that the file already exists
// or perform any other desired actions based on your application's requirements
@ -343,7 +344,7 @@ class BaseResourceFileAction
$fileType = $request->get('filetype');
$resourceLinkList = $request->get('resourceLinkList', []);
if (!empty($resourceLinkList)) {
$resourceLinkList = false === strpos($resourceLinkList, '[') ? json_decode('['.$resourceLinkList.']', true) : json_decode($resourceLinkList, true);
$resourceLinkList = !str_contains($resourceLinkList, '[') ? json_decode('['.$resourceLinkList.']', true) : json_decode($resourceLinkList, true);
if (empty($resourceLinkList)) {
$message = 'resourceLinkList is not a valid json. Use for example: [{"cid":1, "visibility":1}]';
@ -455,7 +456,7 @@ class BaseResourceFileAction
$documents = [];
foreach ($folderStructure as $key => $item) {
if (is_array($item)) {
if (\is_array($item)) {
$folderName = $key;
$subFolderStructure = $item;
@ -463,7 +464,7 @@ class BaseResourceFileAction
$document->setTitle($folderName);
$document->setFiletype('folder');
if ($parentResourceId !== null) {
if (null !== $parentResourceId) {
$document->setParentResourceNode($parentResourceId);
}
@ -477,10 +478,10 @@ class BaseResourceFileAction
$documentId = $document->getResourceNode()->getId();
$documents[$documentId] = [
'name' => $document->getTitle(),
'files' => []
'files' => [],
];
$subDocuments = $this->saveZipContentsAsDocuments($subFolderStructure, $em, $resourceLinkList, $documentId, $currentPath . $folderName . '/', $extractPath, $processedItems);
$subDocuments = $this->saveZipContentsAsDocuments($subFolderStructure, $em, $resourceLinkList, $documentId, $currentPath.$folderName.'/', $extractPath, $processedItems);
$documents[$documentId]['files'] = $subDocuments;
} else {
$fileName = $item;
@ -489,7 +490,7 @@ class BaseResourceFileAction
$document->setTitle($fileName);
$document->setFiletype('file');
if ($parentResourceId !== null) {
if (null !== $parentResourceId) {
$document->setParentResourceNode($parentResourceId);
}
@ -497,7 +498,7 @@ class BaseResourceFileAction
$document->setResourceLinkArray($resourceLinkList);
}
$filePath = $extractPath . '/'. $currentPath . $fileName;
$filePath = $extractPath.'/'.$currentPath.$fileName;
if (file_exists($filePath)) {
$uploadedFile = new UploadedFile(
@ -512,10 +513,11 @@ class BaseResourceFileAction
$documentId = $document->getResourceNode()->getId();
$documents[$documentId] = [
'name' => $document->getTitle(),
'files' => []
'files' => [],
];
} else {
error_log('File does not exist: ' . $filePath);
error_log('File does not exist: '.$filePath);
continue;
}
}
@ -530,11 +532,11 @@ class BaseResourceFileAction
$zipFilePath = $file->getRealPath();
// Create an instance of the ZipArchive class
$zip = new \ZipArchive();
$zip = new ZipArchive();
$zip->open($zipFilePath);
$cacheDirectory = $kernel->getCacheDir();
$extractPath = $cacheDirectory . '/' . uniqid('extracted_', true);
$extractPath = $cacheDirectory.'/'.uniqid('extracted_', true);
mkdir($extractPath);
// Extract the contents of the ZIP file
@ -546,7 +548,7 @@ class BaseResourceFileAction
// Iterate over each file or directory in the ZIP file
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$extractedPaths[] = $extractPath . '/' . $filename;
$extractedPaths[] = $extractPath.'/'.$filename;
}
// Close the ZIP file
@ -558,7 +560,7 @@ class BaseResourceFileAction
// Return the array of folder structure and the extraction path
return [
'folderStructure' => $folderStructure,
'extractPath' => $extractPath
'extractPath' => $extractPath,
];
}
@ -567,7 +569,7 @@ class BaseResourceFileAction
$folderStructure = [];
foreach ($paths as $path) {
$relativePath = str_replace($extractPath . '/', '', $path);
$relativePath = str_replace($extractPath.'/', '', $path);
$parts = explode('/', $relativePath);
$currentLevel = &$folderStructure;
@ -603,9 +605,6 @@ class BaseResourceFileAction
private function generateUniqueTitle(string $title): string
{
$uniqueTitle = $title . '_' . uniqid();
return $uniqueTitle;
return $title.'_'.uniqid();
}
}

@ -16,7 +16,6 @@ class CreateDocumentFileAction extends BaseResourceFileAction
{
public function __invoke(Request $request, CDocumentRepository $repo, EntityManager $em, KernelInterface $kernel): CDocument
{
$isUncompressZipEnabled = $request->get('isUncompressZipEnabled', 'false');
$fileExistsOption = $request->get('fileExistsOption', 'rename');

@ -33,12 +33,10 @@ final class Version20170524120000 extends AbstractMigrationChamilo
'CREATE UNIQUE INDEX UNIQ_4B019DDB2B36786B ON fos_group (title)'
);
}
}
public function down(Schema $schema): void
{
$table = $schema->getTable('fos_group');
if ($table->hasIndex('UNIQ_4B019DDB2B36786B')) {
$this->addSql(

@ -72,11 +72,11 @@ class Version20170625143000 extends AbstractMigrationChamilo
'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E972395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
);
}
if (false === $table->hasForeignKey('FK_62798E97163DDA15')) {
$this->addSql(
'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid) ON DELETE CASCADE'
);
}
/* if (false === $table->hasForeignKey('FK_62798E97163DDA15')) {
$this->addSql(
'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid) ON DELETE CASCADE'
);
}*/
if (false === $table->hasIndex('IDX_62798E97163DDA15')) {
$this->addSql('CREATE INDEX IDX_62798E97163DDA15 ON c_thematic_advance (attendance_id);');
}
@ -134,8 +134,8 @@ class Version20170625143000 extends AbstractMigrationChamilo
$this->addSql('DROP INDEX course ON c_link');
}
$this->addSql('ALTER TABLE c_link CHANGE on_homepage on_homepage VARCHAR(10) DEFAULT NULL');
$this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id = 0');
// $this->addSql('ALTER TABLE c_link CHANGE on_homepage on_homepage VARCHAR(10) DEFAULT NULL');
// $this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id = 0');
if (false === $table->hasForeignKey('FK_9209C2A012469DE2')) {
$this->addSql(

@ -219,7 +219,7 @@ final class Version20201212203625 extends AbstractMigrationChamilo
$course = $courseRepo->find($courseId);
/** @var CDocument $document */
$document = $documentRepo->find($documentId);
$ºdocument = $documentRepo->find($documentId);
if ($document->hasResourceNode()) {
continue;
}

@ -87,7 +87,7 @@ use Symfony\Component\Validator\Constraints as Assert;
'isUncompressZipEnabled' => ['type' => 'boolean'],
'fileExistsOption' => [
'type' => 'string',
'enum' => ['overwrite', 'skip', 'rename']
'enum' => ['overwrite', 'skip', 'rename'],
],
],
],

@ -87,7 +87,8 @@ final class CDocumentRepository extends ResourceRepository
->setParameter('parentResourceNodeId', $parentResourceNodeId)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
->getOneOrNullResult()
;
}
protected function addFileTypeQueryBuilder(string $fileType, QueryBuilder $qb = null): QueryBuilder

Loading…
Cancel
Save