Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Cronjobs
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the main class for the plugin content allocation.
  5:  *
  6:  * @package    Plugin
  7:  * @subpackage CronjobOverview
  8:  * @author     Rusmir Jusufovic
  9:  * @copyright  four for business AG <www.4fb.de>
 10:  * @license    http://www.contenido.org/license/LIZENZ.txt
 11:  * @link       http://www.4fb.de
 12:  * @link       http://www.contenido.org
 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:  * Main class for cronjob overview
 21:  *
 22:  * @package    Plugin
 23:  * @subpackage CronjobOverview
 24:  */
 25: class Cronjobs {
 26:     /**
 27:      * @var string
 28:      */
 29:     public static $CRONTAB_FILE = 'crontab.txt';
 30: 
 31:     /**
 32:      * @var string
 33:      */
 34:     public static $JOB_ENDING = '.job';
 35: 
 36:     /**
 37:      * @var string
 38:      */
 39:     public static $LOG_ENDING = '.log';
 40: 
 41:     /**
 42:      * @var string
 43:      */
 44:     protected $_phpFile = '';
 45: 
 46:     /**
 47:      * Filename without the mimetype
 48:      *
 49:      * @var string
 50:      */
 51:     private $_fileName = '';
 52: 
 53:     /**
 54:      * Path to the cronjob Directory
 55:      *
 56:      * @var string
 57:      */
 58:     protected $_cronjobDirectory = '';
 59: 
 60:     /**
 61:      * Path to the cronlog Directory
 62:      *
 63:      * @var string
 64:      */
 65:     protected $_cronlogDirectory = '';
 66: 
 67:     /**
 68:      * Cronjobs constructor.
 69:      *
 70:      * @param string $phpFile
 71:      */
 72:     public function __construct($phpFile = '') {
 73:         $this->_phpFile = $phpFile;
 74: 
 75:         //get the name of the file withouth the mime type
 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:      * Return the name of file
 87:      *
 88:      * @return string
 89:      */
 90:     public function getFile() {
 91:         return $this->_phpFile;
 92:     }
 93: 
 94:     /**
 95:      * Get the directory path of cronjobs
 96:      *
 97:      * @return string
 98:      */
 99:     public function getCronjobDirectory() {
100:         return $this->_cronjobDirectory;
101:     }
102: 
103:     /**
104:      * Get the directory path of cronlog
105:      *
106:      * @return string
107:      */
108:     public function getCronlogDirectory() {
109:         return $this->_cronlogDirectory;
110:     }
111: 
112:     /**
113:      *
114:      * Get date of last execution of cronjob
115:      *
116:      * @return string date
117:      * @throws cInvalidArgumentException
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:      * Get the contents of the crontab.txt file
132:      *
133:      * @return string
134:      *      contents of the file or ''
135:      * @throws cInvalidArgumentException
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:      * Save the data to crontab.txt file
148:      *
149:      * @param string $data
150:      *
151:      * @return bool
152:      * @throws cInvalidArgumentException
153:      */
154:     public function saveCrontabFile($data) {
155:         return cFileHandler::write($this->_cronlogDirectory . self::$CRONTAB_FILE, $data);
156:     }
157: 
158:     /**
159:      * Set the execute-time to $this->_phpFile.job file.
160:      *
161:      * @param int $timestamp
162:      *
163:      * @throws cInvalidArgumentException
164:      */
165:     public function setRunTime($timestamp) {
166:         cFileHandler::write($this->_cronlogDirectory . $this->_phpFile . self::$JOB_ENDING, $timestamp);
167:     }
168: 
169:     /**
170:      * Get the last lines of log file
171:      *
172:      * @param int $lines
173:      *
174:      * @return string
175:      * @throws cInvalidArgumentException
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:      * Exist the file and is it a php file
195:      *
196:      * @return bool if exist
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:      * Get all Cronjobs in directory cronjobs from contenido
210:      */
211:     public function getAllCronjobs() {
212:         $retArray = array();
213:         
214:         if (is_dir($this->_cronjobDirectory)) {
215:             // get only files
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: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0