Issues (584)

include/update.php (1 issue)

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';
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
    $moduleVersionOld = $module->getInfo('version');
80
    $moduleVersionNew = \str_replace(['.', '-'], '_', $moduleVersionOld);
81
    $fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionNew}_migrate.yml";
82
    //}
83
84
    // create a schema file based on sql/mysql.sql
85
    $migratehelper = new MigrateHelper($fileSql, $fileYaml);
86
    if (!$migratehelper->createSchemaFromSqlfile()) {
87
        \xoops_error('Error: creation schema file failed!');
88
        return false;
89
    }
90
91
    //create copy for XOOPS 2.5.11 Beta 1 and older versions
92
    $fileYaml2 = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . "/sql/{$moduleDirName}_{$moduleVersionOld}_migrate.yml";
93
    \copy($fileYaml, $fileYaml2);
94
95
    // run standard procedure for db migration
96
    $migrate->synchronizeSchema();
97
98
    $errors = $module->getErrors();
99
    if (!empty($errors)) {
100
        print_r($errors);
101
    }
102
103
    return true;
104
105
}
106
107
/**
108
 * @param $module
109
 *
110
 * @return bool
111
 */
112
/*
113
function wggithub_check_db($module)
114
{
115
    $ret = true;
116
    //insert here code for database check
117
118
    return $ret;
119
}
120
*/
121