function mainwp_cronbackups_action() { MainWP_Logger::Instance()->info('CRON :: backups'); @ignore_user_abort(true); @set_time_limit(0); $mem = '512M'; @ini_set('memory_limit', $mem); @ini_set('max_execution_time', 0); MainWP_Utility::update_option('mainwp_cron_last_backups', time()); //Do cronjobs! //Config this in crontab: 0 0 * * * wget -q http://mainwp.com/wp-admin/?do=cron -O /dev/null 2>&1 //this will execute once every day to check to do the scheduled backups $allTasks = array(); $dailyTasks = MainWP_DB::Instance()->getBackupTasksTodoDaily(); if (count($dailyTasks) > 0) { $allTasks = $dailyTasks; } $weeklyTasks = MainWP_DB::Instance()->getBackupTasksTodoWeekly(); if (count($weeklyTasks) > 0) { $allTasks = array_merge($allTasks, $weeklyTasks); } $monthlyTasks = MainWP_DB::Instance()->getBackupTasksTodoMonthly(); if (count($monthlyTasks) > 0) { $allTasks = array_merge($allTasks, $monthlyTasks); } MainWP_Logger::Instance()->debug('CRON :: backups :: Found ' . count($allTasks) . ' to start.'); foreach ($allTasks as $task) { MainWP_Logger::Instance()->debug('CRON :: backups :: Task: ' . $task->name); } foreach ($allTasks as $task) { $threshold = 0; if ($task->schedule == 'daily') { $threshold = 60 * 60 * 24; } else { if ($task->schedule == 'weekly') { $threshold = 60 * 60 * 24 * 7; } else { if ($task->schedule == 'monthly') { $threshold = 60 * 60 * 24 * 30; } } } $task = MainWP_DB::Instance()->getBackupTaskById($task->id); if (time() - $task->last_run < $threshold) { continue; } if (!MainWP_Manage_Backups::validateBackupTasks(array($task))) { $task = MainWP_DB::Instance()->getBackupTaskById($task->id); } $chunkedBackupTasks = get_option('mainwp_chunkedBackupTasks'); MainWP_Manage_Backups::executeBackupTask($task, $chunkedBackupTasks != 0 ? 5 : 0); } }
function prepare_items() { $orderby = null; if (isset($_GET['orderby'])) { if ($_GET['orderby'] == 'task_name') { $orderby = 'name'; } else { if ($_GET['orderby'] == 'type') { $orderby = 'type'; } else { if ($_GET['orderby'] == 'schedule') { $orderby = 'schedule'; } } } if (isset($_GET['order']) && ($_GET['order'] == 'asc' || $_GET['order'] == 'desc')) { $orderby .= ' ' . $_GET['order']; } } $this->items = MainWP_DB::Instance()->getBackupTasksForUser($orderby); if (!MainWP_Manage_Backups::validateBackupTasks($this->items)) { $this->items = MainWP_DB::Instance()->getBackupTasksForUser($orderby); } }