public function scheduleTasks($inclusion_type, $inclusion_tasks) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Gpf_Db_Table_PlannedTasks::getInstance()); $select->from->add(Gpf_Db_Table_PlannedTasks::getName()); $condition = new Gpf_SqlBuilder_CompoundWhereCondition(); $condition->add(Gpf_Db_Table_PlannedTasks::LASTPLANDATE, '<', Gpf_Common_DateUtils::now(), 'OR'); $condition->add(Gpf_Db_Table_PlannedTasks::LASTPLANDATE, 'is', 'NULL', 'OR', false); $select->where->addCondition($condition); if ($inclusion_type == Gpf_Tasks_Runner::INCLUDE_TASKS) { $select->where->add(Gpf_Db_Table_PlannedTasks::CLASSNAME, 'IN', $inclusion_tasks); } else { if ($inclusion_type == Gpf_Tasks_Runner::EXCLUDE_TASKS) { $select->where->add(Gpf_Db_Table_PlannedTasks::CLASSNAME, 'NOT IN', $inclusion_tasks); } } foreach ($select->getAllRows() as $plannedTaskRow) { $plannedTask = new Gpf_Db_PlannedTask(); $plannedTask->fillFromRecord($plannedTaskRow); if ($plannedTask->getLastPlanDate() == null) { $plannedTask->setLastPlanDate(Gpf_Common_DateUtils::now()); } $task = new Gpf_Db_Task(); $task->setClassName($plannedTask->getClassName()); $task->setParams($plannedTask->getParams()); $task->setAccountId($plannedTask->getAccountId()); $task->save(); $preset = new Gpf_Recurrence_Preset(); $preset->setId($plannedTask->getRecurrencePresetId()); $preset->load(); $nextDate = $preset->getNextDate(Gpf_Common_DateUtils::mysqlDateTime2Timestamp($plannedTask->getLastPlanDate())); if ($nextDate != null && $nextDate > 0) { $plannedTask->setLastPlanDate(Gpf_Common_DateUtils::getDateTime($nextDate)); $plannedTask->update(); } } }
/** * @return Gpf_Recurrence_Preset */ public function getRecurrencePreset() { $recurrnecePreset = new Gpf_Recurrence_Preset(); $recurrnecePreset->setId($this->getRecurrencePresetId()); $recurrnecePreset->load(); return $recurrnecePreset; }