Esempio n. 1
0
 public static function cron()
 {
     if (!self::isStarted()) {
         config::save('enableScenario', 1);
         config::save('enableCron', 1);
         $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) {
         }
         try {
             plugin::start();
         } catch (Exception $e) {
         }
         touch('/tmp/jeedom_start');
         self::event('start');
         log::add('core', 'info', 'Démarrage de Jeedom OK');
     }
     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) {
                 if (config::byKey('update::auto') == 1) {
                     update::checkAllUpdate();
                     jeedom::update('', 0);
                 } else {
                     config::save('update::check', rand(1, 59) . ' ' . rand(6, 7) . ' * * *');
                     update::checkAllUpdate();
                     $updates = update::byStatus('update');
                     if (count($updates) > 0) {
                         $toUpdate = '';
                         foreach ($updates as $update) {
                             $toUpdate .= $update->getLogicalId() . ',';
                         }
                         message::add('update', __('De nouvelles mises à jour sont disponibles : ', __FILE__) . trim($toUpdate, ','), '', 'newUpdate');
                     }
                 }
             }
         }
         $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) {
     }
 }
Esempio n. 2
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
 */
try {
    require_once dirname(__FILE__) . '/../../core/php/core.inc.php';
    include_file('core', 'authentification', 'php');
    if (!isConnect('admin')) {
        throw new Exception(__('401 - Accès non autorisé', __FILE__), -1234);
    }
    if (init('action') == 'all') {
        ajax::success(utils::o2a(update::all(init('filter'))));
    }
    if (init('action') == 'checkAllUpdate') {
        update::checkAllUpdate();
        ajax::success();
    }
    if (init('action') == 'update') {
        log::clear('update');
        $update = update::byId(init('id'));
        if (!is_object($update)) {
            throw new Exception(__('Aucune correspondance pour l\'ID : ' . init('id'), __FILE__));
        }
        try {
            if ($update->getType() != 'core') {
                log::add('update', 'update', __("[START UPDATE]\n", __FILE__));
            }
            $update->doUpdate();
            if ($update->getType() != 'core') {
                log::add('update', 'update', __("[END UPDATE SUCCESS]\n", __FILE__));