Code Duplication    Length = 17-21 lines in 4 locations

admin/upgrade.php 2 locations

@@ 35-51 (lines=17) @@
32
if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
33
    $errors = 0;
34
    // 1) Create, if it does not exists, the stories_files table
35
    if (!news_TableExists($xoopsDB->prefix('news_stories_files'))) {
36
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_files') . " (
37
              fileid int(8) unsigned NOT NULL auto_increment,
38
              filerealname varchar(255) NOT NULL default '',
39
              storyid int(8) unsigned NOT NULL default '0',
40
              date int(10) NOT NULL default '0',
41
              mimetype varchar(64) NOT NULL default '',
42
              downloadname varchar(255) NOT NULL default '',
43
              counter int(8) unsigned NOT NULL default '0',
44
              PRIMARY KEY  (fileid),
45
              KEY storyid (storyid)
46
            ) ENGINE=MyISAM;";
47
        if (!$xoopsDB->queryF($sql)) {
48
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED1;
49
            ++$errors;
50
        }
51
    }
52
53
    // 2) Change the topic title's length, in the topics table
54
    $sql    = sprintf('ALTER TABLE ' . $xoopsDB->prefix('news_topics') . ' CHANGE topic_title topic_title VARCHAR( 255 ) NOT NULL;');
@@ 79-96 (lines=18) @@
76
    }
77
78
    // 3) If it does not exists, create the table stories_votedata
79
    if (!news_TableExists($xoopsDB->prefix('news_stories_votedata'))) {
80
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_votedata') . " (
81
              ratingid int(11) unsigned NOT NULL auto_increment,
82
              storyid int(8) unsigned NOT NULL default '0',
83
              ratinguser int(11) NOT NULL default '0',
84
              rating tinyint(3) unsigned NOT NULL default '0',
85
              ratinghostname varchar(60) NOT NULL default '',
86
              ratingtimestamp int(10) NOT NULL default '0',
87
              PRIMARY KEY  (ratingid),
88
              KEY ratinguser (ratinguser),
89
              KEY ratinghostname (ratinghostname),
90
              KEY storyid (storyid)
91
            ) ENGINE=MyISAM;";
92
        if (!$xoopsDB->queryF($sql)) {
93
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED3;
94
            ++$errors;
95
        }
96
    }
97
98
    // 4) Create the four new fields for the votes in the story table
99
    if (!news_FieldExists('rating', $xoopsDB->prefix('news_stories'))) {

include/update_function.php 2 locations

@@ 33-53 (lines=21) @@
30
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED2;
31
            ++$errors;
32
        }
33
    } else {
34
35
        // 1) Create, if it does not exists, the stories_files table
36
        if (!news_TableExists($xoopsDB->prefix('news_stories_files'))) {
37
            $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_files') . " (
38
              fileid int(8) unsigned NOT NULL auto_increment,
39
              filerealname varchar(255) NOT NULL default '',
40
              storyid int(8) unsigned NOT NULL default '0',
41
              date int(10) NOT NULL default '0',
42
              mimetype varchar(64) NOT NULL default '',
43
              downloadname varchar(255) NOT NULL default '',
44
              counter int(8) unsigned NOT NULL default '0',
45
              PRIMARY KEY  (fileid),
46
              KEY storyid (storyid)
47
            ) ENGINE=MyISAM;";
48
            if (!$xoopsDB->queryF($sql)) {
49
                echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED1;
50
                ++$errors;
51
            }
52
        }
53
    }
54
55
    if (news_TableExists($xoopsDB->prefix('stories'))) {
56
        $sql    = sprintf('ALTER TABLE ' . $xoopsDB->prefix('stories') . ' RENAME ' . $xoopsDB->prefix('news_stories'));
@@ 108-125 (lines=18) @@
105
    }
106
107
    // 3) If it does not exists, create the table stories_votedata
108
    if (!news_TableExists($xoopsDB->prefix('news_stories_votedata'))) {
109
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_votedata') . " (
110
              ratingid int(11) unsigned NOT NULL auto_increment,
111
              storyid int(8) unsigned NOT NULL default '0',
112
              ratinguser int(11) NOT NULL default '0',
113
              rating tinyint(3) unsigned NOT NULL default '0',
114
              ratinghostname varchar(60) NOT NULL default '',
115
              ratingtimestamp int(10) NOT NULL default '0',
116
              PRIMARY KEY  (ratingid),
117
              KEY ratinguser (ratinguser),
118
              KEY ratinghostname (ratinghostname),
119
              KEY storyid (storyid)
120
            ) ENGINE=MyISAM;";
121
        if (!$xoopsDB->queryF($sql)) {
122
            echo '<br>' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED3;
123
            ++$errors;
124
        }
125
    }
126
127
    // 4) Create the four new fields for the votes in the story table
128
    if (!news_FieldExists('rating', $xoopsDB->prefix('news_stories'))) {