1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: plugin_include('repository', 'custom/FrontendNavigation.php');
18:
19: 20: 21: 22: 23: 24:
25: class Cronjobs {
26: 27: 28:
29: public static $CRONTAB_FILE = 'crontab.txt';
30:
31: 32: 33:
34: public static $JOB_ENDING = '.job';
35:
36: 37: 38:
39: public static $LOG_ENDING = '.log';
40:
41: 42: 43:
44: protected $_phpFile = '';
45:
46: 47: 48: 49: 50:
51: private $_fileName = '';
52:
53: 54: 55: 56: 57:
58: protected $_cronjobDirectory = '';
59:
60: 61: 62: 63: 64:
65: protected $_cronlogDirectory = '';
66:
67: 68: 69: 70: 71:
72: public function __construct($phpFile = '') {
73: $this->_phpFile = $phpFile;
74:
75:
76: if ($phpFile != '') {
77: $this->_fileName = cString::getPartOfString($phpFile, 0, -4);
78: }
79:
80: $cfg = cRegistry::getConfig();
81: $this->_cronjobDirectory = $cfg['path']['contenido'] . $cfg['path']['cronjobs'];
82: $this->_cronlogDirectory = $cfg['path']['contenido_cronlog'];
83: }
84:
85: 86: 87: 88: 89:
90: public function getFile() {
91: return $this->_phpFile;
92: }
93:
94: 95: 96: 97: 98:
99: public function getCronjobDirectory() {
100: return $this->_cronjobDirectory;
101: }
102:
103: 104: 105: 106: 107:
108: public function getCronlogDirectory() {
109: return $this->_cronlogDirectory;
110: }
111:
112: 113: 114: 115: 116: 117: 118:
119: public function getDateLastExecute() {
120: $timestamp = '';
121: if (cFileHandler::exists($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING)) {
122: if (($timestamp = cFileHandler::read($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING))) {
123: return date("d.m.Y H:i:s", $timestamp);
124: }
125: }
126:
127: return $timestamp;
128: }
129:
130: 131: 132: 133: 134: 135: 136:
137: public function getContentsCrontabFile() {
138: if (cFileHandler::exists($this->_cronlogDirectory . self::$CRONTAB_FILE)) {
139: return cFileHandler::read($this->_cronlogDirectory . self::$CRONTAB_FILE);
140: } else {
141: return '';
142: }
143: }
144:
145: 146: 147: 148: 149: 150: 151: 152: 153:
154: public function saveCrontabFile($data) {
155: return cFileHandler::write($this->_cronlogDirectory . self::$CRONTAB_FILE, $data);
156: }
157:
158: 159: 160: 161: 162: 163: 164:
165: public function setRunTime($timestamp) {
166: cFileHandler::write($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING, $timestamp);
167: }
168:
169: 170: 171: 172: 173: 174: 175: 176:
177: public function getLastLines($lines = 25) {
178: if (cFileHandler::exists($this->_cronlogDirectory . $this->_phpFile . self::$LOG_ENDING)) {
179: $content = explode("\n", cFileHandler::read($this->_cronlogDirectory . $this->_phpFile . self::$LOG_ENDING));
180: $number = count($content);
181: $pos = $number - $lines;
182: if ($pos < 0) {
183: $lines += $pos;
184: $pos = 0;
185: }
186:
187: return implode('<br>', array_slice($content, $pos, $lines));
188: }
189:
190: return '';
191: }
192:
193: 194: 195: 196: 197:
198: public function existFile() {
199: if (!cFileHandler::exists($this->_cronjobDirectory . $this->_phpFile) && !is_dir($this->_cronjobDirectory . $this->_phpFile)) {
200: return false;
201: } elseif (cString::getPartOfString($this->_phpFile, -4) == '.php') {
202: return true;
203: } else {
204: return false;
205: }
206: }
207:
208: 209: 210:
211: public function getAllCronjobs() {
212: $retArray = array();
213:
214: if (is_dir($this->_cronjobDirectory)) {
215:
216: if (false !== ($handle = cDirHandler::read($this->_cronjobDirectory, false, false, true))) {
217: foreach ($handle as $file) {
218: if (cFileHandler::fileNameIsDot($file) === false
219: && cString::getPartOfString($file, -4) == '.php' && $file != 'index.php') {
220: $retArray[] = $file;
221: }
222: }
223: }
224: }
225:
226: return $retArray;
227: }
228: }
229: