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
|
|
|
} |
60
|
|
|
|