forked from moskoweb/AMNameSanitizerBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AMNameSanitizerBundle.php
76 lines (66 loc) · 2.54 KB
/
AMNameSanitizerBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace MauticPlugin\AMNameSanitizerBundle;
use Doctrine\DBAL\Schema\Schema;
use Mautic\PluginBundle\Bundle\PluginBundleBase;
use Mautic\PluginBundle\Entity\Plugin;
use Mautic\CoreBundle\Factory\MauticFactory; //Is depracated and will be removed in Mautic 3.0
class AMNameSanitizerBundle extends PluginBundleBase
{
/**
* Called by PluginController::reloadAction when adding a new plugin that's not already installed
*
* @param Plugin $plugin
* @param MauticFactory $factory
* @param null $metadata
* @param null $installedSchema
*/
public static function onPluginInstall(Plugin $plugin, MauticFactory $factory, $metadata = null, $installedSchema = null)
{
if ($metadata !== null) {
self::installPluginSchema($metadata, $factory);
}
}
/**
* Called by PluginController::reloadAction when the plugin version does not match what's installed
*
* @param Plugin $plugin
* @param MauticFactory $factory
* @param null $metadata
* @param Schema $installedSchema
*
* @throws \Exception
*/
public static function onPluginUpdate(Plugin $plugin, MauticFactory $factory, $metadata = null, Schema $installedSchema = null)
{
$db = $factory->getDatabase();
$platform = $db->getDatabasePlatform()->getName();
$queries = array();
$fromVersion = $plugin->getVersion();
// Simple example - Altering database structure on the plugin update. $fromVersion receives the actual version of the plugin and do the queries acording to it.
switch ($fromVersion) {
case '1.0':
switch ($platform) {
//Commented for future changes
case 'mysql':
//$queries[] = 'ALTER TABLE ' . MAUTIC_TABLE_PREFIX . 'worlds CHANGE CHANGE description description LONGTEXT DEFAULT NULL';
break;
case 'postgresql':
//$queries[] = 'ALTER TABLE ' . MAUTIC_TABLE_PREFIX . 'worlds ALTER description ALTER TYPE TEXT';
break;
}
break;
}
if ( ! empty($queries)) {
$db->beginTransaction();
try {
foreach ($queries as $q) {
$db->query($q);
}
$db->commit();
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
}
}
}