start.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. function backup_tool_init() {
  3. //REGISTER ACTIONS
  4. elgg_register_action("backup-tool/create", elgg_get_plugins_path() . "backup-tool/actions/create.php", "admin");
  5. elgg_register_action("backup-tool/restore", elgg_get_plugins_path() . "backup-tool/actions/restore.php", "admin");
  6. elgg_register_action("backup-tool/download", elgg_get_plugins_path() . "backup-tool/actions/download.php", "admin");
  7. elgg_register_action("backup-tool/remove", elgg_get_plugins_path() . "backup-tool/actions/remove.php", "admin");
  8. elgg_register_action("backup-tool/ftp-test", elgg_get_plugins_path() . "backup-tool/actions/ftp-test.php", "admin");
  9. elgg_register_action("backup-tool/schedule-settings", elgg_get_plugins_path() . "backup-tool/actions/schedule-settings.php", "admin");
  10. //REGISTER LIBRARY
  11. elgg_register_library("backup_tool", elgg_get_plugins_path() . "backup-tool/lib/backup-tool.php");
  12. //EXTEND VIEW
  13. elgg_extend_view('js/elgg', 'backup-tool/js');
  14. //register cron jobs only if schedule was enabled
  15. if (elgg_get_plugin_setting('enable_schedule', 'backup-tool')) {
  16. $schedule_period = elgg_get_plugin_setting('schedule_period', 'backup-tool');
  17. $schedule_delete = elgg_get_plugin_setting('schedule_delete', 'backup-tool');
  18. if ($schedule_period != "never") {
  19. // Register cron hook for creating backup
  20. elgg_register_plugin_hook_handler('cron', $schedule_period, 'backup_tool_cron');
  21. }
  22. if ($schedule_delete != 'never') {
  23. // Register cron hook for deletion of selected archived logs
  24. elgg_register_plugin_hook_handler('cron', 'daily', 'backup_tool_cleanup_cron');
  25. }
  26. }
  27. //register view of dialog of backup creation
  28. elgg_register_ajax_view('backup-tool/create-backup');
  29. }
  30. function backup_tool_pagesetup() {
  31. //add menu item on admin panel to update source from svn
  32. if (elgg_in_context('admin')) {
  33. elgg_register_admin_menu_item('administer', 'list', 'backups', 0);
  34. elgg_register_admin_menu_item('administer', 'schedule', 'backups', 0);
  35. }
  36. }
  37. function backup_tool_cron($hook, $entity_type, $returnvalue, $params) {
  38. elgg_load_library("backup_tool");
  39. $backup_options = unserialize(elgg_get_plugin_setting('backup_options', 'backup-tool'));
  40. $filename = backup_tool_create_backup($backup_options);
  41. //get path to default backup dir specified in plugin settings
  42. $backup_dir = elgg_get_plugin_setting('backup_dir', 'backup-tool');
  43. //get ftp settings
  44. $ftp_enable = elgg_get_plugin_setting('ftp_enable', 'backup-tool');
  45. if ($ftp_enable == "ON") {
  46. //connect to remote ftp server
  47. backup_tool_upload_to_ftp($filename);
  48. }
  49. return $returnvalue;
  50. }
  51. function backup_tool_cleanup_cron($hook, $entity_type, $returnvalue, $params) {
  52. elgg_load_library("backup_tool");
  53. $period = elgg_get_plugin_setting('schedule_delete', 'backup-tool');
  54. $day = 86400;
  55. $offset = 0;
  56. switch ($period) {
  57. case 'weekly':
  58. $offset = $day * 7;
  59. break;
  60. case 'yearly':
  61. $offset = $day * 365;
  62. break;
  63. case 'monthly':
  64. default:
  65. // assume 28 days even if a month is longer. Won't cause data loss.
  66. $offset = $day * 28;
  67. }
  68. backup_tool_cleanup($offset);
  69. return $returnvalue;
  70. }
  71. elgg_register_event_handler('init', 'system', 'backup_tool_init');
  72. elgg_register_event_handler('pagesetup', 'system', 'backup_tool_pagesetup', 1000);