Passed
Push — master ( 30b7f7...cb4ceb )
by Goffy
03:53
created

xoops_module_pre_update_wggithub()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
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
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prev_version is correct as it would always require null to be passed?
Loading history...
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';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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!');
0 ignored issues
show
Bug introduced by
The function xoops_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        /** @scrutinizer ignore-call */ \xoops_error('Error: creation schema file failed!');
Loading history...
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