Passed
Push — master ( 474df4...e81e63 )
by Goffy
03:32
created

include/update.php (1 issue)

Labels
Severity
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * Wggithub module for xoops
14
 *
15
 * @param mixed      $module
16
 * @param null|mixed $prev_version
17
 * @package        Wggithub
18
 * @since          1.0
19
 * @min_xoops      2.5.9
20
 * @author         Wedega - Email:<[email protected]> - Website:<https://wedega.com>
21
 * @version        $Id: 1.0 update.php 1 Mon 2018-03-19 10:04:53Z XOOPS Project (www.xoops.org) $
22
 * @copyright      module for xoops
23
 * @license        GPL 2.0 or later
24
 */
25
26
use XoopsModules\Wggithub;
27
use XoopsModules\Wggithub\Common\ {
28
    Configurator,
29
    Migrate,
30
    MigrateHelper
0 ignored issues
show
The type XoopsModules\Wggithub\Common\MigrateHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
};
32
33
/**
34
 * Prepares system prior to attempting to install module
35
 * @param \XoopsModule $module {@link XoopsModule}
36
 *
37
 * @return bool true if ready to install, false if not
38
 */
39
function xoops_module_pre_update_wggithub(\XoopsModule $module)
40
{
41
    $utility = new Wggithub\Utility();
42
43
    $xoopsSuccess = $utility::checkVerXoops($module);
44
    $phpSuccess   = $utility::checkVerPhp($module);
45
46
    return $xoopsSuccess && $phpSuccess;
47
}
48
49
/**
50
 * @param      $module
51
 * @param null $prev_version
52
 *
53
 * @return bool|null
54
 */
55
function xoops_module_update_wggithub($module, $prev_version = null)
56
{
57
    require \dirname(__DIR__) . '/preloads/autoloader.php';
58
59
    $moduleDirName = $module->dirname();
60
61
    //wggithub_check_db($module);
62
63
    //check upload directory
64
    include_once __DIR__ . '/install.php';
65
    xoops_module_install_wggithub($module);
66
67
    // update DB corresponding to sql/mysql.sql
68
    $configurator = new Configurator();
69
    $migrate = new Migrate($configurator);
70
71
    $fileSql = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/mysql.sql';
72
    // ToDo: add function setDefinitionFile to .\class\libraries\vendor\xoops\xmf\src\Database\Migrate.php
73
    // Todo: once we are using setDefinitionFile this part has to be adapted
74
    //$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/update_' . $moduleDirName . '_migrate.yml';
75
    //try {
76
    //$migrate->setDefinitionFile('update_' . $moduleDirName);
77
    //} catch (\Exception $e) {
78
    // as long as this is not done default file has to be created
79
    $moduleVersion = $module->getInfo('version');
80
    $fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersion}_migrate.yml";
81
    //}
82
83
    // create a schema file based on sql/mysql.sql
84
    $migratehelper = new MigrateHelper($fileSql, $fileYaml);
85
    if (!$migratehelper->createSchemaFromSqlfile()) {
86
        \xoops_error('Error: creation schema file failed!');
87
        return false;
88
    }
89
90
    // run standard procedure for db migration
91
    $migrate->synchronizeSchema();
92
93
    $errors = $module->getErrors();
94
    if (!empty($errors)) {
95
        print_r($errors);
96
    }
97
98
    return true;
99
100
}
101
102
/**
103
 * @param $module
104
 *
105
 * @return bool
106
 */
107
/*
108
function wggithub_check_db($module)
109
{
110
    $ret = true;
111
    //insert here code for database check
112
113
    return $ret;
114
}
115
*/
116