Exemplo n.º 1
0
 public function setCollect($collect)
 {
     if ($collect == 1) {
         cache::set('collect' . $this->getId(), $this->getId());
     } else {
         cache::deleteBySearch('collect' . $this->getId());
     }
 }
Exemplo n.º 2
0
    $cron = cron::byClassAndFunction('plugin', 'cron30');
    if (!is_object($cron)) {
        echo "Création de plugin::cron30\n";
        $cron = new cron();
    }
    $cron->setClass('plugin');
    $cron->setFunction('cron30');
    $cron->setSchedule('*/30 * * * * *');
    $cron->setTimeout(60);
    $cron->save();
    $dynamic_apache_path = dirname(__FILE__) . '/../core/config/apache_jeedom_dynamic_rules';
    if (!file_exists($dynamic_apache_path)) {
        touch($dynamic_apache_path);
    }
    if (jeedom::isCapable('sudo')) {
        if (!file_exists('/var/log/auth.log')) {
            exec('sudo touch /var/log/auth.log');
            exec('sudo service fail2ban restart');
        }
        exec('sudo service cron restart');
    }
    cache::deleteBySearch('widgetHtml');
    cache::deleteBySearch('cmdWidgetdashboard');
    cache::deleteBySearch('cmdWidgetmobile');
    cache::deleteBySearch('scenarioHtmldashboard');
    config::save('hardware_name', '');
} catch (Exception $e) {
    echo "Error : ";
    echo $e->getMessage();
}
echo "[END CONSISTENCY]\n";
Exemplo n.º 3
0
 public static function cron()
 {
     if (!self::isStarted()) {
         echo date('Y-m-d H:i:s') . ' starting Jeedom';
         config::save('enableScenario', 1);
         config::save('enableCron', 1);
         cache::deleteBySearch('widgetHtml');
         cache::deleteBySearch('cmdWidgetdashboard');
         cache::deleteBySearch('cmdWidgetmobile');
         cache::deleteBySearch('scenarioHtmldashboard');
         $cache = cache::byKey('jeedom::usbMapping');
         $cache->remove();
         foreach (cron::all() as $cron) {
             if ($cron->running() && $cron->getClass() != 'jeedom' && $cron->getFunction() != 'cron') {
                 try {
                     $cron->halt();
                 } catch (Exception $e) {
                 }
             }
         }
         try {
             jeedom::start();
         } catch (Exception $e) {
         }
         touch('/tmp/jeedom_start');
         self::event('start');
         log::add('core', 'info', 'Démarrage de Jeedom OK');
         try {
             plugin::start();
         } catch (Exception $e) {
         }
     }
     self::isDateOk();
     try {
         $c = new Cron\CronExpression(config::byKey('update::check'), new Cron\FieldFactory());
         if ($c->isDue()) {
             $lastCheck = strtotime(config::byKey('update::lastCheck'));
             if (strtotime('now') - $lastCheck > 3600) {
                 update::checkAllUpdate();
                 $updates = update::byStatus('update');
                 if (count($updates) > 0) {
                     $toUpdate = '';
                     foreach ($updates as $update) {
                         $toUpdate .= $update->getLogicalId() . ',';
                     }
                 }
                 $updates = update::byStatus('update');
                 if (count($updates) > 0) {
                     message::add('update', __('De nouvelles mises à jour sont disponibles : ', __FILE__) . trim($toUpdate, ','), '', 'newUpdate');
                 }
                 config::save('update::check', rand(1, 59) . ' ' . rand(6, 7) . ' * * *');
             }
         }
         $c = new Cron\CronExpression('35 00 * * 0', new Cron\FieldFactory());
         if ($c->isDue()) {
             cache::clean();
             DB::optimize();
         }
         $c = new Cron\CronExpression('02 02 * * *', new Cron\FieldFactory());
         if ($c->isDue()) {
             try {
                 log::chunk();
                 cron::clean();
             } catch (Exception $e) {
                 log::add('log', 'error', $e->getMessage());
             }
         }
         $c = new Cron\CronExpression('21 23 * * *', new Cron\FieldFactory());
         if ($c->isDue()) {
             try {
                 scenario::cleanTable();
                 user::cleanOutdatedUser();
                 scenario::consystencyCheck();
             } catch (Exception $e) {
                 log::add('scenario', 'error', $e->getMessage());
             }
         }
     } catch (Exception $e) {
     }
 }