|
6 | 6 | * @author Julio Montoya <[email protected]> BeezNest 2012
|
7 | 7 | * @author Angel Fernando Quiroz Campos <[email protected]>
|
8 | 8 | */
|
| 9 | + |
| 10 | +use Chamilo\CoreBundle\Framework\Container; |
| 11 | + |
9 | 12 | $cidReset = true;
|
10 | 13 | require_once __DIR__.'/../inc/global.inc.php';
|
11 | 14 |
|
12 | 15 | api_protect_admin_script();
|
13 | 16 |
|
14 |
| -$pluginName = $_GET['name']; |
15 |
| -$appPlugin = new AppPlugin(); |
16 |
| -$installedPlugins = $appPlugin->getInstalledPlugins(); |
17 |
| -$pluginInfo = $appPlugin->getPluginInfo($pluginName, true); |
| 17 | +$pluginRepo = Container::getPluginRepository(); |
18 | 18 |
|
19 |
| -if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) { |
| 19 | +$plugin = $pluginRepo->getInstalledByName($_GET['plugin']); |
| 20 | + |
| 21 | +if (!$plugin) { |
20 | 22 | api_not_allowed(true);
|
21 | 23 | }
|
22 | 24 |
|
| 25 | +$accessUrl = Container::getAccessUrlHelper()->getCurrent(); |
| 26 | + |
| 27 | +$pluginConfiguration = $plugin->getConfigurationsByAccessUrl($accessUrl); |
| 28 | + |
| 29 | +$appPlugin = new AppPlugin(); |
| 30 | +$pluginInfo = $appPlugin->getPluginInfo($plugin->getTitle(), true); |
| 31 | + |
| 32 | +$em = Container::getEntityManager(); |
| 33 | + |
23 | 34 | $content = '';
|
24 |
| -$currentUrl = api_get_self()."?name=$pluginName"; |
| 35 | +$currentUrl = api_get_self()."?plugin={$plugin->getTitle()}"; |
25 | 36 |
|
26 | 37 | if (isset($pluginInfo['settings_form'])) {
|
27 | 38 | /** @var FormValidator $form */
|
28 | 39 | $form = $pluginInfo['settings_form'];
|
29 |
| - if (isset($form)) { |
30 |
| - // We override the form attributes |
31 |
| - $attributes = ['action' => $currentUrl, 'method' => 'POST']; |
32 |
| - $form->updateAttributes($attributes); |
| 40 | + if (!empty($form)) { |
| 41 | + $form->updateAttributes(['action' => $currentUrl, 'method' => 'POST']); |
33 | 42 | if (isset($pluginInfo['settings'])) {
|
34 | 43 | $form->setDefaults($pluginInfo['settings']);
|
35 | 44 | }
|
|
47 | 56 | $values = $form->getSubmitValues();
|
48 | 57 |
|
49 | 58 | // Fix only for bbb
|
50 |
| - if ('bbb' == $pluginName) { |
51 |
| - if (!isset($values['global_conference_allow_roles'])) { |
52 |
| - $values['global_conference_allow_roles'] = []; |
53 |
| - } |
| 59 | + if ('bbb' == $plugin->getTitle() && !isset($values['global_conference_allow_roles'])) { |
| 60 | + $values['global_conference_allow_roles'] = []; |
54 | 61 | }
|
55 | 62 |
|
56 |
| - $accessUrlId = api_get_current_access_url_id(); |
57 |
| - api_delete_settings_params( |
58 |
| - [ |
59 |
| - 'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => [ |
60 |
| - 'Plugins', |
61 |
| - $accessUrlId, |
62 |
| - $pluginName, |
63 |
| - 'setting', |
64 |
| - 'status', |
65 |
| - ], |
66 |
| - ] |
| 63 | + /** @var Plugin $objPlugin */ |
| 64 | + $objPlugin = $pluginInfo['obj']; |
| 65 | + |
| 66 | + /** @var array<int, string> $pluginFields */ |
| 67 | + $pluginFields = $objPlugin->getFieldNames(); |
| 68 | + |
| 69 | + $pluginConfiguration->setConfiguration( |
| 70 | + array_intersect_key($values, array_flip($pluginFields)) |
67 | 71 | );
|
68 | 72 |
|
69 |
| - foreach ($values as $key => $value) { |
70 |
| - api_add_setting( |
71 |
| - $value, |
72 |
| - $pluginName.'_'.$key, |
73 |
| - $pluginName, |
74 |
| - 'setting', |
75 |
| - 'Plugins', |
76 |
| - $pluginName, |
77 |
| - '', |
78 |
| - '', |
79 |
| - '', |
80 |
| - api_get_current_access_url_id(), |
81 |
| - 1 |
82 |
| - ); |
83 |
| - } |
| 73 | + $em->flush(); |
84 | 74 |
|
85 | 75 | Event::addEvent(
|
86 | 76 | LOG_PLUGIN_CHANGE,
|
87 | 77 | LOG_PLUGIN_SETTINGS_CHANGE,
|
88 |
| - $pluginName, |
| 78 | + $plugin->getTitle(), |
89 | 79 | api_get_utc_datetime(),
|
90 | 80 | api_get_user_id()
|
91 | 81 | );
|
92 | 82 |
|
93 |
| - if (!empty($pluginInfo['plugin_class'])) { |
94 |
| - /** @var \Plugin $objPlugin */ |
95 |
| - $objPlugin = $pluginInfo['plugin_class']::create(); |
96 |
| - $objPlugin->get_settings(true); |
97 |
| - $objPlugin->performActionsAfterConfigure(); |
| 83 | + $objPlugin->performActionsAfterConfigure(); |
98 | 84 |
|
99 |
| - if (isset($values['show_main_menu_tab'])) { |
100 |
| - $objPlugin->manageTab($values['show_main_menu_tab']); |
101 |
| - } |
| 85 | + if (isset($values['show_main_menu_tab'])) { |
| 86 | + $objPlugin->manageTab($values['show_main_menu_tab']); |
102 | 87 | }
|
103 | 88 |
|
104 | 89 | Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
|
|
120 | 105 | 'name' => get_lang('Plugins'),
|
121 | 106 | ];
|
122 | 107 |
|
123 |
| -$tpl = new Template($pluginName, true, true, false, true, false); |
| 108 | +$tpl = new Template($plugin->getTitle(), true, true, false, true, false); |
124 | 109 | $tpl->assign('content', $content);
|
125 | 110 | $tpl->display_one_col_template();
|
0 commit comments