-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Migration: Create shortcut for lp and lp categories publish…
…ed on home #5088
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/CoreBundle/Migrations/Schema/V200/Version20240327172830.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
// File generated in the Version20180928172830 migration | ||
$toolLinksContent = $this->readFile('tool_links'); | ||
|
||
if (empty($toolLinksContent)) { | ||
$this->write('tool_links file not found. Exiting.'); | ||
|
||
return; | ||
} | ||
|
||
$toolLinks = unserialize($toolLinksContent); | ||
|
||
$lpRepo = $this->container->get(CLpRepository::class); | ||
$lpCategoryRepo = $this->container->get(CLpCategoryRepository::class); | ||
$shortcutRepo = $this->container->get(CShortcutRepository::class); | ||
|
||
foreach ($toolLinks as $toolLink) { | ||
$url = parse_url($toolLink['link']); | ||
$query = []; | ||
parse_str($url['query'] ?? '', $query); | ||
|
||
$admin = $this->getAdmin(); | ||
$course = $this->findCourse($toolLink['c_id']); | ||
$session = $this->findSession($toolLink['session_id']); | ||
$resource = null; | ||
|
||
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']); | ||
} | ||
} | ||
|
||
if ($resource) { | ||
$shortcut = $shortcutRepo->getShortcutFromResource($resource); | ||
|
||
if ($shortcut) { | ||
continue; | ||
} | ||
|
||
$shortcutRepo->addShortCut($resource, $admin, $course, $session); | ||
} | ||
} | ||
|
||
$this->entityManager->flush(); | ||
|
||
$this->removeFile('tool_links'); | ||
} | ||
} |