[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the UI controller for Cron table. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * 10 * {@internal License choice 11 * - If you have received this file as part of a package, please find the license.txt file in 12 * the same folder or the closest folder above for complete license terms. 13 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 14 * then you must choose one of the following licenses before using the file: 15 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 16 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 17 * }} 18 * 19 * {@internal Open Source relicensing agreement: 20 * }} 21 * 22 * @package admin 23 * 24 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 25 * @author fplanque: Francois PLANQUE. 26 * 27 * @version $Id: cronjobs.ctrl.php,v 1.1 2007/06/25 10:59:44 fplanque Exp $ 28 */ 29 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 30 31 32 // Check minimum permission: 33 $current_User->check_perm( 'options', 'view', true ); 34 35 $AdminUI->set_path( 'tools', 'cron' ); 36 37 param( 'action', 'string', 'list' ); 38 39 // We want to remember these params from page to page: 40 param( 'ctst_pending', 'integer', 0, true ); 41 param( 'ctst_started', 'integer', 0, true ); 42 param( 'ctst_timeout', 'integer', 0, true ); 43 param( 'ctst_error', 'integer', 0, true ); 44 param( 'ctst_finished', 'integer', 0, true ); 45 param( 'results_crontab_order', 'string', '-A', true ); 46 param( 'results_crontab_page', 'integer', 1, true ); 47 48 49 // fp> The if below was the point where THE LINE WAS CROSSED! 50 // This is bloated here. This has to go into the action handling block (and maybe a function) 51 // THIS IS NO LONGER CONTROLLER INITIALIZATION. THIS IS ACTION EXECUTION! 52 // dh> ok. Moved the other param inits above. Ok? I don't think it should be an extra function.. 53 54 // Init names and params for "static" available jobs and ask Plugins about their jobs: 55 if( $action == 'new' || $action == 'create' ) 56 { 57 // NOTE: keys starting with "plugin_" are reserved for jobs provided by Plugins 58 $cron_job_names = array( 59 'test' => T_('Basic test job'), 60 'error' => T_('Error test job'), 61 'anstispam_poll' => T_('Poll the antispam blacklist'), 62 'prune_hits_sessions' => T_('Prune old hits & sessions'), 63 // post notifications, not user schedulable 64 ); 65 $cron_job_params = array( 66 'test' => array( 67 'ctrl' => 'cron/jobs/_test.job.php', 68 'params' => NULL ), 69 'error' => array( 70 'ctrl' => 'cron/jobs/_error_test.job.php', 71 'params' => NULL ), 72 'anstispam_poll' => array( 73 'ctrl' => 'cron/jobs/_antispam_poll.job.php', 74 'params' => NULL ), 75 'prune_hits_sessions' => array( 76 'ctrl' => 'cron/jobs/_prune_hits_sessions.job.php', 77 'params' => NULL ), 78 // post notifications, not user schedulable 79 ); 80 81 // Get additional jobs from Plugins: 82 foreach( $Plugins->trigger_collect( 'GetCronJobs' ) as $plug_ID => $jobs ) 83 { 84 if( ! is_array($jobs) ) 85 { 86 $Debuglog->add( sprintf('GetCronJobs() for plugin #%d did not return array. Ignoring its jobs.', $plug_ID), array('plugins', 'error') ); 87 continue; 88 } 89 foreach( $jobs as $job ) 90 { 91 // Validate params from plugin: 92 if( ! isset($job['params']) ) 93 { 94 $job['params'] = NULL; 95 } 96 if( ! is_array($job) || ! isset($job['ctrl'], $job['name']) ) 97 { 98 $Debuglog->add( sprintf('GetCronJobs() for plugin #%d did return invalid job. Ignoring.', $plug_ID), array('plugins', 'error') ); 99 continue; 100 } 101 if( isset($job['params']) && ! is_array($job['params']) ) 102 { 103 $Debuglog->add( sprintf('GetCronJobs() for plugin #%d did return invalid job params (not an array). Ignoring.', $plug_ID), array('plugins', 'error') ); 104 continue; 105 } 106 $ctrl_id = 'plugin_'.$plug_ID.'_'.$job['ctrl']; 107 108 $cron_job_names[$ctrl_id] = $job['name']; 109 $cron_job_params[$ctrl_id] = array( 110 'ctrl' => $ctrl_id, 111 'params' => $job['params'], 112 ); 113 } 114 } 115 } 116 117 118 switch( $action ) 119 { 120 case 'new': 121 // Check that we have permission to edit options: 122 $current_User->check_perm( 'options', 'edit', true, NULL ); 123 break; 124 125 case 'create': 126 // Check that we have permission to edit options: 127 $current_User->check_perm( 'options', 'edit', true, NULL ); 128 129 // CREATE OBJECT: 130 load_class( '/cron/model/_cronjob.class.php' ); 131 $edited_Cronjob = & new Cronjob(); 132 133 $cjob_type = param( 'cjob_type', 'string', true ); 134 if( !isset( $cron_job_params[$cjob_type] ) ) 135 { 136 param_error( 'cjob_type', T_('Invalid job type') ); 137 } 138 139 // start datetime: 140 param_date( 'cjob_date', T_('Please enter a valid date.'), true ); 141 param_time( 'cjob_time' ); 142 $edited_Cronjob->set( 'start_datetime', form_date( get_param( 'cjob_date' ), get_param( 'cjob_time' ) ) ); 143 144 // repeat after: 145 $cjob_repeat_after_days = param( 'cjob_repeat_after_days', 'integer', 0 ); 146 $cjob_repeat_after_hours = param( 'cjob_repeat_after_hours', 'integer', 0 ); 147 $cjob_repeat_after_minutes = param( 'cjob_repeat_after_minutes', 'integer', 0 ); 148 $cjob_repeat_after = ( ( ($cjob_repeat_after_days*24) + $cjob_repeat_after_hours )*60 + $cjob_repeat_after_minutes)*60; // seconds 149 if( $cjob_repeat_after == 0 ) 150 { 151 $cjob_repeat_after = NULL; 152 } 153 $edited_Cronjob->set( 'repeat_after', $cjob_repeat_after ); 154 155 // name: 156 $edited_Cronjob->set( 'name', $cron_job_names[$cjob_type] ); 157 158 // controller: 159 $edited_Cronjob->set( 'controller', $cron_job_params[$cjob_type]['ctrl'] ); 160 161 // params: 162 $edited_Cronjob->set( 'params', $cron_job_params[$cjob_type]['params'] ); 163 164 if( ! param_errors_detected() ) 165 { // No errors 166 167 // Save to DB: 168 $edited_Cronjob->dbinsert(); 169 170 $Messages->add( T_('New job has been scheduled.'), 'success' ); 171 172 $action = 'list'; 173 } 174 break; 175 176 case 'delete': 177 // Make sure we got an ord_ID: 178 param( 'ctsk_ID', 'integer', true ); 179 180 // Check that we have permission to edit options: 181 $current_User->check_perm( 'options', 'edit', true, NULL ); 182 183 // TODO: prevent deletion of running tasks. 184 $DB->begin(); 185 186 $tsk_status = $DB->get_var( 187 'SELECT clog_status 188 FROM T_cron__log 189 WHERE clog_ctsk_ID= '.$ctsk_ID, 190 0, 0, 'Check that task is not running' ); 191 192 if( $tsk_status == 'started' ) 193 { 194 $DB->rollback(); 195 196 $Messages->add( sprintf( T_('Job #%d is currently running. It cannot be deleted.'), $ctsk_ID ), 'error' ); 197 } 198 else 199 { 200 // Delete task: 201 $DB->query( 'DELETE FROM T_cron__task 202 WHERE ctsk_ID = '.$ctsk_ID ); 203 204 // Delete log (if exists): 205 $DB->query( 'DELETE FROM T_cron__log 206 WHERE clog_ctsk_ID = '.$ctsk_ID ); 207 208 $DB->commit(); 209 210 $Messages->add( sprintf( T_('Scheduled job #%d deleted.'), $ctsk_ID ), 'success' ); 211 } 212 213 forget_param( 'ctsk_ID' ); 214 $action = 'list'; 215 break; 216 217 218 case 'view': 219 $cjob_ID = param( 'cjob_ID', 'integer', true ); 220 221 $sql = 'SELECT * 222 FROM T_cron__task LEFT JOIN T_cron__log ON ctsk_ID = clog_ctsk_ID 223 WHERE ctsk_ID = '.$cjob_ID; 224 $cjob_row = $DB->get_row( $sql, OBJECT, 0, 'Get cron job and log' ); 225 if( empty( $cjob_row ) ) 226 { 227 $Messages->add( sprintf( T_('Job #%d does not exist any longer.'), $cjob_ID ), 'error' ); 228 $action = 'list'; 229 } 230 break; 231 232 case 'list': 233 // Detect timed out tasks: 234 $sql = " UPDATE T_cron__log 235 SET clog_status = 'timeout' 236 WHERE clog_status = 'started' 237 AND clog_realstart_datetime < ".$DB->quote( date2mysql( time() + $time_difference - $cron_timeout_delay ) ); 238 $DB->query( $sql, 'Detect cron timeouts.' ); 239 240 break; 241 } 242 243 244 // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect) 245 $AdminUI->disp_html_head(); 246 247 // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions) 248 $AdminUI->disp_body_top(); 249 250 // Begin payload block: 251 $AdminUI->disp_payload_begin(); 252 253 switch( $action ) 254 { 255 case 'new': 256 case 'create': 257 // Display VIEW: 258 $AdminUI->disp_view( 'cron/views/_cronjob.form.php' ); 259 break; 260 261 case 'view': 262 // Display VIEW: 263 $AdminUI->disp_view( 'cron/views/_cronjob.view.php' ); // uses $cjob_row 264 break; 265 266 default: 267 // Display VIEW: 268 $AdminUI->disp_view( 'cron/views/_cronjob_list.view.php' ); 269 } 270 271 // End payload block: 272 $AdminUI->disp_payload_end(); 273 274 // Display body bottom, debug info and close </html>: 275 $AdminUI->disp_global_footer(); 276 277 /* 278 * $Log: cronjobs.ctrl.php,v $ 279 * Revision 1.1 2007/06/25 10:59:44 fplanque 280 * MODULES (refactored MVC) 281 * 282 * Revision 1.17 2007/04/26 00:11:15 fplanque 283 * (c) 2007 284 * 285 * Revision 1.16 2007/02/16 11:53:11 waltercruz 286 * Changing double quotes to single quotes 287 * 288 * Revision 1.15 2006/12/05 04:27:49 fplanque 289 * moved scheduler to Tools (temporary until UI redesign) 290 * 291 * Revision 1.14 2006/11/26 01:42:08 fplanque 292 * doc 293 * 294 */ 295 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |