DBConnection::cronCheckDBreplicate PHP Method

cronCheckDBreplicate() static public method

Cron process to check DB replicate state
static public cronCheckDBreplicate ( $task )
$task to log and get param
    static function cronCheckDBreplicate($task)
    {
        global $DB;
        //Lauch cron only is :
        // 1 the master database is avalaible
        // 2 the slave database is configurated
        if (!$DB->isSlave() && self::isDBSlaveActive()) {
            $DBslave = self::getDBSlaveConf();
            if (is_array($DBslave->dbhost)) {
                $hosts = $DBslave->dbhost;
            } else {
                $hosts = array($DBslave->dbhost);
            }
            foreach ($hosts as $num => $name) {
                $diff = self::getReplicateDelay($num);
                // Quite strange, but allow simple stat
                $task->addVolume($diff);
                if ($diff > 1000000000) {
                    // very large means slave is disconnect
                    $task->log(sprintf(__s("SQL server: %s can't connect to the database"), $name));
                } else {
                    //TRANS: %1$s is the server name, %2$s is the time
                    $task->log(sprintf(__('SQL server: %1$s, difference between master and slave: %2$s'), $name, Html::timestampToString($diff, true)));
                }
                if ($diff > $task->fields['param'] * 60) {
                    //Raise event if replicate is not synchronized
                    $options = array('diff' => $diff, 'name' => $name, 'entities_id' => 0);
                    // entity to avoid warning in getReplyTo
                    NotificationEvent::raiseEvent('desynchronization', new self(), $options);
                }
            }
            return 1;
        }
        return 0;
    }