4
4
5
5
namespace MauticPlugin \CustomObjectsBundle \Provider ;
6
6
7
+ use Doctrine \DBAL \Connection ;
8
+ use Doctrine \DBAL \Exception ;
7
9
use Mautic \CoreBundle \Helper \CoreParametersHelper ;
10
+ use MauticPlugin \CustomObjectsBundle \Entity \CustomObject ;
8
11
9
12
class ConfigProvider
10
13
{
11
14
/**
12
15
* @var string
13
16
*/
17
+ public const CONFIG_PLUGIN_NAME = 'CustomObjectsBundle ' ;
14
18
public const CONFIG_PARAM_ENABLED = 'custom_objects_enabled ' ;
15
19
public const CONFIG_PARAM_ITEM_VALUE_TO_CONTACT_RELATION_LIMIT = 'custom_object_item_value_to_contact_relation_limit ' ;
16
20
@@ -21,17 +25,38 @@ class ConfigProvider
21
25
*/
22
26
private $ coreParametersHelper ;
23
27
24
- public function __construct (CoreParametersHelper $ coreParametersHelper )
28
+ /**
29
+ * @var Connection
30
+ */
31
+ private $ connection ;
32
+
33
+ public function __construct (CoreParametersHelper $ coreParametersHelper , Connection $ connection )
25
34
{
26
35
$ this ->coreParametersHelper = $ coreParametersHelper ;
36
+ $ this ->connection = $ connection ;
27
37
}
28
38
29
39
/**
30
40
* Returns true if the Custom Objects plugin is enabled.
31
41
*/
32
42
public function pluginIsEnabled (): bool
33
43
{
34
- return (bool ) $ this ->coreParametersHelper ->get (self ::CONFIG_PARAM_ENABLED , true );
44
+ $ pluginEnabled = (bool ) $ this ->coreParametersHelper ->get (self ::CONFIG_PARAM_ENABLED , true );
45
+ if (!$ pluginEnabled ) {
46
+ return false ;
47
+ }
48
+
49
+ try {
50
+ $ pluginWasInstalledBefore = $ this ->connection
51
+ ->executeQuery ('SELECT id FROM plugins WHERE bundle=:pluginName ' , ['pluginName ' => self ::CONFIG_PLUGIN_NAME ])
52
+ ->rowCount ();
53
+ $ customObjectsTableExists = $ this ->connection
54
+ ->executeQuery ('SHOW TABLES LIKE :tableName ' , ['tableName ' => CustomObject::TABLE_NAME ])
55
+ ->rowCount ();
56
+ return $ pluginWasInstalledBefore && $ customObjectsTableExists ;
57
+ } catch (Exception $ e ) {
58
+ return false ;
59
+ }
35
60
}
36
61
37
62
public function isCustomObjectMergeFilterEnabled (): bool
0 commit comments