<?php

abstract class PeepSoMaintenanceFactory
{
    // Cron event that drives this maintenance module. Defaults to the shared 5-minute
    // maintenance tick; a subclass may override it (e.g. content ranking runs on its own
    // 1-minute CRON_RANKING_EVENT) by setting $this->event before parent::__construct().
    protected $event = '';

    public function __construct()
    {
        if ('' === $this->event) {
            $this->event = PeepSo::CRON_MAINTENANCE_EVENT;
        }

        // Otherwise filters / closures will refer to Factory class
        $that = get_class($this);
        $modules = get_class_methods($that);

        add_action($this->event, function() use ($modules, $that){

            if(count($modules)) {
                foreach ($modules as $module) {

                    if(strstr($module, '__')) {
                        continue;
                    }

                    $start = microtime(TRUE);
                    $count = $that::$module();

                    PeepSoMaintenanceDebug::get_instance()->debug("$that::$module", $start, microtime(TRUE), $count);
                }
            }
        });
    }
}