本文整理汇总了PHP中cron::setOnce方法的典型用法代码示例。如果您正苦于以下问题:PHP cron::setOnce方法的具体用法?PHP cron::setOnce怎么用?PHP cron::setOnce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cron
的用法示例。
在下文中一共展示了cron::setOnce方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkCmdAlert
public function checkCmdAlert($_value)
{
if ($this->getConfiguration('jeedomCheckCmdOperator') == '' || $this->getConfiguration('jeedomCheckCmdTest') == '' || $this->getConfiguration('jeedomCheckCmdTime') == '' || is_nan($this->getConfiguration('jeedomCheckCmdTime'))) {
return;
}
$check = jeedom::evaluateExpression($_value . $this->getConfiguration('jeedomCheckCmdOperator') . $this->getConfiguration('jeedomCheckCmdTest'));
if ($check == 1 || $check || $check == '1') {
if ($this->getConfiguration('jeedomCheckCmdTime') == 0) {
$this->executeAlertCmdAction();
return;
}
$cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
if (!is_object($cron)) {
$cron = new cron();
}
$cron->setClass('cmd');
$cron->setFunction('cmdAlert');
$cron->setOnce(1);
$cron->setOption(array('cmd_id' => intval($this->getId())));
$next = strtotime('+ ' . ($this->getConfiguration('jeedomCheckCmdTime') + 1) . ' minutes ' . date('Y-m-d H:i:s'));
$schedule = date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next);
$cron->setSchedule($schedule);
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->save();
} else {
$cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
if (is_object($cron)) {
$cron->remove();
}
}
}
示例2: executeAndReply
public function executeAndReply($_parameters)
{
$interactDef = interactDef::byId($this->getInteractDef_id());
if (!is_object($interactDef)) {
return __('Inconsistance de la base de données', __FILE__);
}
if (isset($_parameters['profile']) && trim($interactDef->getPerson()) != '') {
$person = strtolower($interactDef->getPerson());
$person = explode('|', $person);
if (!in_array($_parameters['profile'], $person)) {
return __('Vous n\'êtes pas autorisé à exécuter cette action', __FILE__);
}
}
$reply = $interactDef->selectReply();
$replace = array();
$tags = interactDef::getTagFromQuery($this->getQuery(), $_parameters['dictation']);
$tags_replace = array();
foreach ($tags as $key => $value) {
$tags_replace['#' . $key . '#'] = $value;
$replace['#' . $key . '#'] = $value;
}
$executeDate = null;
$dateConvert = array('heure' => 'hour', 'mois' => 'month', 'semaine' => 'week', 'année' => 'year');
if (isset($tags_replace['#duration#'])) {
$tags_replace['#duration#'] = str_replace(array_keys($dateConvert), $dateConvert, $tags_replace['#duration#']);
$executeDate = strtotime('+' . $tags_replace['#duration#']);
}
if (isset($tags_replace['#time#'])) {
$time = str_replace(array('h'), array(':'), $tags_replace['#time#']);
if (strlen($time) == 2) {
$time .= ':00';
} else {
if (strlen($time) == 3) {
$time .= '00';
}
}
$executeDate = strtotime($time);
if ($executeDate < strtotime('now')) {
$executeDate += 3600;
}
}
if ($executeDate !== null && !isset($_parameters['execNow'])) {
if (date('Y', $executeDate) < 2000) {
return __('Erreur impossible de calculer la date de programmation', __FILE__);
}
if ($executeDate < strtotime('now') + 60) {
$executeDate = strtotime('now') + 60;
}
$crons = cron::searchClassAndFunction('interactQuery', 'doIn', '"interactQuery_id":' . $this->getId());
if (is_array($crons)) {
foreach ($crons as $cron) {
if ($cron->getState() != 'run') {
$cron->remove();
}
}
}
$cron = new cron();
$cron->setClass('interactQuery');
$cron->setFunction('doIn');
$cron->setOption(array_merge(array('interactQuery_id' => intval($this->getId())), $_parameters));
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->setOnce(1);
$cron->setSchedule(date('i', $executeDate) . ' ' . date('H', $executeDate) . ' ' . date('d', $executeDate) . ' ' . date('m', $executeDate) . ' * ' . date('Y', $executeDate));
$cron->save();
$replace['#value#'] = date('Y-m-d H:i:s', $executeDate);
$result = scenarioExpression::setTags(str_replace(array_keys($replace), $replace, $reply));
return $result;
}
$colors = config::byKey('convertColor');
foreach ($this->getActions('cmd') as $action) {
try {
$options = array();
if (isset($action['options'])) {
$options = $action['options'];
}
if ($tags != null) {
foreach ($options as &$option) {
$option = str_replace(array_keys($tags_replace), $tags_replace, $option);
}
if (isset($options['color']) && isset($colors[strtolower($options['color'])])) {
$options['color'] = $colors[strtolower($options['color'])];
}
}
$cmd = cmd::byId(str_replace('#', '', $action['cmd']));
if (is_object($cmd) && $cmd->getType() == 'info') {
$replace['#unite#'] = $cmd->getUnite();
$replace['#commande#'] = $cmd->getName();
$replace['#objet#'] = '';
$replace['#equipement#'] = '';
$eqLogic = $cmd->getEqLogic();
if (is_object($eqLogic)) {
$replace['#equipement#'] = $eqLogic->getName();
$object = $eqLogic->getObject();
if (is_object($object)) {
$replace['#objet#'] = $object->getName();
}
}
}
$options['tags'] = $tags_replace;
$return = scenarioExpression::createAndExec('action', $action['cmd'], $options);
//.........这里部分代码省略.........
示例3: execute
public function execute(&$_scenario)
{
if ($this->getType() == 'if') {
if ($this->getSubElement('if')->execute($_scenario)) {
if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
if ($this->getSubElement('if')->getOptions('previousState', -1) != 1) {
$this->getSubElement('if')->setOptions('previousState', 1);
$this->getSubElement('if')->save();
} else {
$_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
return;
}
}
return $this->getSubElement('then')->execute($_scenario);
}
if (!is_object($this->getSubElement('else'))) {
return;
}
if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
if ($this->getSubElement('if')->getOptions('previousState', -1) != 0) {
$this->getSubElement('if')->setOptions('previousState', 0);
$this->getSubElement('if')->save();
} else {
$_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
return;
}
}
return $this->getSubElement('else')->execute($_scenario);
} else {
if ($this->getType() == 'action') {
return $this->getSubElement('action')->execute($_scenario);
} else {
if ($this->getType() == 'code') {
return $this->getSubElement('code')->execute($_scenario);
} else {
if ($this->getType() == 'for') {
$for = $this->getSubElement('for');
$limits = $for->getExpression();
$limits = intval(jeedom::evaluateExpression($limits[0]->getExpression()));
if (!is_numeric($limits)) {
$_scenario->setLog(__('[ERREUR] La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
throw new Exception(__('La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
}
$return = false;
for ($i = 1; $i <= $limits; $i++) {
$return = $this->getSubElement('do')->execute($_scenario);
}
return $return;
} else {
if ($this->getType() == 'in') {
$in = $this->getSubElement('in');
$in = $in->getExpression();
$time = ceil(str_replace('.', ',', jeedom::evaluateExpression($in[0]->getExpression())));
if (!is_numeric($time) || $time < 0) {
$time = 0;
}
if ($time == 0) {
$cmd = '/usr/bin/php ' . dirname(__FILE__) . '/../../core/php/jeeScenario.php ';
$cmd .= ' scenario_id=' . $_scenario->getId();
$cmd .= ' scenarioElement_id=' . $this->getId();
$cmd .= ' >> ' . log::getPathToLog('scenario_element_execution') . ' 2>&1 &';
exec($cmd);
} else {
$crons = cron::searchClassAndFunction('scenario', 'doIn', '"scenarioElement_id":' . $this->getId());
if (is_array($crons)) {
foreach ($crons as $cron) {
if ($cron->getState() != 'run') {
$cron->remove();
}
}
}
$cron = new cron();
$cron->setClass('scenario');
$cron->setFunction('doIn');
$cron->setOption(array('scenario_id' => intval($_scenario->getId()), 'scenarioElement_id' => intval($this->getId()), 'second' => date('s')));
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->setOnce(1);
$next = strtotime('+ ' . $time . ' min');
$cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
$cron->save();
$_scenario->setLog(__('Tâche : ', __FILE__) . $this->getId() . __(' programmé à : ', __FILE__) . date('Y-m-d H:i:00', $next) . ' (+ ' . $time . ' min)');
}
return true;
} else {
if ($this->getType() == 'at') {
$at = $this->getSubElement('at');
$at = $at->getExpression();
$next = jeedom::evaluateExpression($at[0]->getExpression());
if ($next % 100 > 59) {
if (strpos($at[0]->getExpression(), '-') !== false) {
$next -= 40;
} else {
$next += 40;
}
}
if (!is_numeric($next) || $next < 0) {
$_scenario->setLog(__('Erreur dans bloc (type A) : ', __FILE__) . $this->getId() . __(', heure programmée invalide : ', __FILE__) . $next);
}
if ($next < date('Gi') + 1) {
if (strlen($next) == 3) {
//.........这里部分代码省略.........