Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 12 | class v210_beta1 extends \phpbb\db\migration\migration |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Portal config table |
||
| 16 | * @var $portal_config |
||
| 17 | */ |
||
| 18 | private $portal_config = array(); |
||
| 19 | |||
| 20 | public function effectively_installed() |
||
| 24 | |||
| 25 | static public function depends_on() |
||
| 29 | |||
| 30 | public function update_schema() |
||
| 61 | |||
| 62 | public function revert_schema() |
||
| 71 | |||
| 72 | public function update_data() |
||
| 178 | |||
| 179 | public function add_portal_data() |
||
| 180 | { |
||
| 181 | if ($this->db_tools->sql_table_exists($this->table_prefix . 'portal_config')) |
||
| 182 | { |
||
| 183 | $sql = 'SELECT * |
||
| 184 | FROM ' . $this->table_prefix . 'portal_config'; |
||
| 185 | $result = $this->db->sql_query_limit($sql, 1); |
||
| 186 | $row = $this->db->sql_fetchrow($result); |
||
| 187 | $this->db->sql_freeresult($result); |
||
| 188 | if (!empty($row)) |
||
| 189 | { |
||
| 190 | return; |
||
| 191 | } |
||
| 192 | } |
||
| 193 | else |
||
| 194 | { |
||
| 195 | return; |
||
| 196 | } |
||
| 197 | |||
| 198 | // get the correct group IDs from the database |
||
| 199 | $in_ary = array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA'); |
||
| 200 | $groups_ary = array(); |
||
| 201 | |||
| 202 | $sql = 'SELECT group_id, group_name |
||
| 203 | FROM ' . $this->table_prefix . 'groups |
||
| 204 | WHERE ' . $this->db->sql_in_set('group_name', $in_ary); |
||
| 205 | $result = $this->db->sql_query($sql); |
||
| 206 | View Code Duplication | while ($row = $this->db->sql_fetchrow($result)) |
|
| 207 | { |
||
| 208 | $groups_ary[$row['group_name']] = $row['group_id']; |
||
| 209 | } |
||
| 210 | $this->db->sql_freeresult($result); |
||
| 211 | |||
| 212 | // set portal config |
||
| 213 | $this->set_portal_config('board3_menu_array_1', serialize(array( |
||
| 214 | array( |
||
| 215 | 'title' => 'M_CONTENT', |
||
| 216 | 'url' => '', |
||
| 217 | 'type' => '', |
||
| 218 | 'permission' => '', |
||
| 219 | ), |
||
| 220 | array( |
||
| 221 | 'title' => 'INDEX', |
||
| 222 | 'url' => 'index.php', |
||
| 223 | 'type' => 1, |
||
| 224 | 'permission' => '', |
||
| 225 | ), |
||
| 226 | array( |
||
| 227 | 'title' => 'SEARCH', |
||
| 228 | 'url' => 'search.php', |
||
| 229 | 'type' => 1, |
||
| 230 | 'permission' => '', |
||
| 231 | ), |
||
| 232 | array( |
||
| 233 | 'title' => 'REGISTER', |
||
| 234 | 'url' => 'ucp.php?mode=register', |
||
| 235 | 'type' => 1, |
||
| 236 | 'permission' => $groups_ary['GUESTS'], |
||
| 237 | ), |
||
| 238 | array( |
||
| 239 | 'title' => 'MEMBERLIST', |
||
| 240 | 'url' => 'memberlist.php', |
||
| 241 | 'type' => 1, |
||
| 242 | 'permission' => $groups_ary['REGISTERED'] . ',' . $groups_ary['REGISTERED_COPPA'], |
||
| 243 | ), |
||
| 244 | array( |
||
| 245 | 'title' => 'THE_TEAM', |
||
| 246 | 'url' => 'memberlist.php?mode=leaders', |
||
| 247 | 'type' => 1, |
||
| 248 | 'permission' => $groups_ary['REGISTERED'] . ',' . $groups_ary['REGISTERED_COPPA'], |
||
| 249 | ), |
||
| 250 | array( |
||
| 251 | 'title' => 'M_HELP', |
||
| 252 | 'url' => '', |
||
| 253 | 'type' => '', |
||
| 254 | 'permission' => '', |
||
| 255 | ), |
||
| 256 | array( |
||
| 257 | 'title' => 'FAQ', |
||
| 258 | 'url' => 'faq.php', |
||
| 259 | 'type' => 1, |
||
| 260 | 'permission' => '', |
||
| 261 | ), |
||
| 262 | array( |
||
| 263 | 'title' => 'M_BBCODE', |
||
| 264 | 'url' => 'faq.php?mode=bbcode', |
||
| 265 | 'type' => 1, |
||
| 266 | 'permission' => '', |
||
| 267 | ), |
||
| 268 | array( |
||
| 269 | 'title' => 'M_TERMS', |
||
| 270 | 'url' => 'ucp.php?mode=terms', |
||
| 271 | 'type' => 1, |
||
| 272 | 'permission' => '', |
||
| 273 | ), |
||
| 274 | array( |
||
| 275 | 'title' => 'M_PRV', |
||
| 276 | 'url' => 'ucp.php?mode=privacy', |
||
| 277 | 'type' => 1, |
||
| 278 | 'permission' => '', |
||
| 279 | ), |
||
| 280 | ))); |
||
| 281 | $this->set_portal_config('board3_welcome_message_10', 'Welcome to my Community!'); |
||
| 282 | $this->set_portal_config('board3_calendar_events_18', ''); |
||
| 283 | $this->set_portal_config('board3_links_array_21', serialize(array( |
||
| 284 | array( |
||
| 285 | 'title' => 'Board3.de', |
||
| 286 | 'url' => 'http://www.board3.de/', |
||
| 287 | 'type' => 2, |
||
| 288 | 'permission' => '', |
||
| 289 | ), |
||
| 290 | array( |
||
| 291 | 'title' => 'phpBB.com', |
||
| 292 | 'url' => 'http://www.phpbb.com/', |
||
| 293 | 'type' => 2, |
||
| 294 | 'permission' => '', |
||
| 295 | ), |
||
| 296 | ))); |
||
| 297 | |||
| 298 | // Populate module table |
||
| 299 | $board3_sql_query = array( |
||
| 300 | array( |
||
| 301 | 'module_classname' => '\board3\portal\modules\main_menu', |
||
| 302 | 'module_column' => 1, |
||
| 303 | 'module_order' => 1, |
||
| 304 | 'module_name' => 'M_MENU', |
||
| 305 | 'module_image_src' => 'portal_menu.png', |
||
| 306 | 'module_group_ids' => '', |
||
| 307 | 'module_image_width' => 16, |
||
| 308 | 'module_image_height' => 16, |
||
| 309 | 'module_status' => 1, |
||
| 310 | ), |
||
| 311 | array( |
||
| 312 | 'module_classname' => '\board3\portal\modules\stylechanger', |
||
| 313 | 'module_column' => 1, |
||
| 314 | 'module_order' => 2, |
||
| 315 | 'module_name' => 'BOARD_STYLE', |
||
| 316 | 'module_image_src' => 'portal_style.png', |
||
| 317 | 'module_group_ids' => '', |
||
| 318 | 'module_image_width' => 16, |
||
| 319 | 'module_image_height' => 16, |
||
| 320 | 'module_status' => 1, |
||
| 321 | ), |
||
| 322 | array( |
||
| 323 | 'module_classname' => '\board3\portal\modules\birthday_list', |
||
| 324 | 'module_column' => 1, |
||
| 325 | 'module_order' => 3, |
||
| 326 | 'module_name' => 'BIRTHDAYS', |
||
| 327 | 'module_image_src' => 'portal_birthday.png', |
||
| 328 | 'module_group_ids' => '', |
||
| 329 | 'module_image_width' => 16, |
||
| 330 | 'module_image_height' => 16, |
||
| 331 | 'module_status' => 1, |
||
| 332 | ), |
||
| 333 | array( |
||
| 334 | 'module_classname' => '\board3\portal\modules\clock', |
||
| 335 | 'module_column' => 1, |
||
| 336 | 'module_order' => 4, |
||
| 337 | 'module_name' => 'CLOCK', |
||
| 338 | 'module_image_src' => 'portal_clock.png', |
||
| 339 | 'module_group_ids' => '', |
||
| 340 | 'module_image_width' => 16, |
||
| 341 | 'module_image_height' => 16, |
||
| 342 | 'module_status' => 1, |
||
| 343 | ), |
||
| 344 | array( |
||
| 345 | 'module_classname' => '\board3\portal\modules\search', |
||
| 346 | 'module_column' => 1, |
||
| 347 | 'module_order' => 5, |
||
| 348 | 'module_name' => 'PORTAL_SEARCH', |
||
| 349 | 'module_image_src' => 'portal_search.png', |
||
| 350 | 'module_group_ids' => '', |
||
| 351 | 'module_image_width' => 16, |
||
| 352 | 'module_image_height' => 16, |
||
| 353 | 'module_status' => 1, |
||
| 354 | ), |
||
| 355 | array( |
||
| 356 | 'module_classname' => '\board3\portal\modules\attachments', |
||
| 357 | 'module_column' => 1, |
||
| 358 | 'module_order' => 6, |
||
| 359 | 'module_name' => 'PORTAL_ATTACHMENTS', |
||
| 360 | 'module_image_src' => 'portal_attach.png', |
||
| 361 | 'module_group_ids' => '', |
||
| 362 | 'module_image_width' => 16, |
||
| 363 | 'module_image_height' => 16, |
||
| 364 | 'module_status' => 1, |
||
| 365 | ), |
||
| 366 | array( |
||
| 367 | 'module_classname' => '\board3\portal\modules\topposters', |
||
| 368 | 'module_column' => 1, |
||
| 369 | 'module_order' => 7, |
||
| 370 | 'module_name' => 'TOPPOSTERS', |
||
| 371 | 'module_image_src' => 'portal_top_poster.png', |
||
| 372 | 'module_group_ids' => '', |
||
| 373 | 'module_image_width' => 16, |
||
| 374 | 'module_image_height' => 16, |
||
| 375 | 'module_status' => 1, |
||
| 376 | ), |
||
| 377 | array( |
||
| 378 | 'module_classname' => '\board3\portal\modules\latest_members', |
||
| 379 | 'module_column' => 1, |
||
| 380 | 'module_order' => 8, |
||
| 381 | 'module_name' => 'LATEST_MEMBERS', |
||
| 382 | 'module_image_src' => 'portal_members.png', |
||
| 383 | 'module_group_ids' => '', |
||
| 384 | 'module_image_width' => 16, |
||
| 385 | 'module_image_height' => 16, |
||
| 386 | 'module_status' => 1, |
||
| 387 | ), |
||
| 388 | array( |
||
| 389 | 'module_classname' => '\board3\portal\modules\link_us', |
||
| 390 | 'module_column' => 1, |
||
| 391 | 'module_order' => 9, |
||
| 392 | 'module_name' => 'LINK_US', |
||
| 393 | 'module_image_src' => 'portal_link_us.png', |
||
| 394 | 'module_group_ids' => '', |
||
| 395 | 'module_image_width' => 16, |
||
| 396 | 'module_image_height' => 16, |
||
| 397 | 'module_status' => 1, |
||
| 398 | ), |
||
| 399 | array( |
||
| 400 | 'module_classname' => '\board3\portal\modules\welcome', |
||
| 401 | 'module_column' => 2, |
||
| 402 | 'module_order' => 1, |
||
| 403 | 'module_name' => 'PORTAL_WELCOME', |
||
| 404 | 'module_image_src' => '', |
||
| 405 | 'module_group_ids' => '', |
||
| 406 | 'module_image_width' => 16, |
||
| 407 | 'module_image_height' => 16, |
||
| 408 | 'module_status' => 1, |
||
| 409 | ), |
||
| 410 | array( |
||
| 411 | 'module_classname' => '\board3\portal\modules\recent', |
||
| 412 | 'module_column' => 2, |
||
| 413 | 'module_order' => 2, |
||
| 414 | 'module_name' => 'PORTAL_RECENT', |
||
| 415 | 'module_image_src' => '', |
||
| 416 | 'module_group_ids' => '', |
||
| 417 | 'module_image_width' => 16, |
||
| 418 | 'module_image_height' => 16, |
||
| 419 | 'module_status' => 1, |
||
| 420 | ), |
||
| 421 | array( |
||
| 422 | 'module_classname' => '\board3\portal\modules\announcements', |
||
| 423 | 'module_column' => 2, |
||
| 424 | 'module_order' => 3, |
||
| 425 | 'module_name' => 'GLOBAL_ANNOUNCEMENTS', |
||
| 426 | 'module_image_src' => '', |
||
| 427 | 'module_group_ids' => '', |
||
| 428 | 'module_image_width' => 16, |
||
| 429 | 'module_image_height' => 16, |
||
| 430 | 'module_status' => 1, |
||
| 431 | ), |
||
| 432 | array( |
||
| 433 | 'module_classname' => '\board3\portal\modules\news', |
||
| 434 | 'module_column' => 2, |
||
| 435 | 'module_order' => 4, |
||
| 436 | 'module_name' => 'LATEST_NEWS', |
||
| 437 | 'module_image_src' => '', |
||
| 438 | 'module_group_ids' => '', |
||
| 439 | 'module_image_width' => 16, |
||
| 440 | 'module_image_height' => 16, |
||
| 441 | 'module_status' => 1, |
||
| 442 | ), |
||
| 443 | array( |
||
| 444 | 'module_classname' => '\board3\portal\modules\poll', |
||
| 445 | 'module_column' => 2, |
||
| 446 | 'module_order' => 5, |
||
| 447 | 'module_name' => 'PORTAL_POLL', |
||
| 448 | 'module_image_src' => 'portal_poll.png', |
||
| 449 | 'module_group_ids' => '', |
||
| 450 | 'module_image_width' => 16, |
||
| 451 | 'module_image_height' => 16, |
||
| 452 | 'module_status' => 1, |
||
| 453 | ), |
||
| 454 | array( |
||
| 455 | 'module_classname' => '\board3\portal\modules\whois_online', |
||
| 456 | 'module_column' => 2, |
||
| 457 | 'module_order' => 6, |
||
| 458 | 'module_name' => 'PORTAL_WHOIS_ONLINE', |
||
| 459 | 'module_image_src' => 'portal_friends.png', |
||
| 460 | 'module_group_ids' => '', |
||
| 461 | 'module_image_width' => 16, |
||
| 462 | 'module_image_height' => 16, |
||
| 463 | 'module_status' => 1, |
||
| 464 | ), |
||
| 465 | array( |
||
| 466 | 'module_classname' => '\board3\portal\modules\user_menu', |
||
| 467 | 'module_column' => 3, |
||
| 468 | 'module_order' => 1, |
||
| 469 | 'module_name' => 'USER_MENU', |
||
| 470 | 'module_image_src' => 'portal_user.png', |
||
| 471 | 'module_group_ids' => '', |
||
| 472 | 'module_image_width' => 16, |
||
| 473 | 'module_image_height' => 16, |
||
| 474 | 'module_status' => 1, |
||
| 475 | ), |
||
| 476 | array( |
||
| 477 | 'module_classname' => '\board3\portal\modules\statistics', |
||
| 478 | 'module_column' => 3, |
||
| 479 | 'module_order' => 2, |
||
| 480 | 'module_name' => 'STATISTICS', |
||
| 481 | 'module_image_src' => 'portal_statistics.png', |
||
| 482 | 'module_group_ids' => '', |
||
| 483 | 'module_image_width' => 16, |
||
| 484 | 'module_image_height' => 16, |
||
| 485 | 'module_status' => 1, |
||
| 486 | ), |
||
| 487 | array( |
||
| 488 | 'module_classname' => '\board3\portal\modules\calendar', |
||
| 489 | 'module_column' => 3, |
||
| 490 | 'module_order' => 3, |
||
| 491 | 'module_name' => 'PORTAL_CALENDAR', |
||
| 492 | 'module_image_src' => 'portal_calendar.png', |
||
| 493 | 'module_group_ids' => '', |
||
| 494 | 'module_image_width' => 16, |
||
| 495 | 'module_image_height' => 16, |
||
| 496 | 'module_status' => 1, |
||
| 497 | ), |
||
| 498 | array( |
||
| 499 | 'module_classname' => '\board3\portal\modules\leaders', |
||
| 500 | 'module_column' => 3, |
||
| 501 | 'module_order' => 4, |
||
| 502 | 'module_name' => 'THE_TEAM', |
||
| 503 | 'module_image_src' => 'portal_team.png', |
||
| 504 | 'module_group_ids' => '', |
||
| 505 | 'module_image_width' => 16, |
||
| 506 | 'module_image_height' => 16, |
||
| 507 | 'module_status' => 1, |
||
| 508 | ), |
||
| 509 | array( |
||
| 510 | 'module_classname' => '\board3\portal\modules\latest_bots', |
||
| 511 | 'module_column' => 3, |
||
| 512 | 'module_order' => 5, |
||
| 513 | 'module_name' => 'LATEST_BOTS', |
||
| 514 | 'module_image_src' => 'portal_bots.png', |
||
| 515 | 'module_group_ids' => '', |
||
| 516 | 'module_image_width' => 16, |
||
| 517 | 'module_image_height' => 16, |
||
| 518 | 'module_status' => 1, |
||
| 519 | ), |
||
| 520 | array( |
||
| 521 | 'module_classname' => '\board3\portal\modules\links', |
||
| 522 | 'module_column' => 3, |
||
| 523 | 'module_order' => 6, |
||
| 524 | 'module_name' => 'PORTAL_LINKS', |
||
| 525 | 'module_image_src' => 'portal_links.png', |
||
| 526 | 'module_group_ids' => '', |
||
| 527 | 'module_image_width' => 16, |
||
| 528 | 'module_image_height' => 16, |
||
| 529 | 'module_status' => 1, |
||
| 530 | ), |
||
| 531 | ); |
||
| 532 | $this->db->sql_multi_insert($this->table_prefix . 'portal_modules', $board3_sql_query); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Set config value. Creates missing config entry. |
||
| 537 | * Only use this if your config value might exceed 255 characters, otherwise please use set_config |
||
| 538 | * |
||
| 539 | * @param string $config_name Name of config entry to add or update |
||
| 540 | * @param mixed $config_value Value of config entry to add or update |
||
| 541 | */ |
||
| 542 | private function set_portal_config($config_name, $config_value) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Clean portal data upon fresh install from config table |
||
| 564 | */ |
||
| 565 | public function clean_portal_data() |
||
| 584 | } |
||
| 585 |