Esempio n. 1
0
<?php

PerchScheduledTasks::register_task('perch_events', 'update_category_counts', 60, 'scheduled_events_update_category_counts');
function scheduled_events_update_category_counts($last_run)
{
    $API = new PerchAPI(1.0, 'perch_events');
    $Categories = new PerchEvents_Categories();
    $Categories->update_event_counts();
    return array('result' => 'OK', 'message' => 'Event category counts updated.');
}
        }
    }
    echo '<li>DB tables: ' . implode(', ', $tables) . '</li>';
}
?>
			<li>Users: <?php 
echo PerchDB::fetch()->get_value('SELECT COUNT(*) FROM ' . PERCH_DB_PREFIX . 'users');
?>
</li>        
            <li>App runtimes: <pre><?php 
$file = PerchUtil::file_path(PERCH_PATH . '/config/apps.php');
echo PerchUtil::html(file_get_contents($file));
?>
</pre></li>
            <?php 
$ScheduledTasks = new PerchScheduledTasks();
$apps = $ScheduledTasks->get_scheduled();
if (PerchUtil::count($apps)) {
    foreach ($apps as $appID => $tasks) {
        $task_list = array();
        echo '<li>Scheduled tasks for ' . $appID . ': ';
        foreach ($tasks as $task) {
            //print_r($task);
            $task_list[] = $task['taskKey'] . ' (' . $task['frequency'] / 60 . ' mins)';
        }
        echo implode(', ', $task_list);
        echo '</li>';
    }
}
?>
            <?php 
<?php

PerchScheduledTasks::register_task('root_locator', 'geocode_location_batch', 10, 'root_locator_process_task_queue');
function root_locator_process_task_queue($last_run_date)
{
    include __DIR__ . '/lib/vendor/autoload.php';
    spl_autoload_register(function ($class_name) {
        if (strpos($class_name, 'RootLocator') === 0) {
            include PERCH_PATH . '/addons/apps/root_locator/lib/' . $class_name . '.class.php';
            return true;
        }
        return false;
    });
    $API = new PerchAPI(1.0, 'root_locator');
    $Tasks = new RootLocator_Tasks($API);
    $result = $Tasks->processQueue(1);
    if ($result === false) {
        return ['status' => 'ERROR', 'message' => 'There was an error processing the task queue'];
    }
    return ['status' => 'OK', 'message' => sprintf('%s tasks processed', $result)];
}
Esempio n. 4
0
<?php

$ScheduledTasks = new PerchScheduledTasks();
$tasks = $ScheduledTasks->get_recent(20);
$apps = $Perch->get_apps();
$app_lookup = array();
if (PerchUtil::count($apps)) {
    foreach ($apps as $app) {
        $app_lookup[$app['id']] = $app['label'];
    }
}
Esempio n. 5
0
<?php

$API = new PerchAPI(1.0, 'perch_twitter');
if (!class_exists('PerchTwitter_Settings')) {
    include 'PerchTwitter_Settings.class.php';
    include 'PerchTwitter_Setting.class.php';
}
$TwitterSettings = new PerchTwitter_Settings($API);
$CurrentSettings = $TwitterSettings->find();
PerchScheduledTasks::register_task('perch_twitter', 'post_tweets', 1, 'scheduled_post_tweets');
if ((int) $CurrentSettings->settingUpdateInterval() != 0) {
    $interval = (int) $CurrentSettings->settingUpdateInterval();
    PerchScheduledTasks::register_task('perch_twitter', 'update_tweets', $interval, 'scheduled_get_tweets');
}
function scheduled_get_tweets($last_run)
{
    $count = perch_twitter_update_tweets();
    if ($count == 1) {
        $tweets = 'tweet';
    } else {
        $tweets = 'tweets';
    }
    return array('result' => 'OK', 'message' => $count . ' new ' . $tweets . ' fetched.');
}
function scheduled_post_tweets($last_run)
{
    $count = perch_twitter_post_tweets();
    if ($count == 1) {
        $tweets = 'tweet';
    } else {
        $tweets = 'tweets';
<?php

PerchScheduledTasks::register_task('jw_activity_log', 'prune_actions_log', 1440, 'jw_activity_log_prune');
function jw_activity_log_prune($last_run_date)
{
    include_once 'JwActivityLog_Actions.class.php';
    include_once 'JwActivityLog_Action.class.php';
    $API = new PerchAPI(1.0, 'jw_activity_log');
    $Settings = $API->get('Settings');
    $Actions = new JwActivityLog_Actions($API);
    $total_pruned = $Actions->prune_logs((int) $Settings->get('jw_activity_log_prune_time')->settingValue());
    return array('result' => 'OK', 'message' => $total_pruned . ' logs pruned');
}
<?php

PerchScheduledTasks::register_task('perch_mailchimp', 'update_list_stats', 60, 'update_perch_mailchimp');
function update_perch_mailchimp($last_update)
{
    $API = new PerchAPI(1.0, 'perch_mailchimp');
    include 'PerchMailchimp_Stats.class.php';
    include 'PerchMailchimp_Stat.class.php';
    $Settings = $API->get('Settings');
    $api_key = $Settings->get('perch_mailchimp_api_key')->settingValue();
    $list_id = $Settings->get('perch_mailchimp_list_id')->settingValue();
    $Stats = new PerchMailchimp_Stats($API);
    if (!$api_key || $api_key == '' || !$list_id || $list_id == '') {
        return array('result' => 'FAILED', 'message' => 'API key or list ID not provided in Settings.');
    } else {
        if ($Stats->populate($api_key, $list_id)) {
            return array('result' => 'OK', 'message' => 'List statistics updated.');
        } else {
            return array('result' => 'WARNING', 'message' => 'Unable to update list statistics.');
        }
    }
}
Esempio n. 8
0
<?php

PerchScheduledTasks::register_task('perch_mailchimp', 'import_data', 1, function ($last_run) {
    $API = new PerchAPI(1.0, 'perch_mailchimp');
    $Imports = new PerchMailChimp_Imports($API);
    $result = $Imports->run_next_import();
    if ($result && $result['result'] == 'success') {
        return array('result' => 'OK', 'message' => $result['message']);
    } else {
        return array('result' => 'FAILED', 'message' => 'Unknown.');
    }
    return false;
});
<?php

PerchScheduledTasks::register_task('perch_comments', 'delete_spam_comments', 1440, 'scheduled_comments_delete_spam');
function scheduled_comments_delete_spam($last_run)
{
    $API = new PerchAPI(1.0, 'perch_comments');
    $Settings = $API->get('Settings');
    $days = $Settings->get('perch_comments_max_spam_days')->val();
    if (!$days) {
        return array('result' => 'OK', 'message' => 'Spam message deletion not configured.');
    }
    $count = perch_comments_delete_old_spam($days);
    if ($count == 1) {
        $comments = 'comment';
    } else {
        $comments = 'comments';
    }
    return array('result' => 'OK', 'message' => $count . ' old spam ' . $comments . ' deleted.');
}
Esempio n. 10
0
if (!defined('PERCH_SCHEDULE_SECRET')) {
    die('You must set a secret. See http://docs.grabaperch.com/docs/scheduled-tasks/ for configuration instructions.');
}
if (isset($argv)) {
    $cli = true;
    if (!isset($argv[1])) {
        die('No secret found. See http://docs.grabaperch.com/docs/scheduled-tasks/ for configuration instructions.' . "\n");
    }
    if ($argv[1] != PERCH_SCHEDULE_SECRET) {
        die('Incorrect secret.' . "\n");
    }
} else {
    $cli = false;
    if (!isset($_GET['secret'])) {
        die('No secret found. See http://docs.grabaperch.com/docs/scheduled-tasks/ for configuration instructions.' . "\n");
    }
    if ($_GET['secret'] != PERCH_SCHEDULE_SECRET) {
        die('Incorrect secret.' . "\n");
    }
}
/* At this point, all should be good. */
include __DIR__ . '/../lib/PerchScheduledTasks.class.php';
include __DIR__ . '/../lib/PerchScheduledTask.class.php';
$ScheduledTasks = new PerchScheduledTasks();
// Try and install, if not installed already.
if (!$ScheduledTasks->attempt_install()) {
    die('Unable to create required database tables.');
}
// Run!
$ScheduledTasks->run();
//PerchUtil::output_debug();