/** * Build the fullpath for the backup file. * Checks if the target directory is writable. * Returns a string in the format path/stemname_YYYY-MM-DD.sql * * @param string $path The target path where the backup file should be * written to * @param string $fileStemName The file stem name (the part without the date * and extension). * @return string The full path including the .sql extension */ public static function makeDatedFullPath($path, $fileStemName, $includeTime = false) { $extension = '.sql'; $date = $includeTime ? str_replace(':', '', uFormat::spacesToUnderscore(uDateTime::now())) : uDate::today(); $fname = $fileStemName . '_' . $date . $extension; return uFs::mp(array($path, $fname)); }
/** * Use either the passed datetime stamp or the current timestamp to lookup in * sy_tsched_schedule if any tasks are scheduled to be run at this time. If * so, put them on the queue. * * @param <type> $dateTime Optional date time to use for lookup. This can be * used for debuging and development purposes. If no * parameter is passed then the current time is used. */ public function run($dateTime = null) { try { if ($dateTime == null) { $dateTime = uDateTime::now(); } $timeStamp = uDateTime::strtotime($dateTime); $minute = intval(date("i", $timeStamp)); $hour = date("G", $timeStamp); $day = date("j", $timeStamp); $tasks = TschedScheduleTable::getScheduledTasks($minute, $hour, $day); foreach ($tasks as $task) { $queue = $this->newTaskQueue(); $queue->setScheduleId($task->getId()); $queue->save(); $msg = 'TASK SCHEDULER|Queued task: ' . $task->getDescription() . ' (id=' . $task->getId() . ')'; $this->logNotice($msg); } } catch (Exception $e) { $msg = 'TASK SCHEDULER|' . __METHOD__ . ':' . __LINE__ . '|' . $e->getMessage(); $this->logError($msg); } }
/** * Convert a date time string into the components of a cron configuration * string. * * @param string $dateString * @return array */ protected static function timeStampToArray($dateString) { $parts = self::getCronPartsArray(); $timeStamp = uDateTime::strtotime($dateString); $parts['minute'] = intval(date("i", $timeStamp)); $parts['hour'] = date("G", $timeStamp); $parts['day'] = date("j", $timeStamp); $parts['month'] = date("n", $timeStamp); $parts['day_of_week'] = date("N", $timeStamp); return $parts; }
/** * Convert an English date time string to an application date string. * The application date time format is YYYY-MM-DD HH:MM:SS * * @param string $dateTimeStr The string that holds the date time * @return string The app formatted date time string * @throw Exception */ public static function strToAppDate($dateStr) { return substr(uDateTime::strToAppDateTime($dateStr), 0, 10); }