PageRenderTime 67ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/broken-link-checker/includes/activation.php

https://bitbucket.org/lgorence/quickpress
PHP | 89 lines | 59 code | 16 blank | 14 comment | 7 complexity | 89e19d3f8e0dc32de367d2e33b3e5908 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. global $blclog, $blc_config_manager, $wpdb;
  3. $queryCnt = $wpdb->num_queries;
  4. //Completing the installation/upgrade is required for the plugin to work, so make sure
  5. //the script doesn't get aborted by (for example) the browser timing out.
  6. set_time_limit(300); //5 minutes should be plenty, anything more would probably indicate an infinite loop or a deadlock
  7. ignore_user_abort(true);
  8. //Log installation progress to a DB option
  9. $blclog = new blcCachedOptionLogger('blc_installation_log');
  10. register_shutdown_function(array(&$blclog, 'save')); //Make sure the log is saved even if the plugin crashes
  11. $blclog->clear();
  12. $blclog->info( sprintf('Plugin activated at %s.', date_i18n('Y-m-d H:i:s')) );
  13. //Reset the "installation_complete" flag
  14. $blc_config_manager->options['installation_complete'] = false;
  15. //Note the time of the first installation (not very accurate, but still useful)
  16. if ( empty($blc_config_manager->options['first_installation_timestamp']) ){
  17. $blc_config_manager->options['first_installation_timestamp'] = time();
  18. }
  19. $blc_config_manager->save_options();
  20. $blclog->info('Installation/update begins.');
  21. //Load the base classes and utilities
  22. require_once BLC_DIRECTORY . '/includes/links.php';
  23. require_once BLC_DIRECTORY . '/includes/link-query.php';
  24. require_once BLC_DIRECTORY . '/includes/instances.php';
  25. require_once BLC_DIRECTORY . '/includes/utility-class.php';
  26. //Load the module subsystem
  27. require_once BLC_DIRECTORY . '/includes/modules.php';
  28. $moduleManager = blcModuleManager::getInstance();
  29. //If upgrading, activate/deactivate custom field and comment containers based on old ver. settings
  30. if ( isset($blc_config_manager->options['check_comment_links']) ){
  31. if ( !$blc_config_manager->options['check_comment_links'] ){
  32. $moduleManager->deactivate('comment');
  33. }
  34. unset($blc_config_manager->options['check_comment_links']);
  35. }
  36. if ( empty($blc_config_manager->options['custom_fields']) ){
  37. $moduleManager->deactivate('custom_field');
  38. }
  39. //Prepare the database.
  40. $blclog->info('Upgrading the database...');
  41. require_once BLC_DIRECTORY . '/includes/admin/db-upgrade.php';
  42. blcDatabaseUpgrader::upgrade_database();
  43. //Remove invalid DB entries
  44. $blclog->info('Cleaning up the database...');
  45. blc_cleanup_database();
  46. //Notify modules that the plugin has been activated. This will cause container
  47. //modules to create and update synch. records for all new/modified posts and other items.
  48. $blclog->info('Notifying modules...');
  49. $moduleManager->plugin_activated();
  50. blc_got_unsynched_items();
  51. //Turn off load limiting if it's not available on this server.
  52. $blclog->info('Updating server load limit settings...');
  53. $load = blcUtility::get_server_load();
  54. if ( empty($load) ){
  55. $blc_config_manager->options['enable_load_limit'] = false;
  56. }
  57. //And optimize my DB tables, too (for good measure)
  58. $blclog->info('Optimizing the database...');
  59. blcUtility::optimize_database();
  60. $blclog->info('Completing installation...');
  61. $blc_config_manager->options['installation_complete'] = true;
  62. if ( $blc_config_manager->save_options() ){
  63. $blclog->info('Configuration saved.');
  64. } else {
  65. $blclog->error('Error saving plugin configuration!');
  66. };
  67. $blclog->info(sprintf(
  68. 'Installation/update completed at %s with %d queries executed.',
  69. date_i18n('Y-m-d H:i:s'),
  70. $wpdb->num_queries - $queryCnt
  71. ));
  72. $blclog->save();
  73. ?>