Module.php #1

  • //
  • guest/
  • perforce_software/
  • chronicle/
  • main/
  • sites/
  • all/
  • modules/
  • easycron/
  • Module.php
  • View
  • Commits
  • Open Download .zip Download (2 KB)
<?php
/**
 * Sets up view to add easy cron script.
 *
 * The Easy Cron module runs the core Cron operation using normal page requests
 * instead of having to set up a crontab. The module inserts a small amount of
 * JavaScript to send Ajax requests on each page when it is enabled (by default,
 * the module is enabled.)
 *
 * The users should not notice any kind of delay or disruption when viewing the
 * site. However, it does have a performance impact to the server because every
 * page load will send a request to run the cron tasks.  The core Cron module
 * will decide if the tasks need to run upon each request.
 *
 * This module requires that the site gets regular traffic/visitors in order to
 * trigger the cron tasks.
 *
 * @copyright   2011 Perforce Software. All rights reserved.
 * @license     Please see LICENSE.txt in top-level folder of this distribution.
 * @version     <release>/<patch>
 */
class EasyCron_Module extends P4Cms_Module_Integration
{
    /**
     * Load the easy cron scripts into the head section of the page.
     */
    public static function load()
    {
        // add the script to send a cron run request.
        $view = Zend_Layout::getMvcInstance()->getView();
        $view->headScript()->appendScript(
            "
            // we want this to happen last, so we wait until the page
            // is otherwise loaded, then add 100ms for good measure.
            dojo.connect(dojo.body(), 'onload', function() {
                window.setTimeout(
                    function() {
                        dojo.xhrGet({
                            url:   p4cms.url({
                                module:     'cron',
                                background: true,
                                format:     'json'
                            })
                        });
                    },
                    100
                );
            });
"
        );
    }
}
# Change User Description Committed
#1 16170 perforce_software Move Chronicle files to follow new path scheme for branching.
//guest/perforce_software/chronicle/sites/all/modules/easycron/Module.php
#1 8972 Matt Attaway Initial add of the Chronicle source code