GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.8 ( 651d2c...3866ce )
by Thorsten
18:13
created

PMF_Installer::startInstall()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 263
Code Lines 165

Duplication

Lines 23
Ratio 8.75 %

Importance

Changes 0
Metric Value
cc 39
eloc 165
nc 300810240
nop 1
dl 23
loc 263
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * The Installer class installs phpMyFAQ. Classy.
4
 *
5
 * PHP Version 5.3
6
 *
7
 * This Source Code Form is subject to the terms of the Mozilla Public License,
8
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
 * obtain one at http://mozilla.org/MPL/2.0/.
10
 *
11
 * @category  phpMyFAQ
12
 * @package   Installer
13
 * @author    Florian Anderiasch <[email protected]>
14
 * @copyright 2002-2016 phpMyFAQ Team
15
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16
 * @link      http://www.phpmyfaq.de
17
 * @since     2012-08-27
18
 */
19
20
if (!defined('IS_VALID_PHPMYFAQ')) {
21
    exit();
22
}
23
24
/**
25
 * Installer
26
 *
27
 * @category  phpMyFAQ
28
 * @package   Installer
29
 * @author    Florian Anderiasch <[email protected]>
30
 * @copyright 2002-2016 phpMyFAQ Team
31
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
32
 * @link      http://www.phpmyfaq.de
33
 * @since     2012-08-27
34
 */
35
36
class PMF_Installer
37
{
38
    /**
39
     * PMF_System object
40
     *
41
     * @var PMF_System
42
     */
43
    protected $_system;
44
45
    /**
46
     * Array with user rights
47
     * @var array
48
     */
49
    protected $_mainRights = array(
50
        //1 => "adduser",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        array(
52
            'name' => 'adduser',
53
            'description' => 'Right to add user accounts'
54
        ),
55
        //2 => "edituser",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
        array(
57
            'name' => 'edituser',
58
            'description' => 'Right to edit user accounts'
59
        ),
60
        //3 => "deluser",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
        array(
62
            'name' => 'deluser',
63
            'description' => 'Right to delete user accounts'
64
        ),
65
        //4 => "addbt",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        array(
67
            'name' => 'addbt',
68
            'description' => 'Right to add faq entries'
69
        ),
70
        //5 => "editbt",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
        array(
72
            'name' => 'editbt',
73
            'description' => 'Right to edit faq entries'
74
        ),
75
        //6 => "delbt",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
        array(
77
            'name' => 'delbt',
78
            'description' => 'Right to delete faq entries'
79
        ),
80
        //7 => "viewlog",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
        array(
82
            'name' => 'viewlog',
83
            'description' => 'Right to view logfiles'
84
        ),
85
        //8 => "adminlog",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
86
        array(
87
            'name' => 'adminlog',
88
            'description' => 'Right to view admin log'
89
        ),
90
        //9 => "delcomment",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
        array(
92
            'name' => 'delcomment',
93
            'description' => 'Right to delete comments'
94
        ),
95
        //10 => "addnews",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
        array(
97
            'name' => 'addnews',
98
            'description' => 'Right to add news'
99
        ),
100
        //11 => "editnews",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
        array(
102
            'name' => 'editnews',
103
            'description' => 'Right to edit news'
104
        ),
105
        //12 => "delnews",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
106
        array(
107
            'name' => 'delnews',
108
            'description' => 'Right to delete news'
109
        ),
110
        //13 => "addcateg",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
111
        array(
112
            'name' => 'addcateg',
113
            'description' => 'Right to add categories'
114
        ),
115
        //14 => "editcateg",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
        array(
117
            'name' => 'editcateg',
118
            'description' => 'Right to edit categories'
119
        ),
120
        //15 => "delcateg",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
        array(
122
            'name' => 'delcateg',
123
            'description' => 'Right to delete categories'
124
        ),
125
        //16 => "passwd",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
        array(
127
            'name' => 'passwd',
128
            'description' => 'Right to change passwords'
129
        ),
130
        //17 => "editconfig",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
131
        array(
132
            'name' => 'editconfig',
133
            'description' => 'Right to edit configuration'
134
        ),
135
        //18 => "addatt", // Duplicate, removed with 2.7.3
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
136
        //array(
137
        //    'name' => 'addatt',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
138
        //    'description' => 'Right to add attachments'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
139
        //),
140
        //19 => "backup delatt", // Duplicate, removed with 2.7.3
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
141
        //array(
142
        //    'name' => 'delatt',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
143
        //    'description' => 'Right to delete attachments'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
144
        //),
145
        //20 => "backup",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
        array(
147
            'name' => 'backup',
148
            'description' => 'Right to save backups'
149
        ),
150
        //21 => "restore",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
151
        array(
152
            'name' => 'restore',
153
            'description' => 'Right to load backups'
154
        ),
155
        //22 => "delquestion",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
156
        array(
157
            'name' => 'delquestion',
158
            'description' => 'Right to delete questions'
159
        ),
160
        //23 => 'addglossary',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
161
        array(
162
            'name' => 'addglossary',
163
            'description' => 'Right to add glossary entries'
164
        ),
165
        //24 => 'editglossary',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
        array(
167
            'name' => 'editglossary',
168
            'description' => 'Right to edit glossary entries'
169
        ),
170
        //25 => 'delglossary'
171
        array(
172
            'name' => 'delglossary',
173
            'description' => 'Right to delete glossary entries'
174
        ),
175
        //26 => 'changebtrevs'
176
        array(
177
            'name' => 'changebtrevs',
178
            'description' => 'Right to edit revisions'
179
        ),
180
        //27 => "addgroup",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
181
        array(
182
            'name' => 'addgroup',
183
            'description' => 'Right to add group accounts'
184
        ),
185
        //28 => "editgroup",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
186
        array(
187
            'name' => 'editgroup',
188
            'description' => 'Right to edit group accounts'
189
        ),
190
        //29 => "delgroup",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
        array(
192
            'name' => 'delgroup',
193
            'description' => 'Right to delete group accounts'
194
        ),
195
        //30 => "addtranslation",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
196
        array(
197
            'name' => 'addtranslation',
198
            'description' => 'Right to add translation'
199
        ),
200
        //31 => "edittranslation",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
        array(
202
            'name' => 'edittranslation',
203
            'description' => 'Right to edit translations'
204
        ),
205
        //32 => "deltranslation",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
206
        array(
207
            'name' => 'deltranslation',
208
            'description' => 'Right to delete translations'
209
        ),
210
        // 33 => 'approverec'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
211
        array(
212
            'name' => 'approverec',
213
            'description' => 'Right to approve records'
214
        ),
215
        // 34 => 'addattachment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
216
        array(
217
            'name' => 'addattachment',
218
            'description' => 'Right to add attachments'
219
        ),
220
        // 35 => 'editattachment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
221
        array(
222
            'name' => 'editattachment',
223
            'description' => 'Right to edit attachments'
224
        ),
225
        // 36 => 'delattachment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
226
        array(
227
            'name' => 'delattachment',
228
            'description' => 'Right to delete attachments'
229
        ),
230
        // 37 => 'dlattachment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
231
        array(
232
            'name' => 'dlattachment',
233
            'description' => 'Right to download attachments'
234
        ),
235
        // 38 => 'dlattachment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
236
        array(
237
            'name' => 'reports',
238
            'description' => 'Right to generate reports'
239
        ),
240
        // 39 => 'addfaq'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
241
        array(
242
            'name' => 'addfaq',
243
            'description' => 'Right to add FAQs in frontend'
244
        ),
245
        // 40 => 'addquestion'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
246
        array(
247
            'name' => 'addquestion',
248
            'description' => 'Right to add questions in frontend'
249
        ),
250
        // 41 => 'addcomment'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
251
        array(
252
            'name' => 'addcomment',
253
            'description' => 'Right to add comments in frontend'
254
        ),
255
        // 42 => 'editinstances'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
256
        array(
257
            'name' => 'editinstances',
258
            'description' => 'Right to edit multi-site instances'
259
        ),
260
        // 43 => 'addinstances'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
261
        array(
262
            'name' => 'addinstances',
263
            'description' => 'Right to add multi-site instances'
264
        ),
265
        // 44 => 'delinstances'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
266
        array(
267
            'name' => 'delinstances',
268
            'description' => 'Right to delete multi-site instances'
269
        ),
270
        // 45 => 'export'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
271
        array(
272
            'name' => 'export',
273
            'description' => 'Right to export the complete FAQ'
274
        ),
275
    );
276
277
    /**
278
     * Configuration array
279
     *
280
     * @var array
281
     */
282
    protected $_mainConfig = array(
283
        'main.currentVersion'                     => null,
284
        'main.currentApiVersion'                  => null,
285
        'main.language'                           => '__PHPMYFAQ_LANGUAGE__',
286
        'main.languageDetection'                  => 'true',
287
        'main.phpMyFAQToken'                      => null,
288
        'main.referenceURL'                       => '__PHPMYFAQ_REFERENCE_URL__',
289
        'main.administrationMail'                 => '[email protected]',
290
        'main.contactInformations'                => '',
291
        'main.enableAdminLog'                     => 'true',
292
        'main.enableRewriteRules'                 => 'false',
293
        'main.enableUserTracking'                 => 'true',
294
        'main.metaDescription'                    => 'phpMyFAQ should be the answer for all questions in life',
295
        'main.metaKeywords'                       => '',
296
        'main.metaPublisher'                      => '__PHPMYFAQ_PUBLISHER__',
297
        'main.send2friendText'                    => '',
298
        'main.titleFAQ'                           => 'phpMyFAQ Codename Perdita',
299
        'main.urlValidateInterval'                => '86400',
300
        'main.enableWysiwygEditor'                => 'true',
301
        'main.enableWysiwygEditorFrontend'        => 'false',
302
        'main.templateSet'                        => 'default',
303
        'main.optionalMailAddress'                => 'false',
304
        'main.dateFormat'                         => 'Y-m-d H:i',
305
        'main.maintenanceMode'                    => 'false',
306
        'main.enableGravatarSupport'              => 'false',
307
308
        'records.numberOfRecordsPerPage'          => '10',
309
        'records.numberOfShownNewsEntries'        => '3',
310
        'records.defaultActivation'               => 'false',
311
        'records.defaultAllowComments'            => 'false',
312
        'records.enableVisibilityQuestions'       => 'false',
313
        'records.numberOfRelatedArticles'         => '5',
314
        'records.orderby'                         => 'id',
315
        'records.sortby'                          => 'DESC',
316
        'records.orderingPopularFaqs'             => 'visits',
317
        'records.disableAttachments'              => 'true',
318
        'records.maxAttachmentSize'               => '100000',
319
        'records.attachmentsPath'                 => 'attachments',
320
        'records.attachmentsStorageType'          => '0',
321
        'records.enableAttachmentEncryption'      => 'false',
322
        'records.defaultAttachmentEncKey'         => '',
323
        'records.enableCloseQuestion'             => 'false',
324
        'records.enableDeleteQuestion'            => 'false',
325
        'records.autosaveActive'                  => 'false',
326
        'records.autosaveSecs'                    => '180',
327
        'records.randomSort'                      => 'false',
328
329
        'search.useAjaxSearchOnStartpage'         => 'false',
330
        'search.numberSearchTerms'                => '10',
331
        'search.relevance'                        => 'thema,content,keywords',
332
        'search.enableRelevance'                  => 'false',
333
334
        'security.permLevel'                      => 'basic',
335
        'security.ipCheck'                        => 'false',
336
        'security.enableLoginOnly'                => 'false',
337
        'security.ldapSupport'                    => 'false',
338
        'security.bannedIPs'                      => '',
339
        'security.ssoSupport'                     => 'false',
340
        'security.ssoLogoutRedirect'              => '',
341
        'security.useSslForLogins'                => 'false',
342
        'security.useSslOnly'                     => 'false',
343
        'security.forcePasswordUpdate'            => 'false',
344
345
        'spam.checkBannedWords'                   => 'true',
346
        'spam.enableCaptchaCode'                  => null,
347
        'spam.enableSafeEmail'                    => 'true',
348
349
        'socialnetworks.enableTwitterSupport'     => 'false',
350
        'socialnetworks.twitterConsumerKey'       => '',
351
        'socialnetworks.twitterConsumerSecret'    => '',
352
        'socialnetworks.twitterAccessTokenKey'    => '',
353
        'socialnetworks.twitterAccessTokenSecret' => '',
354
        'socialnetworks.enableFacebookSupport'    => 'false',
355
356
        'cache.varnishEnable'                     => 'false',
357
        'cache.varnishHost'                       => '127.0.0.1',
358
        'cache.varnishPort'                       => '2000',
359
        'cache.varnishSecret'                     => '',
360
        'cache.varnishTimeout'                    => '500'
361
    );
362
363
    /**
364
     * Constructor
365
     *
366
     * @return PMF_Installer
367
     */
368
    public function __construct()
369
    {
370
        $this->_system = new PMF_System();
371
        $dynMainConfig = array(
372
            'main.currentVersion'    => PMF_System::getVersion(),
373
            'main.currentApiVersion' => PMF_System::getApiVersion(),
374
            'main.phpMyFAQToken'     => md5(uniqid(rand())),
375
            'spam.enableCaptchaCode' => (extension_loaded('gd') ? 'true' : 'false'),
376
        );
377
        $this->_mainConfig = array_merge($this->_mainConfig, $dynMainConfig);
378
    }
379
380
    /**
381
     * Check absolutely necessary stuff and die
382
     *
383
     * @return void
384
     */
385
    public function checkBasicStuff()
386
    {
387
        if (!$this->checkMinimumPhpVersion()) {
388
            printf('<p class="alert alert-error">Sorry, but you need PHP %s or later!</p>', PMF_System::VERSION_MINIMUM_PHP);
389
            PMF_System::renderFooter();
390
        }
391
392
        if (! function_exists('date_default_timezone_set')) {
393
            echo '<p class="alert alert-error">Sorry, but setting a default timezone doesn\'t work in your environment!</p>';
394
            PMF_System::renderFooter();
395
        }
396
397 View Code Duplication
        if (! $this->_system->checkDatabase()) {
398
            echo '<p class="alert alert-error">No supported database detected! Please install one of the following' .
399
                ' database systems and enable the corresponding PHP extension in php.ini:</p>';
400
            echo '<ul>';
401
            foreach ($this->_system->getSupportedDatabases() as $database) {
402
                printf('    <li>%s</li>', $database[1]);
403
            }
404
            echo '</ul>';
405
            PMF_System::renderFooter();
406
        }
407
408 View Code Duplication
        if (! $this->_system->checkRequiredExtensions()) {
409
            echo '<p class="alert alert-error">The following extensions are missing! Please enable the PHP extension(s) in ' .
410
                'php.ini.</p>';
411
            echo '<ul>';
412
            foreach ($this->_system->getMissingExtensions() as $extension) {
413
                printf('    <li>ext/%s</li>', $extension);
414
            }
415
            echo '</ul>';
416
            PMF_System::renderFooter();
417
        }
418
419
        if (! $this->_system->checkRegisterGlobals()) {
420
            echo '<p class="alert alert-error">Please disable register_globals!</p>';
421
            PMF_System::renderFooter();
422
        }
423
424
        if (! $this->_system->checkMagicQuotesGpc()) {
425
            echo '<p class="alert alert-error">Please disable magic_quotes_gpc!</p>';
426
            PMF_System::renderFooter();
427
        }
428
429
        if (! $this->_system->checkphpMyFAQInstallation()) {
430
            echo '<p class="alert alert-error">It seems you\'re already running a version of phpMyFAQ. Please use the ' .
431
                '<a href="update.php">update script</a>.</p>';
432
            PMF_System::renderFooter();
433
        }
434
    }
435
436
    /**
437
     * Checks for the minimum PHP requirement and if the database credentials file is readable
438
     *
439
     * @return void
440
     */
441
    public function checkPreUpgrade()
442
    {
443
        if (! $this->checkMinimumPhpVersion()) {
444
            printf(
445
                '<p class="alert alert-error">Sorry, but you need PHP %s or later!</p>',
446
                PMF_System::VERSION_MINIMUM_PHP
447
            );
448
            PMF_System::renderFooter();
449
        }
450
451
        if (! is_readable(PMF_ROOT_DIR . '/inc/data.php') && ! is_readable(PMF_ROOT_DIR . '/config/database.php')) {
452
            echo '<p class="alert alert-error">It seems you never run a version of phpMyFAQ.<br />' .
453
                'Please use the <a href="setup.php">install script</a>.</p>';
454
            PMF_System::renderFooter();
455
        }
456
457
        if (! $this->_system->checkRegisterGlobals()) {
458
            echo '<p class="alert alert-error">Please disable register_globals!</p>';
459
            PMF_System::renderFooter();
460
        }
461
462
        if (! $this->_system->checkMagicQuotesGpc()) {
463
            echo '<p class="alert alert-error">Please disable magic_quotes_gpc!</p>';
464
            PMF_System::renderFooter();
465
        }
466
    }
467
468
    /**
469
     * Checks the minimum required PHP version, defined in PMF_System
470
     *
471
     * @return bool
472
     */
473
    public function checkMinimumPhpVersion()
474
    {
475
        if (version_compare(PHP_VERSION, PMF_System::VERSION_MINIMUM_PHP, '<')) {
476
            return false;
477
        }
478
        return true;
479
    }
480
481
    /**
482
     * Checks if the file permissions are okay
483
     *
484
     * @return void
485
     */
486
    public function checkFilesystemPermissions()
487
    {
488
        $instanceSetup = new PMF_Instance_Setup();
489
        $instanceSetup->setRootDir(PMF_ROOT_DIR);
490
491
        $dirs       = array('/attachments', '/config', '/data', '/images');
492
        $failedDirs = $instanceSetup->checkDirs($dirs);
493
        $numDirs    = sizeof($failedDirs);
494
495
        if (1 <= $numDirs) {
496
            printf(
497
                '<p class="alert alert-error">The following %s could not be created or %s not writable:</p><ul>',
498
                (1 < $numDirs) ? 'directories' : 'directory',
499
                (1 < $numDirs) ? 'are' : 'is'
500
            );
501
            foreach ($failedDirs as $dir) {
502
                echo "<li>$dir</li>\n";
503
            }
504
            printf(
505
                '</ul><p class="alert alert-error">Please create %s manually and/or change access to chmod 775 (or ' .
506
                    'greater if necessary).</p>',
507
                (1 < $numDirs) ? 'them' : 'it'
508
            );
509
            PMF_System::renderFooter();
510
        }
511
    }
512
513
    /**
514
     * Checks some non critical settings and print some hints
515
     *
516
     * @todo We should return an array of messages
517
     * @return void
518
     */
519
    public function checkNoncriticalSettings()
520
    {
521 View Code Duplication
        if ((@ini_get('safe_mode') == 'On' || @ini_get('safe_mode') === 1)) {
522
            echo '<p class="alert alert-error">The PHP safe mode is enabled. You may have problems when phpMyFAQ tries to write ' .
523
                ' in some directories.</p>';
524
        }
525
        if (! extension_loaded('gd')) {
526
            echo '<p class="alert alert-error">You don\'t have GD support enabled in your PHP installation. Please enable GD ' .
527
                'support in your php.ini file otherwise you can\'t use Captchas for spam protection.</p>';
528
        }
529
        if (! function_exists('imagettftext')) {
530
            echo '<p class="alert alert-error">You don\'t have Freetype support enabled in the GD extension of your PHP ' .
531
                'installation. Please enable Freetype support in GD extension otherwise the Captchas for spam ' .
532
                'protection will be quite easy to break.</p>';
533
        }
534
        if (! extension_loaded('curl') || ! extension_loaded('openssl')) {
535
            echo '<p class="alert alert-error">You don\'t have cURL and/or OpenSSL support enabled in your PHP installation. ' .
536
                'Please enable cURL and/or OpenSSL support in your php.ini file otherwise you can\'t use the Twitter ' .
537
                ' support.</p>';
538
        }
539
        if (! extension_loaded('fileinfo')) {
540
            echo '<p class="alert alert-error">You don\'t have Fileinfo support enabled in your PHP installation. ' .
541
                'Please enable Fileinfo support in your php.ini file otherwise you can\'t use our backup/restore ' .
542
                'functionality.</p>';
543
        }
544
    }
545
546
    /**
547
     * Checks if we can store data via sessions. If not, e.g. an user can't
548
     * login into the admin section
549
     *
550
     * @return bool
551
     */
552
    public function checkSessionSettings()
553
    {
554
        return true;
555
    }
556
557
    /**
558
     * Starts the installation
559
     *
560
     * @param array $DB
561
     */
562
    public function startInstall(Array $DB = null)
563
    {
564
        $query = $uninst = $dbSetup = array();
565
566
        // Check table prefix
567
        $dbSetup['dbPrefix'] = $sqltblpre = PMF_Filter::filterInput(INPUT_POST, 'sqltblpre', FILTER_SANITIZE_STRING, '');
568
        if ('' !== $dbSetup['dbPrefix']) {
569
            PMF_Db::setTablePrefix($dbSetup['dbPrefix']);
570
        }
571
572
        // Check database entries
573
        $dbSetup['dbType'] = PMF_Filter::filterInput(INPUT_POST, 'sql_type', FILTER_SANITIZE_STRING);
574
        if (!is_null($dbSetup['dbType'])) {
575
            $dbSetup['dbType'] = trim($dbSetup['dbType']);
576
            if (! file_exists(PMF_ROOT_DIR . '/install/' . $dbSetup['dbType'] . '.sql.php')) {
577
                printf(
578
                    '<p class="alert alert-error"><strong>Error:</strong> Invalid server type: %s</p>',
579
                    $dbSetup['dbType']
580
                );
581
                PMF_System::renderFooter(true);
582
            }
583
        } else {
584
            echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please select a database type.</p>\n";
585
            PMF_System::renderFooter(true);
586
        }
587
588
        $dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_server', FILTER_SANITIZE_STRING);
589 View Code Duplication
        if (is_null($dbSetup['dbServer']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
590
            echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database server.</p>\n";
591
            PMF_System::renderFooter(true);
592
        }
593
594
        $dbSetup['dbUser'] = PMF_Filter::filterInput(INPUT_POST, 'sql_user', FILTER_SANITIZE_STRING);
595 View Code Duplication
        if (is_null($dbSetup['dbUser']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
596
            echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database username.</p>\n";
597
            PMF_System::renderFooter(true);
598
        }
599
600
        $dbSetup['dbPassword'] = PMF_Filter::filterInput(INPUT_POST, 'sql_passwort', FILTER_UNSAFE_RAW);
601
        if (is_null($dbSetup['dbPassword']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
602
            // Password can be empty...
603
            $dbSetup['dbPassword'] = '';
604
        }
605
606
        $dbSetup['dbDatabaseName'] = PMF_Filter::filterInput(INPUT_POST, 'sql_db', FILTER_SANITIZE_STRING);
607 View Code Duplication
        if (is_null($dbSetup['dbDatabaseName']) && ! PMF_System::isSqlite($dbSetup['dbType'])) {
608
            echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a database name.</p>\n";
609
            PMF_System::renderFooter(true);
610
        }
611
612
        if (PMF_System::isSqlite($dbSetup['dbType'])) {
613
            $dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_sqlitefile', FILTER_SANITIZE_STRING);
614
            if (is_null($dbSetup['dbServer'])) {
615
                echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a SQLite database filename.</p>\n";
616
                PMF_System::renderFooter(true);
617
            }
618
        }
619
620
        // check database connection
621
        PMF_Db::setTablePrefix($dbSetup['dbPrefix']);
622
        $db = PMF_Db::factory($dbSetup['dbType']);
623
        $db->connect($dbSetup['dbServer'], $dbSetup['dbUser'], $dbSetup['dbPassword'], $dbSetup['dbDatabaseName']);
624
        if (!$db) {
625
            printf("<p class=\"alert alert-error\"><strong>DB Error:</strong> %s</p>\n", $db->error());
626
            PMF_System::renderFooter(true);
627
        }
628
629
        $configuration = new PMF_Configuration($db);
630
631
        // check LDAP if available
632
        $ldapEnabled = PMF_Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_STRING);
633
        if (extension_loaded('ldap') && !is_null($ldapEnabled)) {
634
635
            $ldapSetup = array();
636
637
            // check LDAP entries
638
            $ldapSetup['ldapServer'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_STRING);
639
            if (is_null($ldapSetup['ldapServer'])) {
640
                echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP server.</p>\n";
641
                PMF_System::renderFooter(true);
642
            }
643
644
            $ldapSetup['ldapPort'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_port', FILTER_VALIDATE_INT);
645
            if (is_null($ldapSetup['ldapPort'])) {
646
                echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP port.</p>\n";
647
                PMF_System::renderFooter(true);
648
            }
649
650
            $ldapSetup['ldapBase'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_base', FILTER_SANITIZE_STRING);
651
            if (is_null($ldapSetup['ldapBase'])) {
652
                echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a LDAP base search DN.</p>\n";
653
                PMF_System::renderFooter(true);
654
            }
655
656
            // LDAP User and LDAP password are optional
657
            $ldapSetup['ldapUser']     = PMF_Filter::filterInput(INPUT_POST, 'ldap_user', FILTER_SANITIZE_STRING, '');
658
            $ldapSetup['ldapPassword'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_password', FILTER_SANITIZE_STRING, '');
659
660
            // check LDAP connection
661
            require PMF_ROOT_DIR . "/inc/PMF/Ldap.php";
662
            $ldap = new PMF_Ldap($configuration);
663
            $ldap->connect(
664
                $ldapSetup['ldapServer'],
665
                $ldapSetup['ldapPort'],
666
                $ldapSetup['ldapBase'],
667
                $ldapSetup['ldapUser'],
668
                $ldapSetup['ldapPassword']
669
            );
670
            if (!$ldap) {
671
                echo "<p class=\"alert alert-error\"><strong>LDAP Error:</strong> " . $ldap->error() . "</p>\n";
672
                PMF_System::renderFooter(true);
673
            }
674
        }
675
676
        // check loginname
677
        $loginname = PMF_Filter::filterInput(INPUT_POST, 'loginname', FILTER_SANITIZE_STRING);
678
        if (is_null($loginname)) {
679
            echo '<p class="alert alert-error"><strong>Error:</strong> Please add a loginname for your account.</p>';
680
            PMF_System::renderFooter(true);
681
        }
682
683
        // check user entries
684
        $password = PMF_Filter::filterInput(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
685
        if (is_null($password)) {
686
            echo '<p class="alert alert-error"><strong>Error:</strong> Please add a password for the your account.</p>';
687
            PMF_System::renderFooter(true);
688
        }
689
690
        $password_retyped = PMF_Filter::filterInput(INPUT_POST, 'password_retyped', FILTER_SANITIZE_STRING);
691
        if (is_null($password_retyped)) {
692
            echo '<p class="alert alert-error"><strong>Error:</strong> Please add a retyped password.</p>';
693
            PMF_System::renderFooter(true);
694
        }
695
696
        if (strlen($password) <= 5 || strlen($password_retyped) <= 5) {
697
            echo '<p class="alert alert-error"><strong>Error:</strong> Your password and retyped password are too short.' .
698
                ' Please set your password and your retyped password with a minimum of 6 characters.</p>';
699
            PMF_System::renderFooter(true);
700
        }
701
        if ($password != $password_retyped) {
702
            echo '<p class="alert alert-error"><strong>Error:</strong> Your password and retyped password are not equal.' .
703
                ' Please check your password and your retyped password.</p>';
704
            PMF_System::renderFooter(true);
705
        }
706
707
        $language  = PMF_Filter::filterInput(INPUT_POST, 'language', FILTER_SANITIZE_STRING, 'en');
708
        $realname  = PMF_Filter::filterInput(INPUT_POST, 'realname', FILTER_SANITIZE_STRING, '');
709
        $email     = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL, '');
710
        $permLevel = PMF_Filter::filterInput(INPUT_POST, 'permLevel', FILTER_SANITIZE_STRING, 'basic');
711
712
        $instanceSetup = new PMF_Instance_Setup();
713
        $instanceSetup->setRootDir(PMF_ROOT_DIR);
714
715
        // Write the DB variables in database.php
716
        if (! $instanceSetup->createDatabaseFile($dbSetup)) {
717
            echo "<p class=\"alert alert-error\"><strong>Error:</strong> Setup cannot write to ./config/database.php.</p>";
718
            $this->_system->cleanInstallation();
719
            PMF_System::renderFooter(true);
720
        }
721
722
        // check LDAP if available
723
        if (extension_loaded('ldap') && !is_null($ldapEnabled)) {
724
            if (! $instanceSetup->createLdapFile($ldapSetup, '')) {
725
                echo "<p class=\"alert alert-error\"><strong>Error:</strong> Setup cannot write to ./config/ldap.php.</p>";
726
                $this->_system->cleanInstallation();
727
                PMF_System::renderFooter(true);
728
            }
729
        }
730
731
        // connect to the database using config/database.php
732
        require PMF_ROOT_DIR . '/config/database.php';
733
        $db = PMF_Db::factory($dbSetup['dbType']);
734
        $db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']);
735 View Code Duplication
        if (!$db) {
736
            echo "<p class=\"alert alert-error\"><strong>DB Error:</strong> ".$db->error()."</p>\n";
737
            $this->_system->cleanInstallation();
738
            PMF_System::renderFooter(true);
739
        }
740
741
        require PMF_ROOT_DIR . '/install/' . $dbSetup['dbType'] . '.sql.php'; // CREATE TABLES
742
        require PMF_ROOT_DIR . '/install/stopwords.sql.php';  // INSERTs for stopwords
743
744
        $this->_system->setDatabase($db);
745
746
        echo '<p>';
747
748
        // Erase any table before starting creating the required ones
749
        if (! PMF_System::isSqlite($dbSetup['dbType'])) {
750
            $this->_system->dropTables($uninst);
751
        }
752
753
        // Start creating the required tables
754
        $count = 0;
755
        foreach ($query as $executeQuery) {
756
            $result = @$db->query($executeQuery);
757
            if (!$result) {
758
                echo '<p class="alert alert-error"><strong>Error:</strong> Please install your version of phpMyFAQ once again or send
759
            us a <a href=\"http://www.phpmyfaq.de\" target=\"_blank\">bug report</a>.</p>';
760
                printf('<p class="alert alert-error"><strong>DB error:</strong> %s</p>', $db->error());
761
                printf('<code>%s</code>', htmlentities($executeQuery));
762
                $this->_system->dropTables($uninst);
763
                $this->_system->cleanInstallation();
764
                PMF_System::renderFooter(true);
765
            }
766
            usleep(2500);
767
            $count++;
768
            if (!($count % 10)) {
769
                echo '| ';
770
            }
771
        }
772
773
        $link = new PMF_Link(null, $configuration);
774
775
        // add main configuration, add personal settings
776
        $this->_mainConfig['main.metaPublisher']      = $realname;
777
        $this->_mainConfig['main.administrationMail'] = $email;
778
        $this->_mainConfig['main.language']           = $language;
779
        $this->_mainConfig['security.permLevel']      = $permLevel;
780
781
        foreach ($this->_mainConfig as $name => $value) {
782
            $configuration->add($name, $value);
783
        }
784
785
        $configuration->update(array('main.referenceURL' => $link->getSystemUri('/install/setup.php')));
786
        $configuration->add('security.salt', md5($configuration->get('main.referenceURL')));
787
788
        // add admin account and rights
789
        $admin = new PMF_User($configuration);
790 View Code Duplication
        if (! $admin->createUser($loginname, $password, 1)) {
791
            echo "<p class=\"alert alert-error\"><strong>Fatal installation error:</strong> " .
792
                "Couldn't create the admin user.</p>\n";
793
            $this->_system->cleanInstallation();
794
            PMF_System::renderFooter(true);
795
        }
796
        $admin->setStatus('protected');
797
        $adminData = array(
798
            'display_name' => $realname,
799
            'email'        => $email
800
        );
801
        $admin->setUserData($adminData);
802
803
        // add default rights
804
        foreach ($this->_mainRights as $right) {
805
            $admin->perm->grantUserRight(1, $admin->perm->addRight($right));
806
        }
807
808
        // Add anonymous user account
809
        $instanceSetup->createAnonymousUser($configuration);
810
811
        // Add master instance
812
        $instanceData = array(
813
            'url'      => $link->getSystemUri($_SERVER['SCRIPT_NAME']),
814
            'instance' => $link->getSystemRelativeUri('install/setup.php'),
815
            'comment'  => 'phpMyFAQ ' . PMF_System::getVersion()
816
        );
817
        $faqInstance = new PMF_Instance($configuration);
818
        $faqInstance->addInstance($instanceData);
819
820
        $faqInstanceMaster = new PMF_Instance_Master($configuration);
821
        $faqInstanceMaster->createMaster($faqInstance);
822
823
        echo '</p>';
824
    }
825
826
    /**
827
     * Cleanup all files after an installation
828
     *
829
     * @return void
830
     */
831
    public function cleanUpFiles()
832
    {
833
        // Remove 'setup.php' file
834
        if (@unlink(basename($_SERVER['SCRIPT_NAME']))) {
835
            echo "<p class=\"alert alert-success\">The file <em>./install/setup.php</em> was deleted automatically.</p>\n";
836
        } else {
837
            echo "<p class=\"alert alert-error\">Please delete the file <em>./install/setup.php</em> manually.</p>\n";
838
        }
839
        // Remove 'update.php' file
840
        if (@unlink(dirname($_SERVER['PATH_TRANSLATED']) . '/update.php')) {
841
            echo "<p class=\"alert alert-success\">The file <em>./install/update.php</em> was deleted automatically.</p>\n";
842
        } else {
843
            echo "<p class=\"alert alert-error\">Please delete the file <em>./install/update.php</em> manually.</p>\n";
844
        }
845
    }
846
847
    /**
848
     * Echos the questionnaire data
849
     *
850
     * @return void
851
     */
852
    public function printDataList()
853
    {
854
        $q = new PMF_Questionnaire_Data($this->_mainConfig);
855
        $options = $q->get();
856
        echo '<dl>' . PHP_EOL;
857
        array_walk($options, 'data_printer');
858
        printf(
859
            '</dl><input type="hidden" name="systemdata" value="%s" />',
860
            PMF_String::htmlspecialchars(serialize($q->get()), ENT_QUOTES)
861
        );
862
    }
863
}