Skip to content

Commit

Permalink
Internal: Migration: Create shortcut for lp and lp categories publish…
Browse files Browse the repository at this point in the history
…ed on home #5088
  • Loading branch information
AngelFQC committed Jun 27, 2024
1 parent b3d90e3 commit 0b1e3ff
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function up(Schema $schema): void
}

if ($table->hasColumn('link')) {
$lpTools = $this->connection
->prepare("SELECT c_id, session_id, link FROM c_tool WHERE link LIKE '%lp_controller.php%'")
->executeQuery()
->fetchAllAssociative();

Check warning on line 54 in src/CoreBundle/Migrations/Schema/V200/Version20180928172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20180928172830.php#L51-L54

Added lines #L51 - L54 were not covered by tests

$this->writeFile('tool_links', serialize($lpTools));

Check warning on line 56 in src/CoreBundle/Migrations/Schema/V200/Version20180928172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20180928172830.php#L56

Added line #L56 was not covered by tests

$this->addSql('ALTER TABLE c_tool DROP link');
}

Expand Down
72 changes: 72 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CShortcutRepository;
use Doctrine\DBAL\Schema\Schema;

class Version20240327172830 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Create shortcuts for c_lp and c_lp_category published on course home';
}

public function up(Schema $schema): void

Check warning on line 22 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L22

Added line #L22 was not covered by tests
{
// File generated in the Version20180928172830 migration
$toolLinksContent = $this->readFile('tool_links');

Check warning on line 25 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L25

Added line #L25 was not covered by tests

if (empty($toolLinksContent)) {
$this->write('tool_links file not found. Exiting.');

Check warning on line 28 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L27-L28

Added lines #L27 - L28 were not covered by tests

return;

Check warning on line 30 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L30

Added line #L30 was not covered by tests
}

$toolLinks = unserialize($toolLinksContent);

Check warning on line 33 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L33

Added line #L33 was not covered by tests

$lpRepo = $this->container->get(CLpRepository::class);
$lpCategoryRepo = $this->container->get(CLpCategoryRepository::class);
$shortcutRepo = $this->container->get(CShortcutRepository::class);

Check warning on line 37 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L35-L37

Added lines #L35 - L37 were not covered by tests

foreach ($toolLinks as $toolLink) {
$url = parse_url($toolLink['link']);
$query = [];
parse_str($url['query'] ?? '', $query);

Check warning on line 42 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L39-L42

Added lines #L39 - L42 were not covered by tests

$admin = $this->getAdmin();
$course = $this->findCourse($toolLink['c_id']);
$session = $this->findSession($toolLink['session_id']);
$resource = null;

Check warning on line 47 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L44-L47

Added lines #L44 - L47 were not covered by tests

if (str_contains($url['path'], 'lp_controller.php') && isset($query['action'])) {
if (isset($query['lp_id']) && 'view' === $query['action']) {
$resource = $lpRepo->find($query['lp_id']);
} elseif (isset($query['id']) && 'view_category' === $query['action']) {
$resource = $lpCategoryRepo->find($query['id']);

Check warning on line 53 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L49-L53

Added lines #L49 - L53 were not covered by tests
}
}

if ($resource) {
$shortcut = $shortcutRepo->getShortcutFromResource($resource);

Check warning on line 58 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L57-L58

Added lines #L57 - L58 were not covered by tests

if ($shortcut) {
continue;

Check warning on line 61 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L60-L61

Added lines #L60 - L61 were not covered by tests
}

$shortcutRepo->addShortCut($resource, $admin, $course, $session);

Check warning on line 64 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L64

Added line #L64 was not covered by tests
}
}

$this->entityManager->flush();

Check warning on line 68 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L68

Added line #L68 was not covered by tests

$this->removeFile('tool_links');

Check warning on line 70 in src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php#L70

Added line #L70 was not covered by tests
}
}

0 comments on commit 0b1e3ff

Please sign in to comment.