本文整理汇总了PHP中Cron::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Cron::model方法的具体用法?PHP Cron::model怎么用?PHP Cron::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cron
的用法示例。
在下文中一共展示了Cron::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
$op = EnvUtil::getRequest("op");
$id = intval(EnvUtil::getRequest("id"));
if (EnvUtil::submitCheck("formhash")) {
if ($op == "edit") {
$dayNew = $_POST["weekdaynew"] != -1 ? -1 : $_POST["daynew"];
if (strpos($_POST["minutenew"], ",") !== false) {
$minuteNew = explode(",", $_POST["minutenew"]);
foreach ($minuteNew as $key => $val) {
$minuteNew[$key] = $val = intval($val);
if ($val < 0 || 59 < $val) {
unset($minuteNew[$key]);
}
}
$minuteNew = array_slice(array_unique($minuteNew), 0, 12);
$minuteNew = implode("\t", $minuteNew);
} else {
$minuteNew = intval($_POST["minutenew"]);
$minuteNew = 0 <= $minuteNew && $minuteNew < 60 ? $minuteNew : "";
}
$cronfile = $this->getRealCronFile($_POST["type"], $_POST["filenamenew"], $_POST["module"]);
if (preg_match("/[\\\\\\/\\:\\*\\?\"\\<\\>\\|]+/", $_POST["filenamenew"])) {
$this->error(Ibos::lang("Crons filename illegal"));
} elseif (!is_readable($cronfile)) {
$this->error(Ibos::lang("Crons filename invalid", "", array("{cronfile}" => $cronfile)));
} else {
if ($_POST["weekdaynew"] == -1 && $dayNew == -1 && $_POST["hournew"] == -1 && $minuteNew === "") {
$this->error(Ibos::lang("Crons time invalid"));
}
}
$data = array("weekday" => $_POST["weekdaynew"], "day" => $dayNew, "hour" => $_POST["hournew"], "minute" => $minuteNew, "filename" => trim($_POST["filenamenew"]));
$id && Cron::model()->modify($id, $data);
Ibos::app()->cron->run($id);
} elseif ($op == "delete") {
if (!empty($_POST["delete"])) {
$ids = StringUtil::iImplode($_POST["delete"]);
Cron::model()->deleteAll(sprintf("cronid IN (%s) AND type='user'", $ids));
}
} else {
if (isset($_POST["namenew"]) && !empty($_POST["namenew"])) {
foreach ($_POST["namenew"] as $id => $name) {
$newCron = array("name" => StringUtil::filterCleanHtml($_POST["namenew"][$id]), "available" => isset($_POST["availablenew"][$id]) ? 1 : 0);
if (isset($_POST["availablenew"][$id]) && empty($_POST["availablenew"][$id])) {
$newCron["nextrun"] = "0";
}
Cron::model()->modify($id, $newCron);
}
}
if (!empty($_POST["newname"])) {
$data = array("name" => StringUtil::ihtmlSpecialChars($_POST["newname"]), "type" => "user", "available" => "0", "weekday" => "-1", "day" => "-1", "hour" => "-1", "minute" => "", "nextrun" => TIMESTAMP);
Cron::model()->add($data);
}
$list = Cron::model()->fetchAll(array("select" => "cronid,filename,type,module"));
foreach ($list as $cron) {
$cronFile = $this->getRealCronFile($cron["type"], $cron["filename"], $cron["module"]);
if (!file_exists($cronFile)) {
Cron::model()->modify($cron["cronid"], array("available" => 0, "nextrun" => 0));
}
}
CacheUtil::update("setting");
}
$this->success(Ibos::lang("Crons succeed"), $this->createUrl("cron/index"));
} else {
if ($op && in_array($op, array("edit", "run"))) {
$cron = Cron::model()->fetchByPk($id);
if (!$cron) {
$this->error("Cron not found");
}
$cron["filename"] = str_replace(array("..", "/", "\\"), array("", "", ""), $cron["filename"]);
if ($op == "edit") {
$this->render("edit", array("cron" => $cron));
} elseif ($op == "run") {
$file = $this->getRealCronFile($cron["type"], $cron["filename"], $cron["module"]);
if (!file_exists($file)) {
$this->error(Ibos::lang("Crons run invalid", "", array("{cronfile}" => $file)));
} else {
Ibos::app()->cron->run($cron["cronid"]);
$this->success(Ibos::lang("Crons run succeed"), $this->createUrl("cron/index"));
}
}
} else {
$list = Cron::model()->fetchAll(array("order" => "type desc"));
$this->handleCronList($list);
$this->render("index", array("list" => $list));
}
}
}
示例2: setNextTime
private function setNextTime($cron)
{
if (empty($cron)) {
return false;
}
$timeoffSet = Ibos::app()->setting->get("setting/timeoffset");
list($yearNow, $monthNow, $dayNow, $weekdayNow, $hourNow, $minuteNow) = explode("-", gmdate("Y-m-d-w-H-i", TIMESTAMP + $timeoffSet * 3600));
if ($cron["weekday"] == -1) {
if ($cron["day"] == -1) {
$firstDay = $dayNow;
$secondDay = $dayNow + 1;
} else {
$firstDay = $cron["day"];
$secondDay = $cron["day"] + gmdate("t", TIMESTAMP + $timeoffSet * 3600);
}
} else {
$firstDay = $dayNow + ($cron["weekday"] - $weekdayNow);
$secondDay = $firstDay + 7;
}
if ($firstDay < $dayNow) {
$firstDay = $secondDay;
}
if ($firstDay == $dayNow) {
$todayTime = $this->todayNextRun($cron);
if ($todayTime["hour"] == -1 && $todayTime["minute"] == -1) {
$cron["day"] = $secondDay;
$nextTime = $this->todayNextRun($cron, 0, -1);
$cron["hour"] = $nextTime["hour"];
$cron["minute"] = $nextTime["minute"];
} else {
$cron["day"] = $firstDay;
$cron["hour"] = $todayTime["hour"];
$cron["minute"] = $todayTime["minute"];
}
} else {
$cron["day"] = $firstDay;
$nextTime = $this->todayNextRun($cron, 0, -1);
$cron["hour"] = $nextTime["hour"];
$cron["minute"] = $nextTime["minute"];
}
$nextRun = @gmmktime($cron["hour"], 0 < $cron["minute"] ? $cron["minute"] : 0, 0, $monthNow, $cron["day"], $yearNow) - $timeoffSet * 3600;
$data = array("lastrun" => TIMESTAMP, "nextrun" => $nextRun);
if (!TIMESTAMP < $nextRun) {
$data["available"] = "0";
}
Cron::model()->modify($cron["cronid"], $data);
return true;
}