rmbulletin.php ➔ xnewsletter_plugin_getinfo_rmbulletin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 13
Ratio 92.86 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 13
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * ****************************************************************************
4
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
5
 * ****************************************************************************
6
 *  XNEWSLETTER - MODULE FOR XOOPS
7
 *  Copyright (c) 2007 - 2012
8
 *  Goffy ( wedega.com )
9
 *
10
 *  You may not change or alter any portion of this comment or credits
11
 *  of supporting developers from this source code or any supporting
12
 *  source code which is considered copyrighted (c) material of the
13
 *  original comment or credit authors.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *  ---------------------------------------------------------------------------
20
 * @copyright  Goffy ( wedega.com )
21
 * @license    GPL 2.0
22
 * @package    xnewsletter
23
 * @author     Goffy ( [email protected] )
24
 *
25
 * ****************************************************************************
26
 */
27
28
use XoopsModules\Xnewsletter;
29
30
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
31
require_once dirname(__DIR__) . '/include/common.php';
32
33
/**
34
 * @return array
35
 */
36 View Code Duplication
function xnewsletter_plugin_getinfo_rmbulletin()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
37
{
38
    global $xoopsDB;
39
40
    $pluginInfo         = [];
41
    $pluginInfo['name'] = 'rmbulletin';
42
    $pluginInfo['icon'] = XOOPS_URL . '/modules/rmbulletin/images/logo.png';
43
    //$pluginInfo['modulepath'] = XOOPS_ROOT_PATH . "/modules/rmbulletin/xoops_version.php";
44
    $pluginInfo['tables'][0] = $xoopsDB->prefix('rmb_users');
45
    $pluginInfo['descr']     = 'Import from RM-Bulletin';
46
    $pluginInfo['hasform']   = 0;
47
48
    return $pluginInfo;
49
}
50
51
/**
52
 * @param $cat_id
53
 * @param $action_after_read
54
 * @param $limitcheck
55
 * @param $skipcatsubscrexist
56
 *
57
 * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be null|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
58
 */
59 View Code Duplication
function xnewsletter_plugin_getdata_rmbulletin($cat_id, $action_after_read, $limitcheck, $skipcatsubscrexist)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
60
{
61
    global $xoopsDB;
62
    $helper = Xnewsletter\Helper::getInstance();
63
64
    //$table_import = $xoopsDB->prefix('xnewsletter_import');
65
    $import_status = 0 == $action_after_read ? true : false;
66
    $i             = 0;
67
    $j             = 0;
68
69
    $sql = 'SELECT `email`';
70
    $sql .= ' FROM ' . $xoopsDB->prefix('rmb_users');
71
    if (!$result_users = $xoopsDB->query($sql)) {
72
        die('MySQL-Error: ' . $GLOBALS['xoopsDB']->error());
73
    }
74
    while (false !== ($lineArray = $xoopsDB->fetchBoth($result_users))) {
75
        ++$i;
76
        $email     = $lineArray[0];
77
        $sex       = '';
78
        $firstname = '';
79
        $lastname  = '';
80
81
        $subscr_id    = xnewsletter_pluginCheckEmail($email);
82
        $catsubscr_id = xnewsletter_pluginCheckCatSubscr($subscr_id, $cat_id);
83
84
        if (1 == $skipcatsubscrexist && $catsubscr_id > 0) {
85
            //skip existing subscriptions
86
        } else {
87
            $currcatid = $catsubscr_id > 0 ? 0 : $cat_id;
88
            $importObj = $helper->getHandler('Import')->create();
89
            $importObj->setVar('import_email', $email);
90
            $importObj->setVar('import_sex', $sex);
91
            $importObj->setVar('import_firstname', $firstname);
92
            $importObj->setVar('import_lastname', $lastname);
93
            $importObj->setVar('import_cat_id', $currcatid);
94
            $importObj->setVar('import_subscr_id', $subscr_id);
95
            $importObj->setVar('import_catsubscr_id', $catsubscr_id);
96
            $importObj->setVar('import_status', $import_status);
97
            if (!$helper->getHandler('Import')->insert($importObj)) {
98
                echo $importObj->getHtmlErrors();
99
                exit();
100
            }
101
            //            $sql = "INSERT INTO {$table_import} (import_email, import_sex, import_firstname, import_lastname, import_cat_id, import_subscr_id, import_catsubscr_id, import_status)";
102
            //            $sql .= " VALUES ('$email', '$sex', '$firstname', '$lastname', $currcatid, $subscr_id, $catsubscr_id, $import_status)";
103
            //            $result_insert = $xoopsDB->query($sql) or die ("MySQL-Error: " . $GLOBALS['xoopsDB']->error());
104
            ++$j;
105
        }
106
        ++$i;
107
        if (100000 == $j) {
108
            break;
109
        } //maximum number of processing to avoid cache overflow
110
        if ($limitcheck > 0 && $j == $limitcheck) {
111
            $import_status = false;
112
        }
113
    }
114
115
    return $j;
116
}
117