Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file keeps track of upgrades to the edusharing module
19
 *
20
 * Sometimes, changes between versions involve alterations to database
21
 * structures and other major things that may break installations. The upgrade
22
 * function in this file will attempt to perform all the necessary actions to
23
 * upgrade your older installation to the current version. If there's something
24
 * it cannot do itself, it will tell you what you need to do.  The commands in
25
 * here will all be database-neutral, using the functions defined in
26
 * lib/ddllib.php
27
 *
28
 * @package    mod_edusharing
29
 * @copyright  metaVentis GmbH — http://metaventis.com
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
 
33
use mod_edusharing\EduSharingService;
34
use mod_edusharing\InstallUpgradeLogic;
35
use mod_edusharing\MetadataLogic;
36
use mod_edusharing\PluginRegistration;
37
use mod_edusharing\UtilityFunctions;
38
 
39
/**
40
 * xmldb_edusharing_upgrade
41
 *
42
 * @param int $oldversion
43
 * @return bool
44
 */
45
function xmldb_edusharing_upgrade($oldversion=0): bool {
46
    global $CFG, $DB;
47
    $dbmanager = $DB->get_manager();
48
    $result    = true;
49
    if ($oldversion < 2016011401) {
50
        // Usage2.
51
        try {
52
            $xmldbtable = new xmldb_table('edusharing');
53
            $sql        = 'UPDATE {edusharing} SET object_version = 0 WHERE window_versionshow = 1';
54
            $DB->execute($sql);
55
            $sql = 'UPDATE {edusharing} SET object_version = window_version WHERE window_versionshow = 0';
56
            $DB->execute($sql);
57
            $xmldbfield = new xmldb_field('window_versionshow');
58
            $dbmanager->drop_field($xmldbtable, $xmldbfield);
59
            $xmldbfield = new xmldb_field('window_version');
60
            $dbmanager->drop_field($xmldbtable, $xmldbfield);
61
        } catch (Exception $e) {
62
            trigger_error($e->getMessage(), E_USER_WARNING);
63
        }
64
        $homeconf = dirname(__FILE__).'/../conf/esmain/homeApplication.properties.xml';
65
        if (file_exists($homeconf)) {
66
            $app = new DOMDocument();
67
            $app->load($homeconf);
68
            $app->preserveWhiteSpace = false;
69
            $entries = $app->getElementsByTagName('entry');
70
            foreach ($entries as $entry) {
71
                $homeappproperties[$entry->getAttribute('key')] = $entry->nodeValue;
72
            }
73
            $homeappproperties['blowfishkey'] = 'thetestkey';
74
            $homeappproperties['blowfishiv'] = 'initvect';
75
 
76
            set_config('appProperties', json_encode($homeappproperties), 'edusharing');
77
        }
78
 
79
        $repoconf = dirname(__FILE__).'/../conf/esmain/'.
80
                    'app-'. $homeappproperties['homerepid'] .'.properties.xml';
81
        if (file_exists($repoconf)) {
82
            $app = new DOMDocument();
83
            $app->load($repoconf);
84
            $app->preserveWhiteSpace = false;
85
            $entrys = $app->getElementsByTagName('entry');
86
            foreach ($entrys as $entry) {
87
                $repoproperties[$entry->getAttribute('key')] = $entry->nodeValue;
88
            }
89
 
90
            $repoproperties['authenticationwebservice'] = str_replace(
91
                'authentication',
92
                'authbyapp',
93
                $repoproperties['authenticationwebservice']
94
            );
95
            $repoproperties['authenticationwebservice_wsdl'] = str_replace('authentication',
96
                'authbyapp',
97
                $repoproperties['authenticationwebservice_wsdl']
98
            );
99
            if (mb_substr($repoproperties['usagewebservice'], -1) != '2') {
100
                $repoproperties['usagewebservice'] = $repoproperties['usagewebservice'] . '2';
101
            }
102
            $repoproperties['usagewebservice_wsdl'] = str_replace('usage?wsdl',
103
                'usage2?wsdl',
104
                $repoproperties['usagewebservice_wsdl']
105
            );
106
            $repoproperties['contenturl'] = $repoproperties['clientprotocol'] . '://' . $repoproperties['domain'] . ':' .
107
                                            $repoproperties['clientport'] . '/edu-sharing/renderingproxy';
108
 
109
            set_config('repProperties', json_encode($repoproperties), 'edusharing');
110
        }
111
        try {
112
            include(dirname(__FILE__).'/../conf/cs_conf.php');
113
            set_config('EDU_AUTH_KEY', EDU_AUTH_KEY, 'edusharing');
114
            set_config('EDU_AUTH_PARAM_NAME_USERID', EDU_AUTH_PARAM_NAME_USERID, 'edusharing');
115
            set_config('EDU_AUTH_PARAM_NAME_LASTNAME', EDU_AUTH_PARAM_NAME_LASTNAME, 'edusharing');
116
            set_config('EDU_AUTH_PARAM_NAME_FIRSTNAME', EDU_AUTH_PARAM_NAME_FIRSTNAME, 'edusharing');
117
            set_config('EDU_AUTH_PARAM_NAME_EMAIL', EDU_AUTH_PARAM_NAME_EMAIL, 'edusharing');
118
            upgrade_mod_savepoint(true, 2016011401, 'edusharing');
119
 
120
        } catch (Exception $e) {
121
            trigger_error($e->getMessage(), E_USER_WARNING);
122
        }
123
    }
124
 
125
    if ($result) {
126
        if ($oldversion < 2016120901) {
127
 
128
            $appproperties = get_config('edusharing', 'appProperties');
129
            if (!empty($appproperties)) {
130
                foreach (json_decode($appproperties, true) as $key => $value) {
131
                    set_config('application_' . $key, $value, 'edusharing');
132
                }
133
                set_config('appProperties', null, 'edusharing');
134
            }
135
 
136
            $repproperties = get_config('edusharing', 'repProperties');
137
            if (!empty($repproperties)) {
138
                foreach (json_decode($repproperties, true) as $key => $value) {
139
                    set_config('repository_' . $key, $value, 'edusharing');
140
                }
141
                set_config('repProperties', null, 'edusharing');
142
            }
143
            try {
144
                upgrade_mod_savepoint(true, 2016120901, 'edusharing');
145
            } catch (Exception $exception) {
146
                trigger_error($exception->getMessage(), E_USER_WARNING);
147
            }
148
        }
149
 
150
        if ($oldversion < 2019062110) {
151
 
152
            try {
153
                $xmldbtable = new xmldb_table('edusharing');
154
                $xmldbfield = new xmldb_field(
155
                    'module_id',
156
                    XMLDB_TYPE_INTEGER,
157
                    '10',
158
                    null,
159
                    false,
160
                    false,
161
                    null,
162
                    'name'
163
                );
164
                $dbmanager->add_field($xmldbtable, $xmldbfield);
165
                upgrade_mod_savepoint(true, 2019062110, 'edusharing');
166
            } catch (Exception $e) {
167
                trigger_error($e->getMessage(), E_USER_WARNING);
168
            }
169
        }
170
 
171
        if ($oldversion < 2019062401) {
172
 
173
            try {
174
                $xmldbtable = new xmldb_table('edusharing');
175
                $xmldbfield = new xmldb_field(
176
                    'section_id',
177
                    XMLDB_TYPE_INTEGER,
178
                    '10',
179
                    null,
180
                    true,
181
                    false,
182
                    null,
183
                    'module_id'
184
                );
185
                $dbmanager->add_field($xmldbtable, $xmldbfield);
186
                upgrade_mod_savepoint(true, 2019062401, 'edusharing');
187
            } catch (Exception $e) {
188
                trigger_error($e->getMessage(), E_USER_WARNING);
189
            }
190
        }
191
 
192
        if ($oldversion < 2022042501) {
193
            try {
194
                $xmldbtable = new xmldb_table('edusharing');
195
                $xmldbfield = new xmldb_field(
196
                    'usage_id',
197
                    XMLDB_TYPE_CHAR,
198
                    '255',
199
                    null,
200
                    false,
201
                    false,
202
                    null,
203
                    'section_id'
204
                );
205
                $dbmanager->add_field($xmldbtable, $xmldbfield);
206
                upgrade_mod_savepoint(true, 2022042501, 'edusharing');
207
            } catch (Exception $e) {
208
                trigger_error($e->getMessage(), E_USER_WARNING);
209
            }
210
        }
211
 
212
        if ($oldversion < 2023100100) {
213
            unset_config('repository_restApi', 'edusharing');
214
            try {
215
                upgrade_mod_savepoint(true, 2023100100, 'edusharing');
216
            } catch (Exception $exception) {
217
                trigger_error($exception->getMessage(), E_USER_WARNING);
218
            }
219
        }
220
 
221
        if ($oldversion < 2024050900) {
222
            try {
223
                $salt = get_config('vhb', 'salt');
224
                if ($salt !== false) {
225
                    set_config('SALT', $salt, 'edusharing');
226
                }
227
                upgrade_mod_savepoint(true, 2024050900, 'edusharing');
228
            } catch (Exception $exception) {
229
                trigger_error($exception->getMessage(), E_USER_WARNING);
230
            }
231
        }
232
    }
233
 
234
    $logic = new InstallUpgradeLogic();
235
    try {
236
        $logic->parse_config_data();
237
    } catch (Exception $exception) {
238
        debugging($exception->getMessage());
239
        return $result;
240
    }
241
    $utils = new UtilityFunctions();
242
    $appid = $logic->discern_app_id();
243
    $utils->set_config_entry('application_appid', $appid);
244
    if (empty($data['repoUrl']) || empty($data['repoAdmin']) || empty($data['repoAdminPassword'])) {
245
        return $result;
246
    }
247
    $service       = new EduSharingService();
248
    $metadatalogic = new MetadataLogic($service);
249
    $metadatalogic->set_app_id($appid);
250
    $registrationlogic = new PluginRegistration($service);
251
    $logic->set_registration_logic($registrationlogic);
252
    $logic->set_metadata_logic($metadatalogic);
253
    $logic->perform(false);
254
    return $result;
255
}