forked from e107inc/e107
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
196 lines (160 loc) · 5.45 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/php -q
<?php
/*
+ ----------------------------------------------------------------------------+
|| e107 website system
|
| Copyright (C) 2008-2009 e107 Inc
| http://e107.org
|
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/cron.php,v $
| $Revision$
| $Date$
| $Author$
+----------------------------------------------------------------------------+
*/
// Usage: [full path to this script]cron.php --u=admin --p=password // use your admin login.
// test
$_E107['cli'] = TRUE;
$_E107['debug'] = false;
$_E107['no_online'] = TRUE;
$_E107['no_forceuserupdate'] = TRUE;
$_E107['no_menus'] = TRUE;
// we allow theme init as cron jobs might need to access current theme templates (e.g. custom email templates)
require_once(realpath(dirname(__FILE__)."/class2.php"));
$pwd = ($_E107['debug'] && $_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : 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;
}
e107::getCache()->CachePageMD5 = '_';
e107::getCache()->set('cronLastLoad',time(),TRUE,FALSE,TRUE);
// from the plugin directory:
// realpath(dirname(__FILE__)."/../../")."/";
$list = array();
$sql = e107::getDb();
if($sql->db_Select("cron",'cron_function,cron_tab','cron_active =1'))
{
while($row = $sql->db_Fetch(MYSQL_ASSOC))
{
list($class,$function) = explode("::",$row['cron_function'],2);
$key = $class."__".$function;
$list[$key] = array(
'path' => $class,
'active' => 1,
'tab' => $row['cron_tab'],
'function' => $function,
'class' => $class
);
}
}
// foreach($pref['e_cron_pref'] as $func=>$cron)
// {
// if($cron['active']==1)
// {
// $list[$func] = $cron;
// }
// }
if($_E107['debug'] && $_SERVER['QUERY_STRING'])
{
echo "<h1>Cron Lists</h1>";
print_a($list);
}
require_once(e_HANDLER."cron_class.php");
$cron = new CronParser();
require_once(e_HANDLER."mail.php");
foreach($list as $func=>$val)
{
$cron->calcLastRan($val['tab']);
$due = $cron->getLastRanUnix();
if($_E107['debug'])
{
echo "<br />Cron: ".$val['function'];
}
if($due > (time()-45))
{
if($_E107['debug']) { echo "<br />Running Now...<br />path: ".$val['path']; }
if(($val['path']=='_system') || is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
{
if($val['path'] != '_system') // this is correct.
{
include_once(e_PLUGIN.$val['path']."/e_cron.php");
}
$classname = $val['class']."_cron";
if(class_exists($classname, false))
{
$obj = new $classname;
if(method_exists($obj,$val['function']))
{
// $mes->add("Executing config function <b>".$key." : ".$method_name."()</b>", E_MESSAGE_DEBUG);
if($_E107['debug']) { echo "<br />Method Found: ".$classname."::".$val['function']."()"; }
// Exception handling
$methodname = $val['function'];
$status = false;
try
{
$status = $obj->$methodname();
}
catch (Exception $e)
{
$errorMData = $e->getFile().' '.$e->getLine();
$errorMData .= "\n\n".$e->getCode().''.$e->getMessage();
$errorMData .= "\n\n".implode("\n", $e->getTrace());
//TODO log error in admin log. Pref for sending email to Administator
sendemail($pref['siteadminemail'], $pref['siteadmin'].": Cron Schedule Exception", $errorMData, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
}
// $status = call_user_func(array($obj,$val['function']));
// If task returns value which is not boolean (bc), it'll be used as a message (send email, logs)
if($status && true !== $status)
{
//TODO log error in admin log. Pref for sending email to Administator
// echo "\nerror running the function ".$func.".\n"; // log the error.
if($_E107['debug']) { echo "<br />Method returned message: [{$classname}::".$val['function'].'] '.$status; }
sendemail($pref['siteadminemail'], $pref['siteadmin'].": Cron Schedule Task Report", "Method returned message: [{$classname}::".$val['function'].'] '.$status, $pref['siteadmin'], $pref['siteadminemail'], $pref['siteadmin']);
}
}
else
{
if($_E107['debug']) { echo "<br />Couldn't find method: ".$val['function']; }
}
}
else
{
if($_E107['debug']) { echo "<br />Couldn't find class: ".$classname; }
}
}
}
// echo "Cron Unix = ". $cron->getLastRanUnix();
// echo "<br />Now = ".time();
}
// echo "<br />Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
// $cron->getLastRan() returns last due time in an array
// print_a($cron->getLastRan());
// echo "Debug:<br />" . nl2br($cron->getDebug());
/*
$cron_str1 = "3 12 * * *";
if ($cron->calcLastRan($cron_str1))
{
echo "<p>Cron '$cron_str1' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
print_r($cron->getLastRan());
}
else
{
echo "Error parsing";
}
echo "Debug:<br />" . nl2br($cron->getDebug());
*/
exit;
?>