Conditions | 76 |
Paths | > 20000 |
Total Lines | 513 |
Code Lines | 286 |
Lines | 32 |
Ratio | 6.24 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
101 | function upgradeDB() |
||
102 | { |
||
103 | global $xoopsModule; |
||
104 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection(); |
||
105 | //1. Determine previous release |
||
106 | // *** Update this in sql/mysql.sql for each release ** |
||
107 | View Code Duplication | if (!xhelpTableExists('xhelp_meta')) { |
|
108 | $ver = '0.5'; |
||
109 | } else { |
||
110 | if (!$ver = xhelpGetMeta('version')) { |
||
111 | exit(_AM_XHELP_VERSION_ERR); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | $hStaff =& xhelpGetHandler('staff'); |
||
116 | $hMember =& xhelpGetHandler('membership'); |
||
117 | $hTicket =& xhelpGetHandler('ticket'); |
||
118 | $hXoopsMember =& xoops_gethandler('member'); |
||
119 | $hRole =& xhelpGetHandler('role'); |
||
120 | |||
121 | $mid = $xoopsModule->getVar('mid'); |
||
122 | |||
123 | xoops_cp_header(); |
||
124 | //echo $oAdminButton->renderButtons(''); |
||
125 | $indexAdmin = new ModuleAdmin(); |
||
126 | echo $indexAdmin->addNavigation('upgrade.php'); |
||
127 | |||
128 | echo "<h2>"._AM_XHELP_UPDATE_DB."</h2>"; |
||
129 | $ret = true; |
||
130 | //2. Do All Upgrades necessary to make current |
||
131 | // Break statements are omitted on purpose |
||
132 | switch($ver) { |
||
133 | case '0.5': |
||
134 | set_time_limit(60); |
||
135 | printf("<h3>". _AM_XHELP_UPDATE_TO."</h3>", '0.6' ); |
||
136 | echo "<ul>"; |
||
137 | //Create meta table |
||
138 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (metakey varchar(50) NOT NULL default '', metavalue varchar(255) NOT NULL default '', PRIMARY KEY (metakey)) ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_meta')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_meta'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_meta')); |
||
139 | |||
140 | //Insert Current Version into table |
||
141 | $qry = $xoopsDB->query(sprintf("INSERT INTO %s values('version', %s)", $xoopsDB->prefix('xhelp_meta'), $xoopsDB->quoteString($ver))); |
||
142 | |||
143 | //Update xhelp_responses table |
||
144 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD private INT(11) NOT NULL DEFAULT '0'", $xoopsDB->prefix('xhelp_responses')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_responses'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_responses')) ; |
||
145 | |||
146 | //Retrieve uid's of all staff members |
||
147 | $qry = $xoopsDB->query('SELECT uid FROM '. $xoopsDB->prefix('xhelp_staff'). ' ORDER BY uid'); |
||
148 | |||
149 | //Get email addresses in user profile |
||
150 | $staff = array(); |
||
151 | while ($arr = $xoopsDB->fetchArray($qry)) { |
||
152 | $staff[$arr['uid']] = ''; |
||
153 | } |
||
154 | $xoopsDB->freeRecordSet($qry); |
||
155 | |||
156 | $query = 'SELECT uid, email FROM '. $xoopsDB->prefix('users') . ' WHERE uid IN ('. implode(array_keys($staff), ',') .')'; |
||
157 | $qry = $xoopsDB->query($query); |
||
158 | while($arr = $xoopsDB->fetchArray($qry)) { |
||
159 | $staff[$arr['uid']] = $arr['email']; |
||
160 | } |
||
161 | $xoopsDB->freeRecordSet($qry); |
||
162 | |||
163 | //Update xhelp_staff table |
||
164 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD email varchar(255) NOT NULL default '' AFTER uid, ADD notify int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_staff')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_staff'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_staff')) ; |
||
165 | |||
166 | //Update existing staff records |
||
167 | $staff_tbl = $xoopsDB->prefix('xhelp_staff'); |
||
168 | $notif_tbl = $xoopsDB->prefix('xoopsnotifications'); |
||
169 | $email_tpl = $xoopsModule->getInfo('_email_tpl'); |
||
170 | foreach ($staff as $uid=>$email) { |
||
171 | |||
172 | //get notifications for current user |
||
173 | $usernotif = 0; |
||
174 | $qry = $xoopsDB->query(sprintf("SELECT DISTINCT not_category, not_event FROM %s WHERE not_uid = %u AND not_category='dept' AND not_modid=%u", $notif_tbl, $uid, $mid)); |
||
175 | while($arr = $xoopsDB->fetchArray($qry)) { |
||
176 | //Look for current event information in $email_tpl |
||
177 | foreach($email_tpl as $tpl) { |
||
178 | if (($tpl['name'] == $arr['not_event']) && ($tpl['category'] == $arr['not_category'])) { |
||
179 | $usernotif = $usernotif | pow(2, $tpl['bit_value']); |
||
180 | break; |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
185 | //Update xhelp_staff with user notifications & email address |
||
186 | $ret = $ret && _runQuery(sprintf("UPDATE %s SET email = %s, notify = %u WHERE uid = %u", $staff_tbl, $xoopsDB->quoteString($email), $usernotif, $uid), sprintf(_AM_XHELP_MSG_UPDATESTAFF, $uid), sprintf(_AM_XHELP_MSG_UPDATESTAFF_ERR, $uid)); |
||
187 | } |
||
188 | echo "</ul>"; |
||
189 | case '0.6': |
||
190 | set_time_limit(60); |
||
191 | //Do DB updates to make 0.7 |
||
192 | printf("<h3>". _AM_XHELP_UPDATE_TO."</h3>", '0.7' ); |
||
193 | |||
194 | echo "<ul>"; |
||
195 | // change table names to lowercase |
||
196 | $ret = $ret && _renameTable('xhelp_logMessages', 'xhelp_logmessages'); |
||
197 | $ret = $ret && _renameTable('xhelp_responseTemplates', 'xhelp_responsetemplates'); |
||
198 | $ret = $ret && _renameTable('xhelp_jStaffDept', 'xhelp_jstaffdept'); |
||
199 | $ret = $ret && _renameTable('xhelp_staffReview', 'xhelp_staffreview'); |
||
200 | $ret = $ret && _renameTable('xhelp_emailTpl', 'xhelp_emailtpl'); |
||
201 | |||
202 | // Remove unused table - xhelp_emailtpl |
||
203 | $ret = $ret && _runQuery(sprintf("DROP TABLE %s", $xoopsDB->prefix('xhelp_emailtpl')), |
||
204 | sprintf(_AM_XHELP_MSG_REMOVE_TABLE, 'xhelp_emailtpl'), |
||
205 | sprintf(_AM_XHELP_MSG_NOT_REMOVE_TABLE, 'xhelp_emailtpl')); |
||
206 | |||
207 | // xhelp_staff table - permTimestamp |
||
208 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD permTimestamp INT(11) NOT NULL DEFAULT '0'", $xoopsDB->prefix('xhelp_staff')), |
||
209 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_staff'), |
||
210 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_staff')) ; |
||
211 | |||
212 | //Update xhelp_tickets table |
||
213 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY subject VARCHAR(100) NOT NULL default ''", $xoopsDB->prefix('xhelp_tickets')), |
||
214 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), |
||
215 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets')) ; |
||
216 | |||
217 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (serverid INT(11) DEFAULT NULL, |
||
218 | emailHash VARCHAR(100) DEFAULT NULL, |
||
219 | email VARCHAR(100) DEFAULT NULL, |
||
220 | overdueTime INT(11) NOT NULL DEFAULT '0', |
||
221 | KEY emailHash (emailHash))", $xoopsDB->prefix('xhelp_tickets')), |
||
222 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), |
||
223 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets')) ; |
||
224 | |||
225 | // Create xhelp_department_mailbox table |
||
226 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
227 | departmentid int(11) default NULL, |
||
228 | emailaddress varchar(255) default NULL, |
||
229 | server varchar(50) default NULL, |
||
230 | serverport int(11) default NULL, |
||
231 | username varchar(50) default NULL, |
||
232 | password varchar(50) default NULL, |
||
233 | priority tinyint(4) default NULL, |
||
234 | mboxtype int(11) NOT NULL default 1, |
||
235 | PRIMARY KEY (id), |
||
236 | UNIQUE KEY id (id), |
||
237 | KEY departmentid (departmentid), |
||
238 | KEY emailaddress (emailaddress), |
||
239 | KEY mboxtype (mboxtype) |
||
240 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_department_mailbox')), |
||
241 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_department_mailbox'), |
||
242 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_department_mailbox')); |
||
243 | |||
244 | // Create xhelp_mailevent table |
||
245 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
246 | mbox_id int(11) NOT NULL default '0', |
||
247 | event_desc text, |
||
248 | event_class int(11) NOT NULL default '0', |
||
249 | posted int(11) NOT NULL default '0', |
||
250 | PRIMARY KEY(id) |
||
251 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_mailevent')), |
||
252 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_mailevent'), |
||
253 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_mailevent')); |
||
254 | |||
255 | // Create xhelp_roles table |
||
256 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
257 | name varchar(35) NOT NULL default '', |
||
258 | description mediumtext, |
||
259 | tasks int(11) NOT NULL default '0', |
||
260 | PRIMARY KEY(id) |
||
261 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_roles')), |
||
262 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_roles'), |
||
263 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_roles')); |
||
264 | |||
265 | // Create xhelp_staffroles table |
||
266 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (uid int(11) NOT NULL default '0', |
||
267 | roleid int(11) NOT NULL default '0', |
||
268 | deptid int(11) NOT NULL default '0', |
||
269 | PRIMARY KEY(uid, roleid, deptid) |
||
270 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_staffroles')), |
||
271 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_staffroles'), |
||
272 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_staffroles')); |
||
273 | |||
274 | // Add default roles to db |
||
275 | if(!$hasRoles = xhelpCreateRoles()){ |
||
276 | echo "<li>"._AM_XHELP_MESSAGE_DEF_ROLES_ERROR."</li>"; |
||
277 | } else { |
||
278 | echo "<li>"._AM_XHELP_MESSAGE_DEF_ROLES."</li>"; |
||
279 | } |
||
280 | |||
281 | // Set all staff members to have admin permission role |
||
282 | if($staff =& $hStaff->getObjects()){ |
||
283 | foreach($staff as $stf){ |
||
284 | $uid = $stf->getVar('uid'); |
||
285 | $depts = $hMember->membershipByStaff($uid, true); |
||
286 | if($hStaff->addStaffRole($uid, 1, 0)){ |
||
287 | echo "<li>".sprintf(_AM_XHELP_MSG_GLOBAL_PERMS, $uid)."</li>"; |
||
288 | } |
||
289 | |||
290 | foreach($depts as $dept){ |
||
291 | $deptid = $dept->getVar('id'); |
||
292 | if($hStaff->addStaffRole($uid, 1, $deptid)){ // Departmental permissions |
||
293 | echo "<li>".sprintf(_AM_XHELP_MSG_UPD_PERMS, $uid, $dept->getVar('department'))."</li>"; |
||
294 | } |
||
295 | } |
||
296 | |||
297 | $stf->setVar('permTimestamp', time()); // Set initial value for permTimestamp field |
||
298 | if(!$hStaff->insert($stf)){ |
||
299 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATESTAFF_ERR, $uid)."</li>"; |
||
300 | } else { |
||
301 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATESTAFF, $uid)."</li>"; |
||
302 | } |
||
303 | } |
||
304 | } |
||
305 | echo "</ul>"; |
||
306 | |||
307 | case '0.7': |
||
308 | set_time_limit(60); |
||
309 | //Do DB updates to make 0.71 |
||
310 | printf("<h3>". _AM_XHELP_UPDATE_TO."</h3>", '0.71' ); |
||
311 | |||
312 | echo "<ul>"; |
||
313 | echo "</ul>"; |
||
314 | |||
315 | case '0.71': |
||
316 | set_time_limit(60); |
||
317 | //Do DB updates to make 0.75 |
||
318 | printf("<h3>". _AM_XHELP_UPDATE_TO."</h3>", '0.75' ); |
||
319 | |||
320 | echo "<ul>"; |
||
321 | |||
322 | //Changes for php5 compabibility |
||
323 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY lastUpdated int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_logmessages')), |
||
324 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_logmessages'), |
||
325 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_logmessages')); |
||
326 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY department int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_jstaffdept')), |
||
327 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_jstaffdept'), |
||
328 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_jstaffdept')) ; |
||
329 | |||
330 | // Create table for email template information |
||
331 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (notif_id int(11) NOT NULL default '0', |
||
332 | staff_setting int(11) NOT NULL default '0', |
||
333 | user_setting int(11) NOT NULL default '0', |
||
334 | staff_options mediumtext NOT NULL, |
||
335 | PRIMARY KEY (notif_id) |
||
336 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_notifications')), |
||
337 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_notifications'), |
||
338 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_notifications')); |
||
339 | |||
340 | // Add xhelp_status table |
||
341 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
342 | state int(11) NOT NULL default '0', |
||
343 | description varchar(50) NOT NULL default '', |
||
344 | PRIMARY KEY(id), |
||
345 | KEY state (state) |
||
346 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_status')), |
||
347 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_status'), |
||
348 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_status')); |
||
349 | |||
350 | // Give default statuses for upgrade |
||
351 | $hStatus =& xhelpGetHandler('status'); |
||
352 | $startStatuses = array(_XHELP_STATUS0 => 1, _XHELP_STATUS1 => 1, _XHELP_STATUS2 => 2); |
||
353 | |||
354 | $count = 1; |
||
355 | set_time_limit(60); |
||
356 | foreach($startStatuses as $desc=>$state){ |
||
357 | $newStatus =& $hStatus->create(); |
||
358 | $newStatus->setVar('id', $count); |
||
359 | $newStatus->setVar('description', $desc); |
||
360 | $newStatus->setVar('state', $state); |
||
361 | if(!$hStatus->insert($newStatus)){ |
||
362 | echo "<li>".sprintf(_AM_XHELP_MSG_ADD_STATUS_ERR, $desc)."</li>"; |
||
363 | } else { |
||
364 | echo "<li>".sprintf(_AM_XHELP_MSG_ADD_STATUS, $desc)."</li>"; |
||
365 | } |
||
366 | $count++; |
||
367 | } |
||
368 | |||
369 | // Change old status values to new status values |
||
370 | $oldStatuses = array(2 => 3, 1 => 2, 0 => 1); |
||
371 | |||
372 | foreach($oldStatuses as $cStatus=>$newStatus){ |
||
373 | $crit = new Criteria('status', $cStatus); |
||
374 | $success = $hTicket->updateAll('status', $newStatus, $crit); |
||
375 | } |
||
376 | if($success){ |
||
377 | echo "<li>"._AM_XHELP_MSG_CHANGED_STATUS."</li>"; |
||
378 | } else { |
||
379 | echo "<li>"._AM_XHELP_MSG_CHANGED_STATUS_ERR."</li>"; |
||
380 | } |
||
381 | |||
382 | // Add xhelp_ticket_submit_emails table |
||
383 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (ticketid int(11) NOT NULL default '0', |
||
384 | uid int(11) NOT NULL default '0', |
||
385 | email varchar(100) NOT NULL default '', |
||
386 | suppress int(11) NOT NULL default '0', |
||
387 | PRIMARY KEY(ticketid, email) |
||
388 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_submit_emails')), |
||
389 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_submit_emails'), |
||
390 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_submit_emails')); |
||
391 | |||
392 | // Add records to xhelp_ticket_submit_emails for existing tickets |
||
393 | $count = $hTicket->getCount(); |
||
394 | $batchsize = 100; |
||
395 | |||
396 | $crit = new Criteria('', ''); |
||
397 | $crit->setLimit($batchsize); |
||
398 | $i = 0; |
||
399 | |||
400 | while ($i <= $count) { |
||
401 | set_time_limit(60); |
||
402 | $crit->setStart($i); |
||
403 | $tickets =& $hTicket->getObjects($crit); |
||
404 | |||
405 | $all_users = array(); |
||
406 | foreach($tickets as $ticket){ |
||
407 | $all_users[$ticket->getVar('uid')] = $ticket->getVar('uid'); |
||
408 | } |
||
409 | |||
410 | $crit = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN'); |
||
411 | $users =& $hXoopsMember->getUsers($crit, true); |
||
412 | |||
413 | foreach($users as $user){ |
||
414 | $all_users[$user->getVar('uid')] = $user->getVar('email'); |
||
415 | } |
||
416 | unset($users); |
||
417 | |||
418 | foreach($tickets as $ticket){ |
||
419 | set_time_limit(60); |
||
420 | $ticket_uid = $ticket->getVar('uid'); |
||
421 | if(array_key_exists($ticket_uid, $all_users)){ |
||
422 | $ticket_email = $all_users[$ticket_uid]; |
||
423 | $success = $ticket->addSubmitter($ticket_email, $ticket_uid); |
||
424 | } |
||
425 | } |
||
426 | unset($tickets); |
||
427 | //increment |
||
428 | $i += $batchsize; |
||
429 | } |
||
430 | |||
431 | set_time_limit(60); |
||
432 | // Update xhelp_roles Admin record with new value (2047) |
||
433 | $crit = new Criteria('tasks', 511); |
||
434 | $admin_roles =& $hRole->getObjects($crit); |
||
435 | |||
436 | View Code Duplication | foreach($admin_roles as $role){ |
|
437 | $role->setVar('tasks', 2047); |
||
438 | if($hRole->insert($role)){ |
||
439 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_ROLE, $role->getVar('name'))."</li>"; |
||
440 | } else { |
||
441 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_ROLE_ERR, $role->getVar('name'))."</li>"; |
||
442 | } |
||
443 | } |
||
444 | |||
445 | set_time_limit(60); |
||
446 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (active INT(11) NOT NULL DEFAULT 1, |
||
447 | KEY active (active))", $xoopsDB->prefix('xhelp_department_mailbox')), |
||
448 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_department_mailbox'), |
||
449 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_department_mailbox')); |
||
450 | |||
451 | // Add xhelp_saved_searches table |
||
452 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
453 | uid int(11) NOT NULL default '0', |
||
454 | name varchar(50) NOT NULL default '', |
||
455 | search mediumtext NOT NULL, |
||
456 | pagenav_vars mediumtext NOT NULL, |
||
457 | PRIMARY KEY(id) |
||
458 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_saved_searches')), |
||
459 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_saved_searches'), |
||
460 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_saved_searches')); |
||
461 | |||
462 | set_time_limit(60); |
||
463 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (fieldid int(11) NOT NULL default '0', |
||
464 | deptid int(11) NOT NULL default '0', |
||
465 | PRIMARY KEY (fieldid, deptid) |
||
466 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_field_departments')), |
||
467 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_field_departments'), |
||
468 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_field_departments')); |
||
469 | |||
470 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (ticketid int(11) NOT NULL default '0', |
||
471 | PRIMARY KEY (ticketid) |
||
472 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_values')), |
||
473 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_values'), |
||
474 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_values')); |
||
475 | |||
476 | set_time_limit(60); |
||
477 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
478 | name varchar(64) NOT NULL default '', |
||
479 | description tinytext NOT NULL, |
||
480 | fieldname varchar(64) NOT NULL default '', |
||
481 | controltype int(11) NOT NULL default '0', |
||
482 | datatype varchar(64) NOT NULL default '', |
||
483 | required tinyint(1) NOT NULL default '0', |
||
484 | fieldlength int(11) NOT NULL default '0', |
||
485 | weight int(11) NOT NULL default '0', |
||
486 | fieldvalues mediumtext NOT NULL, |
||
487 | defaultvalue varchar(100) NOT NULL default '', |
||
488 | validation mediumtext NOT NULL, |
||
489 | PRIMARY KEY (id), |
||
490 | KEY weight (weight) |
||
491 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_fields')), |
||
492 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_fields'), |
||
493 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_fields')); |
||
494 | |||
495 | set_time_limit(60); |
||
496 | // Add notifications to new table |
||
497 | set_time_limit(60); |
||
498 | $hasNotifications = xhelpCreateNotifications(); |
||
499 | |||
500 | // Make all departments visible to all groups |
||
501 | $hasDeptVisibility = xhelpCreateDepartmentVisibility(); |
||
502 | |||
503 | // Update staff permTimestamp |
||
504 | $hStaff->updateAll('permTimestamp', time()); |
||
505 | |||
506 | set_time_limit(60); |
||
507 | //Update xhelp_tickets table |
||
508 | set_time_limit(60); |
||
509 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY subject VARCHAR(255) NOT NULL default ''", $xoopsDB->prefix('xhelp_tickets')), |
||
510 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), |
||
511 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets')) ; |
||
512 | |||
513 | case '0.75': |
||
514 | set_time_limit(60); |
||
515 | // Set default department |
||
516 | $xoopsModuleConfig =& xhelpGetModuleConfig(); |
||
517 | if(isset($xoopsModuleConfig['xhelp_defaultDept']) && $xoopsModuleConfig['xhelp_defaultDept'] != 0){ |
||
518 | $ret = xhelpSetMeta('default_department', $xoopsModuleConfig['xhelp_defaultDept']); |
||
519 | View Code Duplication | } else { |
|
520 | $hDepartments =& xhelpGetHandler('department'); |
||
521 | $depts =& $hDepartments->getObjects(); |
||
522 | $aDepts = array(); |
||
523 | foreach($depts as $dpt){ |
||
524 | $aDepts[] = $dpt->getVar('id'); |
||
525 | } |
||
526 | $ret = xhelpSetMeta("default_department", $aDepts[0]); |
||
527 | } |
||
528 | |||
529 | $qry = $xoopsDB->query(sprintf("ALTER TABLE %s DROP PRIMARY KEY", $xoopsDB->prefix('xhelp_ticket_submit_emails'))); |
||
530 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD PRIMARY KEY(ticketid, uid, email)", $xoopsDB->prefix('xhelp_ticket_submit_emails')), |
||
531 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_ticket_submit_emails'), |
||
532 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_ticket_submit_emails')); |
||
533 | |||
534 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY department int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_jstaffdept')), |
||
535 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_jstaffdept'), |
||
536 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_jstaffdept')) ; |
||
537 | |||
538 | echo "<li>"._AM_XHELP_MSG_CHANGED_DEFAULT_DEPT."</li>"; |
||
539 | |||
540 | // Add field to xhelp_saved_searches to determine if custom fields table is needed |
||
541 | $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (hasCustFields int(11) NOT NULL default '0')", |
||
542 | $xoopsDB->prefix('xhelp_saved_searches')), |
||
543 | sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_saved_searches'), |
||
544 | sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_saved_searches')); |
||
545 | |||
546 | // Take existing saved searches and add 'query' field |
||
547 | $hSavedSearch =& xhelpGetHandler('savedSearch'); |
||
548 | $savedSearches =& $hSavedSearch->getObjects(); |
||
549 | |||
550 | foreach($savedSearches as $savedSearch) |
||
551 | { |
||
552 | set_time_limit(60); |
||
553 | $crit =& unserialize($savedSearch->getVar('search')); |
||
554 | if(is_object($crit)){ |
||
555 | $savedSearch->setVar('query', $crit->render()); |
||
556 | |||
557 | if($hSavedSearch->insert($savedSearch)){ |
||
558 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_SEARCH, $savedSearch->getVar('id'))."</li>"; |
||
559 | } else { |
||
560 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_SEARCH_ERR, $savedSearch->getVar('id'))."</li>"; |
||
561 | } |
||
562 | } |
||
563 | } |
||
564 | unset($savedSearches); |
||
565 | |||
566 | // Add ticket list table |
||
567 | set_time_limit(60); |
||
568 | $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment, |
||
569 | uid int(11) NOT NULL default '0', |
||
570 | searchid int(11) NOT NULL default '0', |
||
571 | weight int(11) NOT NULL default '0', |
||
572 | PRIMARY KEY (id), |
||
573 | KEY ticketList (uid, searchid) |
||
574 | )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_lists')), |
||
575 | sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_lists'), |
||
576 | sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_lists')); |
||
577 | |||
578 | // Add global ticket lists for staff members |
||
579 | xhelpCreateDefaultTicketLists(); |
||
580 | |||
581 | set_time_limit(60); |
||
582 | // Update xhelp_roles Admin record with new value (4095) |
||
583 | $crit = new Criteria('tasks', 2047); |
||
584 | $admin_roles =& $hRole->getObjects($crit); |
||
585 | |||
586 | View Code Duplication | foreach($admin_roles as $role){ |
|
587 | $role->setVar('tasks', 4095); |
||
588 | if($hRole->insert($role)){ |
||
589 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_ROLE, $role->getVar('name'))."</li>"; |
||
590 | } else { |
||
591 | echo "<li>".sprintf(_AM_XHELP_MSG_UPDATE_ROLE_ERR, $role->getVar('name'))."</li>"; |
||
592 | } |
||
593 | } |
||
594 | |||
595 | case '0.77': |
||
596 | // No schema changes for 0.78 |
||
597 | |||
598 | case '0.78': |
||
599 | |||
600 | echo "</ul>"; |
||
601 | } |
||
602 | |||
603 | $newversion = round($xoopsModule->getVar('version') / 100, 2); |
||
604 | //if successful, update xhelp_meta table with new ver |
||
605 | if ($ret) { |
||
606 | printf(_AM_XHELP_UPDATE_OK, $newversion); |
||
607 | $ret = xhelpSetMeta('version', $newversion); |
||
608 | } else { |
||
609 | printf(_AM_XHELP_UPDATE_ERR, $newversion); |
||
610 | } |
||
611 | |||
612 | include_once "admin_footer.php"; |
||
613 | } |
||
614 | |||
624 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.