Skip to content

Commit b349f14

Browse files
committed
Migration: Fix plugin titles and remove plugins without a corresponding directory
1 parent 50f4505 commit b349f14

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

src/CoreBundle/Migrations/AbstractMigrationChamilo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Psr\Log\LoggerInterface;
3030
use Symfony\Component\DependencyInjection\ContainerInterface;
3131
use Symfony\Component\Filesystem\Filesystem;
32+
use Symfony\Component\Finder\Finder;
3233
use Symfony\Component\HttpFoundation\File\UploadedFile;
3334

3435
abstract class AbstractMigrationChamilo extends AbstractMigration
@@ -437,4 +438,20 @@ protected function getUpdateRootPath(): string
437438

438439
return $this->container->getParameter('kernel.project_dir');
439440
}
441+
442+
protected function getPluginDirectoryList(): array
443+
{
444+
$pluginDir = $this->container->getParameter('kernel.project_dir').'/public/plugin';
445+
446+
$finder = new Finder();
447+
$finder->directories()->in($pluginDir)->depth('== 0');
448+
449+
$directories = [];
450+
451+
foreach ($finder as $entry) {
452+
$directories[] = $entry->getFilename();
453+
}
454+
455+
return $directories;
456+
}
440457
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,4 @@ private function insertPluginSettingsByUrl(int $pluginId, array $settingsByUrl):
134134
);
135135
}
136136
}
137-
138-
private function getPluginDirectoryList(): array
139-
{
140-
$pluginDir = $this->container->getParameter('kernel.project_dir').'/public/plugin';
141-
142-
$finder = new Finder();
143-
$finder->directories()->in($pluginDir)->depth('== 0');
144-
145-
$directories = [];
146-
147-
foreach ($finder as $entry) {
148-
$directories[] = $entry->getFilename();
149-
}
150-
151-
return $directories;
152-
}
153137
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/* For licensing terms, see /license.txt */
4+
5+
declare(strict_types=1);
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use AppPlugin;
10+
use Chamilo\CoreBundle\Entity\Plugin;
11+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
12+
use Doctrine\DBAL\Schema\Schema;
13+
14+
class Version20251009111300 extends AbstractMigrationChamilo
15+
{
16+
public function getDescription(): string
17+
{
18+
return 'Fix plugin titles and remove plugins without a corresponding directory';
19+
}
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public function up(Schema $schema): void
25+
{
26+
$directories = $this->getPluginDirectoryList();
27+
$idListToDelete = [];
28+
29+
$pluginRows = $this->connection->executeQuery("SELECT id, title, source FROM plugin")->fetchAllAssociative();
30+
31+
foreach ($pluginRows as $pluginRow) {
32+
$title = str_replace(' ', '', ucwords(str_replace('_', ' ', $pluginRow['title'])));
33+
34+
if (!\in_array($title, $directories)) {
35+
$idListToDelete[] = $pluginRow['id'];
36+
37+
continue;
38+
}
39+
40+
$source = \in_array($title, AppPlugin::getOfficialPlugins())
41+
? Plugin::SOURCE_OFFICIAL
42+
: Plugin::SOURCE_THIRD_PARTY;
43+
44+
$this->connection->update(
45+
'plugin',
46+
[
47+
'title' => $title,
48+
'source' => $source,
49+
],
50+
['id' => $pluginRow['id']]
51+
);
52+
}
53+
54+
foreach ($idListToDelete as $idToDelete) {
55+
$this->connection->delete('access_url_rel_plugin', ['plugin_id' => $idToDelete]);
56+
$this->connection->delete('plugin', ['id' => $idToDelete]);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)