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
 * install.php
19
 *
20
 * Performed on every plugin installation
21
 * Checks for settings in installConfig.json
22
 * imports metadata and registers plugin with provided data
23
 *
24
 * @package mod_edusharing
25
 * @copyright metaVentis GmbH — http://metaventis.com
26
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
 
29
use EduSharingApiClient\EduSharingAuthHelper;
30
use EduSharingApiClient\EduSharingHelperBase;
31
use EduSharingApiClient\EduSharingNodeHelper;
32
use EduSharingApiClient\EduSharingNodeHelperConfig;
33
use EduSharingApiClient\UrlHandling;
34
use mod_edusharing\EduSharingService;
35
use mod_edusharing\InstallUpgradeLogic;
36
use mod_edusharing\MetadataLogic;
37
use mod_edusharing\MoodleCurlHandler;
38
use mod_edusharing\PluginRegistration;
39
use mod_edusharing\UtilityFunctions;
40
 
41
/**
42
 * Function xmldb_edusharing_install
43
 *
44
 * @return void
45
 */
46
function xmldb_edusharing_install(): void {
47
    global $CFG;
48
    require_once($CFG->dirroot . '/mod/edusharing/eduSharingAutoloader.php');
49
    $logic = new InstallUpgradeLogic();
50
    try {
51
        $logic->parse_config_data();
52
        $appid = $logic->discern_app_id();
53
        $data  = $logic->get_config_data();
54
        $utils = new UtilityFunctions();
55
        $utils->set_config_entry('application_appid', $appid);
56
        $utils->set_config_entry('send_additional_auth', '1');
57
        $utils->set_config_entry('obfuscate_auth_param', '0');
58
        if (empty($data['repoUrl']) || empty($data['repoAdmin']) || empty($data['repoAdminPassword'])) {
59
            return;
60
        }
61
        $basehelper = new EduSharingHelperBase($data['repoUrl'], '', $appid);
62
        $basehelper->registerCurlHandler(new MoodleCurlHandler());
63
        $authhelper = new EduSharingAuthHelper($basehelper);
64
        $nodeconfig = new EduSharingNodeHelperConfig(new UrlHandling(true));
65
        $nodehelper = new EduSharingNodeHelper($basehelper, $nodeconfig);
66
        $service    = new EduSharingService($authhelper, $nodehelper);
67
        $logic->set_registration_logic(new PluginRegistration($service));
68
        $metadatalogic = new MetadataLogic($service);
69
        $metadatalogic->set_app_id($appid);
70
        $logic->set_metadata_logic($metadatalogic);
71
        $logic->perform();
72
    } catch (Exception $exception) {
73
        debugging(($exception instanceof JsonException
74
                ? 'Metadata import and plugin registration failed, invalid installConfig.json: ' : '') . $exception->getMessage());
75
        return;
76
    }
77
}