Completed
Pull Request — master (#16)
by Michael
01:51
created

admin/upgrade.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
require_once __DIR__ . '/../../../include/cp_header.php';
21
xoops_cp_header();
22
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
23
24
if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
25
    $errors = 0;
26
    // 1) Create, if it does not exists, the stories_files table
27 View Code Duplication
    if (!NewsUtility::existTable($xoopsDB->prefix('news_stories_files'))) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_files') . " (
29
              fileid INT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
30
              filerealname VARCHAR(255) NOT NULL DEFAULT '',
31
              storyid INT(8) UNSIGNED NOT NULL DEFAULT '0',
32
              date INT(10) NOT NULL DEFAULT '0',
33
              mimetype VARCHAR(64) NOT NULL DEFAULT '',
34
              downloadname VARCHAR(255) NOT NULL DEFAULT '',
35
              counter INT(8) UNSIGNED NOT NULL DEFAULT '0',
36
              PRIMARY KEY  (fileid),
37
              KEY storyid (storyid)
38
            ) ENGINE=MyISAM;";
39
        if (!$xoopsDB->queryF($sql)) {
40
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED1;
41
            ++$errors;
42
        }
43
    }
44
45
    // 2) Change the topic title's length, in the topics table
46
    $sql    = sprintf('ALTER TABLE ' . $xoopsDB->prefix('news_topics') . ' CHANGE topic_title topic_title VARCHAR( 255 ) NOT NULL;');
47
    $result = $xoopsDB->queryF($sql);
48
    if (!$result) {
49
        echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED2;
50
        ++$errors;
51
    }
52
53
    // 2.1) Add the new fields to the topic table
54
    if (!NewsUtility::existField('menu', $xoopsDB->prefix('news_topics'))) {
55
        NewsUtility::addField("menu TINYINT( 1 ) DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_topics'));
56
    }
57
    if (!NewsUtility::existField('topic_frontpage', $xoopsDB->prefix('news_topics'))) {
58
        NewsUtility::addField("topic_frontpage TINYINT( 1 ) DEFAULT '1' NOT NULL", $xoopsDB->prefix('news_topics'));
59
    }
60
    if (!NewsUtility::existField('topic_rssurl', $xoopsDB->prefix('news_topics'))) {
61
        NewsUtility::addField('topic_rssurl VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('news_topics'));
62
    }
63
    if (!NewsUtility::existField('topic_description', $xoopsDB->prefix('news_topics'))) {
64
        NewsUtility::addField('topic_description TEXT NOT NULL', $xoopsDB->prefix('news_topics'));
65
    }
66
    if (!NewsUtility::existField('topic_color', $xoopsDB->prefix('news_topics'))) {
67
        NewsUtility::addField("topic_color varchar(6) NOT NULL default '000000'", $xoopsDB->prefix('news_topics'));
68
    }
69
70
    // 3) If it does not exists, create the table stories_votedata
71 View Code Duplication
    if (!NewsUtility::existTable($xoopsDB->prefix('news_stories_votedata'))) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_votedata') . " (
73
              ratingid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
74
              storyid INT(8) UNSIGNED NOT NULL DEFAULT '0',
75
              ratinguser INT(11) NOT NULL DEFAULT '0',
76
              rating TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
77
              ratinghostname VARCHAR(60) NOT NULL DEFAULT '',
78
              ratingtimestamp INT(10) NOT NULL DEFAULT '0',
79
              PRIMARY KEY  (ratingid),
80
              KEY ratinguser (ratinguser),
81
              KEY ratinghostname (ratinghostname),
82
              KEY storyid (storyid)
83
            ) ENGINE=MyISAM;";
84
        if (!$xoopsDB->queryF($sql)) {
85
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED3;
86
            ++$errors;
87
        }
88
    }
89
90
    // 4) Create the four new fields for the votes in the story table
91
    if (!NewsUtility::existField('rating', $xoopsDB->prefix('news_stories'))) {
92
        NewsUtility::addField("rating DOUBLE( 6, 4 ) DEFAULT '0.0000' NOT NULL", $xoopsDB->prefix('news_stories'));
93
    }
94
    if (!NewsUtility::existField('votes', $xoopsDB->prefix('news_stories'))) {
95
        NewsUtility::addField("votes INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_stories'));
96
    }
97
    if (!NewsUtility::existField('keywords', $xoopsDB->prefix('news_stories'))) {
98
        NewsUtility::addField('keywords VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories'));
99
    }
100
    if (!NewsUtility::existField('description', $xoopsDB->prefix('news_stories'))) {
101
        NewsUtility::addField('description VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories'));
102
    }
103
    if (!NewsUtility::existField('pictureinfo', $xoopsDB->prefix('news_stories'))) {
104
        NewsUtility::addField('pictureinfo VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories'));
105
    }
106
    if (!NewsUtility::existField('subtitle', $xoopsDB->prefix('news_stories'))) {
107
        NewsUtility::addField('subtitle VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories'));
108
    }
109
110
    // 5) Add some indexes to the topics table
111
    $sql    = sprintf('ALTER TABLE ' . $xoopsDB->prefix('news_topics') . ' ADD INDEX ( `topic_title` );');
112
    $result = $xoopsDB->queryF($sql);
113
    $sql    = sprintf('ALTER TABLE ' . $xoopsDB->prefix('news_topics') . ' ADD INDEX ( `menu` );');
114
    $result = $xoopsDB->queryF($sql);
115
116
    // At the end, if there was errors, show them or redirect user to the module's upgrade page
117
    if ($errors) {
118
        echo '<H1>' . _AM_NEWS_UPGRADEFAILED . '</H1>';
119
        echo '<br>' . _AM_NEWS_UPGRADEFAILED0;
120
    } else {
121
        echo _AM_NEWS_UPGRADECOMPLETE . " - <a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin&op=update&module=news'>" . _AM_NEWS_UPDATEMODULE . '</a>';
122
    }
123
} else {
124
    printf("<h2>%s</h2>\n", _AM_NEWS_UPGR_ACCESS_ERROR);
125
}
126
xoops_cp_footer();
127