mirror of
https://github.com/e107inc/e107.git
synced 2025-04-19 20:21:51 +02:00
Cron scripts working correctly.
This commit is contained in:
parent
4c7bf15d46
commit
7f5cae55a2
83
cron.php
83
cron.php
@ -12,8 +12,8 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/cron.php,v $
|
||||
| $Revision: 1.4 $
|
||||
| $Date: 2009-10-23 09:08:15 $
|
||||
| $Revision: 1.5 $
|
||||
| $Date: 2009-10-23 14:16:07 $
|
||||
| $Author: e107coders $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
@ -22,11 +22,25 @@
|
||||
|
||||
$_E107['cli'] = TRUE;
|
||||
require_once(realpath(dirname(__FILE__)."/class2.php"));
|
||||
|
||||
$pwd = trim($_SERVER['argv'][1]);
|
||||
if($pref['e_cron_pwd'] != $pwd)
|
||||
{
|
||||
require_once(e_HANDLER."mail.php");
|
||||
$message = "Your Cron Schedule is not configured correctly. Your passwords do not match.
|
||||
<br /><br />
|
||||
Sent from cron: ".$pwd."<br />
|
||||
Stored in e107: ".$pref['e_cron_pwd']."<br /><br />
|
||||
You should regenerate the cron command in admin and enter it again in your server configuration.
|
||||
";
|
||||
|
||||
sendemail($pref['siteadminemail'], "e107 - Cron Schedule Misconfigured.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// from the plugin directory:
|
||||
// realpath(dirname(__FILE__)."/../../")."/";
|
||||
|
||||
//echo "\n\nUSERNAME= ".USERNAME."\n";
|
||||
//echo "\nUSEREMAIL= ".USEREMAIL."\n";
|
||||
|
||||
if($pref['e_cron_pref']) // grab cron
|
||||
{
|
||||
@ -39,29 +53,42 @@ if($pref['e_cron_pref']) // grab cron
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
require_once(e_HANDLER."cron_class.php");
|
||||
|
||||
|
||||
$cron = new CronParser();
|
||||
|
||||
foreach($list as $func=>$val)
|
||||
{
|
||||
$cron->calcLastRan($val['tab']);
|
||||
|
||||
$due = $cron->getLastRanUnix();
|
||||
|
||||
if($due > (time()-45))
|
||||
{
|
||||
if(is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
|
||||
if(($val['path']=='_system') || is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
|
||||
{
|
||||
// echo date("r")." ".$func."\n";
|
||||
require_once(e_PLUGIN.$val['path']."/e_cron.php");
|
||||
|
||||
require_once(e_HANDLER."mail.php");
|
||||
$message = "Your Cron Job worked correctly. Sent at ".date("r").".";
|
||||
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
|
||||
|
||||
if(call_user_func($func)===FALSE)
|
||||
if($val['path'] != '_system')
|
||||
{
|
||||
// echo "\nerror running the function ".$func.".\n"; log the error.
|
||||
include_once(e_PLUGIN.$val['path']."/e_cron.php");
|
||||
}
|
||||
|
||||
$classname = $val['class']."_cron";
|
||||
if(class_exists($classname))
|
||||
{
|
||||
$obj = new $classname;
|
||||
if(method_exists($obj,$val['function']))
|
||||
{
|
||||
// $mes->add("Executing config function <b>".$key." : ".$method_name."()</b>", E_MESSAGE_DEBUG);
|
||||
$status = call_user_func(array($obj,$val['function']));
|
||||
if(!$status)
|
||||
{
|
||||
//TODO log error in admin log.
|
||||
// echo "\nerror running the function ".$func.".\n"; log the error.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// echo "Cron Unix = ". $cron->getLastRanUnix();
|
||||
@ -71,6 +98,32 @@ foreach($list as $func=>$val)
|
||||
|
||||
|
||||
|
||||
class _system_cron
|
||||
{
|
||||
|
||||
// See admin/cron.php to configure more core cron function to be added below.
|
||||
|
||||
|
||||
function myfunction()
|
||||
{
|
||||
// Whatever code you wish.
|
||||
}
|
||||
|
||||
|
||||
function sendEmail() // Test Email.
|
||||
{
|
||||
global $pref;
|
||||
require_once(e_HANDLER."mail.php");
|
||||
$message = "Your Cron test worked correctly. Sent at ".date("r").".";
|
||||
|
||||
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.".date("r"), $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// echo "<br />Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
|
||||
// $cron->getLastRan() returns last due time in an array
|
||||
|
@ -11,8 +11,8 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_admin/cron.php,v $
|
||||
| $Revision: 1.5 $
|
||||
| $Date: 2009-10-23 09:08:15 $
|
||||
| $Revision: 1.6 $
|
||||
| $Date: 2009-10-23 14:16:07 $
|
||||
| $Author: e107coders $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
@ -43,7 +43,8 @@ class cron
|
||||
|
||||
function cron()
|
||||
{
|
||||
|
||||
global $pref;
|
||||
|
||||
$this->cronAction = e_QUERY;
|
||||
|
||||
if(isset($_POST['submit']))
|
||||
@ -58,20 +59,19 @@ class cron
|
||||
|
||||
if(isset($_POST['execute']))
|
||||
{
|
||||
$func = key($_POST['execute']);
|
||||
$this -> cronExecute($func);
|
||||
$class_func = key($_POST['execute']);
|
||||
$this -> cronExecute($class_func);
|
||||
}
|
||||
|
||||
// Set Core Cron Options.
|
||||
|
||||
$this->coreCrons['user'] = array(
|
||||
0 => array('name'=>'User Purge','function' => 'user_purge', 'description'=>'Purge Unactivated Users'),
|
||||
1 => array('name'=>'User UnActivated','function' => 'user_unactivated', 'description'=>'Resend activation email to unactivated users.')
|
||||
);
|
||||
|
||||
$this->coreCrons['news'] = array(
|
||||
0 => array('name'=>'News Sticky','function' => 'news_purge', 'description'=>'Remove Sticky News Items')
|
||||
);
|
||||
$this->coreCrons['_system'] = array(
|
||||
0 => array('name' => "Test Email", 'function' => "sendEmail", 'description' => "Send a test email to ".$pref['siteadminemail']."<br />Recommended to test the scheduling system."),
|
||||
// 1 => array('name'=>'User Purge', 'function' => 'userPurge', 'description'=>'Purge Unactivated Users'),
|
||||
// 2 => array('name'=>'User UnActivated', 'function' => 'userUnactivated', 'description'=>'Resend activation email to unactivated users.'),
|
||||
// 3 => array('name'=>'News Sticky', 'function' => 'newsPurge', 'description'=>'Remove Sticky News Items')
|
||||
);
|
||||
|
||||
|
||||
|
||||
// These core functions need to be put into e_BASE/cron.php ie. news_purge()
|
||||
@ -80,6 +80,8 @@ class cron
|
||||
{
|
||||
$this -> cronRenderPage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($this->cronAction == "pref")
|
||||
{
|
||||
@ -88,7 +90,7 @@ class cron
|
||||
}
|
||||
|
||||
|
||||
function cronExecute($func)
|
||||
function cronExecute($class_func)
|
||||
{
|
||||
//TODO LANs
|
||||
$mes = eMessage::getInstance();
|
||||
@ -114,6 +116,7 @@ class cron
|
||||
global $pref;
|
||||
|
||||
$mes = e107::getMessage();
|
||||
$activeCount = 0;
|
||||
|
||||
foreach($_POST['cron'] as $key=>$val)
|
||||
{
|
||||
@ -121,6 +124,10 @@ class cron
|
||||
{
|
||||
$val['active'] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$activeCount++;
|
||||
}
|
||||
|
||||
$t['minute'] = implode(",",$_POST['tab'][$key]['minute']);
|
||||
$t['hour'] = implode(",",$_POST['tab'][$key]['hour']);
|
||||
@ -135,17 +142,39 @@ class cron
|
||||
|
||||
$val['function'] = $func;
|
||||
$val['class'] = $class;
|
||||
$val['path'] = $class;
|
||||
|
||||
$cron[$key] = $val;
|
||||
}
|
||||
|
||||
$pref['e_cron_pref'] = $cron;
|
||||
|
||||
if(!vartrue($pref['e_cron_pwd']) || varset($_POST['generate_pwd']))
|
||||
{
|
||||
|
||||
require_once (e_HANDLER.'user_handler.php');
|
||||
$userMethods = new UserHandler;
|
||||
|
||||
// # - an alpha character
|
||||
// . - a numeric character
|
||||
// * - an alphanumeric character
|
||||
// ^ - next character from seed
|
||||
|
||||
$newpwd = $userMethods->generateRandomString('*^*#.**^*');
|
||||
$newpwd = sha1($newpwd.time());
|
||||
$pref['e_cron_pwd'] = $newpwd;
|
||||
$setpwd_message = "Use the following Cron Command:<br /><b style='color:black'>".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pref['e_cron_pwd']."</b><br />
|
||||
This cron command is unique and will not be displayed again. Please copy and paste it into your webserver cron area to be run every minute of every day.";
|
||||
$mes->add($setpwd_message, E_MESSAGE_WARNING);
|
||||
}
|
||||
|
||||
|
||||
// print_a($pref['e_cron_pref']);
|
||||
|
||||
if(save_prefs())
|
||||
{
|
||||
$mes->add(LAN_SETSAVED, E_MESSAGE_SUCCESS);
|
||||
$mes->add($activeCount." Cron(s) Active", E_MESSAGE_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,16 +197,12 @@ class cron
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style='width:30%'>bcc: </td>
|
||||
<td style='width:70%'>
|
||||
<input type='text' name='name2' class='tbox' style='width:80%' value='' />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr style='vertical-align:top'>
|
||||
<td colspan='2' class='center buttons-bar'>";
|
||||
$text .= $frm->admin_button('save_prefs',LAN_SAVE, 'update');
|
||||
|
||||
$text .= "</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -203,13 +228,15 @@ class cron
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$core_cron = $this->coreCrons;
|
||||
|
||||
$new_cron = array();
|
||||
|
||||
|
||||
foreach($pref['e_cron_list'] as $key=>$val)
|
||||
{
|
||||
$eplug_cron = array();
|
||||
if(is_readable(e_PLUGIN.$key."/e_cron.php"))
|
||||
{
|
||||
require_once(e_PLUGIN.$key."/e_cron.php");
|
||||
include_once(e_PLUGIN.$key."/e_cron.php");
|
||||
|
||||
$class_name = $key."_cron";
|
||||
$method_name = 'config';
|
||||
@ -234,7 +261,8 @@ class cron
|
||||
}
|
||||
|
||||
$e_cron = array_merge($core_cron,$new_cron);
|
||||
|
||||
|
||||
// print_a($e_cron);
|
||||
|
||||
// ---------------------- List All Functions -----------------------------
|
||||
|
||||
@ -316,7 +344,7 @@ class cron
|
||||
if($sep['minute'] == $key)
|
||||
{
|
||||
$sel = "selected='selected'";
|
||||
$minute = "";
|
||||
$minute = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -342,7 +370,7 @@ class cron
|
||||
if($sep['hour'] == $key)
|
||||
{
|
||||
$sel = "selected='selected'";
|
||||
$hour = "";
|
||||
$hour = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -416,6 +444,7 @@ class cron
|
||||
<div class='center buttons-bar'>";
|
||||
// $text .= "<input class='button' type='submit' name='submit' value='".LAN_SAVE."' />";
|
||||
$text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update');
|
||||
$text .= $frm->checkbox_switch('generate_pwd',1,'','Generate new cron command');
|
||||
$text .= "</div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -433,12 +462,12 @@ class cron
|
||||
|
||||
$var['main']['text'] = PAGE_NAME;
|
||||
$var['main']['link'] = e_SELF;
|
||||
|
||||
/*
|
||||
$var['pref']['text'] = LAN_PREFS;
|
||||
$var['pref']['link'] = e_SELF."?pref";
|
||||
$var['pref']['perm'] = "N";
|
||||
|
||||
$action = ($this->cronAction) ? $this->cronAction : "main";
|
||||
*/ $action = ($this->cronAction) ? $this->cronAction : "main";
|
||||
|
||||
e_admin_menu(PAGE_NAME, $action, $var);
|
||||
}
|
||||
|
@ -11,8 +11,8 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $
|
||||
| $Revision: 1.49 $
|
||||
| $Date: 2009-10-20 03:49:12 $
|
||||
| $Revision: 1.50 $
|
||||
| $Date: 2009-10-23 14:16:08 $
|
||||
| $Author: e107coders $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
@ -220,7 +220,7 @@ class pluginManager{
|
||||
'del_extended' => varset($_POST['delete_xfields'],FALSE),
|
||||
'del_ipool' => varset($_POST['delete_ipool'],FALSE)
|
||||
);
|
||||
$text .= $plugin->manage_plugin_xml($this->id, 'uninstall', $options);
|
||||
$text .= $plugin->install_plugin_xml($this->id, 'uninstall', $options);
|
||||
}
|
||||
else
|
||||
{ // Deprecated - plugin uses plugin.php
|
||||
@ -466,7 +466,7 @@ class pluginManager{
|
||||
$_path = e_PLUGIN.$plug['plugin_path'].'/';
|
||||
if(file_exists($_path.'plugin.xml'))
|
||||
{
|
||||
$plugin->manage_plugin_xml($this->id, 'upgrade');
|
||||
$plugin->install_plugin_xml($this->id, 'upgrade');
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -596,7 +596,7 @@ class pluginManager{
|
||||
$_path = e_PLUGIN.$plug['plugin_path'].'/';
|
||||
if(file_exists($_path.'plugin.xml'))
|
||||
{
|
||||
$text .= $plugin->manage_plugin_xml($this->id, 'refresh');
|
||||
$text .= $plugin->install_plugin_xml($this->id, 'refresh');
|
||||
$admin_log->log_event('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, '');
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id: lan_admin.php,v 1.29 2009-10-06 18:58:08 e107steved Exp $
|
||||
* $Id: lan_admin.php,v 1.30 2009-10-23 14:16:08 e107coders Exp $
|
||||
*
|
||||
* Admin Language File
|
||||
*/
|
||||
@ -175,8 +175,8 @@ define('ADLAN_154', "Error contacting Sourceforge to check for new version");
|
||||
define('ADLAN_155', 'System Logs');
|
||||
define('ADLAN_156', 'Admin log, user audit, rolling log');
|
||||
|
||||
define("ADLAN_157", "Schedule Tasks");
|
||||
define("ADLAN_158", "Cron Jobs and Automated Tasks");
|
||||
define("ADLAN_157", "Schedule Maintenance");
|
||||
define("ADLAN_158", "Cron Jobs and Automated Maintenance");
|
||||
|
||||
define("ADLAN_159", "URL Configuration");
|
||||
define("ADLAN_160", "Configure Site URLs");
|
||||
|
@ -4,12 +4,12 @@
|
||||
| e107 website system - Language File.
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_cron.php,v $
|
||||
| $Revision: 1.1 $
|
||||
| $Date: 2008-06-17 05:39:30 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2009-10-23 14:16:08 $
|
||||
| $Author: e107coders $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
if (!defined("PAGE_NAME")) { define("PAGE_NAME", "Schedule Tasks"); }
|
||||
if (!defined("PAGE_NAME")) { define("PAGE_NAME", "Schedule Maintenance"); }
|
||||
|
||||
define("LAN_CRON_1", "Name");
|
||||
define("LAN_CRON_2", "Description");
|
||||
|
@ -9,8 +9,8 @@
|
||||
* Plugin configuration module - gsitemap
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_plugins/gsitemap/e_cron.php,v $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2009-10-23 09:08:15 $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2009-10-23 14:16:08 $
|
||||
* $Author: e107coders $
|
||||
*
|
||||
*/
|
||||
@ -21,20 +21,6 @@ if (!defined('e107_INIT')) { exit; }
|
||||
return;
|
||||
}*/
|
||||
|
||||
// -------- e_cron setup -----------------------------------------------------
|
||||
|
||||
$cron['name'] = "Update Records";
|
||||
$cron['function'] = "gsitemap_myfunction";
|
||||
$cron['description'] = "Dummy example.";
|
||||
|
||||
$cron2['name'] = "Test Email";
|
||||
$cron2['function'] = "gsitemap_myfunction2";
|
||||
$cron2['description'] = "Sends a test email to ".$pref['siteadminemail'];
|
||||
|
||||
|
||||
// $eplug_cron[] = $cron2;
|
||||
|
||||
// ------------------------- Functions -----------------------------------------
|
||||
|
||||
class gsitemap_cron // include plugin-folder in the name.
|
||||
{
|
||||
@ -43,18 +29,18 @@ class gsitemap_cron // include plugin-folder in the name.
|
||||
global $pref;
|
||||
|
||||
$cron = array();
|
||||
|
||||
/*
|
||||
$cron[] = array(
|
||||
'name' => "Update Records",
|
||||
'function' => "myfunction",
|
||||
'description' => "Dummy example."
|
||||
);
|
||||
|
||||
|
||||
$cron[] = array(
|
||||
'name' => "Test Email",
|
||||
'function' => "sendEmail",
|
||||
'description' => "Sends a test email to ".$pref['siteadminemail']
|
||||
);
|
||||
); */
|
||||
|
||||
return $cron;
|
||||
}
|
||||
@ -73,7 +59,7 @@ class gsitemap_cron // include plugin-folder in the name.
|
||||
global $pref;
|
||||
require_once(e_HANDLER."mail.php");
|
||||
$message = "Your Cron Job worked correctly. Sent at ".date("r").".";
|
||||
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
|
||||
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.".date("r"), $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user